add group membership to raise_not_deletable for lists

This commit is contained in:
Hugh Rundle 2021-10-03 11:45:53 +11:00
parent 602664b8d7
commit 77ac8e0c04
2 changed files with 4 additions and 8 deletions

View file

@ -101,7 +101,6 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
notification_type="ADD",
)
<<<<<<< HEAD
if self.book_list.group:
for membership in self.book_list.group.memberships.all():
if membership.user != self.user:
@ -111,14 +110,16 @@ class ListItem(CollectionItemMixin, BookWyrmModel):
related_list_item=self,
notification_type="ADD"
)
=======
def raise_not_deletable(self, viewer):
"""the associated user OR the list owner can delete"""
if self.book_list.user == viewer:
return
# group members can delete items in group lists
is_group_member = models.GroupMember.objects.filter(group=self.book_list.group, user=viewer).exists()
if is_group_member:
return
super().raise_not_deletable(viewer)
>>>>>>> main
class Meta:
"""A book may only be placed into a list once,
and each order in the list may be used only once"""

View file

@ -341,11 +341,6 @@ def remove_book(request, list_id):
book_list = get_object_or_404(models.List, id=list_id)
item = get_object_or_404(models.ListItem, id=request.POST.get("item"))
# TODO: put this logiv into raise_not_deletable
# is_group_member = models.GroupMember.objects.filter(group=book_list.group, user=request.user).exists()
# if not book_list.user == request.user and not item.user == request.user and not is_group_member:
# return HttpResponseNotFound()
item.raise_not_deletable(request.user)
with transaction.atomic():