Skip to content

Commit

Permalink
Merge pull request #92 from AI4Bharat/revert-91-revert-90-ishvinderse…
Browse files Browse the repository at this point in the history
…thi22-patch-1

Revert "Revert "Update views.py""
  • Loading branch information
ishvindersethi22 authored Jul 3, 2024
2 parents b65d4f1 + e442e57 commit 247cd4b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
26 changes: 20 additions & 6 deletions backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,7 @@ 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
Expand All @@ -1300,9 +1301,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)
Expand All @@ -1322,6 +1323,18 @@ 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_view" in request.query_params:
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)
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)
).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"]
Expand Down Expand Up @@ -1369,11 +1382,9 @@ 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.exclude(annotators=request.user)
excluded_projects = projects.filter(annotators=request.user)
included_projects = projects.filter(annotators=request.user)
excluded_projects = projects.exclude(annotators=request.user)
included_projects_serialized = ProjectSerializerOptimized(
included_projects, many=True
)
Expand Down Expand Up @@ -4346,6 +4357,9 @@ def verify_password(
)
try:
if project.check_project_password(password):
current_user = request.data.get("user_id")
project.annotators.add(current_user)
project.save()
return Response(
{"message": "Authentication Successful"},
status=status.HTTP_200_OK,
Expand Down
10 changes: 5 additions & 5 deletions backend/workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 and projects as an annotator."
"message": "User added to the workspace."
},
status=status.HTTP_200_OK,
)
Expand Down

0 comments on commit 247cd4b

Please sign in to comment.