Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes for guest_auth #96

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions backend/projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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"]
Expand Down
29 changes: 15 additions & 14 deletions backend/workspaces/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,20 @@ def guest_auth(self, request, pk=None, *args, **kwargs):
{"message": "Only guest users can enter this workspace."},
status=status.HTTP_403_FORBIDDEN,
)

serializer = self.get_serializer(
data=request.data, context={"workspace": workspace}
)
if not serializer.is_valid(raise_exception=True) or not serializer.validate(
request.data
if not (
workspace.workspace_password == ""
and request.data["workspace_password"] == ""
):
return Response(
{"message": "Authentication failed!"},
status=status.HTTP_400_BAD_REQUEST,
serializer = self.get_serializer(
data=request.data, context={"workspace": workspace}
)
if not serializer.is_valid(raise_exception=True) or not serializer.validate(
request.data
):
return Response(
{"message": "Authentication failed!"},
status=status.HTTP_400_BAD_REQUEST,
)

response = self.enter_workspace(request, pk=pk)
if response.status_code != 200:
Expand Down Expand Up @@ -262,15 +265,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,
)

Expand Down
Loading