From ad41f19dc53bde368b497d2613fc3b2d9c00261a Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 24 Feb 2022 12:48:52 -0800 Subject: [PATCH] Updates report model --- bookwyrm/forms.py | 2 +- bookwyrm/migrations/0139_report_status.py | 37 +++++++++++++++++++ .../migrations/0140_remove_report_statuses.py | 17 +++++++++ .../migrations/0141_alter_report_status.py | 19 ++++++++++ bookwyrm/models/antispam.py | 2 +- bookwyrm/models/report.py | 7 +++- .../templates/settings/automod/rules.html | 1 + .../templates/settings/reports/report.html | 21 ++++------- .../settings/reports/report_header.html | 2 +- .../templates/snippets/report_button.html | 2 +- bookwyrm/templates/snippets/report_modal.html | 2 +- 11 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 bookwyrm/migrations/0139_report_status.py create mode 100644 bookwyrm/migrations/0140_remove_report_statuses.py create mode 100644 bookwyrm/migrations/0141_alter_report_status.py diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index f2e3f9bbe..7ae4e446f 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -495,7 +495,7 @@ class GroupForm(CustomForm): class ReportForm(CustomForm): class Meta: model = models.Report - fields = ["user", "reporter", "statuses", "links", "note"] + fields = ["user", "reporter", "status", "links", "note"] class EmailBlocklistForm(CustomForm): diff --git a/bookwyrm/migrations/0139_report_status.py b/bookwyrm/migrations/0139_report_status.py new file mode 100644 index 000000000..fc9386335 --- /dev/null +++ b/bookwyrm/migrations/0139_report_status.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.12 on 2022-02-24 20:41 + +from django.db import migrations, models +import django.db.models.deletion + + +def set_report_statuses(apps, schema_editor): + """copy over status fields""" + db_alias = schema_editor.connection.alias + report_model = apps.get_model("bookwyrm", "Report") + reports = report_model.objects.using(db_alias).filter(statuses__isnull=False) + for report in reports: + report.status = report.statuses.first() + report.save() + +def set_reverse(apps, schema_editor): + """copy over status fields""" + db_alias = schema_editor.connection.alias + report_model = apps.get_model("bookwyrm", "Report") + reports = report_model.objects.using(db_alias).filter(status__isnull=False) + for report in reports: + report.statuses.set(report.status) + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0138_automod'), + ] + + operations = [ + migrations.AddField( + model_name='report', + name='status', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='reports', to='bookwyrm.status'), + ), + migrations.RunPython(set_report_statuses, reverse_code=set_reverse), + ] diff --git a/bookwyrm/migrations/0140_remove_report_statuses.py b/bookwyrm/migrations/0140_remove_report_statuses.py new file mode 100644 index 000000000..94303ce9b --- /dev/null +++ b/bookwyrm/migrations/0140_remove_report_statuses.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.12 on 2022-02-24 20:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0139_report_status'), + ] + + operations = [ + migrations.RemoveField( + model_name='report', + name='statuses', + ), + ] diff --git a/bookwyrm/migrations/0141_alter_report_status.py b/bookwyrm/migrations/0141_alter_report_status.py new file mode 100644 index 000000000..e0a7e58ee --- /dev/null +++ b/bookwyrm/migrations/0141_alter_report_status.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.12 on 2022-02-24 20:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('bookwyrm', '0140_remove_report_statuses'), + ] + + operations = [ + migrations.AlterField( + model_name='report', + name='status', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='bookwyrm.status'), + ), + ] diff --git a/bookwyrm/models/antispam.py b/bookwyrm/models/antispam.py index e0d1aa4ef..d948d4190 100644 --- a/bookwyrm/models/antispam.py +++ b/bookwyrm/models/antispam.py @@ -109,7 +109,7 @@ def automod_statuses(reporter): reporter=reporter, note=_("Automatically generated report"), user=s.user, - statuses=[s.id], + status=s, ) for s in statuses ] diff --git a/bookwyrm/models/report.py b/bookwyrm/models/report.py index bd2a1ef0e..bf3184f52 100644 --- a/bookwyrm/models/report.py +++ b/bookwyrm/models/report.py @@ -12,7 +12,12 @@ class Report(BookWyrmModel): ) note = models.TextField(null=True, blank=True) user = models.ForeignKey("User", on_delete=models.PROTECT) - statuses = models.ManyToManyField("Status", blank=True) + status = models.ForeignKey( + "Status", + null=True, + blank=True, + on_delete=models.PROTECT, + ) links = models.ManyToManyField("Link", blank=True) resolved = models.BooleanField(default=False) diff --git a/bookwyrm/templates/settings/automod/rules.html b/bookwyrm/templates/settings/automod/rules.html index d913d5964..5b4b0c767 100644 --- a/bookwyrm/templates/settings/automod/rules.html +++ b/bookwyrm/templates/settings/automod/rules.html @@ -15,6 +15,7 @@

{% trans "Auto-moderation rules will create reports for any user or status with fields matching the provided string." %} + {% trans "Users or statuses that have already been reported (regardless of whether the report was resolved) will not be flagged." %} {% trans "At this time, reports are not being generated automatically, and you must manually trigger a scan." %}

diff --git a/bookwyrm/templates/settings/reports/report.html b/bookwyrm/templates/settings/reports/report.html index 3f83f0169..20fdeca36 100644 --- a/bookwyrm/templates/settings/reports/report.html +++ b/bookwyrm/templates/settings/reports/report.html @@ -1,6 +1,7 @@ {% extends 'settings/layout.html' %} {% load i18n %} {% load humanize %} +{% load feed_page_tags %} {% block title %} {% include "settings/reports/report_header.html" with report=report %} @@ -30,20 +31,14 @@
-{% if report.statuses.exists %} +{% if report.status %}
-

{% trans "Reported statuses" %}

- +

{% trans "Reported status" %}

+ {% if report.status.deleted %} + {% trans "Status has been deleted" %} + {% else %} + {% include 'snippets/status/status.html' with status=report.status|load_subclass moderation_mode=True %} + {% endif %}
{% endif %} diff --git a/bookwyrm/templates/settings/reports/report_header.html b/bookwyrm/templates/settings/reports/report_header.html index d76db1048..878a825da 100644 --- a/bookwyrm/templates/settings/reports/report_header.html +++ b/bookwyrm/templates/settings/reports/report_header.html @@ -1,7 +1,7 @@ {% load i18n %} {% load utilities %} -{% if report.statuses.exists %} +{% if report.status %} {% blocktrans trimmed with report_id=report.id username=report.user|username %} Report #{{ report_id }}: Status posted by @{{ username }} diff --git a/bookwyrm/templates/snippets/report_button.html b/bookwyrm/templates/snippets/report_button.html index 9d94d2af1..60b542f43 100644 --- a/bookwyrm/templates/snippets/report_button.html +++ b/bookwyrm/templates/snippets/report_button.html @@ -12,6 +12,6 @@ > {% trans "Report" %} -{% include 'snippets/report_modal.html' with user=user id=modal_id status=status.id %} +{% include 'snippets/report_modal.html' with user=user id=modal_id status_id=status.id %} {% endwith %} diff --git a/bookwyrm/templates/snippets/report_modal.html b/bookwyrm/templates/snippets/report_modal.html index f65cab590..64e0c298c 100644 --- a/bookwyrm/templates/snippets/report_modal.html +++ b/bookwyrm/templates/snippets/report_modal.html @@ -23,7 +23,7 @@ {% if status_id %} - + {% endif %} {% if link %}