kopia lustrzana https://github.com/tsileo/little-boxes
Add support for Article
rodzic
0326bb9309
commit
f06202c382
|
@ -97,6 +97,8 @@ ACTOR_TYPES = [
|
||||||
ActivityType.SERVICE,
|
ActivityType.SERVICE,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
CREATE_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
||||||
|
|
||||||
COLLECTION_TYPES = [ActivityType.COLLECTION, ActivityType.ORDERED_COLLECTION]
|
COLLECTION_TYPES = [ActivityType.COLLECTION, ActivityType.ORDERED_COLLECTION]
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,7 +226,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
||||||
kwargs.pop("actor")
|
kwargs.pop("actor")
|
||||||
actor = self._validate_actor(actor)
|
actor = self._validate_actor(actor)
|
||||||
self._data["actor"] = actor
|
self._data["actor"] = actor
|
||||||
elif self.ACTIVITY_TYPE == ActivityType.NOTE:
|
elif self.ACTIVITY_TYPE in CREATE_TYPES:
|
||||||
if "attributedTo" not in kwargs:
|
if "attributedTo" not in kwargs:
|
||||||
raise BadActivityError(f"Note is missing attributedTo")
|
raise BadActivityError(f"Note is missing attributedTo")
|
||||||
else:
|
else:
|
||||||
|
@ -445,7 +447,7 @@ class BaseActivity(object, metaclass=_ActivityMeta):
|
||||||
actor = self._data.get("actor")
|
actor = self._data.get("actor")
|
||||||
if not actor and self.ACTOR_REQUIRED:
|
if not actor and self.ACTOR_REQUIRED:
|
||||||
# Quick hack for Note objects
|
# Quick hack for Note objects
|
||||||
if self.ACTIVITY_TYPE == ActivityType.NOTE:
|
if self.ACTIVITY_TYPE in CREATE_TYPES:
|
||||||
actor = str(self._data.get("attributedTo"))
|
actor = str(self._data.get("attributedTo"))
|
||||||
else:
|
else:
|
||||||
raise BadActivityError(f"failed to fetch actor: {self._data!r}")
|
raise BadActivityError(f"failed to fetch actor: {self._data!r}")
|
||||||
|
@ -834,7 +836,7 @@ class Undo(BaseActivity):
|
||||||
|
|
||||||
class Like(BaseActivity):
|
class Like(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.LIKE
|
ACTIVITY_TYPE = ActivityType.LIKE
|
||||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||||
OBJECT_REQUIRED = True
|
OBJECT_REQUIRED = True
|
||||||
ACTOR_REQUIRED = True
|
ACTOR_REQUIRED = True
|
||||||
|
|
||||||
|
@ -880,7 +882,7 @@ class Like(BaseActivity):
|
||||||
|
|
||||||
class Announce(BaseActivity):
|
class Announce(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.ANNOUNCE
|
ACTIVITY_TYPE = ActivityType.ANNOUNCE
|
||||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.ARTICLE]
|
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||||
OBJECT_REQUIRED = True
|
OBJECT_REQUIRED = True
|
||||||
ACTOR_REQUIRED = True
|
ACTOR_REQUIRED = True
|
||||||
|
|
||||||
|
@ -939,7 +941,7 @@ class Announce(BaseActivity):
|
||||||
|
|
||||||
class Delete(BaseActivity):
|
class Delete(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.DELETE
|
ACTIVITY_TYPE = ActivityType.DELETE
|
||||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.TOMBSTONE]
|
ALLOWED_OBJECT_TYPES = CREATE_TYPES + [ActivityType.TOMBSTONE]
|
||||||
OBJECT_REQUIRED = True
|
OBJECT_REQUIRED = True
|
||||||
|
|
||||||
def _get_actual_object(self) -> BaseActivity:
|
def _get_actual_object(self) -> BaseActivity:
|
||||||
|
@ -1008,7 +1010,7 @@ class Delete(BaseActivity):
|
||||||
|
|
||||||
class Update(BaseActivity):
|
class Update(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.UPDATE
|
ACTIVITY_TYPE = ActivityType.UPDATE
|
||||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE, ActivityType.PERSON]
|
ALLOWED_OBJECT_TYPES = CREATE_TYPES + [ActivityType.PERSON]
|
||||||
OBJECT_REQUIRED = True
|
OBJECT_REQUIRED = True
|
||||||
ACTOR_REQUIRED = True
|
ACTOR_REQUIRED = True
|
||||||
|
|
||||||
|
@ -1047,7 +1049,7 @@ class Update(BaseActivity):
|
||||||
|
|
||||||
class Create(BaseActivity):
|
class Create(BaseActivity):
|
||||||
ACTIVITY_TYPE = ActivityType.CREATE
|
ACTIVITY_TYPE = ActivityType.CREATE
|
||||||
ALLOWED_OBJECT_TYPES = [ActivityType.NOTE]
|
ALLOWED_OBJECT_TYPES = CREATE_TYPES
|
||||||
OBJECT_REQUIRED = True
|
OBJECT_REQUIRED = True
|
||||||
ACTOR_REQUIRED = True
|
ACTOR_REQUIRED = True
|
||||||
|
|
||||||
|
@ -1196,6 +1198,12 @@ class Note(BaseActivity):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
class Article(Note):
|
||||||
|
ACTIVITY_TYPE = ActivityType.ARTICLE
|
||||||
|
ACTOR_REQUIRED = True
|
||||||
|
OBJECT_REQURIED = False
|
||||||
|
|
||||||
|
|
||||||
def fetch_remote_activity(
|
def fetch_remote_activity(
|
||||||
iri: str, expected: Optional[ActivityType] = None
|
iri: str, expected: Optional[ActivityType] = None
|
||||||
) -> BaseActivity:
|
) -> BaseActivity:
|
||||||
|
@ -1214,7 +1222,7 @@ class Outbox(Box):
|
||||||
f"{activity.get_actor()!r} cannot post into {self.actor!r} outbox"
|
f"{activity.get_actor()!r} cannot post into {self.actor!r} outbox"
|
||||||
)
|
)
|
||||||
|
|
||||||
if activity.ACTIVITY_TYPE == ActivityType.NOTE:
|
if activity.ACTIVITY_TYPE in CREATE_TYPES:
|
||||||
activity = activity.build_create()
|
activity = activity.build_create()
|
||||||
|
|
||||||
activity.post_to_outbox()
|
activity.post_to_outbox()
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
from little_boxes.collection import parse_collection
|
from little_boxes.collection import parse_collection
|
||||||
from little_boxes.errors import RecursionLimitExceededError
|
from little_boxes.errors import RecursionLimitExceededError
|
||||||
from little_boxes.errors import UnexpectedActivityTypeError
|
from little_boxes.errors import UnexpectedActivityTypeError
|
||||||
|
|
||||||
from test_backend import InMemBackend
|
from test_backend import InMemBackend
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from unittest import mock
|
||||||
|
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
from little_boxes import content_helper
|
from little_boxes import content_helper
|
||||||
|
|
||||||
from test_backend import InMemBackend
|
from test_backend import InMemBackend
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
from little_boxes import httpsig
|
from little_boxes import httpsig
|
||||||
from little_boxes.key import Key
|
from little_boxes.key import Key
|
||||||
|
|
||||||
|
import httpretty
|
||||||
from test_backend import InMemBackend
|
from test_backend import InMemBackend
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from little_boxes import activitypub as ap
|
from little_boxes import activitypub as ap
|
||||||
|
|
||||||
from test_backend import InMemBackend
|
from test_backend import InMemBackend
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from little_boxes import urlutils
|
from little_boxes import urlutils
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,12 +2,12 @@ import json
|
||||||
import logging
|
import logging
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import httpretty
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from little_boxes import urlutils
|
from little_boxes import urlutils
|
||||||
from little_boxes import webfinger
|
from little_boxes import webfinger
|
||||||
|
|
||||||
|
import httpretty
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue