diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py index 88320cf9..90716869 100644 --- a/bookwyrm/models/group.py +++ b/bookwyrm/models/group.py @@ -7,6 +7,7 @@ from .base_model import BookWyrmModel from . import fields from .relationship import UserBlocks + class Group(BookWyrmModel): """A group of users""" @@ -36,6 +37,7 @@ class Group(BookWyrmModel): return queryset.exclude(~Q(memberships__user=viewer), privacy="direct") + class GroupMember(models.Model): """Users who are members of a group""" diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 295032f5..202c830c 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -79,7 +79,9 @@ class List(OrderedCollectionMixin, BookWyrmModel): return queryset.exclude( ~Q( # user isn't following and it isn't their own status and they are not a group member - Q(user__followers=viewer) | Q(user=viewer) | Q(group__memberships__user=viewer) + Q(user__followers=viewer) + | Q(user=viewer) + | Q(group__memberships__user=viewer) ), privacy="followers", # and the status (of the list) is followers only ) @@ -89,10 +91,10 @@ class List(OrderedCollectionMixin, BookWyrmModel): """Override filter for "direct" privacy level to allow group members to see the existence of group lists""" return queryset.exclude( - ~Q( # user not self and not in the group if this is a group list - Q(user=viewer) | Q(group__memberships__user=viewer) - ), - privacy="direct" + ~Q( # user not self and not in the group if this is a group list + Q(user=viewer) | Q(group__memberships__user=viewer) + ), + privacy="direct", ) @classmethod diff --git a/bookwyrm/tests/views/test_group.py b/bookwyrm/tests/views/test_group.py index c8e6208a..3b0aa236 100644 --- a/bookwyrm/tests/views/test_group.py +++ b/bookwyrm/tests/views/test_group.py @@ -72,7 +72,7 @@ class GroupViews(TestCase): view = views.FindUsers.as_view() request = self.factory.get("") request.user = self.local_user - result = view(request,group_id=999) + result = view(request, group_id=999) self.assertIsInstance(result, TemplateResponse) validate_html(result.render()) self.assertEqual(result.status_code, 200) @@ -85,7 +85,7 @@ class GroupViews(TestCase): "name": "Updated Group", "privacy": "private", "description": "Test description", - "user": self.local_user + "user": self.local_user, } request = self.factory.post("", group_fields) request.user = self.local_user diff --git a/bookwyrm/views/group.py b/bookwyrm/views/group.py index 6ef21583..3e510a4d 100644 --- a/bookwyrm/views/group.py +++ b/bookwyrm/views/group.py @@ -25,7 +25,11 @@ class Group(View): group = get_object_or_404(models.Group, id=group_id) group.raise_visible_to_user(request.user) - lists = models.List.privacy_filter(request.user).filter(group=group).order_by("-updated_date") + lists = ( + models.List.privacy_filter(request.user) + .filter(group=group) + .order_by("-updated_date") + ) data = { "group": group, @@ -53,7 +57,11 @@ class UserGroups(View): def get(self, request, username): """display a group""" user = get_user_from_username(request.user, username) - groups = models.Group.privacy_filter(request.user).filter(memberships__user=user).order_by("-updated_date") + groups = ( + models.Group.privacy_filter(request.user) + .filter(memberships__user=user) + .order_by("-updated_date") + ) paginated = Paginator(groups, 12) data = { @@ -164,7 +172,7 @@ def remove_member(request): return HttpResponseBadRequest() # you can't be removed from your own group - if request.POST["user"]== group.user: + if request.POST["user"] == group.user: return HttpResponseBadRequest() is_member = models.GroupMember.objects.filter(group=group, user=user).exists()