Added weight into to the CMS_LINK and provide a `sort' feature for CMS_MENU and related.
Protected cms service from registering many time the same module type.
Moved library/persistence/implementation/* under library/persistence/.
Moved site/www/themes to site/themes
For SQLite storage driver, auto create sqlite db file using associated sql script (to be completed).
Added code in demo module to reuse storage for module purpose.
Always call sql_post_execution in sql_query and sql_change, and not anymore by the callers.
Removed is_web and is_html from {CMS_SETUP}, it was not used.
Reused SHARED_*_ENCODER in CMS_ENCODERS
Added CMS_API.logger rather than using directly the SHARED_LOGGER.log ...
Centralize the implementation of current_user in CMS_REQUEST_UTIL
Removed the inheritance on WSF_FILTER for node handlers, since it is useless and unused.
Added CMS_NODE_API and CMS_USER_API
Prefix html id for block generated html items with "block-", to avoid css name conflict on "main", "content" or similar.
Code cleaning
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
note
|
||||
description: "API for a CMS"
|
||||
date: "$Date: 2015-01-27 19:15:02 +0100 (mar., 27 janv. 2015) $"
|
||||
revision: "$Revision: 96542 $"
|
||||
date: "$Date: 2015-02-13 13:08:13 +0100 (ven., 13 févr. 2015) $"
|
||||
revision: "$Revision: 96616 $"
|
||||
|
||||
class
|
||||
CMS_API
|
||||
@@ -11,35 +11,25 @@ inherit
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
SHARED_HTML_ENCODER
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
|
||||
SHARED_WSF_PERCENT_ENCODER
|
||||
export
|
||||
{NONE} all
|
||||
end
|
||||
CMS_ENCODERS
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialize
|
||||
feature {NONE} -- Initialize
|
||||
|
||||
make (a_setup: CMS_SETUP)
|
||||
-- Create the API service with a setup `a_setup'
|
||||
do
|
||||
setup := a_setup
|
||||
create error_handler.make
|
||||
create {CMS_ENV_LOGGER} logger.make
|
||||
initialize
|
||||
ensure
|
||||
setup_set: setup = a_setup
|
||||
error_handler_set: not error_handler.has_error
|
||||
end
|
||||
|
||||
setup: CMS_SETUP
|
||||
-- CMS setup.
|
||||
|
||||
initialize
|
||||
-- Initialize the persitent layer.
|
||||
do
|
||||
@@ -51,7 +41,18 @@ feature -- Initialize
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Access: Error
|
||||
feature -- Access
|
||||
|
||||
setup: CMS_SETUP
|
||||
-- CMS setup.
|
||||
|
||||
logger: CMS_LOGGER
|
||||
-- Logger
|
||||
|
||||
storage: CMS_STORAGE
|
||||
-- Persistence storage.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
has_error: BOOLEAN
|
||||
-- Has error?
|
||||
@@ -59,162 +60,82 @@ feature -- Access: Error
|
||||
Result := error_handler.has_error
|
||||
end
|
||||
|
||||
as_string_representation: STRING_32
|
||||
string_representation_of_errors: STRING_32
|
||||
-- String representation of all error(s).
|
||||
do
|
||||
Result := error_handler.as_string_representation
|
||||
end
|
||||
|
||||
feature -- Query: module
|
||||
|
||||
module (a_type: TYPE [CMS_MODULE]): detachable CMS_MODULE
|
||||
-- Enabled module typed `a_type', if any.
|
||||
--| usage: if attached module ({FOO_MODULE}) as mod then ...
|
||||
do
|
||||
across
|
||||
setup.modules as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
Result := ic.item
|
||||
if
|
||||
not Result.is_enabled
|
||||
or else Result.generating_type /~ a_type
|
||||
then
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module_by_name (a_name: READABLE_STRING_GENERAL): detachable CMS_MODULE
|
||||
-- Enabled module named `a_name', if any.
|
||||
do
|
||||
across
|
||||
setup.modules as ic
|
||||
until
|
||||
Result /= Void
|
||||
loop
|
||||
Result := ic.item
|
||||
if
|
||||
not Result.is_enabled
|
||||
or else not Result.name.is_case_insensitive_equal_general (a_name)
|
||||
then
|
||||
Result := Void
|
||||
end
|
||||
end
|
||||
ensure
|
||||
Result /= Void implies Result.name.is_case_insensitive_equal_general (a_name)
|
||||
end
|
||||
|
||||
feature -- Query: API
|
||||
|
||||
user_api: CMS_USER_API
|
||||
local
|
||||
l_api: like internal_user_api
|
||||
do
|
||||
l_api := internal_user_api
|
||||
if l_api = Void then
|
||||
create l_api.make (Current)
|
||||
internal_user_api := l_api
|
||||
end
|
||||
Result := l_api
|
||||
end
|
||||
|
||||
feature -- Element Change: Error
|
||||
|
||||
reset
|
||||
reset_error
|
||||
-- Reset error handler.
|
||||
do
|
||||
error_handler.reset
|
||||
end
|
||||
|
||||
feature {NONE}-- Error handler implemenations
|
||||
feature {NONE}-- Implemenation
|
||||
|
||||
error_handler: ERROR_HANDLER
|
||||
-- Error handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_valid_credential (a_auth_login, a_auth_password: READABLE_STRING_32): BOOLEAN
|
||||
-- Is the credentials `a_auth_login' and `a_auth_password' valid?
|
||||
do
|
||||
Result := storage.is_valid_credential (a_auth_login, a_auth_password)
|
||||
end
|
||||
|
||||
feature -- Access: Node
|
||||
|
||||
nodes_count: INTEGER_64
|
||||
do
|
||||
Result := storage.nodes_count
|
||||
end
|
||||
|
||||
nodes: LIST [CMS_NODE]
|
||||
-- List of nodes.
|
||||
do
|
||||
Result := storage.nodes
|
||||
end
|
||||
|
||||
recent_nodes (a_offset, a_rows: INTEGER): LIST [CMS_NODE]
|
||||
-- List of the `a_rows' most recent nodes starting from `a_offset'.
|
||||
do
|
||||
Result := storage.recent_nodes (a_offset, a_rows)
|
||||
end
|
||||
|
||||
node (a_id: INTEGER_64): detachable CMS_NODE
|
||||
-- Node by ID.
|
||||
do
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Check preconditions")
|
||||
end
|
||||
Result := storage.node_by_id (a_id)
|
||||
end
|
||||
|
||||
feature -- Change: Node
|
||||
|
||||
new_node (a_node: CMS_NODE)
|
||||
-- Add a new node `a_node'
|
||||
require
|
||||
no_id: not a_node.has_id
|
||||
do
|
||||
storage.new_node (a_node)
|
||||
end
|
||||
|
||||
delete_node (a_node: CMS_NODE)
|
||||
-- Delete `a_node'.
|
||||
do
|
||||
if a_node.has_id then
|
||||
storage.delete_node (a_node)
|
||||
end
|
||||
end
|
||||
|
||||
update_node (a_node: CMS_NODE)
|
||||
-- Update node `a_node' data.
|
||||
do
|
||||
storage.update_node (a_node)
|
||||
end
|
||||
|
||||
update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
|
||||
-- Update node title, with user identified by `a_id', with node id `a_node_id' and a new title `a_title'.
|
||||
do
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Check preconditions")
|
||||
end
|
||||
storage.update_node_title (a_user_id, a_node_id, a_title)
|
||||
end
|
||||
|
||||
update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
|
||||
-- Update node summary, with user identified by `a_user_id', with node id `a_node_id' and a new summary `a_summary'.
|
||||
do
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Check preconditions")
|
||||
end
|
||||
storage.update_node_summary (a_user_id, a_node_id, a_summary)
|
||||
end
|
||||
|
||||
update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
|
||||
-- Update node content, with user identified by `a_user_id', with node id `a_node_id' and a new content `a_content'.
|
||||
do
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Check preconditions")
|
||||
end
|
||||
storage.update_node_content (a_user_id, a_node_id, a_content)
|
||||
end
|
||||
|
||||
|
||||
feature -- Access: User
|
||||
|
||||
user_by_name (a_username: READABLE_STRING_32): detachable CMS_USER
|
||||
-- User by name `a_user_name', if any.
|
||||
do
|
||||
Result := storage.user_by_name (a_username)
|
||||
end
|
||||
|
||||
feature -- Change User
|
||||
|
||||
new_user (a_user: CMS_USER)
|
||||
-- Add a new user `a_user'.
|
||||
require
|
||||
no_id: not a_user.has_id
|
||||
no_hashed_password: a_user.hashed_password = Void
|
||||
do
|
||||
if
|
||||
attached a_user.password as l_password and then
|
||||
attached a_user.email as l_email
|
||||
then
|
||||
storage.new_user (a_user)
|
||||
else
|
||||
debug ("refactor_fixme")
|
||||
fixme ("Add error")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
update_user (a_user: CMS_USER)
|
||||
-- Update user `a_user'.
|
||||
require
|
||||
has_id: a_user.has_id
|
||||
do
|
||||
storage.update_user (a_user)
|
||||
end
|
||||
|
||||
feature -- Helpers
|
||||
|
||||
html_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
|
||||
-- `a_string' encoded for html output.
|
||||
do
|
||||
Result := html_encoder.general_encoded_string (a_string)
|
||||
end
|
||||
|
||||
percent_encoded (a_string: READABLE_STRING_GENERAL): STRING_8
|
||||
-- `a_string' encoded with percent encoding, mainly used for url.
|
||||
do
|
||||
Result := percent_encoder.percent_encoded_string (a_string)
|
||||
end
|
||||
internal_user_api: detachable like user_api
|
||||
-- Cached value for `user_api'.
|
||||
|
||||
feature -- Layout
|
||||
|
||||
@@ -249,10 +170,5 @@ feature -- Layout
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Implemenataion
|
||||
|
||||
storage: CMS_STORAGE
|
||||
-- Persistence storage.
|
||||
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user