diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index ef9bbc15..e442dbf4 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -444,6 +444,12 @@ class ListForm(CustomForm): fields = ["user", "name", "description", "curation", "privacy", "group"] +class ListItemForm(CustomForm): + class Meta: + model = models.ListItem + fields = ["user", "book", "book_list", "notes"] + + class GroupForm(CustomForm): class Meta: model = models.Group diff --git a/bookwyrm/migrations/0130_alter_listitem_notes.py b/bookwyrm/migrations/0130_alter_listitem_notes.py new file mode 100644 index 00000000..a12efd40 --- /dev/null +++ b/bookwyrm/migrations/0130_alter_listitem_notes.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.10 on 2022-01-24 20:01 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0129_auto_20220117_1716"), + ] + + operations = [ + migrations.AlterField( + model_name="listitem", + name="notes", + field=bookwyrm.models.fields.TextField( + blank=True, max_length=300, null=True + ), + ), + ] diff --git a/bookwyrm/migrations/0131_merge_20220125_1644.py b/bookwyrm/migrations/0131_merge_20220125_1644.py new file mode 100644 index 00000000..954ddacc --- /dev/null +++ b/bookwyrm/migrations/0131_merge_20220125_1644.py @@ -0,0 +1,13 @@ +# Generated by Django 3.2.10 on 2022-01-25 16:44 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0130_alter_listitem_notes"), + ("bookwyrm", "0130_alter_user_preferred_language"), + ] + + operations = [] diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index d159bc4a..7dff7214 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -2,6 +2,7 @@ import uuid from django.apps import apps +from django.core.exceptions import PermissionDenied from django.db import models from django.db.models import Q from django.utils import timezone @@ -74,6 +75,22 @@ class List(OrderedCollectionMixin, BookWyrmModel): return super().raise_not_editable(viewer) + def raise_not_submittable(self, viewer): + """can the user submit a book to the list?""" + # if you can't view the list you can't submit to it + self.raise_visible_to_user(viewer) + + # all good if you're the owner or the list is open + if self.user == viewer or self.curation in ["open", "curated"]: + return + if self.curation == "group": + is_group_member = GroupMember.objects.filter( + group=self.group, user=viewer + ).exists() + if is_group_member: + return + raise PermissionDenied() + @classmethod def followers_filter(cls, queryset, viewer): """Override filter for "followers" privacy level to allow non-following @@ -125,7 +142,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel): user = fields.ForeignKey( "User", on_delete=models.PROTECT, activitypub_field="actor" ) - notes = fields.TextField(blank=True, null=True) + notes = fields.TextField(blank=True, null=True, max_length=300) approved = models.BooleanField(default=True) order = fields.IntegerField() endorsement = models.ManyToManyField("User", related_name="endorsers") diff --git a/bookwyrm/templates/lists/add_item_modal.html b/bookwyrm/templates/lists/add_item_modal.html new file mode 100644 index 00000000..5c210d46 --- /dev/null +++ b/bookwyrm/templates/lists/add_item_modal.html @@ -0,0 +1,45 @@ +{% extends 'components/modal.html' %} +{% load i18n %} +{% load utilities %} +{% load group_tags %} + +{% block modal-title %} +{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %} + {% blocktrans trimmed with title=book|book_title %} + Add "{{ title }}" to this list + {% endblocktrans %} +{% else %} + {% blocktrans trimmed with title=book|book_title %} + Suggest "{{ title }}" for this list + {% endblocktrans %} +{% endif %} +{% endblock %} + +{% block modal-form-open %} +
{% endblock %} diff --git a/bookwyrm/templates/lists/curate.html b/bookwyrm/templates/lists/curate.html index 927fb5b6..9b484eb4 100644 --- a/bookwyrm/templates/lists/curate.html +++ b/bookwyrm/templates/lists/curate.html @@ -1,5 +1,6 @@ {% extends 'lists/layout.html' %} {% load i18n %} +{% load utilities %} {% block breadcrumbs %}