- ignore_fields = ["_id", "name", "_admin"]
- delete_keys = [key for key in final_content.keys() if key not in ignore_fields]
-
- for key in delete_keys:
- del final_content[key]
-
- # Saving the role definition
- for role_def, value in edit_content.items():
- final_content[role_def] = value
-
- if ":" in final_content.keys():
- final_content["root"] = final_content[":"]
- del final_content[":"]
-
- if "root" not in final_content.keys():
- final_content["root"] = False
-
- @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}
-
- 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"]