mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-15 21:31:26 +00:00
Get flagged status out of incoming Flag activity
This commit is contained in:
parent
063f6d6e03
commit
c76087e21d
2 changed files with 54 additions and 16 deletions
|
@ -3,7 +3,12 @@ from dataclasses import dataclass, field
|
|||
from typing import List
|
||||
from django.apps import apps
|
||||
|
||||
from .base_activity import ActivityObject, Signature, resolve_remote_id
|
||||
from .base_activity import (
|
||||
ActivityObject,
|
||||
ActivitySerializerError,
|
||||
Signature,
|
||||
resolve_remote_id,
|
||||
)
|
||||
from .ordered_collection import CollectionItem
|
||||
|
||||
|
||||
|
@ -277,5 +282,20 @@ class Flag(Verb):
|
|||
content: str = None
|
||||
|
||||
def action(self, allow_external_connections=False):
|
||||
"""usually we just want to update and save"""
|
||||
self.to_model(allow_external_connections=allow_external_connections)
|
||||
"""Create the report and attach reported statuses"""
|
||||
report = self.to_model(allow_external_connections=allow_external_connections)
|
||||
# go through "objects" and figure out what they are
|
||||
for obj in self.object:
|
||||
# what type of obj is it?
|
||||
try:
|
||||
item = resolve_remote_id(
|
||||
remote_id=obj,
|
||||
save=False,
|
||||
model="Status",
|
||||
allow_external_connections=allow_external_connections,
|
||||
)
|
||||
except ActivitySerializerError:
|
||||
continue
|
||||
report.status = item
|
||||
report.save()
|
||||
break
|
||||
|
|
|
@ -2,17 +2,15 @@
|
|||
from unittest.mock import patch
|
||||
|
||||
from django.test import TestCase
|
||||
import responses
|
||||
|
||||
from bookwyrm import models, views
|
||||
|
||||
|
||||
# pylint: disable=too-many-public-methods
|
||||
class InboxFlag(TestCase):
|
||||
"""inbox tests"""
|
||||
|
||||
@classmethod
|
||||
def setUpTestData(cls): # pylint: disable=invalid-name
|
||||
def setUpTestData(cls):
|
||||
"""basic user and book data"""
|
||||
with (
|
||||
patch("bookwyrm.suggested_users.rerank_suggestions_task.delay"),
|
||||
|
@ -26,7 +24,6 @@ class InboxFlag(TestCase):
|
|||
local=True,
|
||||
localname="mouse",
|
||||
)
|
||||
cls.local_user.remote_id = "https://example.com/user/mouse"
|
||||
cls.local_user.save(broadcast=False, update_fields=["remote_id"])
|
||||
with patch("bookwyrm.models.user.set_remote_server.delay"):
|
||||
cls.remote_user = models.User.objects.create_user(
|
||||
|
@ -39,26 +36,47 @@ class InboxFlag(TestCase):
|
|||
outbox="https://example.com/users/rat/outbox",
|
||||
)
|
||||
|
||||
cls.status = models.Status.objects.create(
|
||||
user=cls.local_user, content="bad things"
|
||||
)
|
||||
|
||||
models.SiteSettings.objects.create()
|
||||
|
||||
@responses.activate
|
||||
def test_flag_local_user(self):
|
||||
"""Serialize a report from a remote server"""
|
||||
# TODO: is this actually what a Flag object from mastodon looks like?
|
||||
activity = {
|
||||
"id": "https://example.com/shelfbook/6189#add",
|
||||
"id": "https://example.com/settings/reports/6189",
|
||||
"type": "Flag",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": {},
|
||||
"object": [self.local_user.remote_id],
|
||||
"to": self.local_user.remote_id,
|
||||
"cc": ["https://example.com/user/mouse/followers"],
|
||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||
"content": "hello hello",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
# a report should now exist
|
||||
self.assertTrue(
|
||||
models.Report.objects.filter(
|
||||
report = models.Report.objects.get(
|
||||
user=self.remote_user, reported_user=self.local_user
|
||||
).exists()
|
||||
)
|
||||
self.assertEqual(report.note, "hello hello")
|
||||
|
||||
def test_flag_local_user_with_statuses(self):
|
||||
"""A report that includes a user and a status"""
|
||||
activity = {
|
||||
"id": "https://example.com/settings/reports/6189",
|
||||
"type": "Flag",
|
||||
"actor": self.remote_user.remote_id,
|
||||
"object": [self.local_user.remote_id, self.status.remote_id],
|
||||
"to": self.local_user.remote_id,
|
||||
"published": "Mon, 25 May 2020 19:31:20 GMT",
|
||||
"content": "hello hello",
|
||||
"@context": "https://www.w3.org/ns/activitystreams",
|
||||
}
|
||||
views.inbox.activity_task(activity)
|
||||
# a report should now exist
|
||||
report = models.Report.objects.get(
|
||||
user=self.remote_user, reported_user=self.local_user
|
||||
)
|
||||
self.assertEqual(report.note, "hello hello")
|
||||
self.assertEqual(report.status, self.status)
|
||||
|
|
Loading…
Reference in a new issue