Support outgoing retraction of shares in ActivityPub

merge-requests/152/head
Jason Robinson 2019-08-07 00:05:49 +03:00
rodzic a5fe105b6c
commit 6e403cb1ae
3 zmienionych plików z 42 dodań i 3 usunięć

Wyświetl plik

@ -209,17 +209,29 @@ class ActivitypubProfile(ActivitypubEntityMixin, Profile):
class ActivitypubRetraction(ActivitypubEntityMixin, Retraction):
_type = ObjectType.TOMBSTONE.value
def resolve_object_type(self):
return {
"Comment": ObjectType.TOMBSTONE.value,
"Post": ObjectType.TOMBSTONE.value,
"Share": ActivityType.ANNOUNCE.value,
}.get(self.entity_type)
def resolve_type(self):
return {
"Comment": ActivityType.DELETE.value,
"Post": ActivityType.DELETE.value,
"Share": ActivityType.UNDO.value,
}.get(self.entity_type)
def to_as2(self) -> Dict:
as2 = {
"@context": CONTEXTS_DEFAULT,
"id": self.activity_id,
"type": ActivityType.DELETE.value,
"type": self.resolve_type(),
"actor": self.actor_id,
"object": {
"id": self.target_id,
"type": self._type,
"type": self.resolve_object_type(),
},
"published": self.created_at.isoformat(),
}

Wyświetl plik

@ -166,6 +166,22 @@ class TestEntitiesConvertToAS2:
'published': '2019-04-27T00:00:00',
}
def test_retraction_to_as2__announce(self, activitypubretraction_announce):
result = activitypubretraction_announce.to_as2()
assert result == {
'@context': [
'https://www.w3.org/ns/activitystreams',
],
'type': 'Undo',
'id': 'http://127.0.0.1:8000/post/123456/#delete',
'actor': 'http://127.0.0.1:8000/profile/123456/',
'object': {
'id': 'http://127.0.0.1:8000/post/123456/activity',
'type': 'Announce',
},
'published': '2019-04-27T00:00:00',
}
class TestEntitiesPostReceive:
@patch("federation.utils.activitypub.retrieve_and_parse_profile", autospec=True)

Wyświetl plik

@ -93,6 +93,17 @@ def activitypubretraction():
)
@pytest.fixture
def activitypubretraction_announce():
with freeze_time("2019-04-27"):
return ActivitypubRetraction(
target_id="http://127.0.0.1:8000/post/123456/activity",
activity_id="http://127.0.0.1:8000/post/123456/#delete",
actor_id="http://127.0.0.1:8000/profile/123456/",
entity_type="Share",
)
@pytest.fixture
def activitypubundofollow():
return ActivitypubFollow(