This commit is contained in:
Hugh Rundle 2021-10-10 13:18:16 +11:00
parent 14d3158871
commit 726217577f
3 changed files with 16 additions and 14 deletions

View file

@ -22,10 +22,11 @@ class Group(BookWyrmModel):
@classmethod @classmethod
def followers_filter(cls, queryset, viewer): def followers_filter(cls, queryset, viewer):
"""Override filter for "followers" privacy level to allow non-following group members to see the existence of groups and group lists""" """Override filter for "followers" privacy level to allow non-following
group members to see the existence of groups and group lists"""
return queryset.exclude( return queryset.exclude(
~Q( # user isn't following and it isn't their own status and they are not a group member ~Q( # user is not a group member
Q(user__followers=viewer) | Q(user=viewer) | Q(memberships__user=viewer) Q(user__followers=viewer) | Q(user=viewer) | Q(memberships__user=viewer)
), ),
privacy="followers", # and the status of the group is followers only privacy="followers", # and the status of the group is followers only
@ -33,7 +34,8 @@ class Group(BookWyrmModel):
@classmethod @classmethod
def direct_filter(cls, queryset, viewer): def direct_filter(cls, queryset, viewer):
"""Override filter for "direct" privacy level to allow group members to see the existence of groups and group lists""" """Override filter for "direct" privacy level to allow group members
to see the existence of groups and group lists"""
return queryset.exclude(~Q(memberships__user=viewer), privacy="direct") return queryset.exclude(~Q(memberships__user=viewer), privacy="direct")
@ -92,9 +94,8 @@ class GroupMember(models.Model):
"""remove a user from a group""" """remove a user from a group"""
memberships = cls.objects.filter(group__user=owner, user=user).all() memberships = cls.objects.filter(group__user=owner, user=user).all()
for m in memberships: for member in memberships:
# remove this user member.delete()
m.delete()
class GroupMemberInvitation(models.Model): class GroupMemberInvitation(models.Model):

View file

@ -2,7 +2,6 @@
from django.apps import apps from django.apps import apps
from django.db import models from django.db import models
from django.db.models import Q from django.db.models import Q
from django.db.models.fields import NullBooleanField
from django.utils import timezone from django.utils import timezone
from bookwyrm import activitypub from bookwyrm import activitypub
@ -74,10 +73,11 @@ class List(OrderedCollectionMixin, BookWyrmModel):
@classmethod @classmethod
def followers_filter(cls, queryset, viewer): def followers_filter(cls, queryset, viewer):
"""Override filter for "followers" privacy level to allow non-following group members to see the existence of group lists""" """Override filter for "followers" privacy level to allow non-following
group members to see the existence of group lists"""
return queryset.exclude( return queryset.exclude(
~Q( # user isn't following and it isn't their own status and they are not a group member ~Q( # user isn't following or group member
Q(user__followers=viewer) Q(user__followers=viewer)
| Q(user=viewer) | Q(user=viewer)
| Q(group__memberships__user=viewer) | Q(group__memberships__user=viewer)
@ -87,7 +87,8 @@ class List(OrderedCollectionMixin, BookWyrmModel):
@classmethod @classmethod
def direct_filter(cls, queryset, viewer): def direct_filter(cls, queryset, viewer):
"""Override filter for "direct" privacy level to allow group members to see the existence of group lists""" """Override filter for "direct" privacy level to allow
group members to see the existence of group lists"""
return queryset.exclude( return queryset.exclude(
~Q( # user not self and not in the group if this is a group list ~Q( # user not self and not in the group if this is a group list
@ -101,9 +102,10 @@ class List(OrderedCollectionMixin, BookWyrmModel):
"""remove a list from a group""" """remove a list from a group"""
memberships = GroupMember.objects.filter(group__user=owner, user=user).all() memberships = GroupMember.objects.filter(group__user=owner, user=user).all()
for m in memberships:
for membership in memberships:
# remove this user's group-curated lists from the group # remove this user's group-curated lists from the group
cls.objects.filter(group=m.group, user=m.user).update( cls.objects.filter(group=membership.group, user=membership.user).update(
group=None, curation="closed" group=None, curation="closed"
) )

View file

@ -126,8 +126,7 @@ let BookWyrm = new class {
/** /**
* Show form. * Show form.
* If the form has already been revealed, there is no '.is-hidden' element *
* so this doesn't work as a toggle - use hideForm to hide it again
* @param {Event} event * @param {Event} event
* @return {undefined} * @return {undefined}
*/ */