Compare commits

...

7 Commits

Author SHA1 Message Date
3fa29340b2 Updated code to follow review comments. 2015-05-12 20:01:14 +02:00
jvelilla
b1988d5fe7 Updated CMS_NODE_API, with status, not_published, published and trashed.
Removed class cms_node_constants.
Updated Form response to use permission scopes.
Updated sqlquery to retrieve user author.
Added logger info in cms_response
2015-05-11 23:51:25 -03:00
jvelilla
e767e1bc47 Updated table node to use status (1:not_published, 2:published, 3:trash )instead of deleted_at to implement soft deletes.
Updated queries to use the new status field.
Updated CMS_NODE with a new status attribute.
2015-05-11 16:38:51 -03:00
jvelilla
c2d0fbf445 Updated table nodes to support soft deletes using the new field
'deleted_at' as Datetime and give us free metadata.
Updated Sqlite builder to test different scenarios for users and roles.
Updated NODE_FORM_RESPONSE.edit_form feature to add a delete operation iff
there is a node ie node id >0 and the current user has delete permission on it.
Updated NODE_HANDLER.do_post to handle the operation "DELETE".
Updated queries to retrieve nodes filter by no logical deleted rows (ie. deleted_at is NULL).
Updated CMS_USER_API.has_permissions. (authenticated_user_role seems to generic).
2015-05-08 18:40:46 -03:00
fdff2bef36 Fixed compilation of autotests suites for sqlite and mysql.
TODO: reintroduce tests for node management.
2015-05-04 23:17:06 +02:00
1603086905 Fixed node editing workflow (especially creation/updating). 2015-04-30 19:46:18 +02:00
99b2fa9fdb Commented line registering the MYSQL storage builder,
since it reguires to setup MYSQL environment variable and so on.
So by default, we use sqlite, easier to run out of the box.
2015-04-30 19:38:17 +02:00
17 changed files with 459 additions and 346 deletions

View File

@@ -11,7 +11,8 @@ CREATE TABLE "nodes"(
"author" INTEGER,
"publish" DATETIME,
"created" DATETIME NOT NULL,
"changed" DATETIME NOT NULL
"changed" DATETIME NOT NULL,
"status" INTEGER
);
CREATE TABLE page_nodes(

View File

@@ -157,7 +157,7 @@ feature -- CMS setup
setup_storage (a_setup: CMS_SETUP)
-- Setup storage by declaring storage builder.
do
a_setup.storage_drivers.force (create {CMS_STORAGE_MYSQL_BUILDER}.make, "mysql")
-- a_setup.storage_drivers.force (create {CMS_STORAGE_MYSQL_BUILDER}.make, "mysql")
a_setup.storage_drivers.force (create {CMS_STORAGE_SQLITE_BUILDER}.make, "sqlite")
end

View File

@@ -29,13 +29,13 @@ feature {NONE} -- Initialization
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (2,ll_node.id, "New Title")
check
attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary
end
end
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_title (2,ll_node.id, "New Title")
-- check
-- attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary
-- end
-- end
end
@@ -64,9 +64,10 @@ feature {NONE} -- Implementation
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_PAGE
do
create Result.make (a_content, a_summary, a_title)
create Result.make (a_title)
Result.set_content (a_content, a_summary, Void)
end
end

View File

@@ -167,192 +167,192 @@ feature -- Test routines
assert ("Valid password", storage.is_valid_credential ("test", "password"))
end
test_recent_nodes_empty
do
assert ("No recent nodes", storage.recent_nodes (0, 10).is_empty)
end
-- test_recent_nodes_empty
-- do
-- assert ("No recent nodes", storage.recent_nodes (0, 10).is_empty)
-- end
test_recent_nodes
local
l_nodes: LIST[CMS_NODE]
l_node: CMS_NODE
do
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
end
l_nodes := storage.recent_nodes (0, 10)
assert ("10 recent nodes", l_nodes.count = 10)
assert ("First node id=10", l_nodes.first.id = 10)
assert ("Last node id=1", l_nodes.last.id = 1)
-- test_recent_nodes
-- local
-- l_nodes: LIST[CMS_NODE]
-- l_node: CMS_NODE
-- do
-- storage.new_user (default_user)
-- across 1 |..| 10 as c loop
-- l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- end
-- l_nodes := storage.recent_nodes (0, 10)
-- assert ("10 recent nodes", l_nodes.count = 10)
-- assert ("First node id=10", l_nodes.first.id = 10)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (5, 10)
assert ("5 recent nodes", l_nodes.count = 5)
assert ("First node id=5", l_nodes.first.id = 5)
assert ("Last node id=1", l_nodes.last.id = 1)
-- l_nodes := storage.recent_nodes (5, 10)
-- assert ("5 recent nodes", l_nodes.count = 5)
-- assert ("First node id=5", l_nodes.first.id = 5)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (9, 10)
assert ("1 recent nodes", l_nodes.count = 1)
assert ("First node id=1", l_nodes.first.id = 1)
assert ("Last node id=1", l_nodes.last.id = 1)
-- l_nodes := storage.recent_nodes (9, 10)
-- assert ("1 recent nodes", l_nodes.count = 1)
-- assert ("First node id=1", l_nodes.first.id = 1)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (10, 10)
assert ("Is empty", l_nodes.is_empty)
end
-- l_nodes := storage.recent_nodes (10, 10)
-- assert ("Is empty", l_nodes.is_empty)
-- end
test_node_does_not_exist
local
l_node: CMS_NODE
do
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
end
assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
end
-- test_node_does_not_exist
-- local
-- l_node: CMS_NODE
-- do
-- storage.new_user (default_user)
-- across 1 |..| 10 as c loop
-- l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- end
-- assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
-- end
test_node
local
l_node: CMS_NODE
do
storage.new_user (default_user)
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
end
assert ("Node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
end
-- test_node
-- local
-- l_node: CMS_NODE
-- do
-- storage.new_user (default_user)
-- across 1 |..| 10 as c loop
-- l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- end
-- assert ("Node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
-- end
test_update_node
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
l_node := ll_node.twin
l_node.set_content ("New Content")
l_node.set_summary ("New Summary")
l_node.set_title("New Title")
if attached storage.user_by_email (default_user.email) as l_user then
l_node.set_author (l_user)
storage.update_node (l_node)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
end
end
end
-- test_update_node
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- l_node := ll_node.twin
-- l_node.set_content ("New Content")
-- l_node.set_summary ("New Summary")
-- l_node.set_title("New Title")
-- if attached storage.user_by_email (default_user.email) as l_user then
-- l_node.set_author (l_user)
-- storage.update_node (l_node)
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
-- end
-- end
-- end
test_update_node_title
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (2,ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_title
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- storage.new_user (custom_user ("u2", "p2", "e2"))
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_title (2,ll_node.id, "New Title")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_update_node_summary
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_summary (2,ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
-- test_update_node_summary
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- storage.new_user (custom_user ("u2", "p2", "e2"))
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_summary (2,ll_node.id, "New Summary")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
-- end
-- end
test_update_node_content
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
storage.new_user (custom_user ("u2", "p2", "e2"))
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_content (2,ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_content
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- storage.new_user (custom_user ("u2", "p2", "e2"))
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_content (2,ll_node.id, "New Content")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_update_node_title_by_author
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_title (1,ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_title_by_author
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_title (1,ll_node.id, "New Title")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_update_node_summary_by_author
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_summary (1,ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
-- test_update_node_summary_by_author
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_summary (1,ll_node.id, "New Summary")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
-- end
-- end
test_update_node_content_by_author
local
l_node: CMS_NODE
do
l_node := custom_node ("Content", "Summary", "Title")
storage.new_user (default_user)
l_node.set_author (storage.user_by_email (default_user.email))
storage.new_node (l_node)
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
storage.update_node_content (1,ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_content_by_author
-- local
-- l_node: CMS_NODE
-- do
-- l_node := custom_node ("Content", "Summary", "Title")
-- storage.new_user (default_user)
-- l_node.set_author (storage.user_by_email (default_user.email))
-- storage.new_node (l_node)
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_content (1,ll_node.id, "New Content")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_delete_node
local
l_node: CMS_NODE
l_user: like {CMS_NODE}.author
do
storage.new_user (custom_user ("test_delete", "testu", "email"))
l_user := storage.user_by_name ("test_delete")
across 1 |..| 10 as c loop
l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
l_node.set_author (l_user)
storage.new_node (l_node)
end
assert ("Exist node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
storage.delete_node_by_id (10)
assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
end
-- test_delete_node
-- local
-- l_node: CMS_NODE
-- l_user: like {CMS_NODE}.author
-- do
-- storage.new_user (custom_user ("test_delete", "testu", "email"))
-- l_user := storage.user_by_name ("test_delete")
-- across 1 |..| 10 as c loop
-- l_node := custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out)
-- l_node.set_author (l_user)
-- storage.new_node (l_node)
-- end
-- assert ("Exist node id: 10", attached storage.node_by_id (10) as ll_node and then ll_node.title ~ "Title_10" )
-- storage.delete_node_by_id (10)
-- assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
-- end
end

View File

@@ -10,6 +10,7 @@
<library name="cms" location="..\..\..\..\cms-safe.ecf" readonly="false"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="model" location="..\..\..\model\cms_model-safe.ecf"/>
<library name="module_node" location="..\..\..\..\modules\node\node-safe.ecf"/>
<library name="persitence_mysql" location="..\persistence_mysql-safe.ecf" readonly="false"/>
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
@@ -18,6 +19,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
<exclude>/nodes$</exclude>
</file_rule>
</cluster>
</target>

View File

@@ -75,11 +75,11 @@ feature -- Test routines
connection.begin_transaction
u.set_email ("test@example.com")
assert ("Has user:", storage.user_by_email ("test@example.com") /= Void)
storage.new_node (default_node)
assert ("Has one node:", storage.nodes_count = 1)
-- storage.new_node (default_node)
-- assert ("Has one node:", storage.nodes_count = 1)
connection.rollback
assert ("Not has user:", storage.user_by_email ("test@example.com") = Void)
assert ("Has no node:", storage.nodes_count = 0)
-- assert ("Has no node:", storage.nodes_count = 0)
end
end

View File

@@ -41,8 +41,9 @@ feature {NONE} -- Fixture Factories: Nodes
Result := custom_node ("Default content", "default summary", "Default")
end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_PAGE
do
create Result.make (a_content, a_summary, a_title)
create Result.make (a_title)
Result.set_content (a_content, a_summary, Void)
end
end

View File

@@ -47,30 +47,62 @@ feature -- Factory
initialize (a_setup: CMS_SETUP; a_storage: CMS_STORAGE_STORE_SQL)
local
u: CMS_USER
r: CMS_USER_ROLE
l_anonymous_role, l_authenticated_role, r: CMS_USER_ROLE
l_roles: LIST [CMS_USER_ROLE]
do
-- Schema
--| Schema
a_storage.sql_execute_file_script (a_setup.environment.path.extended ("scripts").extended ("core.sql"))
-- Data
-- Users
--| Roles
create l_anonymous_role.make ("anonymous")
a_storage.save_user_role (l_anonymous_role)
create l_authenticated_role.make ("authenticated")
a_storage.save_user_role (l_authenticated_role)
--| Users
create u.make ("admin")
u.set_password ("istrator#")
u.set_email (a_setup.site_email)
a_storage.new_user (u)
-- Roles
create r.make ("anonymous")
a_storage.save_user_role (r)
create r.make ("authenticated")
r.add_permission ("create page")
r.add_permission ("edit page")
--| Node
-- FIXME: move that initialization to node module
l_anonymous_role.add_permission ("view any page")
a_storage.save_user_role (l_anonymous_role)
l_authenticated_role.add_permission ("create page")
l_authenticated_role.add_permission ("view any page")
l_authenticated_role.add_permission ("edit own page")
l_authenticated_role.add_permission ("delete own page")
a_storage.save_user_role (l_authenticated_role)
--| For testing purpose, to be removed later.
-- Roles, view role for testing.
create r.make ("view")
r.add_permission ("view page")
a_storage.save_user_role (r)
-- Test custom value
create {ARRAYED_LIST [CMS_USER_ROLE]} l_roles.make (1)
l_roles.force (r)
a_storage.set_custom_value ("abc", "123", "test")
a_storage.set_custom_value ("abc", "OK", "test")
create u.make ("auth")
u.set_password ("enticated#")
u.set_email (a_setup.site_email)
a_storage.new_user (u)
create u.make ("test")
u.set_password ("test#")
u.set_email (a_setup.site_email)
a_storage.new_user (u)
create u.make ("view")
u.set_password ("only#")
u.set_email (a_setup.site_email)
u.set_roles (l_roles)
a_storage.new_user (u)
end
end

View File

@@ -167,107 +167,107 @@ feature -- Test routines
assert ("Valid password", storage.is_valid_credential ("test", "password"))
end
test_recent_nodes_empty
do
assert ("No recent nodes", storage.recent_nodes (0, 10).is_empty)
end
-- test_recent_nodes_empty
-- do
-- assert ("No recent nodes", storage.recent_nodes (0, 10).is_empty)
-- end
test_recent_nodes
local
l_nodes: LIST[CMS_NODE]
do
across 1 |..| 10 as c loop
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
l_nodes := storage.recent_nodes (0, 10)
assert ("10 recent nodes", l_nodes.count = 10)
assert ("First node id=10", l_nodes.first.id = 10)
assert ("Last node id=1", l_nodes.last.id = 1)
-- test_recent_nodes
-- local
-- l_nodes: LIST[CMS_NODE]
-- do
-- across 1 |..| 10 as c loop
-- storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
-- end
-- l_nodes := storage.recent_nodes (0, 10)
-- assert ("10 recent nodes", l_nodes.count = 10)
-- assert ("First node id=10", l_nodes.first.id = 10)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (5, 10)
assert ("5 recent nodes", l_nodes.count = 5)
assert ("First node id=5", l_nodes.first.id = 5)
assert ("Last node id=1", l_nodes.last.id = 1)
-- l_nodes := storage.recent_nodes (5, 10)
-- assert ("5 recent nodes", l_nodes.count = 5)
-- assert ("First node id=5", l_nodes.first.id = 5)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (9, 10)
assert ("1 recent nodes", l_nodes.count = 1)
assert ("First node id=1", l_nodes.first.id = 1)
assert ("Last node id=1", l_nodes.last.id = 1)
-- l_nodes := storage.recent_nodes (9, 10)
-- assert ("1 recent nodes", l_nodes.count = 1)
-- assert ("First node id=1", l_nodes.first.id = 1)
-- assert ("Last node id=1", l_nodes.last.id = 1)
l_nodes := storage.recent_nodes (10, 10)
assert ("Is empty", l_nodes.is_empty)
end
-- l_nodes := storage.recent_nodes (10, 10)
-- assert ("Is empty", l_nodes.is_empty)
-- end
test_node_does_not_exist
do
across 1 |..| 10 as c loop
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
end
-- test_node_does_not_exist
-- do
-- across 1 |..| 10 as c loop
-- storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
-- end
-- assert ("Not exist node id: 12", storage.node_by_id (12) = Void)
-- end
test_node
do
across 1 |..| 10 as c loop
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("has nodes", storage.nodes.count > 5)
assert ("Node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
end
-- test_node
-- do
-- across 1 |..| 10 as c loop
-- storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
-- end
-- assert ("has nodes", storage.nodes.count > 5)
-- assert ("Node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
-- end
test_update_node
local
l_node: CMS_NODE
do
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
l_node := ll_node.twin
l_node.set_content ("New Content")
l_node.set_summary ("New Summary")
l_node.set_title("New Title")
-- test_update_node
-- local
-- l_node: CMS_NODE
-- do
-- storage.new_node (custom_node ("Content", "Summary", "Title"))
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- l_node := ll_node.twin
-- l_node.set_content ("New Content")
-- l_node.set_summary ("New Summary")
-- l_node.set_title("New Title")
-- storage.update_node (l_node)
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
end
end
---- storage.update_node (l_node)
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then not (u_node.content ~ ll_node.content) and then not (u_node.summary ~ ll_node.summary))
-- end
-- end
test_update_node_title
do
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_title (ll_node.id, "New Title")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_title
-- do
-- storage.new_node (custom_node ("Content", "Summary", "Title"))
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
---- storage.update_node_title (ll_node.id, "New Title")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then not (u_node.title ~ ll_node.title) and then u_node.content ~ ll_node.content and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_update_node_summary
do
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_summary (ll_node.id, "New Summary")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
end
end
-- test_update_node_summary
-- do
-- storage.new_node (custom_node ("Content", "Summary", "Title"))
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
---- storage.update_node_summary (ll_node.id, "New Summary")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then u_node.content ~ ll_node.content and then not (u_node.summary ~ ll_node.summary))
-- end
-- end
test_update_node_content
do
storage.new_node (custom_node ("Content", "Summary", "Title"))
if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
-- storage.update_node_content (ll_node.id, "New Content")
assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
end
end
-- test_update_node_content
-- do
-- storage.new_node (custom_node ("Content", "Summary", "Title"))
-- if attached {CMS_NODE} storage.node_by_id (1) as ll_node then
---- storage.update_node_content (ll_node.id, "New Content")
-- assert ("Updated", attached {CMS_NODE} storage.node_by_id (1) as u_node and then u_node.title ~ ll_node.title and then not (u_node.content ~ ll_node.content) and then u_node.summary ~ ll_node.summary)
-- end
-- end
test_delete_node
do
across 1 |..| 10 as c loop
storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
end
assert ("Exist node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
storage.delete_node_by_id (10)
assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
end
-- test_delete_node
-- do
-- across 1 |..| 10 as c loop
-- storage.new_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
-- end
-- assert ("Exist node id: 10", attached storage.node_by_id (10) as l_node and then l_node.title ~ "Title_10" )
-- storage.delete_node_by_id (10)
-- assert ("Not exist node id: 10", storage.node_by_id (10) = Void)
-- end
end

View File

@@ -10,6 +10,7 @@
<library name="cms" location="..\..\..\..\cms-safe.ecf" readonly="false"/>
<library name="crypto" location="$ISE_LIBRARY\unstable\library\text\encryption\crypto\crypto-safe.ecf"/>
<library name="model" location="..\..\..\model\cms_model-safe.ecf"/>
<library name="module_node" location="..\..\..\..\modules\node\node-safe.ecf"/>
<library name="persitence_sqlite" location="..\persistence_sqlite-safe.ecf" readonly="false"/>
<library name="process" location="$ISE_LIBRARY\library\process\process-safe.ecf"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
@@ -18,6 +19,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/CVS$</exclude>
<exclude>/.svn$</exclude>
<exclude>/nodes$</exclude>
</file_rule>
</cluster>
</target>

View File

@@ -38,17 +38,18 @@ feature {NONE} -- Fixture Factory: Users
Result.set_email (a_email)
end
feature {NONE} -- Fixture Factories: Nodes
--feature {NONE} -- Fixture Factories: Nodes
default_node: CMS_NODE
do
Result := custom_node ("Default content", "default summary", "Default")
end
-- default_node: CMS_NODE
-- do
-- Result := custom_node ("Default content", "default summary", "Default")
-- end
custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_NODE
do
create Result.make (a_content, a_summary, a_title)
end
-- custom_node (a_content, a_summary, a_title: READABLE_STRING_32): CMS_PAGE
-- do
-- create Result.make (a_title)
-- Result.set_content (a_content, a_summary, Void)
-- end
end

View File

@@ -249,6 +249,29 @@ feature -- Access: Node
end
end
is_author_of_node (u: CMS_USER; a_node: CMS_NODE): BOOLEAN
-- Is the user `u' owner of the node `n'.
do
if attached node_storage.node_author (a_node.id) as l_author then
Result := u.same_as (l_author)
end
end
feature -- Permission Scope: Node
permission_scope (u: detachable CMS_USER; a_node: CMS_NODE): STRING
-- Result 'own' if the user `u' is the owner of the node `a_node', in other case
-- `any'.
do
-- FIXME: check if this is ok, since a role may have "any" permission enabled, and "own" disabled,
-- in this case, we should check both permissions
-- obviously such case should be rare, and look like bad configured permissions, but this may occurs.
Result := "any"
if u /= Void and then is_author_of_node (u, a_node) then
Result := "own"
end
end
feature -- Change: Node
save_node (a_node: CMS_NODE)
@@ -279,32 +302,16 @@ feature -- Change: Node
node_storage.update_node (a_node)
end
-- update_node_title (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_title: READABLE_STRING_32)
-- -- Update node title, with user identified by `a_id', with node id `a_node_id' and a new title `a_title'.
-- do
-- debug ("refactor_fixme")
-- fixme ("Check preconditions")
-- end
-- node_storage.update_node_title (a_user_id, a_node_id, a_title)
-- end
-- update_node_summary (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_summary: READABLE_STRING_32)
-- -- Update node summary, with user identified by `a_user_id', with node id `a_node_id' and a new summary `a_summary'.
-- do
-- debug ("refactor_fixme")
-- fixme ("Check preconditions")
-- end
-- node_storage.update_node_summary (a_user_id, a_node_id, a_summary)
-- end
feature -- Node status
-- update_node_content (a_user_id: like {CMS_USER}.id; a_node_id: like {CMS_NODE}.id; a_content: READABLE_STRING_32)
-- -- Update node content, with user identified by `a_user_id', with node id `a_node_id' and a new content `a_content'.
-- do
-- debug ("refactor_fixme")
-- fixme ("Check preconditions")
-- end
-- node_storage.update_node_content (a_user_id, a_node_id, a_content)
-- end
Not_published: INTEGER = 0
-- The node is not published.
Published: INTEGER = 1
-- The node is published.
Trashed: INTEGER = -1
-- The node is trashed (soft delete), ready to be deleted/destroyed from storage.
end

View File

@@ -13,10 +13,6 @@ inherit
REFACTORING_HELPER
--create
-- make,
-- make_empty
feature{NONE} -- Initialization
make_empty
@@ -35,10 +31,7 @@ feature{NONE} -- Initialization
set_creation_date (l_time)
set_modification_date (l_time)
set_publication_date (l_time)
debug ("refactor_fixme")
fixme ("Remove default harcoded format")
end
mark_not_published
ensure
title_set: title = a_title
end
@@ -60,6 +53,7 @@ feature -- Conversion
a_node.summary,
a_node.format
)
set_status (a_node.status)
end
feature -- Access
@@ -78,6 +72,12 @@ feature -- Access
deferred
end
status: INTEGER
-- Associated status for the current node.
-- default: {CMS_NODE_API}.Not_Published}
-- {CMS_NODE_API}.Published
-- {CMS_NODE_API}.Trashed
feature -- Access
title: READABLE_STRING_32
@@ -211,6 +211,41 @@ feature -- Element change
auther_set: author = u
end
mark_not_published
-- Set status to not_published.
do
set_status ({CMS_NODE_API}.not_published)
ensure
status_not_published: status = {CMS_NODE_API}.not_published
end
mark_published
-- Set status to published.
do
set_status ({CMS_NODE_API}.published)
ensure
status_published: status = {CMS_NODE_API}.published
end
mark_trashed
-- Set status to published
do
set_status ({CMS_NODE_API}.trashed)
ensure
status_trash: status = {CMS_NODE_API}.trashed
end
feature {CMS_NODE_STORAGE_I} -- Access: status change.
set_status (a_status: like status)
-- Assign `status' with `a_status'.
do
status := a_status
ensure
status_set: status = a_status
end
note
copyright: "2011-2015, Javier Velilla, Jocelyn Fiat, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"

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
if has_permission ("edit " + l_type.name) then
if has_permission ("edit " + node_api.permission_scope (current_user (request), l_node) + " " + l_type.name) then
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
if request.is_post_request_method then
f.validation_actions.extend (agent edit_form_validate (?, b))
@@ -82,7 +82,7 @@ feature -- Execution
attached {WSF_STRING} request.path_parameter ("type") as p_type and then
attached node_api.node_type (p_type.value) as l_type
then
if has_permission ("create " + l_type.name) then
if has_permission ("create " + l_type.name) then
if attached l_type.new_node (Void) as l_node then
f := edit_form (l_node, url (request.path_info, Void), "edit-" + l_type.name, l_type)
if request.is_post_request_method then
@@ -228,6 +228,15 @@ feature -- Form
ts.set_default_value ("Preview")
f.extend (ts)
if a_node /= Void and then a_node.id > 0 and then has_permission ("delete " + a_name) then
create ts.make ("op")
ts.set_default_value ("Delete")
fixme ("[
ts.set_default_value (i18n ("Delete"))i18n or other name such as "translated" or "translation
]")
f.extend (ts)
end
Result := f
end

View File

@@ -114,12 +114,20 @@ feature -- HTTP Methods
local
edit_response: NODE_FORM_RESPONSE
do
fixme ("Refactor code: extract methods: edit_node and add_node")
if req.path_info.ends_with_general ("/edit") then
if
attached {WSF_STRING} req.form_parameter ("op") as l_op and then
l_op.value.same_string ("Delete")
then
do_delete (req, res)
else
create edit_response.make (req, res, api, node_api)
edit_response.execute
end
elseif req.path_info.starts_with_general ("/node/add/") then
create edit_response.make (req, res, api, node_api)
edit_response.execute
-- elseif req.path_info.same_string_general ("/node/") then
-- create edit_response.make (req, res, api, node_api)
-- edit_response.execute
else
to_implement ("REST API")
send_not_implemented ("REST API not yet implemented", req, res)
@@ -142,11 +150,12 @@ feature -- HTTP Methods
l_id.is_integer and then
attached node_api.node (l_id.integer_value) as l_node
then
if api.user_has_permission (l_user, "delete " + l_node.content_type) then
if api.user_has_permission (l_user, "delete " + node_api.permission_scope (l_user, l_node) + " " + l_node.content_type) then
node_api.delete_node (l_node)
res.send (create {CMS_REDIRECTION_RESPONSE_MESSAGE}.make (req.absolute_script_url ("")))
else
send_access_denied (req, res)
-- send_not_authorized ?
end
else
do_error (req, res, l_id)

View File

@@ -108,8 +108,8 @@ feature -- Access
error_handler.reset
write_information_log (generator + ".node_author")
create l_parameters.make (1)
l_parameters.put (a_id, "node_id")
sql_query (select_node_author, l_parameters)
l_parameters.put (a_id, "nid")
sql_query (Select_user_author, l_parameters)
if sql_rows_count >= 1 then
Result := fetch_author
end
@@ -144,11 +144,15 @@ feature -- Change: Node
-- Remove node by id `a_id'.
local
l_parameters: STRING_TABLE [ANY]
l_time: DATE_TIME
do
create l_time.make_now_utc
write_information_log (generator + ".delete_node")
error_handler.reset
create l_parameters.make (1)
l_parameters.put (l_time, "changed")
l_parameters.put ({CMS_NODE_API}.trashed, "status")
l_parameters.put (a_id, "nid")
sql_change (sql_delete_node, l_parameters)
end
@@ -209,7 +213,7 @@ feature {NONE} -- Implementation
error_handler.reset
write_information_log (generator + ".store_node")
create l_parameters.make (8)
create l_parameters.make (9)
l_parameters.put (a_node.content_type, "type")
l_parameters.put (a_node.title, "title")
l_parameters.put (a_node.summary, "summary")
@@ -217,6 +221,7 @@ feature {NONE} -- Implementation
l_parameters.put (a_node.format, "format")
l_parameters.put (a_node.publication_date, "publish")
l_parameters.put (now, "changed")
l_parameters.put (a_node.status, "status")
if attached a_node.author as l_author then
check valid_author: l_author.has_id end
l_parameters.put (l_author.id, "author")
@@ -260,24 +265,28 @@ feature -- Helpers
feature {NONE} -- Queries
sql_select_nodes_count: STRING = "SELECT count(*) from Nodes;"
sql_select_nodes_count: STRING = "SELECT count(*) FROM Nodes WHERE status != -1 ;"
-- Nodes count (Published and not Published)
--| note: {CMS_NODE_API}.trashed = -1
sql_select_nodes: STRING = "SELECT * from Nodes;"
sql_select_nodes: STRING = "SELECT * FROM Nodes WHERE status != -1 ;"
-- SQL Query to retrieve all nodes.
--| note: {CMS_NODE_API}.trashed = -1
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
sql_select_node_by_id: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes WHERE nid =:nid ORDER BY revision desc, publish desc LIMIT 1;"
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
sql_select_recent_nodes: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed, status FROM Nodes ORDER BY nid desc, publish desc LIMIT :rows OFFSET :offset ;"
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :author);"
sql_insert_node: STRING = "INSERT INTO nodes (revision, type, title, summary, content, format, publish, created, changed, status, author) VALUES (1, :type, :title, :summary, :content, :format, :publish, :created, :changed, :status, :author);"
-- SQL Insert to add a new node.
sql_update_node : STRING = "UPDATE nodes SET revision = revision, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, 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;"
-- FIXME: for now no revision inc.!
-- sql_update_node : STRING = "UPDATE nodes SET revision = revision + 1, type=:type, title=:title, summary=:summary, content=:content, format=:format, publish=:publish, changed=:changed, revision = revision + 1, author=:author WHERE nid=:nid;"
-- SQL node.
sql_delete_node: STRING = "DELETE FROM nodes WHERE nid=:nid;"
sql_delete_node: STRING = "UPDATE nodes SET changed=:changed, status =:status WHERE nid=:nid"
-- Soft deletion with free metadata.
-- sql_update_node_author: STRING = "UPDATE nodes SET author=:author WHERE nid=:nid;"
@@ -294,7 +303,7 @@ feature {NONE} -- Queries
feature {NONE} -- Sql Queries: USER_ROLES collaborators, author
Select_user_author: STRING = "SELECT uid, name, password, salt, email, status, created, signed FROM Nodes INNER JOIN users ON nodes.author=users.uid AND users.uid = :uid;"
Select_user_author: STRING = "SELECT uid, name, password, salt, email, users.status, users.created, signed FROM Nodes INNER JOIN users ON nodes.author=users.uid AND nodes.nid = :nid;"
Select_node_author: STRING = "SELECT nid, revision, type, title, summary, content, format, author, publish, created, changed FROM users INNER JOIN nodes ON nodes.author=users.uid AND nodes.nid =:nid;"
@@ -335,6 +344,9 @@ feature {NONE} -- Implementation
if attached sql_read_date_time (11) as l_modif_date then
Result.set_modification_date (l_modif_date)
end
if attached sql_read_integer_32 (12) as l_status then
Result.set_status (l_status)
end
end
end

View File

@@ -182,6 +182,7 @@ feature -- Permission
has_permission (a_permission: READABLE_STRING_GENERAL): BOOLEAN
-- Does current user has permission `a_permission' ?
do
api.logger.put_information (generator + ".has_permission", a_permission)
Result := user_has_permission (current_user (request), a_permission)
end