From 325672208fc66e698c666d84d6e926a75da1f89d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 18 Aug 2019 12:07:06 +0100 Subject: [PATCH] @context headers --- acceptreject.py | 1 + announce.py | 4 ++++ blocking.py | 2 ++ daemon.py | 4 ++++ delete.py | 2 ++ like.py | 5 +++++ posts.py | 9 ++++++--- session.py | 9 +++++++-- shares.py | 2 ++ 9 files changed, 33 insertions(+), 5 deletions(-) diff --git a/acceptreject.py b/acceptreject.py index fe25ec782..435af832c 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -40,6 +40,7 @@ def createAcceptReject(baseDir: str,federationList: [], \ domain=domain+':'+str(port) newAccept = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': acceptType, 'actor': httpPrefix+'://'+domain+'/users/'+nickname, 'to': [toUrl], diff --git a/announce.py b/announce.py index d3577adba..ee202576f 100644 --- a/announce.py +++ b/announce.py @@ -119,6 +119,7 @@ def updateAnnounceCollection(postFilename: str,actor: str,debug: bool) -> None: if debug: print('DEBUG: Adding initial shares (announcements) to '+postUrl) announcementsJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'id': postUrl, 'type': 'Collection', "totalItems": 1, @@ -195,6 +196,7 @@ def createAnnounce(session,baseDir: str,federationList: [], \ newAnnounceId= \ httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber newAnnounce = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'atomUri': httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber, 'cc': [], @@ -307,6 +309,7 @@ def undoAnnounce(session,baseDir: str,federationList: [], \ fullDomain=domain+':'+str(port) newUndoAnnounce = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'type': 'Undo', 'cc': [], @@ -416,6 +419,7 @@ def sendAnnounceViaServer(session,fromNickname: str,password: str, newAnnounceId= \ httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname+'/statuses/'+statusNumber newAnnounceJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'atomUri': newAnnounceId, 'cc': [ccUrl], diff --git a/blocking.py b/blocking.py index b2adfac59..4a1497238 100644 --- a/blocking.py +++ b/blocking.py @@ -158,6 +158,7 @@ def sendBlockViaServer(session,fromNickname: str,password: str, blockActor=httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname newBlockJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Block', 'actor': blockActor, 'object': blockedUrl, @@ -230,6 +231,7 @@ def sendUndoBlockViaServer(session,fromNickname: str,password: str, blockActor=httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname newBlockJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Undo', 'actor': blockActor, 'object': { diff --git a/daemon.py b/daemon.py index 13cc8b4d9..42292494c 100644 --- a/daemon.py +++ b/daemon.py @@ -875,6 +875,7 @@ class PubServer(BaseHTTPRequestHandler): createSession(self.server.domain,self.server.port,self.server.useTor) undoAnnounceActor=self.server.httpPrefix+'://'+self.server.domainFull+'/users/'+self.postToNickname newUndoAnnounce = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': undoAnnounceActor, 'type': 'Undo', 'cc': [undoAnnounceActor+'/followers'], @@ -942,6 +943,7 @@ class PubServer(BaseHTTPRequestHandler): likeActor=self.server.httpPrefix+'://'+self.server.domainFull+'/users/'+self.postToNickname actorLiked=likeUrl.split('/statuses/')[0] likeJson= { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Like', 'actor': likeActor, 'object': likeUrl, @@ -964,6 +966,7 @@ class PubServer(BaseHTTPRequestHandler): undoActor=self.server.httpPrefix+'://'+self.server.domainFull+'/users/'+self.postToNickname actorLiked=likeUrl.split('/statuses/')[0] undoLikeJson= { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Undo', 'actor': undoActor, 'object': { @@ -1001,6 +1004,7 @@ class PubServer(BaseHTTPRequestHandler): createSession(self.server.domain,self.server.port,self.server.useTor) deleteActor=self.server.httpPrefix+'://'+self.server.domainFull+'/users/'+self.postToNickname deleteJson= { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': actor, 'object': deleteUrl, 'to': ['https://www.w3.org/ns/activitystreams#Public',actor], diff --git a/delete.py b/delete.py index 220166640..44db34bbf 100644 --- a/delete.py +++ b/delete.py @@ -51,6 +51,7 @@ def createDelete(session,baseDir: str,federationList: [], \ newDeleteId= \ httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber newDelete = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'atomUri': httpPrefix+'://'+fullDomain+'/users/'+nickname+'/statuses/'+statusNumber, 'cc': [], @@ -102,6 +103,7 @@ def sendDeleteViaServer(session,fromNickname: str,password: str, ccUrl = httpPrefix + '://'+fromDomainFull+'/users/'+fromNickname+'/followers' newDeleteJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'cc': [ccUrl], 'object': deleteObjectUrl, diff --git a/like.py b/like.py index 2619df89e..f4e2d0a5f 100644 --- a/like.py +++ b/like.py @@ -92,6 +92,7 @@ def updateLikesCollection(postFilename: str,objectUrl: str, actor: str,debug: bo if debug: print('DEBUG: Adding initial likes to '+objectUrl) likesJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'id': objectUrl, 'type': 'Collection', "totalItems": 1, @@ -147,6 +148,7 @@ def like(session,baseDir: str,federationList: [],nickname: str,domain: str,port: likeTo=[objectUrl.split('/statuses/')[0]] newLikeJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Like', 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'object': objectUrl, @@ -240,6 +242,7 @@ def undolike(session,baseDir: str,federationList: [],nickname: str,domain: str,p likeTo=[objectUrl.split('/statuses/')[0]] newUndoLikeJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Undo', 'actor': httpPrefix+'://'+fullDomain+'/users/'+nickname, 'object': { @@ -338,6 +341,7 @@ def sendLikeViaServer(session,fromNickname: str,password: str, toUrl=[likeUrl.split('/statuses/')[0]] newLikeJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Like', 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'object': likeUrl, @@ -412,6 +416,7 @@ def sendUndoLikeViaServer(session,fromNickname: str,password: str, toUrl=[likeUrl.split('/statuses/')[0]] newUndoLikeJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Undo', 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'object': { diff --git a/posts.py b/posts.py index 7ab2e0c3e..f7fd198a7 100644 --- a/posts.py +++ b/posts.py @@ -494,6 +494,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ capabilityIdList=[oc['id']] newPost = { + "@context": "https://www.w3.org/ns/activitystreams", 'id': newPostId+'/activity', 'capability': capabilityIdList, 'type': 'Create', @@ -539,6 +540,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ imageDescription,useBlurhash) else: newPost = { + "@context": "https://www.w3.org/ns/activitystreams", 'id': newPostId, 'type': 'Note', 'summary': summary, @@ -619,6 +621,7 @@ def outboxMessageCreateWrap(httpPrefix: str, \ # TODO capabilityUrl=[] newPost = { + "@context": "https://www.w3.org/ns/activitystreams", 'id': newPostId+'/activity', 'capability': capabilityUrl, 'type': 'Create', @@ -889,8 +892,8 @@ def threadSendPost(session,postJsonStr: str,federationList: [],\ for attempt in range(20): postResult = \ postJsonString(session,postJsonStr,federationList, \ - inboxUrl,signatureHeaderJson, \ - "inbox:write") + inboxUrl,signatureHeaderJson, \ + "inbox:write",debug) if postResult: if debug: print('DEBUG: json post to '+inboxUrl+' succeeded') @@ -1102,7 +1105,7 @@ def sendPostViaServer(projectVersion: str, \ 'Content-type': 'application/json', \ 'Authorization': authHeader} postResult = \ - postJsonString(session,json.dumps(postJsonObject),[],inboxUrl,headers,"inbox:write") + postJsonString(session,json.dumps(postJsonObject),[],inboxUrl,headers,"inbox:write",debug) #if not postResult: # if debug: # print('DEBUG: POST failed for c2s to '+inboxUrl) diff --git a/session.py b/session.py index 602f1a266..dd186f926 100644 --- a/session.py +++ b/session.py @@ -65,7 +65,12 @@ def postJson(session,postJsonObject: {},federationList: [],inboxUrl: str,headers postResult = session.post(url = inboxUrl, data = json.dumps(postJsonObject), headers=headers) return postResult.text -def postJsonString(session,postJsonStr: str,federationList: [],inboxUrl: str,headers: {},capability: str) -> str: +def postJsonString(session,postJsonStr: str, \ + federationList: [], \ + inboxUrl: str, \ + headers: {}, \ + capability: str, \ + debug: bool) -> str: """Post a json message string to the inbox of another person Supplying a capability, such as "inbox:write" NOTE: Here we post a string rather than the original json so that @@ -77,7 +82,7 @@ def postJsonString(session,postJsonStr: str,federationList: [],inboxUrl: str,hea if not capability.startswith('cap'): # check that we are posting to a permitted domain if not urlPermitted(inboxUrl,federationList,capability): - print('postJson: '+inboxUrl+' not permitted') + print('postJson: '+inboxUrl+' not permitted by capabilities') return None postResult = session.post(url = inboxUrl, data = postJsonStr, headers=headers) diff --git a/shares.py b/shares.py index 224095766..13004c8b9 100644 --- a/shares.py +++ b/shares.py @@ -296,6 +296,7 @@ def sendShareViaServer(session,fromNickname: str,password: str, ccUrl = httpPrefix + '://'+fromDomainFull+'/users/'+fromNickname+'/followers' newShareJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Add', 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'target': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname+'/shares', @@ -385,6 +386,7 @@ def sendUndoShareViaServer(session,fromNickname: str,password: str, ccUrl = httpPrefix + '://'+fromDomainFull+'/users/'+fromNickname+'/followers' undoShareJson = { + "@context": "https://www.w3.org/ns/activitystreams", 'type': 'Remove', 'actor': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname, 'target': httpPrefix+'://'+fromDomainFull+'/users/'+fromNickname+'/shares',