fix: slack queryset (#1860)

This commit is contained in:
Nikhil 2023-08-14 18:53:09 +05:30 committed by GitHub
parent 6774eddb66
commit d2cdaaccb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,17 @@ class SlackProjectSyncViewSet(BaseViewSet):
serializer_class = SlackProjectSyncSerializer serializer_class = SlackProjectSyncSerializer
model = SlackProjectSync model = SlackProjectSync
def get_queryset(self):
return (
super()
.get_queryset()
.filter(
workspace__slug=self.kwargs.get("slug"),
project_id=self.kwargs.get("project_id"),
)
.filter(project__project_projectmember__member=self.request.user)
)
def create(self, request, slug, project_id, workspace_integration_id): def create(self, request, slug, project_id, workspace_integration_id):
try: try:
serializer = SlackProjectSyncSerializer(data=request.data) serializer = SlackProjectSyncSerializer(data=request.data)
@ -45,7 +56,10 @@ class SlackProjectSyncViewSet(BaseViewSet):
return Response(serializer.data, status=status.HTTP_200_OK) return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
except IntegrityError: except IntegrityError:
return Response({"error": "Slack is already enabled for the project"}, status=status.HTTP_400_BAD_REQUEST) return Response(
{"error": "Slack is already enabled for the project"},
status=status.HTTP_400_BAD_REQUEST,
)
except WorkspaceIntegration.DoesNotExist: except WorkspaceIntegration.DoesNotExist:
return Response( return Response(
{"error": "Workspace Integration does not exist"}, {"error": "Workspace Integration does not exist"},