diff --git a/modules/node/handler/node_form_response.e b/modules/node/handler/node_form_response.e index c554ef8..b3da352 100644 --- a/modules/node/handler/node_form_response.e +++ b/modules/node/handler/node_form_response.e @@ -260,7 +260,7 @@ feature -- Form l_node_path: READABLE_STRING_8 l_path_alias, l_existing_path_alias, l_auto_path_alias: detachable READABLE_STRING_8 do - fixme ("Refactor code per operation: Preview, Save/Publish/UnPublish") + -- Potential operations : Preview, Save/Publish/UnPublish") l_preview := attached {WSF_STRING} fd.item ("op") as l_op and then l_op.same_string (preview_submit_label) if not l_preview then l_op_save := True diff --git a/modules/node/handler/node_handler.e b/modules/node/handler/node_handler.e index f27056f..47ebd16 100644 --- a/modules/node/handler/node_handler.e +++ b/modules/node/handler/node_handler.e @@ -139,9 +139,7 @@ feature -- HTTP Methods elseif l_node = Void then send_not_found (req, res) else - if - l_rev > 0 and l_is_published - then + if l_is_published then create view_response.make (req, res, api, node_api) view_response.set_node (l_node) view_response.set_revision (l_rev) @@ -149,7 +147,9 @@ feature -- HTTP Methods elseif attached api.user as l_user and then ( node_api.is_author_of_node (l_user, l_node) - or else api.user_has_permission (l_user, "view unpublished " + l_node.content_type) + or else ( + api.user_has_permission (l_user, "view unpublished " + l_node.content_type) + ) ) then create view_response.make (req, res, api, node_api) diff --git a/src/service/cms_execution.e b/src/service/cms_execution.e index 50eec86..48720eb 100644 --- a/src/service/cms_execution.e +++ b/src/service/cms_execution.e @@ -281,11 +281,12 @@ feature -- Filters l_module: CMS_MODULE l_api: like api do - api.logger.put_debug (generator + ".create_filter", Void) + l_api := api + l_api.logger.put_debug (generator + ".create_filter", Void) l_filter := Void -- Maintenance - create {WSF_MAINTENANCE_FILTER} f + create {CMS_MAINTENANCE_FILTER} f.make (Void, l_api) f.set_next (l_filter) l_filter := f @@ -295,7 +296,6 @@ feature -- Filters -- l_filter := f -- Include filters from modules - l_api := api across modules as ic loop diff --git a/src/service/filter/cms_maintenance_filter.e b/src/service/filter/cms_maintenance_filter.e new file mode 100644 index 0000000..e424723 --- /dev/null +++ b/src/service/filter/cms_maintenance_filter.e @@ -0,0 +1,109 @@ +note + description: "Summary description for {CMS_MAINTENANCE_FILTER}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + CMS_MAINTENANCE_FILTER + +inherit + WSF_FILTER + +create + make + +feature {NONE} -- Initialization + + make (a_name: detachable READABLE_STRING_GENERAL; a_api: CMS_API) + do + api := a_api + if a_name /= Void then + maintenance_fn := a_name + else + maintenance_fn := ".maintenance" + end + end + +feature -- Access + + api: CMS_API + + maintenance_fn: READABLE_STRING_GENERAL + +feature -- Basic operations + + execute (req: WSF_REQUEST; res: WSF_RESPONSE) + -- Execute the filter + local + l_line,s: STRING + h: HTTP_HEADER + f: PLAIN_TEXT_FILE + l_allow_user: STRING_8 + l_allow_ip: STRING_8 + do + create f.make_with_name (maintenance_fn) + if f.exists then + create s.make (64) + if f.is_access_readable then + f.open_read + from + until + f.exhausted + loop + f.read_line + l_line := f.last_string + if l_line.starts_with_general ("#") then + if l_line.starts_with_general ("#allow-user:") then + l_allow_user := l_line.substring (l_line.index_of (':', 1) + 1, l_line.count) + l_allow_user.adjust + if l_allow_user.is_empty then + l_allow_user := Void + end + elseif l_line.starts_with_general ("#allow-ip:") then + l_allow_ip := l_line.substring (l_line.index_of (':', 1) + 1, l_line.count) + l_allow_ip.adjust + if l_allow_ip.is_empty then + l_allow_ip := Void + end + end + else + s.append (l_line) + s.append_character ('%N') + end + end + f.close + end + if s.is_empty then + s.append ("In maintenance, please come back later ...") + end + if + l_allow_user /= Void and then + attached api.user as u and then + u.name.same_string_general (l_allow_user) + then + -- User allowed! + execute_next (req, res) + elseif + l_allow_ip /= Void and then + req.remote_addr.same_string (l_allow_ip) + then + -- IP allowed! + execute_next (req, res) + else + create h.make_with_count (1) + h.put_content_length (s.count) + h.put_content_type_text_plain + res.set_status_code ({HTTP_STATUS_CODE}.service_unavailable) + res.put_header_lines (h) + res.put_string (s) + end + else + execute_next (req, res) + end + end + +note + copyright: "2011-2017, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" +end