Added finer control on path_alias.
- added a permission to edit path alias. - added an admin handler to manage path aliases. When path alias is changed on node, always keep previous path alias. (can be unset from the related admin section). CMS_API.storage.path_aliases returns the list of path aliases (recents aliases come first).
This commit is contained in:
@@ -60,6 +60,7 @@ feature -- Access: router
|
||||
l_admin_cache_handler: CMS_ADMIN_CACHE_HANDLER
|
||||
l_admin_export_handler: CMS_ADMIN_EXPORT_HANDLER
|
||||
l_admin_import_handler: CMS_ADMIN_IMPORT_HANDLER
|
||||
l_admin_path_alias_handler: CMS_ADMIN_PATH_ALIAS_HANDLER
|
||||
|
||||
l_uri_mapping: WSF_URI_MAPPING
|
||||
do
|
||||
@@ -83,6 +84,10 @@ feature -- Access: router
|
||||
create l_uri_mapping.make_trailing_slash_ignored ("/admin/logs", l_admin_logs_handler)
|
||||
a_router.map (l_uri_mapping, a_router.methods_get)
|
||||
|
||||
create l_admin_path_alias_handler.make (a_api)
|
||||
create l_uri_mapping.make_trailing_slash_ignored ("/admin/path_alias", l_admin_path_alias_handler)
|
||||
a_router.map (l_uri_mapping, a_router.methods_get_post)
|
||||
|
||||
|
||||
create l_admin_cache_handler.make (a_api)
|
||||
create l_uri_mapping.make_trailing_slash_ignored ("/admin/cache", l_admin_cache_handler)
|
||||
@@ -119,14 +124,10 @@ feature -- Security
|
||||
Result.force ("admin users")
|
||||
Result.force ("admin roles")
|
||||
Result.force ("admin modules")
|
||||
Result.force ("install modules")
|
||||
Result.force ("view logs")
|
||||
Result.force ("admin core caches")
|
||||
Result.force ("clear blocks cache")
|
||||
Result.force ("admin export")
|
||||
Result.force ("admin import")
|
||||
Result.force ("export core")
|
||||
Result.force ("import core")
|
||||
end
|
||||
|
||||
feature -- Hooks
|
||||
|
||||
124
modules/admin/handler/cms_admin_path_alias_handler.e
Normal file
124
modules/admin/handler/cms_admin_path_alias_handler.e
Normal file
@@ -0,0 +1,124 @@
|
||||
note
|
||||
description: "[
|
||||
Administrate path aliases.
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_ADMIN_PATH_ALIAS_HANDLER
|
||||
|
||||
inherit
|
||||
CMS_HANDLER
|
||||
|
||||
WSF_URI_HANDLER
|
||||
rename
|
||||
new_mapping as new_uri_mapping
|
||||
end
|
||||
|
||||
WSF_RESOURCE_HANDLER_HELPER
|
||||
redefine
|
||||
do_get,
|
||||
do_post
|
||||
end
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Execution
|
||||
|
||||
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Execute request handler
|
||||
do
|
||||
execute_methods (req, res)
|
||||
end
|
||||
|
||||
do_get (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_response: CMS_RESPONSE
|
||||
l_sources: ARRAYED_LIST [READABLE_STRING_8]
|
||||
l_alias: detachable READABLE_STRING_8
|
||||
s: STRING
|
||||
b: BOOLEAN
|
||||
do
|
||||
if api.has_permission ("admin path_alias") then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
||||
if attached api.storage.path_aliases as tb then
|
||||
create s.make_empty
|
||||
s.append ("<h1>Path aliases</h1>%N")
|
||||
s.append ("<ul class=%"path_aliases%">")
|
||||
create l_sources.make (tb.count)
|
||||
l_sources.compare_objects
|
||||
across
|
||||
tb as ic
|
||||
loop
|
||||
b := l_sources.has (ic.item)
|
||||
if b then
|
||||
s.append ("<li class=%"warning%">")
|
||||
else
|
||||
s.append ("<li>")
|
||||
l_sources.force (ic.item)
|
||||
end
|
||||
if ic.key.is_valid_as_string_8 then
|
||||
l_alias := ic.key.to_string_8
|
||||
s.append (l_response.link (ic.key, l_alias, Void))
|
||||
else
|
||||
l_alias := Void
|
||||
s.append (l_response.html_encoded (ic.key))
|
||||
end
|
||||
s.append (" => ")
|
||||
s.append (l_response.link (ic.item, ic.item, Void))
|
||||
if b then
|
||||
s.append (" <span class=%"warning%">(archived)</span>")
|
||||
if l_alias /= Void then
|
||||
s.append ("<form action=%"%" method=%"POST%"><input type=%"hidden%" name=%"path_alias%" value=%"" + l_alias + "%"/><input type=%"hidden%" name=%"source%" value=%"" + ic.item + "%"/><input type=%"submit%" name=%"op%" value=%"unset%"/></form>")
|
||||
end
|
||||
end
|
||||
s.append ("</li>")
|
||||
end
|
||||
s.append ("</ul>")
|
||||
end
|
||||
l_response.set_main_content (s)
|
||||
else
|
||||
create {FORBIDDEN_ERROR_CMS_RESPONSE} l_response.make (req, res, api)
|
||||
end
|
||||
l_response.execute
|
||||
end
|
||||
|
||||
do_post (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
local
|
||||
l_response: CMS_RESPONSE
|
||||
s: STRING
|
||||
do
|
||||
if api.has_permission ("admin path_alias") then
|
||||
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
|
||||
create s.make_empty
|
||||
|
||||
if
|
||||
attached {WSF_STRING} req.form_parameter ("op") as p_op and then p_op.same_string ("unset") and then
|
||||
attached {WSF_STRING} req.form_parameter ("path_alias") as p_alias and then
|
||||
attached {WSF_STRING} req.form_parameter ("source") as p_source
|
||||
then
|
||||
api.unset_path_alias (p_source.value.to_string_8, p_alias.value.to_string_8) -- FIXME: avoid `to_string_8`
|
||||
if api.has_error then
|
||||
s.append ("<div class=%"error%">ERROR: Path alias %"" + l_response.html_encoded (p_alias.value) + "%" raised error!</div>")
|
||||
else
|
||||
s.append ("<div class=%"success%">Path alias %"" + l_response.html_encoded (p_alias.value) + "%" is now unset!</div>")
|
||||
end
|
||||
end
|
||||
s.append ("<p><a href=%"%">Back to list of path aliases ...</a><p>")
|
||||
s.append ("(in 3 seconds...)")
|
||||
l_response.set_main_content (s)
|
||||
|
||||
l_response.set_redirection (l_response.location)
|
||||
l_response.set_redirection_delay (3)
|
||||
else
|
||||
create {FORBIDDEN_ERROR_CMS_RESPONSE} l_response.make (req, res, api)
|
||||
l_response.set_redirection (l_response.location)
|
||||
end
|
||||
l_response.execute
|
||||
end
|
||||
|
||||
end
|
||||
@@ -27,9 +27,10 @@ feature -- Process
|
||||
l_admin_links.force (["core", <<"admin roles">>, local_link ("Roles", "admin/roles"), "View/Edit/Add Roles"])
|
||||
l_admin_links.force (["core", <<"admin modules">>, local_link ("Modules", "admin/modules"), "(un)Install modules"])
|
||||
l_admin_links.force (["core", <<"view logs">>, local_link ("Logs", "admin/logs"), "View logs"])
|
||||
l_admin_links.force (["core", <<"admin path_alias">>, local_link ("Path Alias", "admin/path_alias"), "Manage path aliases"])
|
||||
l_admin_links.force (["support", <<"admin cache">>, local_link ("Cache", "admin/cache"), "Clear caches"])
|
||||
l_admin_links.force (["support", <<"admin export">>, local_link ("Export", "admin/export"), "Export CMS contents, and modules contents."])
|
||||
l_admin_links.force (["support", <<"admin import">>, local_link ("Export", "admin/import"), "Import CMS contents, and modules contents."])
|
||||
l_admin_links.force (["support", <<"admin import">>, local_link ("Import", "admin/import"), "Import CMS contents, and modules contents."])
|
||||
create categories.make_caseless (3)
|
||||
across
|
||||
l_admin_links as ic
|
||||
|
||||
Reference in New Issue
Block a user