Skip to content

Commit

Permalink
feat(my-permissions): Add tag based permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi committed Nov 11, 2024
1 parent 0f9b24b commit 59199ce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion api/permissions/permissions_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,26 @@ def permissions(self) -> typing.Set[str]:
).union(
reduce(
lambda a, b: a.union(b),
[role.permissions for role in self.roles],
[
role_permission.permissions
for role_permission in self.roles
if not role_permission.role.tags
],
set(),
)
)

@property
def tag_based_permissions(self) -> list[dict]:
return [
{
"permissions": role_permission.permissions,
"tags": role_permission.role.tags,
}
for role_permission in self.roles
if role_permission.role.tags
]


def get_project_permission_data(project_id: int, user_id: int) -> PermissionData:
project_permission_svc = _ProjectPermissionService(project_id, user_id)
Expand Down
6 changes: 6 additions & 0 deletions api/permissions/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def update(self, instance, validated_data):
return instance


class TagBasedPermissionSerializer(serializers.Serializer):
permissions = serializers.ListField(child=serializers.CharField())
tags = serializers.ListField(child=serializers.IntegerField())


class UserObjectPermissionsSerializer(serializers.Serializer):
permissions = serializers.ListField(child=serializers.CharField())
admin = serializers.BooleanField()
tag_based_permissions = TagBasedPermissionSerializer(many=True)

0 comments on commit 59199ce

Please sign in to comment.