- # @staticmethod
- # def format_on_show(content):
- # """
- # Modifies the content of the role information to separate the role
- # metadata from the role definition. Eases the reading process of the
- # role definition.
- #
- # :param definition: role definition to be processed
- # """
- # content["_id"] = str(content["_id"])
- #
- # def show(self, session, _id):
- # """
- # Get complete information on an topic
- #
- # :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
- # :param _id: server internal id
- # :return: dictionary, raise exception if not found.
- # """
- # filter_db = {"_id": _id}
- # filter_db = { BaseTopic.id_field(self.topic, _id): _id } # To allow role addressing by name
- #
- # role = self.db.get_one(self.topic, filter_db)
- # new_role = dict(role)
- # self.format_on_show(new_role)
- #
- # return new_role
-
- # def list(self, session, filter_q=None):
- # """
- # Get a list of the topic that matches a filter
- #
- # :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
- # :param filter_q: filter of data to be applied
- # :return: The list, it can be empty if no one match the filter.
- # """
- # if not filter_q:
- # filter_q = {}
- #
- # if ":" in filter_q:
- # filter_q["root"] = filter_q[":"]
- #
- # for key in filter_q.keys():
- # if key == "name":
- # continue
- # filter_q[key] = filter_q[key] in ["True", "true"]
- #
- # roles = self.db.get_list(self.topic, filter_q)
- # new_roles = []
- #
- # for role in roles:
- # new_role = dict(role)
- # self.format_on_show(new_role)
- # new_roles.append(new_role)
- #
- # return new_roles
+ def list(self, session, filter_q=None):
+ """
+ Get a list of the topic that matches a filter
+
+ :param session: contains "username", "admin", "force", "public", "project_id", "set_project"
+ :param filter_q: filter of data to be applied
+ :return: The list, it can be empty if no one match the filter.
+ """
+ role_list = self.auth.get_role_list(filter_q)
+ if not session["allow_show_user_project_role"]:
+ # Bug 853 - Default filtering
+ user = self.auth.get_user(session["username"])
+ roles = [prm["role"] for prm in user["project_role_mappings"]]
+ role_list = [role for role in role_list if role["_id"] in roles]
+ return role_list