Add system actor and shared inbox

This commit is contained in:
Andrew Godwin 2022-12-10 13:24:49 -07:00
parent fd52500591
commit 602e5a3780
6 changed files with 13 additions and 1 deletions

1
.gitignore vendored
View File

@ -13,4 +13,5 @@
/media/
/static-collected
__pycache__/
api-test.*
notes.md

View File

@ -199,6 +199,8 @@ urlpatterns = [
path(".well-known/nodeinfo", activitypub.NodeInfo.as_view()),
path("nodeinfo/2.0/", activitypub.NodeInfo2.as_view()),
path("actor/", activitypub.SystemActorView.as_view()),
path("actor/inbox/", activitypub.Inbox.as_view()),
path("inbox/", activitypub.Inbox.as_view(), name="shared_inbox"),
# Stator
path(".stator/", stator.RequestRunner.as_view()),
# Django admin

View File

@ -14,6 +14,7 @@ def test_webfinger_actor(client, identity):
# Fetch their actor
data = client.get("/@test@example.com/", HTTP_ACCEPT="application/ld+json").json()
assert data["id"] == "https://example.com/@test@example.com/"
assert data["endpoints"]["sharedInbox"] == "https://example.com/inbox/"
@pytest.mark.django_db
@ -31,6 +32,7 @@ def test_webfinger_system_actor(client):
data = client.get("/actor/", HTTP_ACCEPT="application/ld+json").json()
assert data["id"] == "https://example.com/actor/"
assert data["inbox"] == "https://example.com/actor/inbox/"
assert data["endpoints"]["sharedInbox"] == "https://example.com/inbox/"
@pytest.mark.django_db

View File

@ -296,6 +296,10 @@ class Identity(StatorModel):
"mediaType": media_type_from_filename(self.image.name),
"url": self.image.url,
}
if self.local:
response["endpoints"] = {
"sharedInbox": f"https://{self.domain.uri_domain}/inbox/",
}
return response
### ActivityPub (inbound) ###

View File

@ -43,6 +43,9 @@ class SystemActor:
"id": self.actor_uri,
"type": "Application",
"inbox": self.actor_uri + "inbox/",
"endpoints": {
"sharedInbox": f"https://{settings.MAIN_DOMAIN}/inbox/",
},
"preferredUsername": self.username,
"url": self.profile_uri,
"as:manuallyApprovesFollowers": True,

View File

@ -138,7 +138,7 @@ class Inbox(View):
AP Inbox endpoint
"""
def post(self, request, handle):
def post(self, request, handle=None):
# Load the LD
document = canonicalise(json.loads(request.body), include_security=True)
# Find the Identity by the actor on the incoming item