Beispiel #1
0
 def apply(self, policy: Policy, role: Role, user: User, group: Group, param_obj=None):
     """Apply Role to User and/or Group"""
     for obj in policy.get_objects(param_obj):
         for perm in role.get_permissions():
             if user is not None:
                 uop = UserObjectPermission.objects.assign_perm(perm, user, obj)
                 policy.user_object_perm.add(uop)
             if group is not None:
                 gop = GroupObjectPermission.objects.assign_perm(perm, group, obj)
                 policy.group_object_perm.add(gop)
Beispiel #2
0
 def apply(self, policy: Policy, role: Role, user: User, group: Group, param_obj=None):
     """Apply Role to User and/or Group"""
     for perm in role.get_permissions():
         if group is not None:
             group.permissions.add(perm)
             pp = PolicyPermission(policy=policy, group=group, permission=perm)
             pp.save()
             policy.model_perm.add(pp)
         if user is not None:
             user.user_permissions.add(perm)
             pp = PolicyPermission(policy=policy, user=user, permission=perm)
             pp.save()
             policy.model_perm.add(pp)