- {{ list.name }}{% include 'snippets/privacy-icons.html' with item=list %}
+ {{ list.get_name }}{% include 'snippets/privacy-icons.html' with item=list %}
{% if request.user.is_authenticated and request.user|saved:list %}
@@ -33,9 +33,9 @@
{% endwith %}
-
- {% if list.description %}
- {{ list.description|to_markdown|safe|truncatechars_html:30 }}
+
{{ list.get_name }} {% include 'snippets/privacy-icons.html' with item=list %}
+ {% if list.suggests_for == None %}
{% include 'lists/created_text.html' with list=list %}
+ {% endif %}
- {% if request.user == list.user %}
+ {% if request.user == list.user and list.suggests_for == None %}
{% trans "Edit List" as button_text %}
{% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_list" focus="edit_list_header" %}
diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html
index 04fcd253c8..6a5208a555 100644
--- a/bookwyrm/templates/lists/list.html
+++ b/bookwyrm/templates/lists/list.html
@@ -177,6 +177,7 @@
+ {% if list.suggests_for == None %}
{% trans "Sort List" %}
@@ -199,6 +200,7 @@
+ {% endif %}
{% if request.user.is_authenticated and not list.curation == 'closed' or request.user == list.user %}
{% if list.curation == 'open' or request.user == list.user or list.group|is_member:request.user %}
diff --git a/bookwyrm/views/list/list.py b/bookwyrm/views/list/list.py
index 61f870928b..079d7a035e 100644
--- a/bookwyrm/views/list/list.py
+++ b/bookwyrm/views/list/list.py
@@ -73,7 +73,7 @@ def get(self, request, list_id, **kwargs):
if request.user.is_authenticated:
data["suggested_books"] = get_list_suggestions(
- book_list, request.user, query=query
+ book_list, request.user, query=query, ignore_id=book_list.suggests_for.id
)
return TemplateResponse(request, "lists/list.html", data)
diff --git a/bookwyrm/views/list/lists.py b/bookwyrm/views/list/lists.py
index 90cca49737..ff4c931779 100644
--- a/bookwyrm/views/list/lists.py
+++ b/bookwyrm/views/list/lists.py
@@ -54,9 +54,7 @@ class SavedLists(View):
def get(self, request):
"""display book lists"""
# hide lists with no approved books
- lists = request.user.saved_lists.order_by("-updated_date").filter(
- suggests_for__isnull=True
- )
+ lists = request.user.saved_lists.order_by("-updated_date")
paginated = Paginator(lists, 12)
data = {
From 067ce297bc9c9ad11a4dce556263fd1c12c24002 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 18:14:04 +0100
Subject: [PATCH 011/962] black
---
bookwyrm/models/list.py | 4 +++-
bookwyrm/views/list/list.py | 5 ++++-
2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py
index 2b18b733c9..2862a0695c 100644
--- a/bookwyrm/models/list.py
+++ b/bookwyrm/models/list.py
@@ -76,7 +76,9 @@ def get_name(self):
@property
def get_description(self):
if self.suggests_for:
- return _("This is the list of suggestions for %(title)s") % {
+ return _(
+ "This is the list of suggestions for %(title)s"
+ ) % {
"title": self.suggests_for.title,
"url": self.suggests_for.local_path,
}
diff --git a/bookwyrm/views/list/list.py b/bookwyrm/views/list/list.py
index 079d7a035e..ef9c7a53d3 100644
--- a/bookwyrm/views/list/list.py
+++ b/bookwyrm/views/list/list.py
@@ -73,7 +73,10 @@ def get(self, request, list_id, **kwargs):
if request.user.is_authenticated:
data["suggested_books"] = get_list_suggestions(
- book_list, request.user, query=query, ignore_id=book_list.suggests_for.id
+ book_list,
+ request.user,
+ query=query,
+ ignore_id=book_list.suggests_for.id,
)
return TemplateResponse(request, "lists/list.html", data)
From 2faaea6ef76e19968a0ddf611f2b2cb472ac6027 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 18:14:26 +0100
Subject: [PATCH 012/962] docstrings
---
bookwyrm/models/list.py | 2 ++
1 file changed, 2 insertions(+)
diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py
index 2862a0695c..68ce6e8621 100644
--- a/bookwyrm/models/list.py
+++ b/bookwyrm/models/list.py
@@ -68,6 +68,7 @@ def collection_queryset(self):
@property
def get_name(self):
+ """The name comes from the book title if it's a suggestion list"""
if self.suggests_for:
return _("Suggestions for %(title)s") % {"title": self.suggests_for.title}
@@ -75,6 +76,7 @@ def get_name(self):
@property
def get_description(self):
+ """The description comes from the book title if it's a suggestion list"""
if self.suggests_for:
return _(
"This is the list of suggestions for %(title)s"
From 62c9c71343f187112d18188e7f82058d49576458 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 18:31:24 +0100
Subject: [PATCH 013/962] Replace ignore_id with ignore_book
---
bookwyrm/views/books/books.py | 2 +-
bookwyrm/views/list/list.py | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py
index b55af8ea6b..ff2d2ce551 100644
--- a/bookwyrm/views/books/books.py
+++ b/bookwyrm/views/books/books.py
@@ -132,7 +132,7 @@ def get(self, request, book_id, **kwargs):
book.suggestion_list,
request.user,
query=query,
- ignore_id=book.id,
+ ignore_book=book,
)
return TemplateResponse(request, "book/book.html", data)
diff --git a/bookwyrm/views/list/list.py b/bookwyrm/views/list/list.py
index ef9c7a53d3..11b4cd77f7 100644
--- a/bookwyrm/views/list/list.py
+++ b/bookwyrm/views/list/list.py
@@ -76,7 +76,7 @@ def get(self, request, list_id, **kwargs):
book_list,
request.user,
query=query,
- ignore_id=book_list.suggests_for.id,
+ ignore_book=book_list.suggests_for,
)
return TemplateResponse(request, "lists/list.html", data)
@@ -97,7 +97,7 @@ def post(self, request, list_id):
return redirect(book_list.local_path)
-def get_list_suggestions(book_list, user, query=None, ignore_id=None):
+def get_list_suggestions(book_list, user, query=None, ignore_book=None):
"""What books might a user want to add to a list"""
if query:
# search for books
@@ -105,12 +105,12 @@ def get_list_suggestions(book_list, user, query=None, ignore_id=None):
query,
filters=[
~Q(parent_work__editions__in=book_list.books.all()),
- ~Q(parent_work__editions__in=[ignore_id]),
+ ~Q(parent_work__editions__in=[ignore_book]),
],
)
# just suggest whatever books are nearby
suggestions = user.shelfbook_set.filter(~Q(book__in=book_list.books.all())).exclude(
- book__id=ignore_id
+ book=ignore_book
)
suggestions = [s.book for s in suggestions[:5]]
if len(suggestions) < 5:
@@ -118,7 +118,7 @@ def get_list_suggestions(book_list, user, query=None, ignore_id=None):
s.default_edition
for s in models.Work.objects.filter(
~Q(editions__in=book_list.books.all()),
- ~Q(editions__in=[ignore_id]),
+ ~Q(editions__in=[ignore_book]),
).order_by("-updated_date")[: 5 - len(suggestions)]
]
return suggestions
From 80ce4eca459d5bdb57e6767b9f7ec9b5e0973f71 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 18:46:34 +0100
Subject: [PATCH 014/962] Display the right lists in the Book sidebar
---
bookwyrm/templates/book/book.html | 2 +-
bookwyrm/views/books/books.py | 22 ++++++++++++++--------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html
index e920a496ca..62df9b2ea6 100644
--- a/bookwyrm/templates/book/book.html
+++ b/bookwyrm/templates/book/book.html
@@ -367,7 +367,7 @@
{% trans "Places" %}
{% endif %}
- {% if lists.exists or request.user.list_set.exists %}
+ {% if lists.exists or list_options.exists %}
{% trans "Lists" %}
diff --git a/bookwyrm/views/books/books.py b/bookwyrm/views/books/books.py
index ff2d2ce551..8c4ee0e1c0 100644
--- a/bookwyrm/views/books/books.py
+++ b/bookwyrm/views/books/books.py
@@ -76,11 +76,15 @@ def get(self, request, book_id, **kwargs):
queryset = queryset.select_related("user").order_by("-published_date")
paginated = Paginator(queryset, PAGE_LENGTH)
- query = request.GET.get("suggestion_query", "")
-
- lists = models.List.privacy_filter(request.user,).filter(
- listitem__approved=True,
- listitem__book__in=book.parent_work.editions.all(),
+ lists = (
+ models.List.privacy_filter(
+ request.user,
+ )
+ .filter(
+ listitem__approved=True,
+ listitem__book__in=book.parent_work.editions.all(),
+ )
+ .filter(suggests_for__isnull=True)
)
data = {
"book": book,
@@ -94,11 +98,13 @@ def get(self, request, book_id, **kwargs):
"rating": reviews.aggregate(Avg("rating"))["rating__avg"],
"lists": lists,
"update_error": kwargs.get("update_error", False),
- "query": query,
+ "query": request.GET.get("suggestion_query", ""),
}
if request.user.is_authenticated:
- data["list_options"] = request.user.list_set.exclude(id__in=data["lists"])
+ data["list_options"] = request.user.list_set.filter(
+ suggests_for__isnull=True
+ ).exclude(id__in=data["lists"])
data["file_link_form"] = forms.FileLinkForm()
readthroughs = models.ReadThrough.objects.filter(
user=request.user,
@@ -131,7 +137,7 @@ def get(self, request, book_id, **kwargs):
data["suggested_books"] = get_list_suggestions(
book.suggestion_list,
request.user,
- query=query,
+ query=request.GET.get("suggestion_query", ""),
ignore_book=book,
)
From 88da8257d56ccf776d26de30a4cc5c642040f7c6 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 19:44:02 +0100
Subject: [PATCH 015/962] Update ordered_collection.py
---
bookwyrm/activitypub/ordered_collection.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/bookwyrm/activitypub/ordered_collection.py b/bookwyrm/activitypub/ordered_collection.py
index 32e37c9966..7d8437d09b 100644
--- a/bookwyrm/activitypub/ordered_collection.py
+++ b/bookwyrm/activitypub/ordered_collection.py
@@ -40,6 +40,7 @@ class BookList(OrderedCollectionPrivate):
summary: str = None
curation: str = "closed"
+ book: str
type: str = "BookList"
From bee38cdf1f2594d46c763d42a66fab2463ea378c Mon Sep 17 00:00:00 2001
From: Joachim
Date: Sun, 1 Jan 2023 19:44:33 +0100
Subject: [PATCH 016/962] Add defauult
---
bookwyrm/activitypub/ordered_collection.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/bookwyrm/activitypub/ordered_collection.py b/bookwyrm/activitypub/ordered_collection.py
index 7d8437d09b..a3da6d24cb 100644
--- a/bookwyrm/activitypub/ordered_collection.py
+++ b/bookwyrm/activitypub/ordered_collection.py
@@ -40,7 +40,7 @@ class BookList(OrderedCollectionPrivate):
summary: str = None
curation: str = "closed"
- book: str
+ book: str = None
type: str = "BookList"
From 486278bbf44aaf4c63ffbd37852290ca9e71f0c9 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Tue, 1 Aug 2023 15:12:50 +0200
Subject: [PATCH 017/962] =?UTF-8?q?Black=20=F0=9F=95=B4=EF=B8=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
bookwyrm/views/list/list.py | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/bookwyrm/views/list/list.py b/bookwyrm/views/list/list.py
index ceb5fc2185..227725b2eb 100644
--- a/bookwyrm/views/list/list.py
+++ b/bookwyrm/views/list/list.py
@@ -102,8 +102,8 @@ def post(self, request, list_id):
def get_list_suggestions(
- book_list, user, query=None, num_suggestions=5, ignore_book=None
- ):
+ book_list, user, query=None, num_suggestions=5, ignore_book=None
+):
"""What books might a user want to add to a list"""
if query:
# search for books
@@ -115,9 +115,11 @@ def get_list_suggestions(
],
)
# just suggest whatever books are nearby
- suggestions = user.shelfbook_set.filter(
- ~Q(book__in=book_list.books.all())
- ).exclude(book=ignore_book).distinct()[:num_suggestions]
+ suggestions = (
+ user.shelfbook_set.filter(~Q(book__in=book_list.books.all()))
+ .exclude(book=ignore_book)
+ .distinct()[:num_suggestions]
+ )
suggestions = [s.book for s in suggestions[:num_suggestions]]
if len(suggestions) < num_suggestions:
others = [
From 0f93833b4fcb91d8b094591ae7ea7eeff654fa82 Mon Sep 17 00:00:00 2001
From: Joachim
Date: Tue, 1 Aug 2023 15:12:57 +0200
Subject: [PATCH 018/962] Update migration
---
.../{0173_list_suggests_for.py => 0180_list_suggests_for.py} | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
rename bookwyrm/migrations/{0173_list_suggests_for.py => 0180_list_suggests_for.py} (83%)
diff --git a/bookwyrm/migrations/0173_list_suggests_for.py b/bookwyrm/migrations/0180_list_suggests_for.py
similarity index 83%
rename from bookwyrm/migrations/0173_list_suggests_for.py
rename to bookwyrm/migrations/0180_list_suggests_for.py
index 48c9456967..dcd2e09858 100644
--- a/bookwyrm/migrations/0173_list_suggests_for.py
+++ b/bookwyrm/migrations/0180_list_suggests_for.py
@@ -1,4 +1,4 @@
-# Generated by Django 3.2.16 on 2023-01-01 16:19
+# Generated by Django 3.2.20 on 2023-08-01 13:12
import bookwyrm.models.fields
from django.db import migrations
@@ -8,7 +8,7 @@
class Migration(migrations.Migration):
dependencies = [
- ("bookwyrm", "0172_alter_user_preferred_language"),
+ ("bookwyrm", "0179_populate_sort_title"),
]
operations = [
From 5b229fa362dae4cd22495765b7e7c7e21f44fde8 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Tue, 2 Jan 2024 13:57:19 -0800
Subject: [PATCH 019/962] Makes reports an activitypub model
---
bookwyrm/activitypub/__init__.py | 1 +
bookwyrm/activitypub/verbs.py | 10 ++++
.../migrations/0192_auto_20240102_2156.py | 57 +++++++++++++++++++
bookwyrm/models/report.py | 25 +++++---
4 files changed, 86 insertions(+), 7 deletions(-)
create mode 100644 bookwyrm/migrations/0192_auto_20240102_2156.py
diff --git a/bookwyrm/activitypub/__init__.py b/bookwyrm/activitypub/__init__.py
index 41decd68af..5789986378 100644
--- a/bookwyrm/activitypub/__init__.py
+++ b/bookwyrm/activitypub/__init__.py
@@ -24,6 +24,7 @@
from .verbs import Add, Remove
from .verbs import Announce, Like
from .verbs import Move
+from .verbs import Flag
# this creates a list of all the Activity types that we can serialize,
# so when an Activity comes in from outside, we can check if it's known
diff --git a/bookwyrm/activitypub/verbs.py b/bookwyrm/activitypub/verbs.py
index a365f4cc07..13a303af71 100644
--- a/bookwyrm/activitypub/verbs.py
+++ b/bookwyrm/activitypub/verbs.py
@@ -268,3 +268,13 @@ def action(self, allow_external_connections=True):
else:
# we might do something with this to move other objects at some point
pass
+
+
+@dataclass(init=False)
+class Flag(Verb):
+ """Report a user to their home server"""
+
+ to: str
+ object: List[str] = None
+ links: List[str] = None
+ type: str = "Flag"
diff --git a/bookwyrm/migrations/0192_auto_20240102_2156.py b/bookwyrm/migrations/0192_auto_20240102_2156.py
new file mode 100644
index 0000000000..7537bbbaae
--- /dev/null
+++ b/bookwyrm/migrations/0192_auto_20240102_2156.py
@@ -0,0 +1,57 @@
+# Generated by Django 3.2.23 on 2024-01-02 21:56
+
+import bookwyrm.models.fields
+from django.conf import settings
+from django.db import migrations
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("bookwyrm", "0191_merge_20240102_0326"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="report",
+ name="links",
+ field=bookwyrm.models.fields.ManyToManyField(
+ blank=True, to="bookwyrm.Link"
+ ),
+ ),
+ migrations.AlterField(
+ model_name="report",
+ name="note",
+ field=bookwyrm.models.fields.TextField(blank=True, null=True),
+ ),
+ migrations.AlterField(
+ model_name="report",
+ name="reporter",
+ field=bookwyrm.models.fields.ForeignKey(
+ on_delete=django.db.models.deletion.PROTECT,
+ related_name="reporter",
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ migrations.AlterField(
+ model_name="report",
+ name="status",
+ field=bookwyrm.models.fields.ForeignKey(
+ blank=True,
+ null=True,
+ on_delete=django.db.models.deletion.PROTECT,
+ to="bookwyrm.status",
+ ),
+ ),
+ migrations.AlterField(
+ model_name="report",
+ name="user",
+ field=bookwyrm.models.fields.ForeignKey(
+ blank=True,
+ null=True,
+ on_delete=django.db.models.deletion.PROTECT,
+ to=settings.AUTH_USER_MODEL,
+ ),
+ ),
+ ]
diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py
index 74a9bbe411..153ba6dc29 100644
--- a/bookwyrm/models/report.py
+++ b/bookwyrm/models/report.py
@@ -3,8 +3,11 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
+from bookwyrm import activitypub
from bookwyrm.settings import DOMAIN
+from .activitypub_mixin import ActivityMixin
from .base_model import BookWyrmModel
+from . import fields
# Report action enums
@@ -22,21 +25,29 @@
DELETE_ITEM = "delete_item"
-class Report(BookWyrmModel):
+class Report(ActivityMixin, BookWyrmModel):
"""reported status or user"""
- reporter = models.ForeignKey(
- "User", related_name="reporter", on_delete=models.PROTECT
+ activity_serializer = activitypub.Flag
+
+ reporter = fields.ForeignKey(
+ "User",
+ related_name="reporter",
+ on_delete=models.PROTECT,
+ activitypub_field="actor",
+ )
+ note = fields.TextField(null=True, blank=True, activitypub_field="content")
+ user = fields.ForeignKey(
+ "User", on_delete=models.PROTECT, null=True, blank=True, activitypub_field="to"
)
- note = models.TextField(null=True, blank=True)
- user = models.ForeignKey("User", on_delete=models.PROTECT, null=True, blank=True)
- status = models.ForeignKey(
+ status = fields.ForeignKey(
"Status",
null=True,
blank=True,
on_delete=models.PROTECT,
+ activitypub_field="object",
)
- links = models.ManyToManyField("Link", blank=True)
+ links = fields.ManyToManyField("Link", blank=True)
resolved = models.BooleanField(default=False)
def raise_not_editable(self, viewer):
From 5c0ade5346726e39453c202b1c6cf7ea78969252 Mon Sep 17 00:00:00 2001
From: Mouse Reeve
Date: Tue, 2 Jan 2024 14:38:35 -0800
Subject: [PATCH 020/962] Changes field names in report model so the reporter
is "user"
This is such an annoying change but it is objectively better. Just gotta
be real sure they didn't get mixed up anywhere along the way.
---
bookwyrm/emailing.py | 8 ++--
bookwyrm/forms/forms.py | 2 +-
.../0193_rename_user_report_reported_user.py | 18 ++++++++
.../0194_rename_reporter_report_user.py | 18 ++++++++
bookwyrm/models/antispam.py | 8 ++--
bookwyrm/models/report.py | 23 ++++++----
bookwyrm/templates/report.html | 2 +-
.../templates/settings/reports/report.html | 20 ++++----
.../settings/reports/report_header.html | 8 ++--
.../settings/reports/report_preview.html | 2 +-
bookwyrm/templates/snippets/report_modal.html | 8 ++--
bookwyrm/tests/models/test_report_model.py | 46 +++++++++++++++++++
bookwyrm/tests/views/admin/test_reports.py | 18 +++++---
bookwyrm/tests/views/admin/test_user_admin.py | 2 +-
bookwyrm/tests/views/test_notifications.py | 4 +-
bookwyrm/tests/views/test_report.py | 10 ++--
16 files changed, 145 insertions(+), 52 deletions(-)
create mode 100644 bookwyrm/migrations/0193_rename_user_report_reported_user.py
create mode 100644 bookwyrm/migrations/0194_rename_reporter_report_user.py
create mode 100644 bookwyrm/tests/models/test_report_model.py
diff --git a/bookwyrm/emailing.py b/bookwyrm/emailing.py
index 5e08ebba13..758da962c0 100644
--- a/bookwyrm/emailing.py
+++ b/bookwyrm/emailing.py
@@ -50,9 +50,11 @@ def password_reset_email(reset_code):
def moderation_report_email(report):
"""a report was created"""
data = email_data()
- data["reporter"] = report.reporter.localname or report.reporter.username
- if report.user:
- data["reportee"] = report.user.localname or report.user.username
+ data["reporter"] = report.user.localname or report.user.username
+ if report.reported_user:
+ data["reportee"] = (
+ report.reported_user.localname or report.reported_user.username
+ )
data["report_link"] = report.remote_id
data["link_domain"] = report.links.exists()
diff --git a/bookwyrm/forms/forms.py b/bookwyrm/forms/forms.py
index 3d555f308d..4764b871a7 100644
--- a/bookwyrm/forms/forms.py
+++ b/bookwyrm/forms/forms.py
@@ -44,7 +44,7 @@ class Meta:
class ReportForm(CustomForm):
class Meta:
model = models.Report
- fields = ["user", "reporter", "status", "links", "note"]
+ fields = ["reported_user", "user", "status", "links", "note"]
class ReadThroughForm(CustomForm):
diff --git a/bookwyrm/migrations/0193_rename_user_report_reported_user.py b/bookwyrm/migrations/0193_rename_user_report_reported_user.py
new file mode 100644
index 0000000000..0633e69fa1
--- /dev/null
+++ b/bookwyrm/migrations/0193_rename_user_report_reported_user.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.23 on 2024-01-02 22:16
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("bookwyrm", "0192_auto_20240102_2156"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="report",
+ old_name="user",
+ new_name="reported_user",
+ ),
+ ]
diff --git a/bookwyrm/migrations/0194_rename_reporter_report_user.py b/bookwyrm/migrations/0194_rename_reporter_report_user.py
new file mode 100644
index 0000000000..3c2c0f1802
--- /dev/null
+++ b/bookwyrm/migrations/0194_rename_reporter_report_user.py
@@ -0,0 +1,18 @@
+# Generated by Django 3.2.23 on 2024-01-02 22:17
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("bookwyrm", "0193_rename_user_report_reported_user"),
+ ]
+
+ operations = [
+ migrations.RenameField(
+ model_name="report",
+ old_name="reporter",
+ new_name="user",
+ ),
+ ]
diff --git a/bookwyrm/models/antispam.py b/bookwyrm/models/antispam.py
index 1067cbf1d7..da58e8aa68 100644
--- a/bookwyrm/models/antispam.py
+++ b/bookwyrm/models/antispam.py
@@ -109,9 +109,9 @@ def automod_users(reporter):
return report_model.objects.bulk_create(
[
report_model(
- reporter=reporter,
+ user=reporter,
note=_("Automatically generated report"),
- user=u,
+ reported_user=u,
)
for u in users
]
@@ -143,9 +143,9 @@ def automod_statuses(reporter):
return report_model.objects.bulk_create(
[
report_model(
- reporter=reporter,
+ user=reporter,
note=_("Automatically generated report"),
- user=s.user,
+ reported_user=s.user,
status=s,
)
for s in statuses
diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py
index 153ba6dc29..9a9b0393c5 100644
--- a/bookwyrm/models/report.py
+++ b/bookwyrm/models/report.py
@@ -1,5 +1,4 @@
""" flagged for moderation """
-from django.core.exceptions import PermissionDenied
from django.db import models
from django.utils.translation import gettext_lazy as _
@@ -30,15 +29,19 @@ class Report(ActivityMixin, BookWyrmModel):
activity_serializer = activitypub.Flag
- reporter = fields.ForeignKey(
+ user = fields.ForeignKey(
"User",
- related_name="reporter",
on_delete=models.PROTECT,
activitypub_field="actor",
)
note = fields.TextField(null=True, blank=True, activitypub_field="content")
- user = fields.ForeignKey(
- "User", on_delete=models.PROTECT, null=True, blank=True, activitypub_field="to"
+ reported_user = fields.ForeignKey(
+ "User",
+ related_name="reported_user",
+ on_delete=models.PROTECT,
+ null=True,
+ blank=True,
+ activitypub_field="to",
)
status = fields.ForeignKey(
"Status",
@@ -50,11 +53,11 @@ class Report(ActivityMixin, BookWyrmModel):
links = fields.ManyToManyField("Link", blank=True)
resolved = models.BooleanField(default=False)
- def raise_not_editable(self, viewer):
- """instead of user being the owner field, it's reporter"""
- if self.reporter == viewer or viewer.has_perm("bookwyrm.moderate_user"):
- return
- raise PermissionDenied()
+ def get_recipients(self, software=None):
+ """Send this to the public inbox of the offending instance"""
+ if self.user.local:
+ return None
+ return [self.user.shared_inbox or self.user.inbox]
def get_remote_id(self):
return f"https://{DOMAIN}/settings/reports/{self.id}"
diff --git a/bookwyrm/templates/report.html b/bookwyrm/templates/report.html
index be7ed68f7a..b1ea826925 100644
--- a/bookwyrm/templates/report.html
+++ b/bookwyrm/templates/report.html
@@ -6,5 +6,5 @@
{% endblock %}
{% block content %}
-{% include "snippets/report_modal.html" with user=user active=True static=True id="report-modal" %}
+{% include "snippets/report_modal.html" with reported_user=reported_user active=True static=True id="report-modal" %}
{% endblock %}
diff --git a/bookwyrm/templates/settings/reports/report.html b/bookwyrm/templates/settings/reports/report.html
index df45341c6d..f26892af51 100644
--- a/bookwyrm/templates/settings/reports/report.html
+++ b/bookwyrm/templates/settings/reports/report.html
@@ -27,7 +27,7 @@
{% trans "Update on your report:" as dm_template %}
- {% include 'snippets/create_status/status.html' with type="direct" uuid=1 mention=report.reporter prepared_content=dm_template no_script=True %}
+ {% include 'snippets/create_status/status.html' with type="direct" uuid=1 mention=report.user prepared_content=dm_template no_script=True %}
@@ -56,10 +56,10 @@
{% trans "Reported links" %}
{% endif %}
-{% if report.user %}
-{% include 'settings/users/user_info.html' with user=report.user %}
+{% if report.reported_user %}
+{% include 'settings/users/user_info.html' with reported_user=report.reported_user %}
-{% include 'settings/users/user_moderation_actions.html' with user=report.user %}
+{% include 'settings/users/user_moderation_actions.html' with reported_user=report.reported_user %}
{% endif %}
@@ -70,8 +70,8 @@
{% trans "Moderation Activity" %}
- {% blocktrans trimmed with user=report.reporter|username user_link=report.reporter.local_path %}
- {{ user}} opened this report
+ {% blocktrans trimmed with reported_user=report.user|username user_link=report.user.local_path %}
+ {{ reported_user}} opened this report
{% endblocktrans %}
{{ report.created_date }}
@@ -83,12 +83,12 @@
{% trans "Moderation Activity" %}
{% if comment.action_type == "comment" %}
- {% blocktrans trimmed with user=comment.user|username user_link=comment.user.local_path %}
- {{ user}} commented on this report:
+ {% blocktrans trimmed with reported_user=comment.reported_user|username user_link=comment.reported_user.local_path %}
+ {{ reported_user}} commented on this report:
{% endblocktrans %}
{% else %}
- {% blocktrans trimmed with user=comment.user|username user_link=comment.user.local_path %}
- {{ user}} took an action on this report:
+ {% blocktrans trimmed with reported_user=comment.reported_user|username user_link=comment.reported_user.local_path %}
+ {{ reported_user}} took an action on this report:
{% endblocktrans %}
{{ comment.get_action_type_display }}
diff --git a/bookwyrm/templates/settings/reports/report_header.html b/bookwyrm/templates/settings/reports/report_header.html
index b77c6c6ae6..1c9b01c9b2 100644
--- a/bookwyrm/templates/settings/reports/report_header.html
+++ b/bookwyrm/templates/settings/reports/report_header.html
@@ -3,14 +3,14 @@
{% if report.status %}
-{% blocktrans trimmed with report_id=report.id username=report.user|username %}
+{% blocktrans trimmed with report_id=report.id username=report.reported_user|username %}
Report #{{ report_id }}: Status posted by @{{ username }}
{% endblocktrans %}
{% elif report.links.exists %}
- {% if report.user %}
- {% blocktrans trimmed with report_id=report.id username=report.user|username %}
+ {% if report.reported_user %}
+ {% blocktrans trimmed with report_id=report.id username=report.reported_user|username %}
Report #{{ report_id }}: Link added by @{{ username }}
{% endblocktrans %}
{% else %}
@@ -21,7 +21,7 @@
{% else %}
-{% blocktrans trimmed with report_id=report.id username=report.user|username %}
+{% blocktrans trimmed with report_id=report.id username=report.reported_user|username %}
Report #{{ report_id }}: User @{{ username }}
{% endblocktrans %}
diff --git a/bookwyrm/templates/settings/reports/report_preview.html b/bookwyrm/templates/settings/reports/report_preview.html
index bd0009c519..26afd273cf 100644
--- a/bookwyrm/templates/settings/reports/report_preview.html
+++ b/bookwyrm/templates/settings/reports/report_preview.html
@@ -21,7 +21,7 @@