mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-09 00:35:51 +00:00
Use correct model type for federated links
This commit is contained in:
parent
4b88ea142f
commit
6323b0e700
2 changed files with 13 additions and 2 deletions
|
@ -227,7 +227,7 @@ def set_related_field(
|
|||
model_field = getattr(model, related_field_name)
|
||||
if hasattr(model_field, "activitypub_field"):
|
||||
setattr(activity, getattr(model_field, "activitypub_field"), instance.remote_id)
|
||||
item = activity.to_model()
|
||||
item = activity.to_model(model=model)
|
||||
|
||||
# if the related field isn't serialized (attachments on Status), then
|
||||
# we have to set it post-creation
|
||||
|
@ -298,6 +298,7 @@ class Link(ActivityObject):
|
|||
mediaType: str = None
|
||||
id: str = None
|
||||
attributedTo: str = None
|
||||
availability: str = None
|
||||
type: str = "Link"
|
||||
|
||||
def serialize(self, **kwargs):
|
||||
|
@ -305,7 +306,6 @@ class Link(ActivityObject):
|
|||
omit = ("id", "type", "@context")
|
||||
return super().serialize(omit=omit)
|
||||
|
||||
|
||||
@dataclass(init=False)
|
||||
class Mention(Link):
|
||||
"""a subtype of Link for mentioning an actor"""
|
||||
|
|
|
@ -80,6 +80,17 @@ class LinkViews(TestCase):
|
|||
activity = json.loads(mock.call_args[1]["args"][1])
|
||||
self.assertEqual(activity["type"], "Update")
|
||||
self.assertEqual(activity["object"]["type"], "Edition")
|
||||
self.assertIsInstance(activity["object"]["fileLinks"], list)
|
||||
self.assertEqual(
|
||||
activity["object"]["fileLinks"][0]["href"], "https://www.example.com"
|
||||
)
|
||||
self.assertEqual(
|
||||
activity["object"]["fileLinks"][0]["mediaType"], "HTML"
|
||||
)
|
||||
self.assertEqual(
|
||||
activity["object"]["fileLinks"][0]["attributedTo"],
|
||||
self.local_user.remote_id
|
||||
)
|
||||
|
||||
link = models.FileLink.objects.get()
|
||||
self.assertEqual(link.name, "www.example.com")
|
||||
|
|
Loading…
Reference in a new issue