mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-06-25 00:10:40 +00:00
Allow the user to decide if they want to send along a report
This commit is contained in:
parent
5c0ade5346
commit
052823e0c9
39
bookwyrm/migrations/0195_auto_20240102_2310.py
Normal file
39
bookwyrm/migrations/0195_auto_20240102_2310.py
Normal 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
|
||||
),
|
||||
),
|
||||
]
|
|
@ -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"""
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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 }}">
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue