diff --git a/backend/projects/views.py b/backend/projects/views.py index 6f5687f5..ac7f82f3 100644 --- a/backend/projects/views.py +++ b/backend/projects/views.py @@ -1290,7 +1290,6 @@ def list_optimized(self, request): List all projects with some optimizations. """ try: - projects = self.queryset.filter(annotators=request.user) if request.user.is_superuser: projects = self.queryset @@ -1301,9 +1300,9 @@ def list_optimized(self, request): elif request.user.role == User.WORKSPACE_MANAGER: projects = ( self.queryset.filter( - workspace_id__in=Workspace.objects.filter( + workspace_id__in=Workspace.objects.filter( managers=request.user - ).values_list("id", flat=True) + ).values_list("id", flat=True) ) | self.queryset.filter(annotators=request.user) | self.queryset.filter(annotation_reviewers=request.user) @@ -1324,17 +1323,26 @@ def list_optimized(self, request): projects = self.queryset.filter(annotators=request.user) projects = projects.filter(is_published=True).filter(is_archived=False) if "guest_view" in request.query_params: - projects = self.queryset.filter( + projects = ( + self.queryset.filter( workspace_id__in=Workspace.objects.filter( members=request.user ).values_list("id", flat=True) - ).filter(is_published=True).filter(is_archived=False) + ) + .filter(is_published=True) + .filter(is_archived=False) + ) if "guest_workspace_filter" in request.query_params: - projects = self.queryset.filter(workspace_id__guest_workspace=True).filter( + projects = ( + self.queryset.filter(workspace_id__guest_workspace=True) + .filter( workspace_id__in=Workspace.objects.filter( members=request.user ).values_list("id", flat=True) - ).filter(is_published=True).filter(is_archived=False) + ) + .filter(is_published=True) + .filter(is_archived=False) + ) if "project_user_type" in request.query_params: project_user_type = request.query_params["project_user_type"] diff --git a/backend/workspaces/views.py b/backend/workspaces/views.py index 86a1335d..008bbeba 100644 --- a/backend/workspaces/views.py +++ b/backend/workspaces/views.py @@ -262,15 +262,13 @@ def enter_workspace(self, request, pk=None): workspace.members.add(request.user) workspace.save() - #projects = Project.objects.filter(workspace_id=workspace.id) - #for project in projects: + # projects = Project.objects.filter(workspace_id=workspace.id) + # for project in projects: # project.annotators.add(request.user) # project.save() return Response( - { - "message": "User added to the workspace." - }, + {"message": "User added to the workspace."}, status=status.HTTP_200_OK, )