Skip to content

Commit

Permalink
Expands tests and fixes logic error in report recipients
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Jan 3, 2024
1 parent 0612930 commit 8de3668
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 3 additions & 3 deletions bookwyrm/models/report.py
Expand Up @@ -64,9 +64,9 @@ def broadcast(self, activity, sender, *args, **kwargs):

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}"
Expand Down
1 change: 0 additions & 1 deletion bookwyrm/templates/snippets/report_modal.html
Expand Up @@ -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:" %}
Expand Down
14 changes: 14 additions & 0 deletions bookwyrm/tests/models/test_report_model.py
Expand Up @@ -45,3 +45,17 @@ def test_report_local_user(self):
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])
4 changes: 2 additions & 2 deletions bookwyrm/tests/views/admin/test_reports.py
Expand Up @@ -118,7 +118,7 @@ def test_resolve_report(self):
# 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()
)

Expand All @@ -130,7 +130,7 @@ def test_resolve_report(self):
# 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()
)

Expand Down

0 comments on commit 8de3668

Please sign in to comment.