Added CMS_NODE.is_published and is_trashed: BOOLEAN
For now, whenever we save a node, it is marked as published. Display a node only if published. Updated /trash page. Updated /nodes/ page to take into account the node status.
This commit is contained in:
@@ -220,11 +220,11 @@ feature -- Access: Node
|
|||||||
Result := node_storage.nodes
|
Result := node_storage.nodes
|
||||||
end
|
end
|
||||||
|
|
||||||
trashed_nodes (a_user: CMS_USER): LIST [CMS_NODE]
|
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
|
||||||
-- List of nodes with status in {CMS_NODE_API}.trashed.
|
-- List of nodes with status in {CMS_NODE_API}.trashed.
|
||||||
-- if the current user is admin, it will retrieve all the trashed nodes
|
-- if `a_user' is set, return nodes related to this user.
|
||||||
do
|
do
|
||||||
Result := node_storage.trashed_nodes (a_user.id)
|
Result := node_storage.trashed_nodes (a_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
recent_nodes (params: CMS_DATA_QUERY_PARAMETERS): ITERABLE [CMS_NODE]
|
recent_nodes (params: CMS_DATA_QUERY_PARAMETERS): ITERABLE [CMS_NODE]
|
||||||
|
|||||||
@@ -73,12 +73,30 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
feature -- Status reports
|
||||||
|
|
||||||
status: INTEGER
|
status: INTEGER
|
||||||
-- Associated status for the current node.
|
-- Associated status for the current node.
|
||||||
-- default: {CMS_NODE_API}.Not_Published}
|
-- default: {CMS_NODE_API}.Not_Published}
|
||||||
-- {CMS_NODE_API}.Published
|
-- {CMS_NODE_API}.Published
|
||||||
-- {CMS_NODE_API}.Trashed
|
-- {CMS_NODE_API}.Trashed
|
||||||
|
|
||||||
|
is_published: BOOLEAN
|
||||||
|
-- Is Current published?
|
||||||
|
do
|
||||||
|
Result := status = {CMS_NODE_API}.published
|
||||||
|
ensure
|
||||||
|
Result implies not is_trashed
|
||||||
|
end
|
||||||
|
|
||||||
|
is_trashed: BOOLEAN
|
||||||
|
-- Is Current trashed?
|
||||||
|
do
|
||||||
|
Result := status = {CMS_NODE_API}.trashed
|
||||||
|
ensure
|
||||||
|
Result implies not is_published
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
title: READABLE_STRING_32
|
title: READABLE_STRING_32
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ feature -- Execution
|
|||||||
attached node_api.node (nid) as l_node
|
attached node_api.node (nid) as l_node
|
||||||
then
|
then
|
||||||
if attached node_api.node_type_for (l_node) as l_type then
|
if attached node_api.node_type_for (l_node) as l_type then
|
||||||
fixme ("refactor: process_edit, process_create porcess edit")
|
fixme ("refactor: process_edit, process_create process edit")
|
||||||
if
|
if
|
||||||
request.path_info.ends_with_general ("/edit") and then
|
request.path_info.ends_with_general ("/edit") and then
|
||||||
node_api.has_permission_for_action_on_node ("edit", l_node, current_user (request))
|
node_api.has_permission_for_action_on_node ("edit", l_node, current_user (request))
|
||||||
@@ -249,6 +249,9 @@ feature -- Form
|
|||||||
l_node.set_author (user)
|
l_node.set_author (user)
|
||||||
s := "created"
|
s := "created"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
fixme ("for now, publishing is not implemented, so let's assume any node saved is published.") -- FIXME
|
||||||
|
l_node.mark_published
|
||||||
node_api.save_node (l_node)
|
node_api.save_node (l_node)
|
||||||
if attached current_user (request) as u then
|
if attached current_user (request) as u then
|
||||||
api.log ("node",
|
api.log ("node",
|
||||||
|
|||||||
@@ -102,7 +102,9 @@ feature -- HTTP Methods
|
|||||||
l_nid := node_id_path_parameter (req)
|
l_nid := node_id_path_parameter (req)
|
||||||
if l_nid > 0 then
|
if l_nid > 0 then
|
||||||
l_node := node_api.node (l_nid)
|
l_node := node_api.node (l_nid)
|
||||||
if l_node /= Void then
|
if
|
||||||
|
l_node /= Void and then l_node.is_published
|
||||||
|
then
|
||||||
create view_response.make (req, res, api, node_api)
|
create view_response.make (req, res, api, node_api)
|
||||||
view_response.set_node (l_node)
|
view_response.set_node (l_node)
|
||||||
view_response.execute
|
view_response.execute
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ feature -- HTTP Methods
|
|||||||
l_page_helper: CMS_PAGINATION_GENERATOR
|
l_page_helper: CMS_PAGINATION_GENERATOR
|
||||||
s_pager: STRING
|
s_pager: STRING
|
||||||
l_count: NATURAL_64
|
l_count: NATURAL_64
|
||||||
|
l_include_trashed: BOOLEAN
|
||||||
do
|
do
|
||||||
-- At the moment the template are hardcoded, but we can
|
-- At the moment the template are hardcoded, but we can
|
||||||
-- get them from the configuration file and load them into
|
-- get them from the configuration file and load them into
|
||||||
@@ -71,19 +72,35 @@ 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 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 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
|
||||||
s.append ("<ul class=%"cms-nodes%">%N")
|
s.append ("<ul class=%"cms-nodes%">%N")
|
||||||
across
|
across
|
||||||
lst as ic
|
lst as ic
|
||||||
loop
|
loop
|
||||||
n := ic.item
|
n := ic.item
|
||||||
lnk := node_api.node_link (n)
|
if not n.is_trashed or else l_include_trashed then
|
||||||
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
|
lnk := node_api.node_link (n)
|
||||||
s.append (l_response.link (lnk.title, lnk.location, Void))
|
s.append ("<li class=%"cms_type_"+ n.content_type)
|
||||||
debug
|
if not n.is_published then
|
||||||
if attached node_api.content_type (n.content_type) as ct then
|
s.append (" not-published")
|
||||||
s.append ("<span class=%"description%">")
|
elseif n.is_trashed then
|
||||||
s.append (html_encoded (ct.title))
|
s.append (" trashed")
|
||||||
s.append ("</span>")
|
end
|
||||||
|
s.append ("%">")
|
||||||
|
s.append (l_response.link (lnk.title, lnk.location, Void))
|
||||||
|
if not n.is_published then
|
||||||
|
s.append (" <em>(not-published)</em>")
|
||||||
|
elseif n.is_trashed then
|
||||||
|
s.append (" <em>(trashed)</em>")
|
||||||
|
end
|
||||||
|
debug
|
||||||
|
if attached node_api.content_type (n.content_type) as ct then
|
||||||
|
s.append ("<span class=%"description%">")
|
||||||
|
s.append (html_encoded (ct.title))
|
||||||
|
s.append ("</span>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
s.append ("</li>%N")
|
s.append ("</li>%N")
|
||||||
@@ -93,6 +110,20 @@ feature -- HTTP Methods
|
|||||||
-- Again the pager at the bottom, if needed
|
-- Again the pager at the bottom, if needed
|
||||||
s.append (s_pager)
|
s.append (s_pager)
|
||||||
|
|
||||||
|
if l_response.has_permissions (<<"view trash", "view any trash">>) then
|
||||||
|
if not l_include_trashed then
|
||||||
|
s.append (l_response.link ("With trashed items", l_response.location + "?include_trash=yes", Void))
|
||||||
|
s.append (" | ")
|
||||||
|
end
|
||||||
|
|
||||||
|
s.append (l_response.link ("Global-Trash", "trash", Void))
|
||||||
|
s.append (" | ")
|
||||||
|
end
|
||||||
|
if attached l_response.user as u and then l_response.has_permission ("view own trash") then
|
||||||
|
s.append (l_response.link ("Your-trash", "trash?user=" + l_response.url_encoded (u.name), Void))
|
||||||
|
s.append (" | ")
|
||||||
|
end
|
||||||
|
|
||||||
l_response.set_main_content (s)
|
l_response.set_main_content (s)
|
||||||
l_response.execute
|
l_response.execute
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,19 +42,29 @@ feature -- HTTP Methods
|
|||||||
s: STRING
|
s: STRING
|
||||||
n: CMS_NODE
|
n: CMS_NODE
|
||||||
lnk: CMS_LOCAL_LINK
|
lnk: CMS_LOCAL_LINK
|
||||||
|
l_username: detachable READABLE_STRING_32
|
||||||
|
l_trash_owner: detachable CMS_USER
|
||||||
do
|
do
|
||||||
-- At the moment the template is hardcoded, but we can
|
-- At the moment the template is hardcoded, but we can
|
||||||
-- get them from the configuration file and load them into
|
-- get them from the configuration file and load them into
|
||||||
-- the setup class.
|
-- the setup class.
|
||||||
|
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
||||||
if attached current_user (req) as l_user then
|
if attached {WSF_STRING} req.query_parameter ("user") as p_username then
|
||||||
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
|
l_username := p_username.value
|
||||||
|
l_trash_owner := api.user_api.user_by_name (l_username)
|
||||||
l_page.add_variable (node_api.trashed_nodes (l_user), "nodes")
|
end
|
||||||
|
if
|
||||||
|
(l_trash_owner /= Void and then l_page.has_permissions (<<"view any trash", "view own trash">>))
|
||||||
|
or else (l_page.has_permission ("view trash"))
|
||||||
|
then
|
||||||
-- NOTE: for development purposes we have the following hardcode output.
|
-- NOTE: for development purposes we have the following hardcode output.
|
||||||
create s.make_from_string ("<p>Nodes:</p>")
|
if l_trash_owner /= Void then
|
||||||
if attached node_api.trashed_nodes (l_user) as lst then
|
create s.make_from_string ("<p>Trash for user " + l_page.html_encoded (l_trash_owner.name) + "</p>")
|
||||||
|
else
|
||||||
|
create s.make_from_string ("<p>Trash</p>")
|
||||||
|
end
|
||||||
|
|
||||||
|
if attached node_api.trashed_nodes (l_trash_owner) as lst then
|
||||||
s.append ("<ul class=%"cms-nodes%">%N")
|
s.append ("<ul class=%"cms-nodes%">%N")
|
||||||
across
|
across
|
||||||
lst as ic
|
lst as ic
|
||||||
|
|||||||
@@ -73,8 +73,10 @@ feature -- Access
|
|||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
|
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
|
||||||
-- List of nodes by user `a_user_id'.
|
-- List of nodes by user `a_user' if set, or any.
|
||||||
|
require
|
||||||
|
a_user /= Void implies a_user.has_id
|
||||||
deferred
|
deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -41,8 +41,8 @@ feature -- Access: node
|
|||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|
||||||
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
|
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
|
||||||
-- List of nodes by user `a_user_id'.
|
-- <Precursor>.
|
||||||
do
|
do
|
||||||
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
create {ARRAYED_LIST [CMS_NODE]} Result.make (0)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ feature -- Access
|
|||||||
-- end
|
-- end
|
||||||
end
|
end
|
||||||
|
|
||||||
trashed_nodes (a_user_id: INTEGER_64): LIST [CMS_NODE]
|
trashed_nodes (a_user: detachable CMS_USER): LIST [CMS_NODE]
|
||||||
-- List of nodes.
|
-- List of nodes.
|
||||||
local
|
local
|
||||||
l_parameters: STRING_TABLE [detachable ANY]
|
l_parameters: STRING_TABLE [detachable ANY]
|
||||||
@@ -72,9 +72,8 @@ feature -- Access
|
|||||||
|
|
||||||
from
|
from
|
||||||
create l_parameters.make (1)
|
create l_parameters.make (1)
|
||||||
if a_user_id > 1 then
|
if a_user /= Void and then a_user.has_id then
|
||||||
-- Not admin user
|
l_parameters.put (a_user.id, "author")
|
||||||
l_parameters.put (a_user_id, "author")
|
|
||||||
sql_query (sql_select_trash_nodes_by_author, l_parameters)
|
sql_query (sql_select_trash_nodes_by_author, l_parameters)
|
||||||
else
|
else
|
||||||
sql_query (sql_select_trash_nodes, Void)
|
sql_query (sql_select_trash_nodes, Void)
|
||||||
@@ -295,15 +294,15 @@ feature {NONE} -- Queries
|
|||||||
-- Nodes count (Published and not Published)
|
-- Nodes count (Published and not Published)
|
||||||
--| note: {CMS_NODE_API}.trashed = -1
|
--| note: {CMS_NODE_API}.trashed = -1
|
||||||
|
|
||||||
sql_select_nodes: STRING = "SELECT * FROM nodes WHERE status != -1 ;"
|
sql_select_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status != -1 ;"
|
||||||
-- SQL Query to retrieve all nodes.
|
-- SQL Query to retrieve all nodes.
|
||||||
--| note: {CMS_NODE_API}.trashed = -1
|
--| note: {CMS_NODE_API}.trashed = -1
|
||||||
|
|
||||||
sql_select_trash_nodes: STRING = "SELECT * FROM nodes WHERE status = -1 ;"
|
sql_select_trash_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 ;"
|
||||||
-- SQL Query to retrieve all trahsed nodes.
|
-- SQL Query to retrieve all trahsed nodes.
|
||||||
--| note: {CMS_NODE_API}.trashed = -1
|
--| note: {CMS_NODE_API}.trashed = -1
|
||||||
|
|
||||||
sql_select_trash_nodes_by_author: STRING = "SELECT * FROM nodes WHERE status = -1 and author = :author ;"
|
sql_select_trash_nodes_by_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM nodes WHERE status = -1 and author = :author ;"
|
||||||
-- SQL Query to retrieve all nodes by a given author.
|
-- SQL Query to retrieve all nodes by a given author.
|
||||||
--| note: {CMS_NODE_API}.trashed = -1
|
--| note: {CMS_NODE_API}.trashed = -1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user