Store follow requests if manual approval is needed

master
Bob Mottram 2019-07-20 14:31:20 +01:00
parent c49eee530d
commit f2d5e1e05f
1 changed files with 51 additions and 27 deletions

View File

@ -261,7 +261,46 @@ def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
if debug: if debug:
print('DEBUG: Actor file not found: '+actorFilename) print('DEBUG: Actor file not found: '+actorFilename)
return manuallyApproveFollows return manuallyApproveFollows
def storeFollowRequest(baseDir: str, \
nicknameToFollow: str,domainToFollow: str,port: int, \
followJson: {}, \
debug: bool) -> bool:
"""Stores the follow request for later use
"""
accountsDir=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow
if not os.path.isdir(accountDir):
return False
if port!=80 and port!=443:
approveHandle=nicknameToFollow+'@'+domainToFollow+':'+str(port)
else:
approveHandle=nicknameToFollow+'@'+domainToFollow
# add to a file which contains a list of requests
approveFollowsFilename=accountDir+'/followrequests.txt'
if os.path.isfile(approveFollowsFilename):
if approveHandle not in open(approveFollowsFilename).read():
with open(approveFollowsFilename, "a") as fp:
fp.write(approveHandle+'\n')
else:
if debug:
print('DEBUG: '+approveHandle+' is already awaiting approval')
else:
with open(approveFollowsFilename, "w") as fp:
fp.write(approveHandle+'\n')
# store the follow request in its own directory
# We don't rely upon the inbox because items in there could expire
requestsDir=accountsDir+'/requests'
if not os.path.isdir(requestsDir):
os.mkdir(requestsDir)
followActivityfilename=requestsDir+'/'+approveHandle+'.follow'
with open(followActivityfilename, 'w') as fp:
commentjson.dump(followJson, fp, indent=4, sort_keys=False)
return True
return False
def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
port: int,sendThreads: [],postLog: [], \ port: int,sendThreads: [],postLog: [], \
cachedWebfingers: {},personCache: {}, \ cachedWebfingers: {},personCache: {}, \
@ -334,33 +373,18 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
# what is the followers policy? # what is the followers policy?
if followApprovalRequired(baseDir,nicknameToFollow, \ if followApprovalRequired(baseDir,nicknameToFollow, \
domainToFollow,debug): domainToFollow,debug):
accountsDir=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow return storeFollowRequest(baseDir, \
if os.path.isdir(accountDir): nicknameToFollow,domainToFollow,port, \
if port!=80 and port!=443: messageJson,debug)
approveHandle=nicknameToFollow+'@'+domainToFollow+':'+str(port)
else: return followedAccountAccepts(session,baseDir,httpPrefix, \
approveHandle=nicknameToFollow+'@'+domainToFollow nicknameToFollow,domainToFollow,port, \
approveFollowsFilename=accountDir+'/followrequests.txt' nickname,domain,fromPort, \
if os.path.isfile(approveFollowsFilename): messageJson['actor'],federationList,
if approveHandle not in open(approveFollowsFilename).read(): messageJson,acceptedCaps, \
with open(approveFollowsFilename, "a") as fp: sendThreads,postLog, \
fp.write(approveHandle+'\n') cachedWebfingers,personCache, \
else: debug)
if debug:
print('DEBUG: '+approveHandle+' is already awaiting approval')
else:
with open(approveFollowsFilename, "w") as fp:
fp.write(approveHandle+'\n')
return True
return False
followedAccountAccepts(session,baseDir,httpPrefix, \
nicknameToFollow,domainToFollow,port, \
nickname,domain,fromPort, \
messageJson['actor'],federationList,
messageJson,acceptedCaps, \
sendThreads,postLog, \
cachedWebfingers,personCache, \
debug)
def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \ def followedAccountAccepts(session,baseDir: str,httpPrefix: str, \
nicknameToFollow: str,domainToFollow: str,port: int, \ nicknameToFollow: str,domainToFollow: str,port: int, \