Skip to content

Commit 2dc973e

Browse files
committed
Fix error with permissions in project chats
1 parent e94537b commit 2dc973e

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

chats/permissions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from rest_framework.permissions import BasePermission
2+
3+
4+
class IsProjectChatMember(BasePermission):
5+
def has_object_permission(self, request, view, obj):
6+
collaborators = [
7+
collaborator.user for collaborator in obj.project.collaborator_set.all()
8+
]
9+
if request.user in collaborators:
10+
return True
11+
return False

chats/serializers.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class Meta:
4343
fields = [
4444
"id",
4545
"users",
46-
"messages",
4746
]
4847

4948

@@ -82,7 +81,6 @@ class Meta:
8281
"id",
8382
"name",
8483
"image_address",
85-
"messages",
8684
"users",
8785
]
8886

chats/views.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from chats.models import ProjectChat, DirectChat
1414
from chats.pagination import MessageListPagination
15+
from chats.permissions import IsProjectChatMember
1516
from chats.serializers import (
1617
DirectChatListSerializer,
1718
DirectChatMessageListSerializer,
@@ -47,7 +48,7 @@ def get_queryset(self):
4748
class ProjectChatDetail(RetrieveAPIView):
4849
queryset = ProjectChat.objects.all()
4950
serializer_class = ProjectChatDetailSerializer
50-
permission_classes = [IsAuthenticated]
51+
permission_classes = [IsProjectChatMember]
5152

5253

5354
class DirectChatDetail(RetrieveAPIView):

0 commit comments

Comments
 (0)