Improved node management.

- List node by node types
- fixed the trash/restore/delete workflow
Added messaging module to send message to cms users (by email for now).
Added early protection for cache, export and import functionalities.
This commit is contained in:
2017-02-28 11:24:48 +01:00
parent dc84e79952
commit a341bd98eb
35 changed files with 1055 additions and 212 deletions

View File

@@ -291,9 +291,12 @@ feature -- Output
a_response.add_to_primary_tabs (lnk)
if a_node.status = {CMS_NODE_API}.trashed then
create lnk.make ("Delete", l_node_api.node_path (a_node) + "/delete")
create lnk.make ("Restore", l_node_api.node_path (a_node) + "/trash")
lnk.set_weight (2)
a_response.add_to_primary_tabs (lnk)
create lnk.make ("Delete", l_node_api.node_path (a_node) + "/delete")
lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk)
elseif a_node.has_id then
-- Node in {{CMS_NODE_API}.published} or {CMS_NODE_API}.not_published} status.
create lnk.make ("Edit", l_node_api.node_path (a_node) + "/edit")
@@ -320,7 +323,17 @@ feature -- Output
if is_teaser then
a_output.append (" cms-teaser")
end
a_output.append ("cms-node node-" + a_node.content_type + "%">")
a_output.append ("cms-node node-" + a_node.content_type)
if a_node.is_published then
a_output.append (" cms-status-published")
elseif a_node.is_trashed then
a_output.append (" cms-status-trashed")
elseif a_node.is_not_published then
a_output.append (" cms-status-unpublished")
else
a_output.append (" cms-status-" + a_node.status.out)
end
a_output.append ("%">")
a_output.append ("<div class=%"info%"> ")
if attached a_node.author as l_author then

View File

@@ -159,7 +159,6 @@ feature {NONE} -- Create a new node
end
end
delete_node (a_node: CMS_NODE; a_type: CMS_NODE_TYPE [CMS_NODE]; b: STRING_8)
local
f: like new_edit_form
@@ -187,7 +186,7 @@ feature {NONE} -- Create a new node
f.append_to_html (wsf_theme, b)
end
else
--
b.append ("ERROR: node is not in the trash!")
end
end
@@ -381,7 +380,7 @@ feature -- Form
create f.make (a_url, a_name)
f.extend_html_text ("<br/>")
f.extend_html_text ("<legend>Are you sure you want to delete?</legend>")
f.extend_html_text ("<legend>Are you sure you want to delete? (impossible to undo)</legend>")
-- TODO check if we need to check for has_permissions!!
if
@@ -400,46 +399,42 @@ feature -- Form
ts.set_formmethod ("GET")
f.extend (ts)
end
f.extend_html_text ("<br/>")
f.extend_html_text ("<legend>Do you want to restore the current node?</legend>")
if
a_node /= Void and then
a_node.id > 0
then
create ts.make ("op")
ts.set_default_value ("Restore")
ts.set_formaction ("/node/"+a_node.id.out+"/delete")
ts.set_formmethod ("POST")
fixme ("[
ts.set_default_value (translation ("Restore"))
]")
f.extend (ts)
end
Result := f
end
new_trash_form (a_node: detachable CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
-- Create a web form named `a_name' for node `a_node' (if set), using form action url `a_url', and for type of node `a_node_type'.
new_trash_form (a_node: CMS_NODE; a_url: READABLE_STRING_8; a_name: STRING; a_node_type: CMS_NODE_TYPE [CMS_NODE]): CMS_FORM
-- Create a web form named `a_name' for node `a_node', using form action url `a_url', and for type of node `a_node_type'.
local
f: CMS_FORM
ts: WSF_FORM_SUBMIT_INPUT
do
create f.make (a_url, a_name)
f.set_method_post
f.extend_html_text ("<br/>")
f.extend_html_text ("<legend>Are you sure you want to trash the current node?</legend>")
if
a_node /= Void and then
a_node.id > 0
then
if a_node.is_trashed then
f.extend_html_text ("<legend>Are you sure you want to restore the current node?</legend>")
create ts.make ("op")
ts.set_default_value ("Trash")
ts.set_default_value ("Restore")
ts.set_formaction ("/node/" + a_node.id.out + "/trash")
ts.set_formmethod ("POST")
fixme ("[
ts.set_default_value (translation ("Trash"))
]")
f.extend (ts)
else
f.extend_html_text ("<legend>Are you sure you want to trash the current node?</legend>")
create ts.make ("op")
ts.set_default_value ("Trash")
ts.set_formaction ("/node/" + a_node.id.out + "/trash")
ts.set_formmethod ("POST")
fixme ("[
ts.set_default_value (translation ("Trash"))
]")
end
f.extend (ts)
Result := f
end

View File

@@ -174,18 +174,20 @@ feature -- HTTP Methods
l_op.value.same_string ("Delete")
then
do_delete (req, res)
elseif
attached {WSF_STRING} req.form_parameter ("op") as l_op and then
l_op.value.same_string ("Restore")
then
do_restore (req, res)
else
send_bad_request (req, res)
end
elseif req.percent_encoded_path_info.ends_with ("/trash") then
if
attached {WSF_STRING} req.form_parameter ("op") as l_op and then
l_op.value.same_string ("Trash")
then
do_trash (req, res)
if attached {WSF_STRING} req.form_parameter ("op") as l_op then
if l_op.is_case_insensitive_equal ("Trash") then
do_trash (req, res)
elseif l_op.is_case_insensitive_equal ("Restore") then
do_restore (req, res)
else
send_bad_request (req, res)
end
else
send_bad_request (req, res)
end
elseif req.percent_encoded_path_info.starts_with ("/node/add/") then
create edit_response.make (req, res, api, node_api)
@@ -206,6 +208,14 @@ feature -- HTTP Methods
send_not_implemented ("REST API not yet implemented", req, res)
end
process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER)
do
to_implement ("REST API")
send_not_implemented ("REST API not yet implemented", req, res)
end
feature {NONE} -- Trash:Restore
do_trash (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Trash a node, soft delete.
do
@@ -233,14 +243,6 @@ feature -- HTTP Methods
end
end
process_node_creation (req: WSF_REQUEST; res: WSF_RESPONSE; a_user: CMS_USER)
do
to_implement ("REST API")
send_not_implemented ("REST API not yet implemented", req, res)
end
feature {NONE} -- Trash:Restore
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Delete a node from the database.
local
@@ -283,7 +285,7 @@ feature {NONE} -- Trash:Restore
then
if node_api.has_permission_for_action_on_node ("restore", l_node, l_user) then
node_api.restore_node (l_node)
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("/" + node_api.node_path (l_node))))
else
send_access_denied (req, res)
-- send_not_authorized ?

View File

@@ -11,7 +11,16 @@ inherit
WSF_URI_HANDLER
rename
new_mapping as new_uri_mapping
new_mapping as new_uri_mapping,
execute as execute_uri
end
WSF_URI_TEMPLATE_HANDLER
rename
new_mapping as new_uri_template_mapping,
execute as execute_uri_template
select
new_uri_template_mapping
end
WSF_RESOURCE_HANDLER_HELPER
@@ -26,6 +35,16 @@ create
feature -- execute
execute_uri (req: WSF_REQUEST; res: WSF_RESPONSE)
do
execute (req, res)
end
execute_uri_template (req: WSF_REQUEST; res: WSF_RESPONSE)
do
execute (req, res)
end
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Execute request handler
do
@@ -39,30 +58,57 @@ feature -- HTTP Methods
local
l_response: CMS_RESPONSE
s: STRING
l_content_type: detachable CMS_CONTENT_TYPE
n: CMS_NODE
lnk: CMS_LOCAL_LINK
l_page_helper: CMS_PAGINATION_GENERATOR
s_pager: STRING
l_count: NATURAL_64
inc: BOOLEAN
l_include_trashed: BOOLEAN
lst: detachable ITERABLE [CMS_NODE]
do
-- At the moment the template are hardcoded, but we can
-- get them from the configuration file and load them into
-- the setup class.
l_count := node_api.nodes_count
if attached {WSF_STRING} req.path_parameter ("type") as p_node_type and then attached api.content_type (p_node_type.value) as ct then
l_content_type := api.content_type (p_node_type.value)
end
create {GENERIC_VIEW_CMS_RESPONSE} l_response.make (req, res, api)
create s.make_empty
if l_count > 1 then
l_response.set_title ("Listing " + l_count.out + " nodes")
else
l_response.set_title ("Listing " + l_count.out + " node")
across
api.content_types as ic
loop
if attached {CMS_NODE_TYPE [CMS_NODE]} ic.item as l_note_type then
create lnk.make (l_note_type.name, "nodes/" + l_note_type.name)
if l_note_type = l_content_type then
lnk.set_is_active (True)
end
l_response.add_to_primary_tabs (lnk)
end
end
create s_pager.make_empty
create l_page_helper.make ("nodes/?page={page}&size={size}", node_api.nodes_count, 25) -- FIXME: Make this default page size a global CMS settings
if l_content_type /= Void then
l_count := node_api.nodes_of_type_count (l_content_type)
if l_count > 1 then
l_response.set_title ("Listing " + l_count.out + " " + l_content_type.name + " nodes")
else
l_response.set_title ("Listing " + l_count.out + " " + l_content_type.name + " node")
end
create l_page_helper.make ("nodes/" + l_content_type.name + "/?page={page}&size={size}", l_count, 25) -- FIXME: Make this default page size a global CMS settings
else
l_count := node_api.nodes_count
if l_count > 1 then
l_response.set_title ("Listing " + l_count.out + " nodes")
else
l_response.set_title ("Listing " + l_count.out + " node")
end
create l_page_helper.make ("nodes/?page={page}&size={size}", l_count, 25) -- FIXME: Make this default page size a global CMS settings
end
l_page_helper.get_setting_from_request (req)
if l_page_helper.has_upper_limit and then l_page_helper.pages_count > 1 then
l_page_helper.append_to_html (l_response, s_pager)
@@ -71,7 +117,12 @@ feature -- HTTP Methods
end
end
if attached node_api.recent_nodes (create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size)) as lst then
if l_content_type /= Void then
lst := node_api.recent_nodes_of_type (l_content_type, create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
else
lst := node_api.recent_nodes (create {CMS_DATA_QUERY_PARAMETERS}.make (l_page_helper.current_page_offset, l_page_helper.page_size))
end
if lst /= Void then
if attached {WSF_STRING} req.query_parameter ("include_trash") as v and then v.is_case_insensitive_equal ("yes") then
l_include_trashed := l_response.has_permissions (<<"view trash", "view any trash">>)
end
@@ -80,7 +131,14 @@ feature -- HTTP Methods
lst as ic
loop
n := ic.item
if not n.is_trashed or else l_include_trashed then
inc := True
if not n.is_published then
inc := view_unpublished_node_permitted (n)
end
if inc and n.is_trashed then
inc := l_include_trashed
end
if inc then
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type)
if not n.is_published then
@@ -131,4 +189,15 @@ feature -- HTTP Methods
l_response.execute
end
feature -- Helper
view_unpublished_node_permitted (n: CMS_NODE): BOOLEAN
do
if api.has_permission ("view unpublished " + n.content_type) then
Result := True
elseif attached api.user as u then
Result := u.same_as (n.author)
end
end
end