From f3181690a2121082d9d31d91322e1ab0cfd7849d Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 27 Sep 2021 15:36:41 +1000 Subject: [PATCH] change group owner from 'manager' to 'user' This will allow privacy management to use existing code. Some template updates also are for rationalising how groups are created and edited. --- bookwyrm/models/base_model.py | 4 ++++ bookwyrm/models/group.py | 2 +- bookwyrm/models/list.py | 5 +++-- bookwyrm/templates/groups/created_text.html | 2 +- bookwyrm/templates/groups/form.html | 6 +++--- bookwyrm/templates/groups/layout.html | 2 +- bookwyrm/templates/groups/members.html | 2 +- bookwyrm/templates/groups/user_groups.html | 2 +- bookwyrm/templates/snippets/add_to_group_button.html | 2 +- bookwyrm/templates/user/groups.html | 2 +- 10 files changed, 17 insertions(+), 12 deletions(-) diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index aa174a14..3a2d758b 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -76,6 +76,10 @@ class BookWyrmModel(models.Model): and self.mention_users.filter(id=viewer.id).first() ): return True + +# TODO: if privacy is direct and the object is a group and viewer is a member of the group +# then return True + return False diff --git a/bookwyrm/models/group.py b/bookwyrm/models/group.py index c1aa2d70..6810779c 100644 --- a/bookwyrm/models/group.py +++ b/bookwyrm/models/group.py @@ -12,7 +12,7 @@ class Group(BookWyrmModel): """A group of users""" name = fields.CharField(max_length=100) - manager = fields.ForeignKey( + user = fields.ForeignKey( "User", on_delete=models.PROTECT) description = fields.TextField(blank=True, null=True) privacy = fields.PrivacyField() diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 75f34b9e..7ea33a8b 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -36,9 +36,10 @@ class List(OrderedCollectionMixin, BookWyrmModel): ) group = models.ForeignKey( "Group", - on_delete=models.CASCADE, + on_delete=models.PROTECT, default=None, - blank=True + blank=True, + null=True, ) books = models.ManyToManyField( "Edition", diff --git a/bookwyrm/templates/groups/created_text.html b/bookwyrm/templates/groups/created_text.html index e7409942..5e6ce513 100644 --- a/bookwyrm/templates/groups/created_text.html +++ b/bookwyrm/templates/groups/created_text.html @@ -1,6 +1,6 @@ {% load i18n %} {% spaceless %} -{% blocktrans with username=group.manager.display_name path=group.manager.local_path %}Managed by {{ username }}{% endblocktrans %} +{% blocktrans with username=group.user.display_name path=group.user.local_path %}Managed by {{ username }}{% endblocktrans %} {% endspaceless %} diff --git a/bookwyrm/templates/groups/form.html b/bookwyrm/templates/groups/form.html index f764db6f..c47cbbc4 100644 --- a/bookwyrm/templates/groups/form.html +++ b/bookwyrm/templates/groups/form.html @@ -5,7 +5,7 @@
- +
@@ -20,9 +20,9 @@
- +
diff --git a/bookwyrm/templates/groups/layout.html b/bookwyrm/templates/groups/layout.html index 03a957d0..f558f169 100644 --- a/bookwyrm/templates/groups/layout.html +++ b/bookwyrm/templates/groups/layout.html @@ -12,7 +12,7 @@

- {% if request.user == group.manager %} + {% if request.user == group.user %} {% trans "Edit group" as button_text %} {% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_group" focus="edit_group_header" %} {% endif %} diff --git a/bookwyrm/templates/groups/members.html b/bookwyrm/templates/groups/members.html index 80dab21c..df5f1602 100644 --- a/bookwyrm/templates/groups/members.html +++ b/bookwyrm/templates/groups/members.html @@ -38,7 +38,7 @@ {{ member.display_name|truncatechars:10 }} @{{ member|username|truncatechars:8 }} - {% if group.manager == member %} + {% if group.user == member %} Manager diff --git a/bookwyrm/templates/groups/user_groups.html b/bookwyrm/templates/groups/user_groups.html index 9c48a842..5239a365 100644 --- a/bookwyrm/templates/groups/user_groups.html +++ b/bookwyrm/templates/groups/user_groups.html @@ -8,7 +8,7 @@

- {{ group.name }} {% include 'snippets/privacy-icons.html' with item=group %} + {{ group.name }} {% include 'snippets/privacy-icons.html' with item=group %}

{% if request.user.is_authenticated and request.user|saved:list %}
diff --git a/bookwyrm/templates/snippets/add_to_group_button.html b/bookwyrm/templates/snippets/add_to_group_button.html index f533af6e..cc394684 100644 --- a/bookwyrm/templates/snippets/add_to_group_button.html +++ b/bookwyrm/templates/snippets/add_to_group_button.html @@ -1,5 +1,5 @@ {% load i18n %} -{% if request.user == user or not request.user == group.manager or not request.user.is_authenticated %} +{% if request.user == user or not request.user == group.user or not request.user.is_authenticated %} {% elif user in request.user.blocks.all %} {% include 'snippets/block_button.html' with blocks=True %} diff --git a/bookwyrm/templates/user/groups.html b/bookwyrm/templates/user/groups.html index 912d5ec3..1a594072 100644 --- a/bookwyrm/templates/user/groups.html +++ b/bookwyrm/templates/user/groups.html @@ -24,7 +24,7 @@ {% block panel %}
-