Store user that added link

This commit is contained in:
Mouse Reeve 2022-01-10 13:27:01 -08:00
parent 6c78a7b6ef
commit 34f375c53c
4 changed files with 9 additions and 4 deletions

View file

@ -225,7 +225,7 @@ class LinkDomainForm(CustomForm):
class FileLinkForm(CustomForm): class FileLinkForm(CustomForm):
class Meta: class Meta:
model = models.FileLink model = models.FileLink
fields = ["url", "filetype", "book"] fields = ["url", "filetype", "book", "added_by"]
class EditionForm(CustomForm): class EditionForm(CustomForm):

View file

@ -15,6 +15,12 @@ class Link(ActivitypubMixin, BookWyrmModel):
"""a link to a website""" """a link to a website"""
url = fields.URLField(max_length=255, activitypub_field="href") 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( domain = models.ForeignKey(
"LinkDomain", "LinkDomain",
on_delete=models.CASCADE, on_delete=models.CASCADE,
@ -22,9 +28,6 @@ class Link(ActivitypubMixin, BookWyrmModel):
blank=True, blank=True,
related_name="links", related_name="links",
) )
added_by = fields.ForeignKey(
"User", on_delete=models.SET_NULL, null=True, activitypub_field="attributedTo"
)
activity_serializer = activitypub.Link activity_serializer = activitypub.Link
reverse_unfurl = True reverse_unfurl = True

View file

@ -12,6 +12,7 @@
{% block modal-body %} {% block modal-body %}
{% csrf_token %} {% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}"> <input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="added_by" value="{{ request.user.id }}">
<p class="notification"> <p class="notification">
{% trans "Links from unknown domains will need to be approved by a moderator before they are added." %} {% trans "Links from unknown domains will need to be approved by a moderator before they are added." %}

View file

@ -66,6 +66,7 @@ class LinkViews(TestCase):
form.data["url"] = "https://www.example.com" form.data["url"] = "https://www.example.com"
form.data["filetype"] = "HTML" form.data["filetype"] = "HTML"
form.data["book"] = self.book.id form.data["book"] = self.book.id
form.data["added_by"] = self.local_user
request = self.factory.post("", form.data) request = self.factory.post("", form.data)
request.user = self.local_user request.user = self.local_user