def get_roles_perms(self, roles, kind=None):
     roles_perms = {}
     if not roles:
         return []
     role_ids = roles.values_list("ID", flat=True)
     for role_id in role_ids:
         roles_perms.update({str(role_id): []})
     roles_perm_relation_mode = role_perm_relation_repo.get_roles_perm_relation(
         role_ids)
     if roles_perm_relation_mode:
         roles_perm_relations = roles_perm_relation_mode.values(
             "role_id", "perm_code")
         for roles_perm_relation in roles_perm_relations:
             roles_perms[str(roles_perm_relation["role_id"])].append(
                 roles_perm_relation["perm_code"])
     data = []
     for role_id, rule_perms in roles_perms.items():
         role_perms_info = {"role_id": int(role_id)}
         if kind == "team":
             permissions = self.pack_role_perms_tree(
                 get_team_perms_model(), rule_perms)
         elif kind == "enterprise":
             permissions = self.pack_role_perms_tree(
                 get_enterprise_perms_model(), rule_perms)
         else:
             permissions = self.pack_role_perms_tree(
                 get_perms_model(), rule_perms)
         role_perms_info.update({"permissions": permissions})
         data.append(role_perms_info)
     return data
 def get_role_perms(self, role, kind=None):
     if not role:
         return None
     roles_perms = {str(role.ID): []}
     role_perm_relation_mode = role_perm_relation_repo.get_role_perm_relation(
         role.ID)
     if role_perm_relation_mode:
         roles_perm_relations = role_perm_relation_mode.values(
             "role_id", "perm_code")
         for roles_perm_relation in roles_perm_relations:
             if str(roles_perm_relation["role_id"]) not in roles_perms:
                 roles_perms[str(roles_perm_relation["role_id"])] = []
             roles_perms[str(roles_perm_relation["role_id"])].append(
                 roles_perm_relation["perm_code"])
     data = []
     for role_id, rule_perms in roles_perms.items():
         role_perms_info = {"role_id": role_id}
         if kind == "team":
             permissions = self.pack_role_perms_tree(
                 get_team_perms_model(), rule_perms)
         elif kind == "enterprise":
             permissions = self.pack_role_perms_tree(
                 get_enterprise_perms_model(), rule_perms)
         else:
             permissions = self.pack_role_perms_tree(
                 get_perms_model(), rule_perms)
         role_perms_info.update({"permissions": permissions})
         data.append(role_perms_info)
     return data[0]
Esempio n. 3
0
 def get_roles_union_perms(self, roles, kind=None, is_owner=False):
     union_role_perms = []
     if roles:
         role_ids = roles.values_list("role_id", flat=True)
         roles_perm_relation_mode = role_perm_relation_repo.get_roles_perm_relation(role_ids)
         if roles_perm_relation_mode:
             roles_perm_relations = roles_perm_relation_mode.values("role_id", "perm_code")
             for roles_perm_relation in roles_perm_relations:
                 union_role_perms.append(roles_perm_relation["perm_code"])
     if kind == "team":
         permissions = self.pack_role_perms_tree(get_team_perms_model(), union_role_perms, is_owner)
     elif kind == "enterprise":
         permissions = self.pack_role_perms_tree(get_enterprise_perms_model(), union_role_perms, is_owner)
     else:
         permissions = self.pack_role_perms_tree(get_perms_model(), union_role_perms, is_owner)
     return {"permissions": permissions}