From 1d820e21999da3528cf5606212adf8c710da8c2e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 9 Jul 2019 09:39:50 +0100 Subject: [PATCH] Include the handle within the capability id. This improves the matching confidence for shared inbox --- capabilities.py | 9 ++++++++- inbox.py | 13 ++++++++----- utils.py | 8 ++++---- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/capabilities.py b/capabilities.py index 38efc70a..7da73eb2 100644 --- a/capabilities.py +++ b/capabilities.py @@ -12,6 +12,8 @@ import time import json import commentjson from auth import createPassword +from utils import getNicknameFromActor +from utils import getDomainFromActor def getOcapFilename(baseDir :str,nickname: str,domain: str,actor :str,subdir: str) -> str: if ':' in domain: @@ -118,7 +120,12 @@ def capabilitiesAccept(baseDir: str,httpPrefix: str, \ ocapAccept=commentjson.load(fp) # otherwise create a new capability if not ocapAccept: - ocapId=createPassword(32) + acceptedActorNickname=getNicknameFromActor(acceptedActor) + acceptedActorDomain,acceptedActorPort=getDomainFromActor(acceptedActor) + if acceptedActorPort: + ocapId=acceptedActorNickname+'@'+acceptedActorDomain+':'+str(acceptedActorPort)+'#'+createPassword(32) + else: + ocapId=acceptedActorNickname+'@'+acceptedActorDomain+'#'+createPassword(32) ocapAccept = { "id": httpPrefix+"://"+fullDomain+"/caps/"+ocapId, "type": "Capability", diff --git a/inbox.py b/inbox.py index d2b0cb8b..2322e516 100644 --- a/inbox.py +++ b/inbox.py @@ -414,10 +414,11 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache # get recipients list recipientsDict=inboxPostRecipients(baseDir,queueJson['post'],httpPrefix,domain,port) - print('*************************************') - print('Resolved recipients list:') - pprint(recipientsDict) - print('*************************************') + if debug: + print('*************************************') + print('Resolved recipients list:') + pprint(recipientsDict) + print('*************************************') if queueJson['post'].get('capability'): if not isinstance(queueJson['post']['capability'], list): @@ -433,7 +434,9 @@ def runInboxQueue(baseDir: str,httpPrefix: str,sendThreads: [],postLog: [],cache if queueJson['post'].get('capability'): capabilityIdList=queueJson['post']['capability'] # does the capability id list within the post contain the id - # of one of the recipients? + # of the recipient with this handle? + # Here the capability id begins with the handle, so this could also + # be matched separately, but it's probably not necessary if capsId in capabilityIdList: if debug: print('DEBUG: object capabilities passed') diff --git a/utils.py b/utils.py index 0a048dde..49cb6e13 100644 --- a/utils.py +++ b/utils.py @@ -8,7 +8,7 @@ __status__ = "Production" import os import datetime -from capabilities import isCapable +#from capabilities import isCapable def getStatusNumber() -> (str,str): """Returns the status number and published date @@ -50,9 +50,9 @@ def domainPermitted(domain: str, federationList: []): return False def urlPermitted(url: str, federationList: [],ocapGranted: {},capability: str): - if ocapGranted: - if not isCapable(url,ocapGranted,capability): - return False + #if ocapGranted: + # if not isCapable(url,ocapGranted,capability): + # return False if len(federationList)==0: return True for domain in federationList: