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:
2015-07-16 17:16:35 +02:00
parent 769c14caf8
commit d8ac46f8b0
9 changed files with 97 additions and 32 deletions

View File

@@ -48,7 +48,7 @@ feature -- Execution
attached node_api.node (nid) as l_node
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
request.path_info.ends_with_general ("/edit") and then
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)
s := "created"
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)
if attached current_user (request) as u then
api.log ("node",

View File

@@ -102,7 +102,9 @@ feature -- HTTP Methods
l_nid := node_id_path_parameter (req)
if l_nid > 0 then
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)
view_response.set_node (l_node)
view_response.execute

View File

@@ -44,6 +44,7 @@ feature -- HTTP Methods
l_page_helper: CMS_PAGINATION_GENERATOR
s_pager: STRING
l_count: NATURAL_64
l_include_trashed: BOOLEAN
do
-- At the moment the template are hardcoded, but we can
-- get them from the configuration file and load them into
@@ -71,19 +72,35 @@ feature -- HTTP Methods
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 {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")
across
lst as ic
loop
n := ic.item
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type +"%">")
s.append (l_response.link (lnk.title, lnk.location, Void))
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>")
if not n.is_trashed or else l_include_trashed then
lnk := node_api.node_link (n)
s.append ("<li class=%"cms_type_"+ n.content_type)
if not n.is_published then
s.append (" not-published")
elseif n.is_trashed then
s.append (" trashed")
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
s.append ("</li>%N")
@@ -93,6 +110,20 @@ feature -- HTTP Methods
-- Again the pager at the bottom, if needed
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.execute
end

View File

@@ -42,19 +42,29 @@ feature -- HTTP Methods
s: STRING
n: CMS_NODE
lnk: CMS_LOCAL_LINK
l_username: detachable READABLE_STRING_32
l_trash_owner: detachable CMS_USER
do
-- At the moment the template is hardcoded, but we can
-- get them from the configuration file and load them into
-- the setup class.
if attached current_user (req) as l_user then
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
l_page.add_variable (node_api.trashed_nodes (l_user), "nodes")
create {GENERIC_VIEW_CMS_RESPONSE} l_page.make (req, res, api)
if attached {WSF_STRING} req.query_parameter ("user") as p_username then
l_username := p_username.value
l_trash_owner := api.user_api.user_by_name (l_username)
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.
create s.make_from_string ("<p>Nodes:</p>")
if attached node_api.trashed_nodes (l_user) as lst then
if l_trash_owner /= Void 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")
across
lst as ic