Skip to content

Commit

Permalink
Merge pull request #322 from seanmorley15/sharing_fix
Browse files Browse the repository at this point in the history
Sharing fix
  • Loading branch information
seanmorley15 authored Sep 29, 2024
2 parents 7c5b448 + e41d938 commit 44db008
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions backend/server/adventures/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,22 @@ def apply_sorting(self, queryset):
return queryset.order_by(ordering)

def get_queryset(self):
# if the user is not authenticated return only public adventures for retrieve action
# if the user is not authenticated return only public adventures for retrieve action
if not self.request.user.is_authenticated:
if self.action == 'retrieve':
return Adventure.objects.filter(is_public=True)
return Adventure.objects.filter(is_public=True).distinct().order_by('-updated_at')
return Adventure.objects.none()


if self.action == 'retrieve':
# For individual adventure retrieval, include public adventures
return Adventure.objects.filter(
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')
else:
# For other actions, include user's own adventures and shared adventures
return Adventure.objects.filter(
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')

def retrieve(self, request, *args, **kwargs):
queryset = self.get_queryset()
Expand Down Expand Up @@ -270,6 +269,7 @@ def perform_update(self, serializer):
serializer.save()

# when creating an adventure, make sure the user is the owner of the collection or shared with the collection
@transaction.atomic
def perform_create(self, serializer):
# Retrieve the collection from the validated data
collection = serializer.validated_data.get('collection')
Expand Down Expand Up @@ -619,20 +619,20 @@ def get_queryset(self):
# if the user is not authenticated return only public transportations for retrieve action
if not self.request.user.is_authenticated:
if self.action == 'retrieve':
return Transportation.objects.filter(is_public=True)
return Transportation.objects.filter(is_public=True).distinct().order_by('-updated_at')
return Transportation.objects.none()


if self.action == 'retrieve':
# For individual adventure retrieval, include public adventures
return Transportation.objects.filter(
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')
else:
# For other actions, include user's own adventures and shared adventures
return Transportation.objects.filter(
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')

def partial_update(self, request, *args, **kwargs):
# Retrieve the current object
Expand Down Expand Up @@ -741,20 +741,20 @@ def get_queryset(self):
# if the user is not authenticated return only public transportations for retrieve action
if not self.request.user.is_authenticated:
if self.action == 'retrieve':
return Note.objects.filter(is_public=True)
return Note.objects.filter(is_public=True).distinct().order_by('-updated_at')
return Note.objects.none()


if self.action == 'retrieve':
# For individual adventure retrieval, include public adventures
return Note.objects.filter(
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')
else:
# For other actions, include user's own adventures and shared adventures
return Note.objects.filter(
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')

def partial_update(self, request, *args, **kwargs):
# Retrieve the current object
Expand Down Expand Up @@ -863,20 +863,20 @@ def get_queryset(self):
# if the user is not authenticated return only public transportations for retrieve action
if not self.request.user.is_authenticated:
if self.action == 'retrieve':
return Checklist.objects.filter(is_public=True)
return Checklist.objects.filter(is_public=True).distinct().order_by('-updated_at')
return Checklist.objects.none()


if self.action == 'retrieve':
# For individual adventure retrieval, include public adventures
return Checklist.objects.filter(
Q(is_public=True) | Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')
else:
# For other actions, include user's own adventures and shared adventures
return Checklist.objects.filter(
Q(user_id=self.request.user.id) | Q(collection__shared_with=self.request.user)
)
).distinct().order_by('-updated_at')

def partial_update(self, request, *args, **kwargs):
# Retrieve the current object
Expand Down

0 comments on commit 44db008

Please sign in to comment.