Skip to content

Commit

Permalink
feat(my-permissions): Add tag based permissions (#4824)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagantrivedi authored Nov 12, 2024
1 parent f7220ea commit cbd60d9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ POETRY_VERSION ?= 1.8.3
GUNICORN_LOGGER_CLASS ?= util.logging.GunicornJsonCapableLogger

SAML_REVISION ?= v1.6.4
RBAC_REVISION ?= v0.9.0
RBAC_REVISION ?= v0.10.0

-include .env-local
-include $(DOTENV_OVERRIDE_FILE)
Expand Down
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 cbd60d9

Please sign in to comment.