Added support for path_aliases.
Refactored CMS_MODULE.router (..): WSF_ROUTER design, to create only one router object of type CMS_ROUTER. Added optional CMS_NODE.link: CMS_LOCAL_LINK Reviewed permissions related to node module. Refactor and add CMS_STORAGE_SQL(_BUILDER) abstractions for implementation relying only on SQL statements. Factorized sql builder initialization (to work for sqlite and mysql storage builders). Added CMS_RESPONSE.formatted_string (a_text: READABLE_STRING_GENERAL; args: TUPLE): STRING_32 Added function "translation", but not implemented for now. Updated indexing notes and comments. Code cleaning.
This commit is contained in:
@@ -232,6 +232,66 @@ feature -- Query: API
|
||||
Result := l_api
|
||||
end
|
||||
|
||||
feature -- Path aliases
|
||||
|
||||
set_path_alias (a_source, a_alias: READABLE_STRING_8; a_keep_previous: BOOLEAN)
|
||||
-- Set `a_alias' as alias of `a_source',
|
||||
-- and eventually unset previous alias if any.
|
||||
local
|
||||
l_continue: BOOLEAN
|
||||
do
|
||||
if attached storage.path_alias (a_source) as l_existing_alias then
|
||||
if a_alias.same_string (l_existing_alias) then
|
||||
-- Already aliased as expected
|
||||
else
|
||||
-- New alias
|
||||
if a_keep_previous then
|
||||
l_continue := True
|
||||
else
|
||||
storage.replace_path_alias (a_source, l_existing_alias, a_alias)
|
||||
end
|
||||
end
|
||||
elseif a_alias.is_whitespace then
|
||||
-- Ignore
|
||||
elseif a_source.same_string (a_alias) then
|
||||
-- No need for alias
|
||||
else
|
||||
l_continue := True
|
||||
end
|
||||
if l_continue then
|
||||
storage.set_path_alias (a_source, a_alias)
|
||||
end
|
||||
end
|
||||
|
||||
unset_path_alias (a_source: READABLE_STRING_8; a_alias: READABLE_STRING_8)
|
||||
do
|
||||
storage.unset_path_alias (a_source, a_alias)
|
||||
end
|
||||
|
||||
path_alias (a_source: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Path alias associated with `a_source' or the source itself.
|
||||
do
|
||||
Result := a_source
|
||||
if attached storage.path_alias (Result) as l_path then
|
||||
Result := l_path
|
||||
end
|
||||
end
|
||||
|
||||
source_of_path_alias (a_alias: READABLE_STRING_8): READABLE_STRING_8
|
||||
-- Resolved path for alias `a_alias'.
|
||||
--| the CMS supports aliases for path, and then this function simply returns
|
||||
--| the effective target path/url for this `a_alias'.
|
||||
--| For instance: /articles/2015/may/this-is-an-article can be an alias to /node/123
|
||||
--| This function will return "/node/123".
|
||||
--| If the alias is bad (i.e does not alias real path), then this function
|
||||
--| returns the alias itself.
|
||||
do
|
||||
Result := a_alias
|
||||
if attached storage.source_of_path_alias (Result) as l_path then
|
||||
Result := l_path
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Element Change: Error
|
||||
|
||||
reset_error
|
||||
|
||||
@@ -66,10 +66,8 @@ feature {CMS_API} -- Module management
|
||||
|
||||
feature -- Router
|
||||
|
||||
router (a_api: CMS_API): WSF_ROUTER
|
||||
-- Router configuration.
|
||||
require
|
||||
is_enabled: is_enabled
|
||||
setup_router (a_router: WSF_ROUTER; a_api: CMS_API)
|
||||
-- Setup url dispatching for Current module.
|
||||
deferred
|
||||
end
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ inherit
|
||||
undefine
|
||||
requires_proxy
|
||||
redefine
|
||||
execute_default
|
||||
execute_default,
|
||||
create_router,
|
||||
router
|
||||
end
|
||||
|
||||
WSF_FILTERED_SERVICE
|
||||
@@ -82,10 +84,17 @@ feature {NONE} -- Initialization
|
||||
|
||||
feature -- Settings: router
|
||||
|
||||
router: CMS_ROUTER
|
||||
|
||||
create_router
|
||||
-- Create `router'.
|
||||
do
|
||||
create router.make (api, 30)
|
||||
end
|
||||
|
||||
setup_router
|
||||
-- <Precursor>
|
||||
local
|
||||
l_module: CMS_MODULE
|
||||
l_api: like api
|
||||
l_router: like router
|
||||
do
|
||||
@@ -100,8 +109,7 @@ feature -- Settings: router
|
||||
across
|
||||
modules as ic
|
||||
loop
|
||||
l_module := ic.item
|
||||
l_router.import (l_module.router (l_api))
|
||||
ic.item.setup_router (l_router, l_api)
|
||||
end
|
||||
-- Configure files handler.
|
||||
configure_api_file_handler (l_router)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
note
|
||||
description: "Specific version of WSF_ROUTER for CMS component."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_ROUTER
|
||||
|
||||
inherit
|
||||
WSF_ROUTER
|
||||
rename
|
||||
make as make_router
|
||||
redefine
|
||||
path_to_dispatch
|
||||
end
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make (a_api: CMS_API; a_capacity: INTEGER)
|
||||
do
|
||||
api := a_api
|
||||
make_router (a_capacity)
|
||||
end
|
||||
|
||||
api: CMS_API
|
||||
|
||||
feature {WSF_ROUTER_MAPPING} -- Dispatch helper
|
||||
|
||||
path_to_dispatch (req: WSF_REQUEST): READABLE_STRING_8
|
||||
-- Path used by the router, to apply url dispatching of request `req'.
|
||||
do
|
||||
Result := api.source_of_path_alias (Precursor (req))
|
||||
end
|
||||
|
||||
end
|
||||
@@ -76,6 +76,26 @@ feature -- Access
|
||||
redirection: detachable READABLE_STRING_8
|
||||
-- Location for eventual redirection.
|
||||
|
||||
feature -- Internationalization (i18n)
|
||||
|
||||
translation (a_text: READABLE_STRING_GENERAL; opts: detachable CMS_API_OPTIONS): STRING_32
|
||||
-- Translated text `a_text' according to expected context (lang, ...)
|
||||
-- and adapt according to options eventually set by `opts'.
|
||||
do
|
||||
to_implement ("Implement i18n support [2015-may]")
|
||||
Result := a_text.as_string_32
|
||||
end
|
||||
|
||||
formatted_string (a_text: READABLE_STRING_GENERAL; args: TUPLE): STRING_32
|
||||
-- Format `a_text' using arguments `args'.
|
||||
--| ex: formatted_string ("hello $1, see page $title.", ["bob", "contact"] -> "hello bob, see page contact"
|
||||
local
|
||||
l_formatter: CMS_STRING_FORMATTER
|
||||
do
|
||||
create l_formatter
|
||||
Result := l_formatter.formatted_string (a_text, args)
|
||||
end
|
||||
|
||||
feature -- API
|
||||
|
||||
api: CMS_API
|
||||
@@ -185,12 +205,30 @@ feature -- Permission
|
||||
Result := user_has_permission (current_user (request), a_permission)
|
||||
end
|
||||
|
||||
has_permissions (a_permission_list: ITERABLE [READABLE_STRING_GENERAL]): BOOLEAN
|
||||
-- Does current user has any of the permissions `a_permission_list' ?
|
||||
do
|
||||
Result := user_has_permissions (current_user (request), a_permission_list)
|
||||
end
|
||||
|
||||
user_has_permission (a_user: detachable CMS_USER; a_permission: READABLE_STRING_GENERAL): BOOLEAN
|
||||
-- Does `a_user' has permission `a_permission' ?
|
||||
do
|
||||
Result := api.user_has_permission (a_user, a_permission)
|
||||
end
|
||||
|
||||
user_has_permissions (a_user: detachable CMS_USER; a_permission_list: ITERABLE [READABLE_STRING_GENERAL]): BOOLEAN
|
||||
-- Does `a_user' has any of the permissions `a_permission_list' ?
|
||||
do
|
||||
across
|
||||
a_permission_list as ic
|
||||
until
|
||||
Result
|
||||
loop
|
||||
Result := user_has_permission (a_user, ic.item)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Head customization
|
||||
|
||||
add_additional_head_line (s: READABLE_STRING_8; a_allow_duplication: BOOLEAN)
|
||||
|
||||
Reference in New Issue
Block a user