Skip to content

Commit

Permalink
Fix error with permissions in project chats
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakser committed Aug 8, 2023
1 parent e94537b commit 2dc973e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
11 changes: 11 additions & 0 deletions chats/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from rest_framework.permissions import BasePermission


class IsProjectChatMember(BasePermission):
def has_object_permission(self, request, view, obj):
collaborators = [
collaborator.user for collaborator in obj.project.collaborator_set.all()
]
if request.user in collaborators:
return True
return False
2 changes: 0 additions & 2 deletions chats/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Meta:
fields = [
"id",
"users",
"messages",
]


Expand Down Expand Up @@ -82,7 +81,6 @@ class Meta:
"id",
"name",
"image_address",
"messages",
"users",
]

Expand Down
3 changes: 2 additions & 1 deletion chats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from chats.models import ProjectChat, DirectChat
from chats.pagination import MessageListPagination
from chats.permissions import IsProjectChatMember
from chats.serializers import (
DirectChatListSerializer,
DirectChatMessageListSerializer,
Expand Down Expand Up @@ -47,7 +48,7 @@ def get_queryset(self):
class ProjectChatDetail(RetrieveAPIView):
queryset = ProjectChat.objects.all()
serializer_class = ProjectChatDetailSerializer
permission_classes = [IsAuthenticated]
permission_classes = [IsProjectChatMember]


class DirectChatDetail(RetrieveAPIView):
Expand Down

0 comments on commit 2dc973e

Please sign in to comment.