Updates report model

This commit is contained in:
Mouse Reeve 2022-02-24 12:48:52 -08:00
parent 3ce8b3390e
commit ad41f19dc5
11 changed files with 93 additions and 19 deletions

View file

@ -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):

View file

@ -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),
]

View file

@ -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',
),
]

View file

@ -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'),
),
]

View file

@ -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
]

View file

@ -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)

View file

@ -15,6 +15,7 @@
<div class="notification content">
<p>
{% 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 <em>not</em> being generated automatically, and you must manually trigger a scan." %}
</p>
<form name="run-scan" method="POST" action="{% url 'settings-automod-run' %}">

View file

@ -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 @@
</details>
</div>
{% if report.statuses.exists %}
{% if report.status %}
<div class="block">
<h3 class="title is-4">{% trans "Reported statuses" %}</h3>
<ul>
{% for status in report.statuses.select_subclasses.all %}
<li>
{% if status.deleted %}
<h3 class="title is-4">{% trans "Reported status" %}</h3>
{% if report.status.deleted %}
<em>{% trans "Status has been deleted" %}</em>
{% else %}
{% include 'snippets/status/status.html' with status=status moderation_mode=True %}
{% include 'snippets/status/status.html' with status=report.status|load_subclass moderation_mode=True %}
{% endif %}
</li>
{% endfor %}
</ul>
</div>
{% endif %}

View file

@ -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 }}

View file

@ -12,6 +12,6 @@
>
{% trans "Report" %}
</button>
{% 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 %}

View file

@ -23,7 +23,7 @@
<input type="hidden" name="reporter" value="{{ request.user.id }}">
<input type="hidden" name="user" value="{{ user.id }}">
{% if status_id %}
<input type="hidden" name="statuses" value="{{ status_id }}">
<input type="hidden" name="status" value="{{ status_id }}">
{% endif %}
{% if link %}
<input type="hidden" name="links" value="{{ link.id }}">