summaryrefslogtreecommitdiffstats
path: root/users
diff options
context:
space:
mode:
authorMichael Manfre2022-11-22 23:53:02 -0500
committerGitHub2022-11-22 21:53:02 -0700
commitf88efa40d497995a5f645d03f99345c804f808d7 (patch)
tree1989e2386dba401b2fed981120d779c399110556 /users
parent96f863d5d8ffa2a326a889eb6b0f8c4c11efb200 (diff)
downloadtakahe-f88efa40d497995a5f645d03f99345c804f808d7.tar.gz
takahe-f88efa40d497995a5f645d03f99345c804f808d7.tar.bz2
takahe-f88efa40d497995a5f645d03f99345c804f808d7.zip
Code dedupe Webfinger and fix SystemActor inbox URL
Diffstat (limited to 'users')
-rw-r--r--users/models/system_actor.py5
-rw-r--r--users/views/activitypub.py67
2 files changed, 29 insertions, 43 deletions
diff --git a/users/models/system_actor.py b/users/models/system_actor.py
index 28ef1a8..c337d78 100644
--- a/users/models/system_actor.py
+++ b/users/models/system_actor.py
@@ -22,6 +22,9 @@ class SystemActor:
self.profile_uri = f"https://{settings.MAIN_DOMAIN}/about/"
self.username = "__system__"
+ def absolute_profile_uri(self):
+ return self.profile_uri
+
def generate_keys(self):
self.private_key, self.public_key = RsaKeys.generate_keypair()
Config.set_system("system_actor_private_key", self.private_key)
@@ -39,7 +42,7 @@ class SystemActor:
return {
"id": self.actor_uri,
"type": "Application",
- "inbox": self.actor_uri + "/inbox/",
+ "inbox": self.actor_uri + "inbox/",
"preferredUsername": self.username,
"url": self.profile_uri,
"as:manuallyApprovesFollowers": True,
diff --git a/users/views/activitypub.py b/users/views/activitypub.py
index 1ca80a1..2c7020a 100644
--- a/users/views/activitypub.py
+++ b/users/views/activitypub.py
@@ -99,51 +99,34 @@ class Webfinger(View):
if not resource.startswith("acct:"):
return HttpResponseBadRequest("Not an account resource")
handle = resource[5:]
+
if handle.startswith("__system__@"):
# They are trying to webfinger the system actor
- system_actor = SystemActor()
- return JsonResponse(
- {
- "subject": f"acct:{handle}",
- "aliases": [
- system_actor.profile_uri,
- ],
- "links": [
- {
- "rel": "http://webfinger.net/rel/profile-page",
- "type": "text/html",
- "href": system_actor.profile_uri,
- },
- {
- "rel": "self",
- "type": "application/activity+json",
- "href": system_actor.actor_uri,
- },
- ],
- }
- )
+ actor = SystemActor()
else:
- identity = by_handle_or_404(request, handle)
- return JsonResponse(
- {
- "subject": f"acct:{identity.handle}",
- "aliases": [
- identity.absolute_profile_uri(),
- ],
- "links": [
- {
- "rel": "http://webfinger.net/rel/profile-page",
- "type": "text/html",
- "href": identity.absolute_profile_uri(),
- },
- {
- "rel": "self",
- "type": "application/activity+json",
- "href": identity.actor_uri,
- },
- ],
- }
- )
+ actor = by_handle_or_404(request, handle)
+ handle = actor.handle
+
+ return JsonResponse(
+ {
+ "subject": f"acct:{handle}",
+ "aliases": [
+ actor.absolute_profile_uri(),
+ ],
+ "links": [
+ {
+ "rel": "http://webfinger.net/rel/profile-page",
+ "type": "text/html",
+ "href": actor.absolute_profile_uri(),
+ },
+ {
+ "rel": "self",
+ "type": "application/activity+json",
+ "href": actor.actor_uri,
+ },
+ ],
+ }
+ )
@method_decorator(csrf_exempt, name="dispatch")