indexing description: "Provide an interface to community data." author: "Marco Zietzling " date: "$Date$" revision: "$Revision$" class COMMUNITY_INTERFACE inherit BASE_INTERFACE redefine make end create make feature {NONE} -- Initialization make (a_node: like node; a_db_handler: like db_handler; a_policy_cache: like policy_cache) is -- Initialize. do Precursor (a_node, a_db_handler, a_policy_cache) end feature -- Commands community_create (a_msg: O_MESSAGE) is -- Create a new community according to a_msg. require a_msg_ok: a_msg /= Void local l_create_msg: O_COMMUNITY_CREATE_MESSAGE l_community: COMMUNITY l_status: O_GENERAL_STATUS_MESSAGE l_name: STRING l_creator: USER do l_create_msg ?= a_msg check valid_message: l_create_msg /= Void end l_name := l_create_msg.name.out -- l_name.to_lower create l_community.make l_community.set_name (l_name) l_community.set_description (l_create_msg.description) l_community.set_logo ("no") community_access.retrieve_community_by_name (l_name) if community_access.is_found then create l_status.make (False, err_community_name_already_used) else -- add creator as admin user_access.retrieve_user_by_session (l_create_msg.session) if user_access.is_found then l_creator := user_access.last_user community_access.insert_community (l_community) user_access.update_user_community_association (community_access.last_insert_id, l_creator.user_id, 6) -- retrieve the user and team associations and add them to the cache in case the user was logged in policy_cache.retrieve_associations (l_creator.user_id) create l_status.make (True, Void) else create l_status.make (False, err_invalid_session) end end node.send_message_reply (l_status, a_msg) end community_list (a_msg: O_MESSAGE) is -- List all existing communities. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_LIST_MESSAGE l_reply: O_COMMUNITY_LIST_REPLY_MESSAGE l_list: LIST [COMMUNITY] l_communities: DS_ARRAYED_LIST [STRING] l_community: COMMUNITY l_status: O_GENERAL_STATUS_MESSAGE do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then -- retrieve communities and map them into a DS_ARRAYED_LIST community_access.retrieve_all_communities from l_list := community_access.last_community_list create l_communities.make (l_list.count) l_list.start until l_list.after loop l_community := l_list.item l_communities.force_last (l_community.name) l_list.forth end create l_reply.make (l_communities) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_retrieve (a_msg: O_MESSAGE) is -- Retrieve detailed information about a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_RETRIEVE_MESSAGE l_reply: O_COMMUNITY_RETRIEVE_REPLY_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community create l_reply.make (l_community.community_id, l_community.name, l_community.description, l_community.logo) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_invalid_community) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_delete (a_msg: O_MESSAGE) is -- Delete an entire community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_DELETE_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community -- now delete this community community_access.delete_community (l_community.community_id) create l_status.make (True, Void) else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end node.send_message_reply (l_status, a_msg) end community_change_group (a_msg: O_MESSAGE) is -- Change access_group of a user for a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_CHANGE_GROUP_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_access_group: INTEGER l_user_name: STRING l_user: USER l_community_name: STRING l_community: COMMUNITY do l_msg ?= a_msg check valid_msg: l_msg /= Void end l_community_name := l_msg.community l_user_name := l_msg.user l_access_group := l_msg.group -- is the access group valid? if l_access_group = 0 or policy_cache.community_access_groups.has (l_access_group) then -- is session valid? user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then -- is user valid? user_access.retrieve_user_by_name (l_user_name, False) if user_access.is_found then l_user := user_access.last_user -- is community vaild? community_access.retrieve_community_by_name (l_community_name) if community_access.is_found then l_community := community_access.last_community user_access.update_user_community_association (l_community.community_id, l_user.user_id, l_access_group) -- retrieve the user and team associations and add them to the cache in case the user was logged in policy_cache.retrieve_associations (l_user.user_id) -- TODO marcozi edit here to eventually enable workitem notification per community if needed? -- if l_grp = 0 then -- -- remove all workitem subscriptions if user hasn't already bookmarked project -- if not user_access.has_bookmarked_project (l_project, l_user_ret.user_id) then -- user_access.delete_project_workitem_subscriptions (l_user_ret.user_id, l_project) -- end -- else -- -- subscribe to all workitems if user hasn't already bookmarked project -- if not user_access.has_bookmarked_project (l_project, l_user_ret.user_id) then -- user_access.insert_all_project_workitem_subscriptions (l_user_ret.user_id, l_project) -- end -- end create l_status.make (True, Void) else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_user) end else create l_status.make (False, err_invalid_session) end else create l_status.make (False, err_invalid_group) end -- send status node.send_message_reply (l_status, a_msg) end community_list_members (a_msg: O_MESSAGE) is -- List community admins/members. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_LIST_MEMBERS_MESSAGE l_reply: O_USER_LIST_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_lst: LIST [USER] l_members: HASH_TABLE [STRING, INTEGER] l_usr: USER do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then community_access.retrieve_community_by_name (l_msg.community) if community_access.is_found then -- retrieve users and map them into a HASH_TABLE community_access.retrieve_members (community_access.last_community.community_id, l_msg.group) from l_lst := community_access.last_member_list create l_members.make (l_lst.count) l_lst.start until l_lst.after loop l_usr := l_lst.item l_members.force (l_usr.name, l_usr.user_id) l_lst.forth end create l_reply.make (l_members) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_invalid_community) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_list_projects (a_msg: O_MESSAGE) is -- List community projects. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_LIST_PROJECTS_MESSAGE l_reply: O_PROJECT_LIST_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_project_list: LIST [PROJECT] l_projects: HASH_TABLE [STRING, INTEGER] l_project: PROJECT do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then community_access.retrieve_community_by_name (l_msg.community) if community_access.is_found then -- retrieve projects and map them into a HASH_TABLE community_access.retrieve_projects (community_access.last_community.community_id) from l_project_list := community_access.last_project_list create l_projects.make (l_project_list.count) l_project_list.start until l_project_list.after loop l_project := l_project_list.item l_projects.force (l_project.name, l_project.project_id) l_project_list.forth end create l_reply.make (l_projects) node.send_message_reply (l_reply, a_msg) else create l_status.make (FALSE, err_invalid_community) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_add_project (a_msg: O_MESSAGE) is -- Add a project to a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_ADD_PROJECT_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_project: PROJECT do l_msg ?= a_msg check valid_msg: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then project_access.retrieve_project_by_name (l_msg.project) if project_access.is_found then l_project := project_access.last_project community_access.retrieve_community_by_name (l_msg.community) if community_access.is_found then l_community := community_access.last_community -- only insert association if it does not already exist if community_access.is_associated_with_project (l_community.community_id, l_project.project_id) then create l_status.make (False, err_community_project_already_associated) else community_access.insert_community_project_association (l_community.community_id, l_project.project_id) create l_status.make (True, Void) end else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_project) end else create l_status.make (False, err_invalid_session) end node.send_message_reply (l_status, a_msg) end community_remove_project (a_msg: O_MESSAGE) is -- Remove a project from a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_REMOVE_PROJECT_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_project: PROJECT do l_msg ?= a_msg check valid_msg: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then project_access.retrieve_project_by_name (l_msg.project) if project_access.is_found then l_project := project_access.last_project community_access.retrieve_community_by_name (l_msg.community) if community_access.is_found then l_community := community_access.last_community community_access.delete_community_project_association (l_community.community_id, l_project.project_id) create l_status.make (True, Void) else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_project) end else create l_status.make (False, err_invalid_session) end node.send_message_reply (l_status, a_msg) end community_change_description (a_msg: O_MESSAGE) is -- Change description of a community require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_CHANGE_DESCRIPTION_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY do l_msg ?= a_msg check valid_msg: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community community_access.update_community_description (l_community.community_id, l_msg.description) create l_status.make (True, Void) else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end -- send status node.send_message_reply (l_status, a_msg) end community_list_wiki_pages (a_msg: O_MESSAGE) is -- List community wiki pages. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_LIST_WIKI_PAGES_MESSAGE l_reply: O_COMMUNITY_LIST_WIKI_PAGES_REPLY_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then -- retrieve users and map them into a HASH_TABLE l_community := community_access.last_community community_access.retrieve_wiki_page_titles (l_community.community_id) create l_reply.make (community_access.last_wiki_page_title_list) node.send_message_reply (l_reply, a_msg) else create l_status.make (False, err_invalid_community) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_retrieve_wiki_page (a_msg: O_MESSAGE) is -- Retrieve detailed wiki page of a community require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_RETRIEVE_WIKI_PAGE_MESSAGE l_reply: O_COMMUNITY_RETRIEVE_WIKI_PAGE_REPLY_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_user: USER l_is_member_admin: BOOLEAN l_is_origo_admin: BOOLEAN do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then l_user := user_access.last_user -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community community_access.retrieve_wiki_page (l_community.community_id, l_msg.wiki_title) if community_access.is_found then -- check privacy status of the retrieved wiki page if not community_access.last_wiki_page.private then -- not private - reply create l_reply.make (community_access.last_wiki_page.title, community_access.last_wiki_page.text, community_access.last_wiki_page.private) node.send_message_reply (l_reply, a_msg) else --check if user has necessary rights to view a private wiki page policy_cache.retrieve_associations (l_user.user_id) l_is_member_admin := policy_cache.user_community_associations.item (l_user.user_id) /= Void and then policy_cache.user_community_associations.item (l_user.user_id).item (l_community.community_id) /= Void and then (policy_cache.user_community_associations.item (l_user.user_id).item (l_community.community_id).has (6) or else policy_cache.user_community_associations.item (l_user.user_id).item (l_community.community_id).has (7)) l_is_origo_admin := policy_cache.user_associations.item (l_user.user_id) /= Void and then policy_cache.user_associations.item (l_user.user_id).has (1) if l_is_member_admin or else l_is_origo_admin then -- user has rights - send it create l_reply.make (community_access.last_wiki_page.title, community_access.last_wiki_page.text, community_access.last_wiki_page.private) node.send_message_reply (l_reply, a_msg) else -- user does not have rights - send reply create l_status.make (False, err_private_wiki_page) node.send_message_reply (l_status, a_msg) end end else create l_status.make (False, err_invalid_wiki_page) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_community) node.send_message_reply (l_status, a_msg) end else create l_status.make (False, err_invalid_session) node.send_message_reply (l_status, a_msg) end end community_add_wiki_page (a_msg: O_MESSAGE) is -- Add a wiki page to a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_ADD_WIKI_PAGE_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_user: USER do l_msg ?= a_msg check valid_message: l_msg /= Void end -- retrieve user user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then l_user := user_access.last_user -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community -- check if a wiki page with same title already exists community_access.retrieve_wiki_page (l_community.community_id, l_msg.title) if not community_access.is_found then community_access.insert_wiki_page (l_community.community_id, l_user.user_id, l_msg.title, l_msg.text, l_msg.private) create l_status.make (True, Void) else create l_status.make (False, err_wiki_title_already_used) end else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end --send reply node.send_message_reply (l_status, a_msg) end community_edit_wiki_page (a_msg: O_MESSAGE) is -- Edit a wiki page of a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_EDIT_WIKI_PAGE_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_user: USER do l_msg ?= a_msg check valid_message: l_msg /= Void end -- retrieve user user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then l_user := user_access.last_user -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community -- check if a wiki page with same title exists community_access.retrieve_wiki_page (l_community.community_id, l_msg.title) if community_access.is_found then community_access.update_wiki_page (l_community.community_id, l_user.user_id, l_msg.title, l_msg.text, l_msg.private) create l_status.make (True, Void) else create l_status.make (False, err_no_such_wiki_title) end else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end --send reply node.send_message_reply (l_status, a_msg) end community_rename_wiki_page (a_msg: O_MESSAGE) is -- Rename a wiki page of a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_RENAME_WIKI_PAGE_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY l_user: USER do l_msg ?= a_msg check valid_message: l_msg /= Void end -- retrieve user user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then l_user := user_access.last_user -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community -- check if a wiki page with same title exists community_access.retrieve_wiki_page (l_community.community_id, l_msg.old_title) if community_access.is_found then community_access.rename_wiki_page (l_community.community_id, l_user.user_id, l_msg.old_title, l_msg.new_title) create l_status.make (True, Void) else create l_status.make (False, err_no_such_wiki_title) end else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end --send reply node.send_message_reply (l_status, a_msg) end community_delete_wiki_page (a_msg: O_MESSAGE) is -- Delete a wiki page of a community. require a_msg_ok: a_msg /= Void local l_msg: O_COMMUNITY_DELETE_WIKI_PAGE_MESSAGE l_status: O_GENERAL_STATUS_MESSAGE l_community: COMMUNITY do l_msg ?= a_msg check valid_message: l_msg /= Void end user_access.retrieve_user_by_session (l_msg.session) if user_access.is_found then -- retrieve community community_access.retrieve_community_by_name (l_msg.community_name) if community_access.is_found then l_community := community_access.last_community -- retrieve wiki page community_access.retrieve_wiki_page (l_community.community_id, l_msg.wiki_title) if community_access.is_found then community_access.delete_wiki_page (l_community.community_id, l_msg.wiki_title) create l_status.make (True, Void) else create l_status.make (False, err_invalid_wiki_page) end else create l_status.make (False, err_invalid_community) end else create l_status.make (False, err_invalid_session) end -- send reply node.send_message_reply (l_status, a_msg) end end