Expands tests and fixes logic error in report recipients

This commit is contained in:
Mouse Reeve 2024-01-02 19:24:27 -08:00
parent 0612930fb9
commit 8de3668065
4 changed files with 19 additions and 6 deletions

View file

@ -64,9 +64,9 @@ class Report(ActivityMixin, BookWyrmModel):
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]
if self.reported_user.local:
return []
return [self.reported_user.shared_inbox or self.reported_user.inbox]
def get_remote_id(self):
return f"https://{DOMAIN}/settings/reports/{self.id}"

View file

@ -44,7 +44,6 @@
{% else %}
<input type="hidden" name="allow_broadcast">
{% endif %}
</p>
<div class="control">
<label class="label" for="id_{{ controls_uid }}_report_note">
{% trans "More info about this report:" %}

View file

@ -45,3 +45,17 @@ class Relationship(TestCase):
self.assertEqual(activity["type"], "Flag")
self.assertEqual(activity["actor"], self.local_user.remote_id)
self.assertEqual(activity["to"], self.another_local_user.remote_id)
# self.assertEqual(activity["object"], [self.another_local_user.remote_id])
self.assertEqual(report.get_recipients(), [])
def test_report_remote_user_with_broadcast(self):
"""a report to the outside needs to broadcast"""
with patch("bookwyrm.models.report.Report.broadcast") as broadcast_mock:
report = models.Report.objects.create(
user=self.local_user,
note="oh no bad",
reported_user=self.remote_user,
allow_broadcast=True,
)
self.assertEqual(broadcast_mock.call_count, 1)
self.assertEqual(report.get_recipients(), [self.remote_user.inbox])

View file

@ -118,7 +118,7 @@ class ReportViews(TestCase):
# check that the action was noted
self.assertTrue(
models.ReportAction.objects.filter(
report=report, action_type="resolve", reported_user=self.local_user
report=report, action_type="resolve", user=self.local_user
).exists()
)
@ -130,7 +130,7 @@ class ReportViews(TestCase):
# check that the action was noted
self.assertTrue(
models.ReportAction.objects.filter(
report=report, action_type="reopen", reported_user=self.local_user
report=report, action_type="reopen", user=self.local_user
).exists()
)