Commit c261eb93 authored by jaywink's avatar jaywink

Merge branch 'fix-share-retract-ap' into 'master'

Fix share retraction towards ActivityPub platforms

See merge request !567
parents 17c2510d 8319b8f9
Pipeline #5422 passed with stages
in 17 minutes and 8 seconds
......@@ -24,6 +24,11 @@ Changed
relay endpoint, however by default it is now unset. Also change the default value of
``SOCIALHOME_RELAY_SCOPE`` from ``all`` to ``none`` (ie not subscribing to relays).
Fixed
.....
* Fix share retraction towards ActivityPub platforms.
0.12.1 (2020-12-12)
-------------------
......
......@@ -2,8 +2,10 @@ from django.conf import settings
from django.test import override_settings, RequestFactory
from federation.entities import base
from socialhome.content.tests.factories import PublicContentFactory, SiteContentFactory
from socialhome.federate.utils import get_federable_object, get_profile, make_federable_profile
from socialhome.content.tests.factories import PublicContentFactory, SiteContentFactory, ContentFactory
from socialhome.federate.utils import (
get_federable_object, get_profile, make_federable_profile, make_federable_retraction,
)
from socialhome.tests.utils import SocialhomeTestCase
from socialhome.users.tests.factories import UserFactory, PublicUserFactory, SiteUserFactory
......@@ -95,3 +97,16 @@ class TestGetProfile(SocialhomeTestCase):
maked = make_federable_profile(self.profile)
self.assertEqual(returned.id, maked.id)
self.assertTrue(isinstance(returned, base.Profile))
class TestMakeFederableRetraction(SocialhomeTestCase):
@classmethod
def setUpTestData(cls) -> None:
super().setUpTestData()
cls.create_local_and_remote_user()
cls.content = ContentFactory(author=cls.remote_profile)
cls.share = ContentFactory(share_of=cls.content, author=cls.profile)
def test_target_id_correct_for_share(self):
obj = make_federable_retraction(self.share, author=self.profile)
self.assertEqual(obj.target_id, self.share.activities.first().fid)
......@@ -692,7 +692,7 @@ class TestMakeFederableContent(SocialhomeTestCase):
class TestMakeFederableRetraction(SocialhomeTestCase):
def test_returns_entity(self):
content = ContentFactory()
content = PublicContentFactory()
entity = make_federable_retraction(content, content.author)
self.assertEqual(entity.entity_type, "Post")
self.assertEqual(entity.target_id, content.fid)
......
......@@ -163,17 +163,22 @@ def make_federable_retraction(obj: Union[Content, Profile], author: Optional[Pro
}.get(obj.content_type)
actor_id = author.fid
handle = author.handle
if obj.content_type == ContentType.SHARE:
target_id = obj.activities.first().fid
else:
target_id = obj.fid
elif isinstance(obj, Profile):
entity_type = "Profile"
actor_id = obj.fid
handle = obj.handle
target_id = obj.fid
else:
logger.warning("make_federable_retraction - Unknown object type %s", obj)
return
return base.Retraction(
entity_type=entity_type,
actor_id=actor_id,
target_id=obj.fid,
target_id=target_id,
handle=handle,
target_guid=obj.guid,
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment