Added revisions support to node management.
Updated node extension implementation. Updated known permissions for node module. Improved code for node storage extension , in preparation to code factorization. Ensured that author is updated when saved.
This commit is contained in:
@@ -187,7 +187,8 @@ feature -- Forms ...
|
||||
a_node.set_content (b, s, f.name)
|
||||
end
|
||||
|
||||
|
||||
-- Update author
|
||||
a_node.set_author (response.user)
|
||||
end
|
||||
|
||||
new_node (response: NODE_RESPONSE; fd: WSF_FORM_DATA; a_node: detachable CMS_NODE): G
|
||||
@@ -272,20 +273,25 @@ feature -- Output
|
||||
lnk.set_weight (1)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
|
||||
|
||||
if a_node.status = {CMS_NODE_API}.trashed then
|
||||
create lnk.make ("Trash", node_api.node_path (a_node) + "/trash")
|
||||
lnk.set_weight (2)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
else
|
||||
elseif a_node /= Void and then a_node.has_id then
|
||||
-- Node in {{CMS_NODE_API}.published} or {CMS_NODE_API}.not_published} status.
|
||||
create lnk.make ("Edit", node_api.node_path (a_node) + "/edit")
|
||||
lnk.set_weight (2)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
if
|
||||
node_api.has_permission_for_action_on_node ("view revisions", a_node, l_user)
|
||||
then
|
||||
create lnk.make ("Revisions", node_api.node_path (a_node) + "/revision")
|
||||
lnk.set_weight (3)
|
||||
a_response.add_to_primary_tabs (lnk)
|
||||
end
|
||||
|
||||
if
|
||||
a_node /= Void and then
|
||||
a_node.id > 0 and then
|
||||
attached node_api.node_type_for (a_node) as l_type and then
|
||||
node_api.has_permission_for_action_on_node ("delete", a_node, l_user)
|
||||
then
|
||||
create lnk.make ("Delete", node_api.node_path (a_node) + "/delete")
|
||||
|
||||
@@ -236,17 +236,15 @@ feature -- Form
|
||||
end
|
||||
if a_node /= Void then
|
||||
l_node := a_node
|
||||
apply_form_data_to_node (a_type, fd, a_node)
|
||||
|
||||
if l_node.has_id then
|
||||
change_node (a_type, fd, a_node)
|
||||
s := "modified"
|
||||
else
|
||||
change_node (a_type, fd, a_node)
|
||||
l_node.set_author (user)
|
||||
s := "created"
|
||||
end
|
||||
else
|
||||
l_node := new_node (a_type, fd, Void)
|
||||
l_node.set_author (user)
|
||||
s := "created"
|
||||
end
|
||||
|
||||
@@ -261,7 +259,11 @@ feature -- Form
|
||||
else
|
||||
api.log ("node", "Anonymous " + s + " node " + a_type.name +" #" + l_node.id.out, 0, node_local_link (l_node, Void))
|
||||
end
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
if node_api.has_error then
|
||||
add_error_message ("Node #" + l_node.id.out + " failed to save.")
|
||||
else
|
||||
add_success_message ("Node #" + l_node.id.out + " saved.")
|
||||
end
|
||||
|
||||
if
|
||||
attached fd.string_item ("path_alias") as f_path_alias and then
|
||||
@@ -398,9 +400,10 @@ feature -- Form
|
||||
else
|
||||
Result := a_content_type.new_node (a_node)
|
||||
end
|
||||
Result.set_author (user)
|
||||
end
|
||||
|
||||
change_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
apply_form_data_to_node (a_content_type: CMS_NODE_TYPE [CMS_NODE]; a_form_data: WSF_FORM_DATA; a_node: CMS_NODE)
|
||||
-- Update node `a_node' with form_data `a_form_data' for the given content type `a_content_type'.
|
||||
do
|
||||
if attached node_api.node_type_webform_manager (a_content_type) as wf then
|
||||
|
||||
@@ -81,7 +81,7 @@ feature -- HTTP Methods
|
||||
-- <Precursor>
|
||||
local
|
||||
l_node: detachable CMS_NODE
|
||||
l_nid: INTEGER_64
|
||||
l_nid, l_rev: INTEGER_64
|
||||
edit_response: NODE_FORM_RESPONSE
|
||||
view_response: NODE_VIEW_RESPONSE
|
||||
do
|
||||
@@ -97,16 +97,32 @@ feature -- HTTP Methods
|
||||
check valid_url: req.percent_encoded_path_info.starts_with ("/node/") end
|
||||
create edit_response.make (req, res, api, node_api)
|
||||
edit_response.execute
|
||||
elseif req.percent_encoded_path_info.ends_with ("/revision") then
|
||||
do_revisions (req, res)
|
||||
else
|
||||
-- Display existing node
|
||||
l_nid := node_id_path_parameter (req)
|
||||
if l_nid > 0 then
|
||||
if
|
||||
attached {WSF_STRING} req.query_parameter ("revision") as p_rev and then
|
||||
p_rev.value.is_integer_64
|
||||
then
|
||||
l_rev := p_rev.value.to_integer_64
|
||||
end
|
||||
l_node := node_api.node (l_nid)
|
||||
if
|
||||
l_node /= Void and then l_node.is_published
|
||||
l_node /= Void and then
|
||||
l_rev > 0 and then
|
||||
node_api.has_permission_for_action_on_node ("view revisions", l_node, current_user (req))
|
||||
then
|
||||
l_node := node_api.revision_node (l_nid, l_rev)
|
||||
end
|
||||
if
|
||||
l_node /= Void and then (l_rev > 0 or else l_node.is_published)
|
||||
then
|
||||
create view_response.make (req, res, api, node_api)
|
||||
view_response.set_node (l_node)
|
||||
view_response.set_revision (l_rev)
|
||||
view_response.execute
|
||||
else
|
||||
send_not_found (req, res)
|
||||
@@ -234,7 +250,7 @@ feature {NONE} -- Trash:Restore
|
||||
l_id.is_integer and then
|
||||
attached node_api.node (l_id.integer_value) as l_node
|
||||
then
|
||||
if node_api.has_permission_for_action_on_node ("trash", l_node, current_user (req)) then
|
||||
if node_api.has_permission_for_action_on_node ("restore", l_node, current_user (req)) then
|
||||
node_api.restore_node (l_node)
|
||||
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
|
||||
else
|
||||
@@ -252,6 +268,58 @@ feature {NONE} -- Trash:Restore
|
||||
end
|
||||
end
|
||||
|
||||
do_revisions (req: WSF_REQUEST; res: WSF_RESPONSE)
|
||||
-- Display revisions of a node.
|
||||
local
|
||||
r: GENERIC_VIEW_CMS_RESPONSE
|
||||
b: STRING
|
||||
n: CMS_NODE
|
||||
l_link: CMS_LOCAL_LINK
|
||||
do
|
||||
if attached {WSF_STRING} req.path_parameter ("id") as l_id then
|
||||
if
|
||||
l_id.is_integer and then
|
||||
attached node_api.node (l_id.integer_value) as l_node
|
||||
then
|
||||
if node_api.has_permission_for_action_on_node ("view revisions", l_node, current_user (req)) then
|
||||
create r.make (req, res, api)
|
||||
create b.make_empty
|
||||
b.append ("<ul>")
|
||||
across
|
||||
node_api.node_revisions (l_node) as ic
|
||||
loop
|
||||
n := ic.item
|
||||
b.append ("<li>")
|
||||
b.append ("<a href=%"")
|
||||
b.append (r.url (node_api.node_path (n) + "?revision=" + n.revision.out, Void))
|
||||
b.append ("%">")
|
||||
|
||||
b.append (n.revision.out)
|
||||
b.append (" : ")
|
||||
b.append (n.modification_date.out)
|
||||
b.append ("</a>")
|
||||
if attached n.author as l_author then
|
||||
b.append (" by ")
|
||||
b.append (r.link (l_author.name, "user/" + l_author.id.out, Void))
|
||||
end
|
||||
b.append ("</li>")
|
||||
end
|
||||
b.append ("</ul>")
|
||||
r.set_title ("Revisions for " + html_encoded (l_node.title))
|
||||
r.set_main_content (b)
|
||||
r.execute
|
||||
else
|
||||
send_access_denied (req, res)
|
||||
-- send_not_authorized ?
|
||||
end
|
||||
else
|
||||
do_error (req, res, l_id)
|
||||
end
|
||||
else
|
||||
(create {INTERNAL_SERVER_ERROR_CMS_RESPONSE}.make (req, res, api)).execute
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Error
|
||||
|
||||
do_error (req: WSF_REQUEST; res: WSF_RESPONSE; a_id: detachable WSF_STRING)
|
||||
|
||||
@@ -36,6 +36,9 @@ feature -- Access
|
||||
|
||||
node: detachable CMS_NODE
|
||||
|
||||
revision: INTEGER_64
|
||||
-- If not zero, about history version of the node.
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_node (a_node: like node)
|
||||
@@ -43,18 +46,22 @@ feature -- Element change
|
||||
node := a_node
|
||||
end
|
||||
|
||||
set_revision (a_rev: like revision)
|
||||
do
|
||||
revision := a_rev
|
||||
end
|
||||
|
||||
feature -- Execution
|
||||
|
||||
process
|
||||
-- Computed response message.
|
||||
local
|
||||
b: STRING_8
|
||||
b: detachable STRING_8
|
||||
nid: INTEGER_64
|
||||
l_node: like node
|
||||
do
|
||||
l_node := node
|
||||
if l_node = Void then
|
||||
create b.make_empty
|
||||
nid := node_id_path_parameter (request)
|
||||
if nid > 0 then
|
||||
l_node := node_api.node (nid)
|
||||
@@ -67,8 +74,16 @@ feature -- Execution
|
||||
then
|
||||
l_manager.append_html_output_to (l_node, Current)
|
||||
end
|
||||
elseif revision > 0 then
|
||||
set_main_content ("Missing revision node!")
|
||||
else
|
||||
set_main_content ("Missing node")
|
||||
set_main_content ("Missing node!")
|
||||
end
|
||||
if revision > 0 then
|
||||
add_warning_message ("The revisions let you track differences between multiple versions of a post.")
|
||||
end
|
||||
if l_node /= Void and revision > 0 then
|
||||
set_title ("Revision #" + revision.out + " of " + html_encoded (l_node.title))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user