Skip to content

Commit

Permalink
feat: use new projectadmindto when not cached aswell
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Oct 17, 2024
1 parent 1c6f57c commit 61e8865
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions chats/apps/accounts/authentication/drf/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ def _authenticate_credentials(self, key):
authorization = model.auth.get(uuid=key)
if not authorization.is_admin:
raise exceptions.PermissionDenied()

return (authorization.user, authorization)
authorization = ProjectAdminDTO(
pk=str(authorization.pk),
project=str(authorization.project_id),
user_email=authorization.user_id,
user_first_name=authorization.user.first_name,
role=authorization.role,
)
return (authorization.user_email, authorization)
except ProjectPermission.DoesNotExist:
raise exceptions.AuthenticationFailed(_("Invalid token."))

Expand Down
2 changes: 1 addition & 1 deletion chats/apps/api/v1/external/msgs/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class MessageFlowViewset(

def perform_create(self, serializer):
validated_data = serializer.validated_data
room = validated_data.room
room = validated_data.get("room")
if room.project_uuid != self.request.auth.project:
self.permission_denied(
self.request,
Expand Down
2 changes: 1 addition & 1 deletion chats/apps/api/v1/external/rooms/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def create(self, request, *args, **kwargs):

def perform_create(self, serializer):
validated_data = serializer.validated_data
queue_or_sector = validated_data.queue or validated_data.sector
queue_or_sector = validated_data.get("queue") or validated_data.get("sector")
project = queue_or_sector.project
if str(project.pk) != self.request.auth.project:
self.permission_denied(
Expand Down

0 comments on commit 61e8865

Please sign in to comment.