Renamed CMS_API_SERVICE as CMS_API .
Reversed the design, and break dependency CMS_SETUP => CMS_API . Now CMS_API has attribute setup: CMS_SETUP . Moved error_handler from CMS_SETUP to CMS_API. The instance of CMS_SETUP is used when instanciating modules. The instance of CMS_API is used when instanciating CMS_REPONSE and Handlers/Filters. The instance of CMS_API is passed as argument to build the CMS_MODULE.router and filter.
This commit is contained in:
@@ -17,7 +17,6 @@ feature {NONE} -- Initialization
|
||||
|
||||
make (a_layout: CMS_LAYOUT)
|
||||
do
|
||||
create error_handler.make
|
||||
layout := a_layout
|
||||
create configuration.make (layout)
|
||||
initialize
|
||||
@@ -27,7 +26,6 @@ feature {NONE} -- Initialization
|
||||
do
|
||||
configure
|
||||
create modules.make (3)
|
||||
build_api_service
|
||||
build_mailer
|
||||
initialize_modules
|
||||
end
|
||||
@@ -85,49 +83,6 @@ feature -- Access
|
||||
|
||||
end
|
||||
|
||||
build_api_service
|
||||
local
|
||||
l_database: DATABASE_CONNECTION
|
||||
l_retry: BOOLEAN
|
||||
l_message: STRING
|
||||
do
|
||||
if not l_retry then
|
||||
to_implement ("Refactor database setup")
|
||||
if attached (create {JSON_CONFIGURATION}).new_database_configuration (layout.application_config_path) as l_database_config then
|
||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
||||
create api_service.make (create {CMS_STORAGE_MYSQL}.make (l_database))
|
||||
else
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create api_service.make (create {CMS_STORAGE_NULL})
|
||||
end
|
||||
else
|
||||
to_implement ("Workaround code, persistence layer does not implement yet this kind of error handling.")
|
||||
-- error hanling.
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create api_service.make (create {CMS_STORAGE_NULL})
|
||||
create l_message.make (1024)
|
||||
if attached ((create {EXCEPTION_MANAGER}).last_exception) as l_exception then
|
||||
if attached l_exception.description as l_description then
|
||||
l_message.append (l_description.as_string_32)
|
||||
l_message.append ("%N%N")
|
||||
elseif attached l_exception.trace as l_trace then
|
||||
l_message.append (l_trace)
|
||||
l_message.append ("%N%N")
|
||||
else
|
||||
l_message.append (l_exception.out)
|
||||
l_message.append ("%N%N")
|
||||
end
|
||||
else
|
||||
l_message.append ("The application crash without available information")
|
||||
l_message.append ("%N%N")
|
||||
end
|
||||
error_handler.add_custom_error (0, " Database Connection ", l_message)
|
||||
end
|
||||
rescue
|
||||
l_retry := True
|
||||
retry
|
||||
end
|
||||
|
||||
build_auth_engine
|
||||
do
|
||||
to_implement ("Not implemented authentication")
|
||||
|
||||
@@ -14,9 +14,6 @@ feature -- Access
|
||||
layout: CMS_LAYOUT
|
||||
-- CMS layout.
|
||||
|
||||
api_service: CMS_API_SERVICE
|
||||
-- cms api service.
|
||||
|
||||
is_html: BOOLEAN
|
||||
-- api with progressive enhancements css and js, server side rendering.
|
||||
deferred
|
||||
@@ -32,12 +29,6 @@ feature -- Access
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
error_handler: ERROR_HANDLER
|
||||
-- Error handler.
|
||||
|
||||
feature -- Access: Site
|
||||
|
||||
site_id: READABLE_STRING_8
|
||||
|
||||
@@ -18,63 +18,58 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_config: CMS_SETUP)
|
||||
make
|
||||
do
|
||||
name := "basic auth"
|
||||
version := "1.0"
|
||||
description := "Service to manage basic authentication"
|
||||
package := "core"
|
||||
config := a_config
|
||||
end
|
||||
|
||||
config: CMS_SETUP
|
||||
-- Node configuration.
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
router: WSF_ROUTER
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
create Result.make (2)
|
||||
configure_api_login (Result)
|
||||
configure_api_logoff (Result)
|
||||
configure_api_login (a_api, Result)
|
||||
configure_api_logoff (a_api, Result)
|
||||
end
|
||||
|
||||
feature -- Access: filter
|
||||
|
||||
filters: detachable LIST [WSF_FILTER]
|
||||
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
||||
-- Possibly list of Filter's module.
|
||||
do
|
||||
create {ARRAYED_LIST [WSF_FILTER]} Result.make (2)
|
||||
Result.extend (create {CORS_FILTER})
|
||||
Result.extend (create {BASIC_AUTH_FILTER}.make (config))
|
||||
Result.extend (create {BASIC_AUTH_FILTER}.make (a_api))
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: routes
|
||||
|
||||
configure_api_login (a_router: WSF_ROUTER)
|
||||
configure_api_login (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_bal_handler: BASIC_AUTH_LOGIN_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_bal_handler.make (config)
|
||||
create l_bal_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
a_router.handle_with_request_methods ("/basic_auth_login", l_bal_handler, l_methods)
|
||||
end
|
||||
|
||||
configure_api_logoff (a_router: WSF_ROUTER)
|
||||
configure_api_logoff (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_bal_handler: BASIC_AUTH_LOGOFF_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_bal_handler.make (config)
|
||||
create l_bal_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
a_router.handle_with_request_methods ("/basic_auth_logoff", l_bal_handler, l_methods)
|
||||
end
|
||||
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
|
||||
@@ -31,8 +31,8 @@ feature -- Basic operations
|
||||
-- A valid user
|
||||
if (attached l_auth.type as l_auth_type and then l_auth_type.is_case_insensitive_equal_general ("basic")) and then
|
||||
attached l_auth.login as l_auth_login and then attached l_auth.password as l_auth_password then
|
||||
if api_service.is_valid_credential (l_auth_login, l_auth_password) then
|
||||
if attached api_service.user_by_name (l_auth_login) as l_user then
|
||||
if api.is_valid_credential (l_auth_login, l_auth_password) then
|
||||
if attached api.user_by_name (l_auth_login) as l_user then
|
||||
req.set_execution_variable ("user", l_user)
|
||||
execute_next (req, res)
|
||||
else
|
||||
|
||||
@@ -50,7 +50,7 @@ feature -- HTTP Methods
|
||||
if attached req.query_parameter ("prompt") as l_prompt then
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
else
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.set_status_code ({HTTP_STATUS_CODE}.unauthorized)
|
||||
l_page.execute
|
||||
end
|
||||
|
||||
@@ -20,15 +20,13 @@ feature -- Access
|
||||
|
||||
feature -- Router
|
||||
|
||||
router: WSF_ROUTER
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Router configuration.
|
||||
require
|
||||
is_enabled: is_enabled
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
|
||||
feature -- Hooks configuration
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
@@ -40,7 +38,7 @@ feature -- Hooks configuration
|
||||
|
||||
feature -- Filter
|
||||
|
||||
filters: detachable LIST [WSF_FILTER]
|
||||
filters (a_api: CMS_API): detachable LIST [WSF_FILTER]
|
||||
-- Optional list of filter for Current module.
|
||||
require
|
||||
is_enabled: is_enabled
|
||||
|
||||
@@ -69,8 +69,8 @@ feature -- HTTP Methods
|
||||
if attached current_user_name (req) then
|
||||
-- Existing node
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (l_node.content, "node_content")
|
||||
l_page.add_variable (l_id.value, "id")
|
||||
l_page.execute
|
||||
@@ -78,7 +78,7 @@ feature -- HTTP Methods
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -91,19 +91,19 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached current_user_name (req) then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||
if l_method.is_case_insensitive_equal ("PUT") then
|
||||
do_put (req, res)
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
end
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -118,16 +118,16 @@ feature -- HTTP Methods
|
||||
to_implement ("Check if user has permissions")
|
||||
if attached current_user (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
api_service.update_node_content (l_user.id, u_node.id, u_node.content)
|
||||
api.update_node_content (l_user.id, u_node.id, u_node.content)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -140,7 +140,7 @@ feature -- Error
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (req.absolute_script_url (req.path_info), "request")
|
||||
if a_id.is_integer then
|
||||
-- resource not found
|
||||
|
||||
@@ -68,8 +68,8 @@ feature -- HTTP Methods
|
||||
do
|
||||
-- Existing node
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (l_node, "node")
|
||||
l_page.execute
|
||||
else
|
||||
@@ -89,14 +89,14 @@ feature -- HTTP Methods
|
||||
to_implement ("Check user permissions!!!")
|
||||
if attached current_user (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||
if l_method.is_case_insensitive_equal ("DELETE") then
|
||||
do_delete (req, res)
|
||||
elseif l_method.is_case_insensitive_equal ("PUT") then
|
||||
do_put (req, res)
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -106,7 +106,7 @@ feature -- HTTP Methods
|
||||
-- New node
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_author (l_user)
|
||||
api_service.new_node (u_node)
|
||||
api.new_node (u_node)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
end
|
||||
else
|
||||
@@ -122,16 +122,16 @@ feature -- HTTP Methods
|
||||
|
||||
if attached current_user (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
api_service.update_node (l_user.id,u_node)
|
||||
api.update_node (l_user.id,u_node)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -144,14 +144,14 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached current_user_name (req) then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
api_service.delete_node (l_id.integer_value)
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
api.delete_node (l_id.integer_value)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -165,7 +165,7 @@ feature -- Error
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (req.absolute_script_url (req.path_info), "request")
|
||||
if a_id.is_integer then
|
||||
-- resource not found
|
||||
@@ -186,7 +186,7 @@ feature {NONE} -- Node
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
if attached current_user_name (req) then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (setup.is_html, "html")
|
||||
l_page.add_variable (setup.is_web, "web")
|
||||
l_page.execute
|
||||
|
||||
@@ -68,8 +68,8 @@ feature -- HTTP Methods
|
||||
if attached current_user_name (req) then
|
||||
-- Existing node
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (l_id.value, "id")
|
||||
l_page.add_variable (l_node.summary, "node_summary")
|
||||
l_page.execute
|
||||
@@ -77,7 +77,7 @@ feature -- HTTP Methods
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -90,19 +90,19 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached current_user_name (req) then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||
if l_method.is_case_insensitive_equal ("PUT") then
|
||||
do_put (req, res)
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
end
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -116,16 +116,16 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached current_user (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
api_service.update_node_summary (l_user.id,u_node.id, u_node.summary)
|
||||
api.update_node_summary (l_user.id,u_node.id, u_node.summary)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -140,7 +140,7 @@ feature -- Error
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (req.absolute_script_url (req.path_info), "request")
|
||||
if a_id.is_integer then
|
||||
-- resource not found
|
||||
|
||||
@@ -68,8 +68,8 @@ feature -- HTTP Methods
|
||||
if attached current_user_name (req) as l_user then
|
||||
-- Existing node
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (l_node.title, "node_title")
|
||||
l_page.add_variable (l_id.value, "id")
|
||||
l_page.execute
|
||||
@@ -77,7 +77,7 @@ feature -- HTTP Methods
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -89,19 +89,19 @@ feature -- HTTP Methods
|
||||
do
|
||||
if attached current_user_name (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
if attached {WSF_STRING} req.form_parameter ("method") as l_method then
|
||||
if l_method.is_case_insensitive_equal ("PUT") then
|
||||
do_put (req, res)
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
end
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -116,16 +116,16 @@ feature -- HTTP Methods
|
||||
to_implement ("Check if user has permissions")
|
||||
if attached current_user (req) as l_user then
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api_service.node (l_id.integer_value) as l_node then
|
||||
if l_id.is_integer and then attached {CMS_NODE} api.node (l_id.integer_value) as l_node then
|
||||
u_node := extract_data_form (req)
|
||||
u_node.set_id (l_id.integer_value)
|
||||
api_service.update_node_title (l_user.id,u_node.id, u_node.title)
|
||||
api.update_node_title (l_user.id,u_node.id, u_node.title)
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_redirect (req, res, req.absolute_script_url (""))
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
else
|
||||
(create {CMS_GENERIC_RESPONSE}).new_response_unauthorized (req, res)
|
||||
@@ -139,7 +139,7 @@ feature -- Error
|
||||
local
|
||||
l_page: CMS_RESPONSE
|
||||
do
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (req.absolute_script_url (req.path_info), "request")
|
||||
if a_id.is_integer then
|
||||
-- resource not found
|
||||
|
||||
@@ -52,8 +52,8 @@ feature -- HTTP Methods
|
||||
-- At the moment the template is hardcoded, but we can
|
||||
-- get them from the configuration file and load them into
|
||||
-- the setup class.
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, setup)
|
||||
l_page.add_variable (api_service.nodes, "nodes")
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||
l_page.add_variable (api.nodes, "nodes")
|
||||
l_page.execute
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,47 +20,48 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_config: CMS_SETUP)
|
||||
make (a_setup: CMS_SETUP)
|
||||
-- Create Current module, disabled by default.
|
||||
do
|
||||
name := "node"
|
||||
version := "1.0"
|
||||
description := "Service to manage content based on 'node'"
|
||||
package := "core"
|
||||
config := a_config
|
||||
config := a_setup
|
||||
end
|
||||
|
||||
|
||||
config: CMS_SETUP
|
||||
-- Node configuration.
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
router: WSF_ROUTER
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
create Result.make (5)
|
||||
configure_api_node (Result)
|
||||
configure_api_nodes (Result)
|
||||
configure_api_node_title (Result)
|
||||
configure_api_node_summary (Result)
|
||||
configure_api_node_content (Result)
|
||||
configure_api_node (a_api, Result)
|
||||
configure_api_nodes (a_api, Result)
|
||||
configure_api_node_title (a_api, Result)
|
||||
configure_api_node_summary (a_api, Result)
|
||||
configure_api_node_content (a_api, Result)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation: routes
|
||||
|
||||
configure_api_node (a_router: WSF_ROUTER)
|
||||
configure_api_node (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_node_handler: NODE_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_node_handler.make (config)
|
||||
create l_node_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
l_methods.enable_post
|
||||
l_methods.enable_put
|
||||
a_router.handle_with_request_methods ("/node", l_node_handler, l_methods)
|
||||
|
||||
create l_node_handler.make (config)
|
||||
create l_node_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
l_methods.enable_post
|
||||
@@ -69,23 +70,23 @@ feature {NONE} -- Implementation: routes
|
||||
a_router.handle_with_request_methods ("/node/{id}", l_node_handler, l_methods)
|
||||
end
|
||||
|
||||
configure_api_nodes (a_router: WSF_ROUTER)
|
||||
configure_api_nodes (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_nodes_handler: NODES_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_nodes_handler.make (config)
|
||||
create l_nodes_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
a_router.handle_with_request_methods ("/nodes", l_nodes_handler, l_methods)
|
||||
end
|
||||
|
||||
configure_api_node_summary (a_router: WSF_ROUTER)
|
||||
configure_api_node_summary (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_report_handler: NODE_SUMMARY_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_report_handler.make (config)
|
||||
create l_report_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
l_methods.enable_post
|
||||
@@ -94,12 +95,12 @@ feature {NONE} -- Implementation: routes
|
||||
end
|
||||
|
||||
|
||||
configure_api_node_title (a_router: WSF_ROUTER)
|
||||
configure_api_node_title (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_report_handler: NODE_TITLE_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_report_handler.make (config)
|
||||
create l_report_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
l_methods.enable_post
|
||||
@@ -107,12 +108,12 @@ feature {NONE} -- Implementation: routes
|
||||
a_router.handle_with_request_methods ("/node/{id}/title", l_report_handler, l_methods)
|
||||
end
|
||||
|
||||
configure_api_node_content (a_router: WSF_ROUTER)
|
||||
configure_api_node_content (api: CMS_API; a_router: WSF_ROUTER)
|
||||
local
|
||||
l_report_handler: NODE_CONTENT_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
create l_report_handler.make (config)
|
||||
create l_report_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
l_methods.enable_post
|
||||
@@ -120,7 +121,6 @@ feature {NONE} -- Implementation: routes
|
||||
a_router.handle_with_request_methods ("/node/{id}/content", l_report_handler, l_methods)
|
||||
end
|
||||
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
register_hooks (a_response: CMS_RESPONSE)
|
||||
@@ -150,7 +150,7 @@ feature -- Hooks
|
||||
menu_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE)
|
||||
local
|
||||
lnk: CMS_LOCAL_LINK
|
||||
perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
-- perms: detachable ARRAYED_LIST [READABLE_STRING_8]
|
||||
do
|
||||
create lnk.make ("List of nodes", "/nodes")
|
||||
a_menu_system.main_menu.extend (lnk)
|
||||
|
||||
@@ -1,33 +1,86 @@
|
||||
note
|
||||
description: "Summary description for {CMS_API_SERVICE}."
|
||||
description: "Summary description for {CMS_API}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_API_SERVICE
|
||||
CMS_API
|
||||
|
||||
inherit
|
||||
|
||||
SHARED_ERROR
|
||||
REFACTORING_HELPER
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialize
|
||||
|
||||
make (a_storage: CMS_STORAGE)
|
||||
make (a_setup: CMS_SETUP)
|
||||
-- Create the API service with an storege `a_storage'.
|
||||
do
|
||||
storage := a_storage
|
||||
setup := a_setup
|
||||
create error_handler.make
|
||||
initialize
|
||||
set_successful
|
||||
ensure
|
||||
storage_set: storage = a_storage
|
||||
-- storage_set: storage = a_storage
|
||||
end
|
||||
|
||||
setup: CMS_SETUP
|
||||
-- CMS setup.
|
||||
|
||||
initialize
|
||||
local
|
||||
l_database: DATABASE_CONNECTION
|
||||
retried: BOOLEAN
|
||||
l_message: STRING
|
||||
do
|
||||
if not retried then
|
||||
to_implement ("Refactor database setup")
|
||||
if attached (create {JSON_CONFIGURATION}).new_database_configuration (setup.layout.application_config_path) as l_database_config then
|
||||
create {DATABASE_CONNECTION_MYSQL} l_database.login_with_connection_string (l_database_config.connection_string)
|
||||
create {CMS_STORAGE_MYSQL} storage.make (l_database)
|
||||
else
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create {CMS_STORAGE_NULL} storage
|
||||
end
|
||||
else
|
||||
to_implement ("Workaround code, persistence layer does not implement yet this kind of error handling.")
|
||||
-- error hanling.
|
||||
create {DATABASE_CONNECTION_NULL} l_database.make_common
|
||||
create {CMS_STORAGE_NULL} storage
|
||||
create l_message.make (1024)
|
||||
if attached ((create {EXCEPTION_MANAGER}).last_exception) as l_exception then
|
||||
if attached l_exception.description as l_description then
|
||||
l_message.append (l_description.as_string_32)
|
||||
l_message.append ("%N%N")
|
||||
elseif attached l_exception.trace as l_trace then
|
||||
l_message.append (l_trace)
|
||||
l_message.append ("%N%N")
|
||||
else
|
||||
l_message.append (l_exception.out)
|
||||
l_message.append ("%N%N")
|
||||
end
|
||||
else
|
||||
l_message.append ("The application crash without available information")
|
||||
l_message.append ("%N%N")
|
||||
end
|
||||
error_handler.add_custom_error (0, " Database Connection ", l_message)
|
||||
end
|
||||
rescue
|
||||
retried := True
|
||||
retry
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
error_handler: ERROR_HANDLER
|
||||
-- Error handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_valid_credential (l_auth_login, l_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
do
|
||||
Result := storage.is_valid_credential (l_auth_login, l_auth_password)
|
||||
@@ -41,11 +41,11 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_setup: CMS_SETUP)
|
||||
make (a_api: CMS_API)
|
||||
-- Build a CMS service with `a_setup' configuration.
|
||||
do
|
||||
setup := a_setup
|
||||
configuration := a_setup.configuration
|
||||
api := a_api
|
||||
configuration := a_api.setup.configuration
|
||||
initialize
|
||||
end
|
||||
|
||||
@@ -103,36 +103,41 @@ feature -- Settings: router
|
||||
-- <Precursor>
|
||||
local
|
||||
l_module: CMS_MODULE
|
||||
l_api: like api
|
||||
l_router: like router
|
||||
do
|
||||
log.write_debug (generator + ".setup_router")
|
||||
-- Configure root of api handler.
|
||||
configure_api_root
|
||||
|
||||
l_router := router
|
||||
configure_api_root (l_router)
|
||||
|
||||
-- Include routes from modules.
|
||||
l_api := api
|
||||
across
|
||||
modules as ic
|
||||
loop
|
||||
l_module := ic.item
|
||||
router.import (l_module.router)
|
||||
l_router.import (l_module.router (l_api))
|
||||
end
|
||||
-- Configure files handler.
|
||||
configure_api_file_handler
|
||||
configure_api_file_handler (l_router)
|
||||
end
|
||||
|
||||
configure_api_root
|
||||
configure_api_root (a_router: WSF_ROUTER)
|
||||
local
|
||||
l_root_handler: CMS_ROOT_HANDLER
|
||||
l_methods: WSF_REQUEST_METHODS
|
||||
do
|
||||
log.write_debug (generator + ".configure_api_root")
|
||||
create l_root_handler.make (setup)
|
||||
create l_root_handler.make (api)
|
||||
create l_methods
|
||||
l_methods.enable_get
|
||||
router.handle_with_request_methods ("/", l_root_handler, l_methods)
|
||||
router.handle_with_request_methods ("", l_root_handler, l_methods)
|
||||
a_router.handle_with_request_methods ("/", l_root_handler, l_methods)
|
||||
a_router.handle_with_request_methods ("", l_root_handler, l_methods)
|
||||
end
|
||||
|
||||
configure_api_file_handler
|
||||
configure_api_file_handler (a_router: WSF_ROUTER)
|
||||
local
|
||||
fhdl: WSF_FILE_SYSTEM_HANDLER
|
||||
do
|
||||
@@ -143,7 +148,7 @@ feature -- Settings: router
|
||||
do
|
||||
execute_default (ia_req, ia_res)
|
||||
end)
|
||||
router.handle_with_request_methods ("/", fhdl, router.methods_GET)
|
||||
a_router.handle_with_request_methods ("/", fhdl, router.methods_GET)
|
||||
end
|
||||
|
||||
feature -- Execute Filter
|
||||
@@ -162,6 +167,7 @@ feature -- Filters
|
||||
local
|
||||
f, l_filter: detachable WSF_FILTER
|
||||
l_module: CMS_MODULE
|
||||
l_api: like api
|
||||
do
|
||||
log.write_debug (generator + ".create_filter")
|
||||
l_filter := Void
|
||||
@@ -172,18 +178,19 @@ feature -- Filters
|
||||
l_filter := f
|
||||
|
||||
-- Error Filter
|
||||
create {CMS_ERROR_FILTER} f.make (setup)
|
||||
create {CMS_ERROR_FILTER} f.make (api)
|
||||
f.set_next (l_filter)
|
||||
l_filter := f
|
||||
|
||||
-- Include filters from modules
|
||||
l_api := api
|
||||
across
|
||||
modules as ic
|
||||
loop
|
||||
l_module := ic.item
|
||||
if
|
||||
l_module.is_enabled and then
|
||||
attached l_module.filters as l_m_filters
|
||||
attached l_module.filters (l_api) as l_m_filters
|
||||
then
|
||||
across l_m_filters as f_ic loop
|
||||
f := f_ic.item
|
||||
@@ -213,11 +220,16 @@ feature -- Filters
|
||||
f.set_next (Current)
|
||||
end
|
||||
|
||||
|
||||
feature -- Access
|
||||
|
||||
api: CMS_API
|
||||
-- API service.
|
||||
|
||||
setup: CMS_SETUP
|
||||
-- CMS setup.
|
||||
do
|
||||
Result := api.setup
|
||||
end
|
||||
|
||||
configuration: CMS_CONFIGURATION
|
||||
-- CMS configuration.
|
||||
|
||||
@@ -20,13 +20,13 @@ feature -- Basic operations
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute the filter
|
||||
do
|
||||
if not setup.error_handler.has_error then
|
||||
if not api.error_handler.has_error then
|
||||
log.write_information (generator + ".execute")
|
||||
execute_next (req, res)
|
||||
else
|
||||
log.write_critical (generator + ".execute" + setup.error_handler.as_string_representation )
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
setup.error_handler.reset
|
||||
log.write_critical (generator + ".execute" + api.error_handler.as_string_representation )
|
||||
(create {ERROR_500_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
api.error_handler.reset
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -19,20 +19,20 @@ inherit
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_setup: CMS_SETUP)
|
||||
make (a_api: CMS_API)
|
||||
do
|
||||
setup := a_setup
|
||||
api := a_api
|
||||
end
|
||||
|
||||
feature -- Setup
|
||||
|
||||
setup: CMS_SETUP
|
||||
do
|
||||
Result := api.setup
|
||||
end
|
||||
|
||||
feature -- API Service
|
||||
|
||||
api_service: CMS_API_SERVICE
|
||||
do
|
||||
Result := setup.api_service
|
||||
end
|
||||
api: CMS_API
|
||||
|
||||
end
|
||||
|
||||
@@ -48,7 +48,7 @@ feature -- HTTP Methods
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- <Precursor>
|
||||
do
|
||||
(create {HOME_CMS_RESPONSE}.make (req, res, setup)).execute
|
||||
(create {HOME_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -15,10 +15,10 @@ inherit
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make(req: WSF_REQUEST; res: WSF_RESPONSE; a_setup: like setup)
|
||||
make(req: WSF_REQUEST; res: WSF_RESPONSE; a_api: like api)
|
||||
do
|
||||
status_code := {HTTP_STATUS_CODE}.ok
|
||||
setup := a_setup
|
||||
api := a_api
|
||||
request := req
|
||||
response := res
|
||||
create header.make
|
||||
@@ -56,8 +56,14 @@ feature -- Access
|
||||
|
||||
response: WSF_RESPONSE
|
||||
|
||||
api: CMS_API
|
||||
-- Current CMS API.
|
||||
|
||||
setup: CMS_SETUP
|
||||
-- Current setup
|
||||
-- Current setup
|
||||
do
|
||||
Result := api.setup
|
||||
end
|
||||
|
||||
status_code: INTEGER
|
||||
|
||||
@@ -222,8 +228,6 @@ feature -- Menu
|
||||
primary_tabs: CMS_MENU
|
||||
do
|
||||
Result := menu_system.primary_tabs
|
||||
debug
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Blocks initialization
|
||||
@@ -378,8 +382,6 @@ feature -- Blocks
|
||||
header_block: CMS_CONTENT_BLOCK
|
||||
local
|
||||
s: STRING
|
||||
tpl: SMARTY_CMS_PAGE_TEMPLATE
|
||||
l_page: CMS_HTML_PAGE
|
||||
l_hb: STRING
|
||||
do
|
||||
create s.make_from_string (theme.menu_html (main_menu, True))
|
||||
|
||||
@@ -21,7 +21,7 @@ feature -- Generation
|
||||
custom_prepare (page: CMS_HTML_PAGE)
|
||||
do
|
||||
Precursor (page)
|
||||
page.register_variable (setup.api_service.recent_nodes (0, 5), "nodes")
|
||||
page.register_variable (api.recent_nodes (0, 5), "nodes")
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
@@ -15,21 +15,17 @@ create
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_config: CMS_SETUP)
|
||||
make
|
||||
do
|
||||
name := "Demo module"
|
||||
version := "1.0"
|
||||
description := "Service to demonstrate and test cms system"
|
||||
package := "demo"
|
||||
config := a_config
|
||||
end
|
||||
|
||||
config: CMS_SETUP
|
||||
-- Node configuration.
|
||||
|
||||
feature -- Access: router
|
||||
|
||||
router: WSF_ROUTER
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Node router.
|
||||
do
|
||||
create Result.make (2)
|
||||
|
||||
@@ -117,12 +117,12 @@ feature -- CMS Initialization
|
||||
initialize_cms (a_setup: CMS_SETUP)
|
||||
local
|
||||
cms: CMS_SERVICE
|
||||
api: CMS_API
|
||||
do
|
||||
log.write_debug (generator + ".initialize_cms")
|
||||
|
||||
setup_modules (a_setup)
|
||||
|
||||
create cms.make (a_setup)
|
||||
create api.make (a_setup)
|
||||
create cms.make (api)
|
||||
cms_service := cms
|
||||
end
|
||||
|
||||
@@ -133,14 +133,13 @@ feature -- CMS setup
|
||||
local
|
||||
m: CMS_MODULE
|
||||
do
|
||||
create {BASIC_AUTH_MODULE} m.make (a_setup)
|
||||
create {BASIC_AUTH_MODULE} m.make
|
||||
m.enable
|
||||
a_setup.modules.extend (m)
|
||||
|
||||
create {CMS_DEMO_MODULE} m.make (a_setup)
|
||||
create {CMS_DEMO_MODULE} m.make
|
||||
m.enable
|
||||
a_setup.modules.extend (m)
|
||||
|
||||
end
|
||||
|
||||
setup_storage (a_setup: CMS_SETUP)
|
||||
|
||||
Reference in New Issue
Block a user