From 34f375c53cd63795ace4821bd7a0bae3a780cffc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 10 Jan 2022 13:27:01 -0800 Subject: [PATCH] Store user that added link --- bookwyrm/forms.py | 2 +- bookwyrm/models/link.py | 9 ++++++--- bookwyrm/templates/book/file_link_modal.html | 1 + bookwyrm/tests/views/books/test_links.py | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 5ad36501..e08f3a3a 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -225,7 +225,7 @@ class LinkDomainForm(CustomForm): class FileLinkForm(CustomForm): class Meta: model = models.FileLink - fields = ["url", "filetype", "book"] + fields = ["url", "filetype", "book", "added_by"] class EditionForm(CustomForm): diff --git a/bookwyrm/models/link.py b/bookwyrm/models/link.py index 22241ddd..3e21642f 100644 --- a/bookwyrm/models/link.py +++ b/bookwyrm/models/link.py @@ -15,6 +15,12 @@ class Link(ActivitypubMixin, BookWyrmModel): """a link to a website""" url = fields.URLField(max_length=255, activitypub_field="href") + added_by = fields.ForeignKey( + "User", + on_delete=models.SET_NULL, + null=True, + activitypub_field="attributedTo" + ) domain = models.ForeignKey( "LinkDomain", on_delete=models.CASCADE, @@ -22,9 +28,6 @@ class Link(ActivitypubMixin, BookWyrmModel): blank=True, related_name="links", ) - added_by = fields.ForeignKey( - "User", on_delete=models.SET_NULL, null=True, activitypub_field="attributedTo" - ) activity_serializer = activitypub.Link reverse_unfurl = True diff --git a/bookwyrm/templates/book/file_link_modal.html b/bookwyrm/templates/book/file_link_modal.html index 04e21557..379f1a07 100644 --- a/bookwyrm/templates/book/file_link_modal.html +++ b/bookwyrm/templates/book/file_link_modal.html @@ -12,6 +12,7 @@ {% block modal-body %} {% csrf_token %} +

{% trans "Links from unknown domains will need to be approved by a moderator before they are added." %} diff --git a/bookwyrm/tests/views/books/test_links.py b/bookwyrm/tests/views/books/test_links.py index 1214e0e2..1961bde0 100644 --- a/bookwyrm/tests/views/books/test_links.py +++ b/bookwyrm/tests/views/books/test_links.py @@ -66,6 +66,7 @@ class LinkViews(TestCase): form.data["url"] = "https://www.example.com" form.data["filetype"] = "HTML" form.data["book"] = self.book.id + form.data["added_by"] = self.local_user request = self.factory.post("", form.data) request.user = self.local_user