Refactor notion of trash and delete.

- Trash a node now does a soft delete (move to trash container).
 - Delete a node now remove it from the storage (no undo).

Signed-off-by: jvelilla <javier.hector@gmail.com>
This commit is contained in:
2015-09-09 22:05:23 +02:00
parent 32a409b7e9
commit 62e74ea6cd
4 changed files with 19 additions and 18 deletions

View File

@@ -411,6 +411,7 @@ feature -- Change: Node
delete_node (a_node: CMS_NODE) delete_node (a_node: CMS_NODE)
-- Delete `a_node'. -- Delete `a_node'.
--! remove the node from the storage.
do do
reset_error reset_error
if a_node.has_id then if a_node.has_id then
@@ -429,7 +430,7 @@ feature -- Change: Node
trash_node (a_node: CMS_NODE) trash_node (a_node: CMS_NODE)
-- Trash node `a_node'. -- Trash node `a_node'.
--! remove the node from the storage. -- Soft delete
do do
reset_error reset_error
node_storage.trash_node (a_node) node_storage.trash_node (a_node)

View File

@@ -274,7 +274,7 @@ feature -- Output
if a_node.status = {CMS_NODE_API}.trashed then if a_node.status = {CMS_NODE_API}.trashed then
create lnk.make ("Trash", node_api.node_path (a_node) + "/trash") create lnk.make ("Delete", node_api.node_path (a_node) + "/delete")
lnk.set_weight (2) lnk.set_weight (2)
a_response.add_to_primary_tabs (lnk) a_response.add_to_primary_tabs (lnk)
elseif a_node.has_id then elseif a_node.has_id then
@@ -291,9 +291,9 @@ feature -- Output
end end
if if
node_api.has_permission_for_action_on_node ("delete", a_node, l_user) node_api.has_permission_for_action_on_node ("trash", a_node, l_user)
then then
create lnk.make ("Delete", node_api.node_path (a_node) + "/delete") create lnk.make ("Trash", node_api.node_path (a_node) + "/trash")
lnk.set_weight (3) lnk.set_weight (3)
a_response.add_to_primary_tabs (lnk) a_response.add_to_primary_tabs (lnk)
end end

View File

@@ -205,8 +205,8 @@ feature -- HTTP Methods
send_not_implemented ("REST API not yet implemented", req, res) send_not_implemented ("REST API not yet implemented", req, res)
end end
do_delete (req: WSF_REQUEST; res: WSF_RESPONSE) do_trash (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor> -- Trash a node, soft delete.
do do
if attached current_user (req) as l_user then if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then if attached {WSF_STRING} req.path_parameter ("id") as l_id then
@@ -214,8 +214,8 @@ feature -- HTTP Methods
l_id.is_integer and then l_id.is_integer and then
attached node_api.node (l_id.integer_value) as l_node attached node_api.node (l_id.integer_value) as l_node
then then
if node_api.has_permission_for_action_on_node ("delete", l_node, current_user (req)) then if node_api.has_permission_for_action_on_node ("trash", l_node, current_user (req)) then
node_api.delete_node (l_node) node_api.trash_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 ("")))
else else
send_access_denied (req, res) send_access_denied (req, res)
@@ -240,8 +240,8 @@ feature -- HTTP Methods
feature {NONE} -- Trash:Restore feature {NONE} -- Trash:Restore
do_trash (req: WSF_REQUEST; res: WSF_RESPONSE) do_delete (req: WSF_REQUEST; res: WSF_RESPONSE)
-- Trash a node from the database. -- Delete a node from the database.
do do
if attached current_user (req) as l_user then if attached current_user (req) as l_user then
if attached {WSF_STRING} req.path_parameter ("id") as l_id then if attached {WSF_STRING} req.path_parameter ("id") as l_id then
@@ -249,8 +249,8 @@ feature {NONE} -- Trash:Restore
l_id.is_integer and then l_id.is_integer and then
attached node_api.node (l_id.integer_value) as l_node attached node_api.node (l_id.integer_value) as l_node
then 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 ("delete", l_node, current_user (req)) then
node_api.trash_node (l_node) node_api.delete_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 ("")))
else else
send_access_denied (req, res) send_access_denied (req, res)

View File

@@ -321,7 +321,7 @@ feature -- Change: Node
store_node (a_node) store_node (a_node)
end end
delete_node_by_id (a_id: INTEGER_64) trash_node_by_id (a_id: INTEGER_64)
-- Remove node by id `a_id'. -- Remove node by id `a_id'.
local local
l_parameters: STRING_TABLE [ANY] l_parameters: STRING_TABLE [ANY]
@@ -333,10 +333,10 @@ feature -- Change: Node
l_parameters.put (create {DATE_TIME}.make_now_utc, "changed") l_parameters.put (create {DATE_TIME}.make_now_utc, "changed")
l_parameters.put ({CMS_NODE_API}.trashed, "status") l_parameters.put ({CMS_NODE_API}.trashed, "status")
l_parameters.put (a_id, "nid") l_parameters.put (a_id, "nid")
sql_change (sql_delete_node, l_parameters) sql_change (sql_trash_node, l_parameters)
end end
trash_node_by_id (a_id: INTEGER_64) delete_node_by_id (a_id: INTEGER_64)
-- <Precursor> -- <Precursor>
local local
l_parameters: STRING_TABLE [ANY] l_parameters: STRING_TABLE [ANY]
@@ -348,7 +348,7 @@ feature -- Change: Node
error_handler.reset error_handler.reset
create l_parameters.make (1) create l_parameters.make (1)
l_parameters.put (a_id, "nid") l_parameters.put (a_id, "nid")
sql_change (sql_trash_node, l_parameters) sql_change (sql_delete_node, l_parameters)
end end
restore_node_by_id (a_id: INTEGER_64) restore_node_by_id (a_id: INTEGER_64)
@@ -492,10 +492,10 @@ feature {NONE} -- Queries
sql_update_node : STRING = "UPDATE nodes SET revision=:revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, status=:status, author=:author WHERE nid=:nid;" sql_update_node : STRING = "UPDATE nodes SET revision=:revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, status=:status, author=:author WHERE nid=:nid;"
-- SQL update node. -- SQL update node.
sql_delete_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid" sql_trash_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid"
-- Soft deletion with free metadata. -- Soft deletion with free metadata.
sql_trash_node: STRING = "DELETE FROM nodes WHERE nid=:nid" sql_delete_node: STRING = "DELETE FROM nodes WHERE nid=:nid"
-- Physical deletion with free metadata. -- Physical deletion with free metadata.
sql_restore_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid" sql_restore_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid"