Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(my-permissions): Add tag based permissions #4824

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
matthewelwell marked this conversation as resolved.
Show resolved Hide resolved
],
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)
Loading