From 848d2c33d8b6057d0adbeec73c7799aaafa69a80 Mon Sep 17 00:00:00 2001 From: Ishvinder Sethi Date: Wed, 3 Jul 2024 16:11:55 +0530 Subject: [PATCH] Revert "Update views.py" --- backend/projects/views.py | 15 +++++---------- backend/workspaces/views.py | 10 +++++----- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/backend/projects/views.py b/backend/projects/views.py index 8b42019d..cd671e23 100644 --- a/backend/projects/views.py +++ b/backend/projects/views.py @@ -1290,8 +1290,7 @@ def list_optimized(self, request): List all projects with some optimizations. """ try: - if "guest_view" not in request.query_params: - projects = self.queryset.filter(annotators=request.user) + projects = self.queryset.filter(annotators=request.user) if request.user.is_superuser: projects = self.queryset elif request.user.role == User.ORGANIZATION_OWNER: @@ -1323,12 +1322,6 @@ def list_optimized(self, request): elif request.user.role == User.ANNOTATOR: projects = self.queryset.filter(annotators=request.user) projects = projects.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( - workspace_id__in=Workspace.objects.filter( - members=request.user - ).values_list("id", flat=True) - ) if "project_user_type" in request.query_params: project_user_type = request.query_params["project_user_type"] @@ -1376,9 +1369,11 @@ def list_optimized(self, request): else: projects = projects.order_by(F("published_at").desc(nulls_last=True)) + if "guest_workspace_filter" in request.query_params: + projects = projects.filter(workspace_id__guest_workspace=True) if "guest_view" in request.query_params: - included_projects = projects.filter(annotators=request.user) - excluded_projects = projects.exclude(annotators=request.user) + included_projects = projects.exclude(annotators=request.user) + excluded_projects = projects.filter(annotators=request.user) included_projects_serialized = ProjectSerializerOptimized( included_projects, many=True ) diff --git a/backend/workspaces/views.py b/backend/workspaces/views.py index 86a1335d..0b9d0063 100644 --- a/backend/workspaces/views.py +++ b/backend/workspaces/views.py @@ -262,14 +262,14 @@ 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: - # project.annotators.add(request.user) - # project.save() + 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 and projects as an annotator." }, status=status.HTTP_200_OK, )