Allow the user to decide if they want to send along a report

This commit is contained in:
Mouse Reeve 2024-01-02 15:13:56 -08:00
parent 5c0ade5346
commit 052823e0c9
5 changed files with 54 additions and 5 deletions

View file

@ -0,0 +1,39 @@
# Generated by Django 3.2.23 on 2024-01-02 23:10
import bookwyrm.models.fields
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0194_rename_reporter_report_user"),
]
operations = [
migrations.AddField(
model_name="report",
name="allow_broadcast",
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name="report",
name="reported_user",
field=bookwyrm.models.fields.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="reported_user",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="report",
name="user",
field=bookwyrm.models.fields.ForeignKey(
on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL
),
),
]

View file

@ -52,6 +52,15 @@ class Report(ActivityMixin, BookWyrmModel):
)
links = fields.ManyToManyField("Link", blank=True)
resolved = models.BooleanField(default=False)
allow_broadcast = models.BooleanField(default=False)
def broadcast(self, activity, sender, *args, **kwargs):
"""only need to send an activity for remote offenders"""
# don't try to broadcast if the reporter doesn't want you to,
# or if the reported user is local
if self.reported_user.local or not self.allow_broadcast:
return
super().broadcast(activity, sender, *args, **kwargs)
def get_recipients(self, software=None):
"""Send this to the public inbox of the offending instance"""

View file

@ -12,6 +12,6 @@
>
{% trans "Report" %}
</button>
{% include 'snippets/report_modal.html' with user=user id=modal_id status_id=status.id %}
{% include 'snippets/report_modal.html' with reported_user=user id=modal_id status_id=status.id %}
{% endwith %}

View file

@ -20,7 +20,7 @@
{% block modal-body %}
{% csrf_token %}
<input type="hidden" name="user" value="{{ request.reported_user.id }}">
<input type="hidden" name="user" value="{{ request.user.id }}">
<input type="hidden" name="reported_user" value="{{ reported_user.id }}">
{% if status_id %}
<input type="hidden" name="status" value="{{ status_id }}">

View file

@ -40,7 +40,8 @@ class Relationship(TestCase):
note="oh no bad",
reported_user=self.another_local_user,
)
activity = report.to_activity()
self.assertEqual(activity.type, "Flag")
self.assertEqual(activity.actor, self.local_user)
self.assertEqual(activity.to, self.another_local_user.remote_id)
self.assertEqual(activity["type"], "Flag")
self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["to"], self.another_local_user.remote_id)