diff --git a/persistence/implementation/common/cms_storage_null.e b/persistence/implementation/common/cms_storage_null.e index 0917b13..88b12cb 100644 --- a/persistence/implementation/common/cms_storage_null.e +++ b/persistence/implementation/common/cms_storage_null.e @@ -41,6 +41,18 @@ feature -- Access: user do end +feature -- User Nodes + + user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is a collaborator. + do + end + + user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is the author. + do + end + feature -- Change: user save_user (a_user: CMS_USER) @@ -48,6 +60,24 @@ feature -- Change: user do end +feature -- Access: roles and permissions + + user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE + do + end + + user_roles: LIST [CMS_USER_ROLE] + do + end + + +feature -- Change: roles and permissions + + save_user_role (a_user_role: CMS_USER_ROLE) + do + end + + feature -- Access: node nodes: LIST[CMS_NODE] @@ -63,10 +93,19 @@ feature -- Access: node end node (a_id: INTEGER_64): detachable CMS_NODE - -- + -- do end + node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER + -- Node's author. if any. + do + end + + node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] + -- Possible list of node's collaborator. + do + end feature -- Node @@ -76,22 +115,37 @@ feature -- Node end delete_node (a_id: INTEGER_64) + -- do end update_node (a_node: CMS_NODE) + -- do end update_node_title (a_id: INTEGER_64; a_title: READABLE_STRING_32) + -- do end update_node_summary (a_id: INTEGER_64; a_summary: READABLE_STRING_32) + -- do end update_node_content (a_id: INTEGER_64; a_content: READABLE_STRING_32) + -- + do + end + + add_node_author (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add author `a_user_id' to the node `a_node_id'. + do + end + + add_node_collaborator (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add/Update collaborator with `a_user_id' to the node `a_node_id'. do end diff --git a/persistence/implementation/mysql/scripts/triggers.sql b/persistence/implementation/mysql/scripts/triggers.sql new file mode 100644 index 0000000..b3e10a4 --- /dev/null +++ b/persistence/implementation/mysql/scripts/triggers.sql @@ -0,0 +1,8 @@ +DELIMITER $$ +CREATE TRIGGER update_editor +AFTER INSERT ON `users_nodes` FOR EACH ROW + UPDATE Nodes + SET editor_id = NEW.users_id + WHERE id = NEW.nodes_id; +$$ +DELIMITER ; \ No newline at end of file diff --git a/persistence/implementation/mysql/src/cms_storage_mysql.e b/persistence/implementation/mysql/src/cms_storage_mysql.e index b134f72..0470fa7 100644 --- a/persistence/implementation/mysql/src/cms_storage_mysql.e +++ b/persistence/implementation/mysql/src/cms_storage_mysql.e @@ -85,6 +85,42 @@ feature -- Access: user post_user_provider_execution end +feature -- User Nodes + + user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is a collaborator. + do + fixme ("Not implemented!!!") + create {ARRAYED_LIST[CMS_NODE]} Result.make (0) + end + + user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is the author. + do + fixme ("Not implemented!!!") + create {ARRAYED_LIST[CMS_NODE]} Result.make (0) + end + +feature -- Access: roles and permissions + + user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE + do + fixme ("Not Implemented!!!") + end + + user_roles: LIST [CMS_USER_ROLE] + do + fixme ("Not Implemented!!!") + create {ARRAYED_LIST[CMS_USER_ROLE]} Result.make (0) + end + +feature -- Change: roles and permissions + + save_user_role (a_user_role: CMS_USER_ROLE) + do + fixme ("Not Implemented!!!") + end + feature -- Change: user save_user (a_user: CMS_USER) @@ -123,13 +159,27 @@ feature -- Access: node end node (a_id: INTEGER_64): detachable CMS_NODE - -- + -- do Result := node_provider.node (a_id) post_node_provider_execution end + node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER + -- + do + fixme ("Not implemented") + end + + node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] + -- Possible list of node's collaborator. + do + fixme ("Not implemented") + create {ARRAYED_LIST[CMS_USER]} Result.make (0) + end + + feature -- Node save_node (a_node: CMS_NODE) @@ -170,6 +220,18 @@ feature -- Node end + add_node_author (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add author `a_user_id' to the node `a_node_id'. + do + fixme ("Not Implemented") + end + + add_node_collaborator (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add/Update collaborator with `a_user_id' to the node `a_node_id'. + do + fixme ("Not implemented") + end + feature -- User new_user (a_user: CMS_USER) diff --git a/persistence/implementation/mysql/src/provider/node_data_provider.e b/persistence/implementation/mysql/src/provider/node_data_provider.e index 7b63544..525b118 100644 --- a/persistence/implementation/mysql/src/provider/node_data_provider.e +++ b/persistence/implementation/mysql/src/provider/node_data_provider.e @@ -227,12 +227,12 @@ feature -- Basic Operations: User_Nodes post_execution end - user_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE] + author_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE] -- List of Nodes for the given user `a_id'. (the user is the author of the node) local l_parameters: STRING_TABLE [ANY] do - log.write_information (generator + ".user_nodes") + log.write_information (generator + ".author_nodes") create l_parameters.make (1) l_parameters.put (a_id, "user_id") db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_author, l_parameters)) @@ -241,6 +241,21 @@ feature -- Basic Operations: User_Nodes post_execution end + collaborator_nodes (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [CMS_NODE] + -- List of Nodes for the given user `a_id' as collaborator. + local + l_parameters: STRING_TABLE [ANY] + do + log.write_information (generator + ".collaborator_nodes") + create l_parameters.make (1) + l_parameters.put (a_id, "user_id") + db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_collaborator, l_parameters)) + db_handler.execute_query + create Result.make (db_handler, agent fetch_node) + post_execution + end + + node_author (a_id: INTEGER_64): detachable CMS_USER -- Node's author for the given node id. local @@ -303,13 +318,13 @@ feature {NONE} -- Queries SQL_Insert_node: STRING = "insert into nodes (title, summary, content, publication_date, creation_date, modification_date) values (:title, :summary, :content, :publication_date, :creation_date, :modification_date);" -- SQL Insert to add a new node. - SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date where id=:id;" + SQL_Update_node_title: STRING ="update nodes SET title=:title, modification_date=:modification_date, version = version + 1 where id=:id;" -- SQL update node title. - SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date where id=:id;" + SQL_Update_node_summary: STRING ="update nodes SET summary=:summary, modification_date=:modification_date, version = version + 1 where id=:id;" -- SQL update node summary. - SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date where id=:id;" + SQL_Update_node_content: STRING ="update nodes SET content=:content, modification_date=:modification_date, version = version + 1 where id=:id;" -- SQL node content. SQL_Update_node : STRING = "update nodes SET title=:title, summary=:summary, content=:content, publication_date=:publication_date, creation_date=:creation_date, modification_date=:modification_date where id=:id;" @@ -323,11 +338,13 @@ feature {NONE} -- Sql Queries: USER_ROLES collaborators, author Sql_insert_users_nodes: STRING = "insert into users_nodes (users_id, nodes_id) values (:users_id, :nodes_id);" - select_node_collaborators: STRING = "SELECT * FROM Users INNER JOIN users_nodes ON users.id=users_nodes.users_id and users_nodes.nodes_id = :nodes_id;" + select_node_collaborators: STRING = "SELECT * FROM Users INNER JOIN users_nodes ON users.id=users_nodes.users_id and users_nodes.nodes_id = :node_id;" Select_user_author: STRING = "SELECT * FROM Nodes INNER JOIN users ON nodes.author_id=users.id and users.id = :user_id;" - Select_node_author: STRING = "SELECT * FROM User INNER JOIN nodes ON nodes.author_id=users.id and node_id =:node_id;" + Select_node_author: STRING = "SELECT * FROM Users INNER JOIN nodes ON nodes.author_id=users.id and nodes.id =:node_id;" + + Select_user_collaborator: STRING = "SELECT * FROM Nodes INNER JOIN users_nodes ON users_nodes.nodes_id = nodes.id and users_nodes.users_id = :user_id;" feature -- diff --git a/persistence/implementation/mysql/tests/application.e b/persistence/implementation/mysql/tests/application.e index 04417b4..03f877f 100644 --- a/persistence/implementation/mysql/tests/application.e +++ b/persistence/implementation/mysql/tests/application.e @@ -65,6 +65,14 @@ feature {NONE} -- Initialization end + if attached user.user_by_name ("u1") as ll_user then + node.add_author (ll_user.id, 1) + if attached node.node_author (1) as l_author then + print (l_author.name) + end + end + + end end diff --git a/persistence/implementation/mysql/tests/nodes/node_test_set.e b/persistence/implementation/mysql/tests/nodes/node_test_set.e index adc87b4..3b6713e 100644 --- a/persistence/implementation/mysql/tests/nodes/node_test_set.e +++ b/persistence/implementation/mysql/tests/nodes/node_test_set.e @@ -203,22 +203,33 @@ feature -- Test routines node_provider.new_node (default_node) user_provider.new_user ("u1", "u1", "email") if attached user_provider.user_by_name ("u1") as l_user then - assert ("Empty nodes", node_provider.user_nodes (l_user.id).after) + assert ("Empty nodes", node_provider.author_nodes (l_user.id).after) end end - test_new_node_add_author do node_provider.new_node (default_node) + assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1)) user_provider.new_user ("u1", "u1", "email") if attached user_provider.user_by_name ("u1") as l_user then - node_provider.add_collaborator (l_user.id, 1) - assert ("Not Empty nodes", not node_provider.node_collaborators (1).after) + node_provider.add_author (l_user.id, 1) + assert ("Author not void for node 1", attached node_provider.node_author (1)) end end - test_multiple_nodes_add_author + test_new_node_add_collaborator + do + node_provider.new_node (default_node) + assert ("Exist node with id 1", attached {CMS_NODE} node_provider.node (1)) + user_provider.new_user ("u1", "u1", "email") + if attached user_provider.user_by_name ("u1") as l_user then + node_provider.add_collaborator (l_user.id, 1) + assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after) + end + end + + test_multiple_nodes_add_collaborator local l_list: LIST[CMS_NODE] do @@ -233,6 +244,33 @@ feature -- Test routines node_provider.add_collaborator (l_user.id, 2) node_provider.add_collaborator (l_user.id, 3) node_provider.add_collaborator (l_user.id, 4) + assert ("Not Empty Collaborator for node 1", not node_provider.node_collaborators (1).after) + assert ("Not Empty Collaborator for node 2", not node_provider.node_collaborators (2).after) + assert ("Not Empty Collaborator for node 3", not node_provider.node_collaborators (3).after) + assert ("Not Empty Collaborator for node 4", not node_provider.node_collaborators (4).after) + end + end + + test_nodes_collaborator + local + l_list: LIST[CMS_NODE] + do + create {ARRAYED_LIST[CMS_NODE]} l_list.make (0) + node_provider.new_node (default_node) + node_provider.new_node (custom_node ("content1", "summary1", "title1")) + node_provider.new_node (custom_node ("content2", "summary2", "title2")) + node_provider.new_node (custom_node ("content3", "summary3", "title3")) + user_provider.new_user ("u1", "u1", "email") + if attached user_provider.user_by_name ("u1") as l_user then + node_provider.add_collaborator (l_user.id, 1) + node_provider.add_collaborator (l_user.id, 2) + node_provider.add_collaborator (l_user.id, 3) + node_provider.add_collaborator (l_user.id, 4) + across node_provider.collaborator_nodes (l_user.id) as c loop + l_list.force (c.item) + end + + assert ("User is collaborating in 4 nodes", l_list.count = 4) end end diff --git a/persistence/interface/cms_storage.e b/persistence/interface/cms_storage.e index 22ea3a1..d93f64b 100644 --- a/persistence/interface/cms_storage.e +++ b/persistence/interface/cms_storage.e @@ -59,6 +59,22 @@ feature -- Access: user deferred end +feature -- User Nodes + + user_collaborator_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is a collaborator. + require + a_id > 0 + deferred + end + + user_author_nodes (a_id: like {CMS_USER}.id): LIST[CMS_NODE] + -- Possible list of nodes where the user identified by `a_id', is the author. + require + a_id > 0 + deferred + end + feature -- Change: user save_user (a_user: CMS_USER) @@ -67,14 +83,14 @@ feature -- Change: user feature -- Access: roles and permissions --- user_has_permission (u: detachable CMS_USER; s: detachable READABLE_STRING_8): BOOLEAN --- -- Anonymous or user `u' has permission for `s' ? --- --| `s' could be "create page", --- do + user_has_permission (u: detachable CMS_USER; s: detachable READABLE_STRING_8): BOOLEAN + -- Anonymous or user `u' has permission for `s' ? + --| `s' could be "create page", + do -- if s = Void then -- Result := True -- elseif u = Void then --- Result := user_role_has_permission (anonymous_user_role, s) +---- Result := user_role_has_permission (anonymous_user_role, s) -- else -- Result := user_role_has_permission (authenticated_user_role, s) -- if not Result and attached u.roles as l_roles then @@ -89,44 +105,26 @@ feature -- Access: roles and permissions -- end -- end -- end --- end + end --- anonymous_user_role: CMS_USER_ROLE --- do --- if attached user_role_by_id (1) as l_anonymous then --- Result := l_anonymous --- else --- create Result.make ("anonymous") --- end --- end + user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN + do + Result := a_role.has_permission (s) + end --- authenticated_user_role: CMS_USER_ROLE --- do --- if attached user_role_by_id (2) as l_authenticated then --- Result := l_authenticated --- else --- create Result.make ("authenticated") --- end --- end + user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE + deferred + end --- user_role_has_permission (a_role: CMS_USER_ROLE; s: READABLE_STRING_8): BOOLEAN --- do --- Result := a_role.has_permission (s) --- end - --- user_role_by_id (a_id: like {CMS_USER_ROLE}.id): detachable CMS_USER_ROLE --- deferred --- end - --- user_roles: LIST [CMS_USER_ROLE] --- deferred --- end + user_roles: LIST [CMS_USER_ROLE] + deferred + end feature -- Change: roles and permissions --- save_user_role (a_user_role: CMS_USER_ROLE) --- deferred --- end + save_user_role (a_user_role: CMS_USER_ROLE) + deferred + end feature -- Email @@ -153,6 +151,7 @@ feature -- Email feature -- Access: Node recent_nodes (a_lower: INTEGER; a_count: INTEGER): LIST [CMS_NODE] + -- List of recent `a_count' nodes with an offset of `lower'. deferred end @@ -163,6 +162,19 @@ feature -- Access: Node deferred end + node_author (a_id: like {CMS_NODE}.id): detachable CMS_USER + -- Node's author. if any. + require + valid_node: a_id >0 + deferred + end + + node_collaborators (a_id: like {CMS_NODE}.id): LIST [CMS_USER] + -- Possible list of node's collaborator. + require + valid_node: a_id > 0 + deferred + end feature -- Change: Node @@ -207,9 +219,21 @@ feature -- Change: Node deferred end + add_node_author (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add author `a_user_id' to the node `a_node_id'. + require + valid_node: a_node_id > 0 + valid_user: a_user_id > 0 + deferred + end - - + add_node_collaborator (a_node_id: like {CMS_NODE}.id; a_user_id: like {CMS_USER}.id) + -- Add/Update collaborator with `a_user_id' to the node `a_node_id'. + require + valid_node: a_node_id > 0 + valid_user: a_user_id > 0 + deferred + end --feature -- Misc