summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-10 13:24:49 -0700
committerAndrew Godwin2022-12-10 13:24:49 -0700
commit602e5a378057f3cd5ca355fd3ed2a17fcc147c72 (patch)
treeeaa950ac15e45a4a900ce7fa0fed400fadf50a17
parentfd5250059118a3f6932b4d39a085164b10577706 (diff)
downloadtakahe-602e5a378057f3cd5ca355fd3ed2a17fcc147c72.tar.gz
takahe-602e5a378057f3cd5ca355fd3ed2a17fcc147c72.tar.bz2
takahe-602e5a378057f3cd5ca355fd3ed2a17fcc147c72.zip
Add system actor and shared inbox
-rw-r--r--.gitignore1
-rw-r--r--takahe/urls.py2
-rw-r--r--tests/users/views/test_activitypub.py2
-rw-r--r--users/models/identity.py4
-rw-r--r--users/models/system_actor.py3
-rw-r--r--users/views/activitypub.py2
6 files changed, 13 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index bc256e2..fd7ddf6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,4 +13,5 @@
/media/
/static-collected
__pycache__/
+api-test.*
notes.md
diff --git a/takahe/urls.py b/takahe/urls.py
index 98d1cd5..762e091 100644
--- a/takahe/urls.py
+++ b/takahe/urls.py
@@ -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
diff --git a/tests/users/views/test_activitypub.py b/tests/users/views/test_activitypub.py
index c6e7faf..c15e232 100644
--- a/tests/users/views/test_activitypub.py
+++ b/tests/users/views/test_activitypub.py
@@ -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
diff --git a/users/models/identity.py b/users/models/identity.py
index 21ac0fd..fe85d41 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -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) ###
diff --git a/users/models/system_actor.py b/users/models/system_actor.py
index c4319b9..fb5a9e1 100644
--- a/users/models/system_actor.py
+++ b/users/models/system_actor.py
@@ -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,
diff --git a/users/views/activitypub.py b/users/views/activitypub.py
index 93a6eae..b44edfb 100644
--- a/users/views/activitypub.py
+++ b/users/views/activitypub.py
@@ -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