forked from indymedia/epicyon
Store follow requests if manual approval is needed
parent
c49eee530d
commit
f2d5e1e05f
64
follow.py
64
follow.py
|
@ -262,6 +262,45 @@ def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
|
||||||
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,26 +373,11 @@ 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
|
|
||||||
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')
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
followedAccountAccepts(session,baseDir,httpPrefix, \
|
|
||||||
nicknameToFollow,domainToFollow,port, \
|
nicknameToFollow,domainToFollow,port, \
|
||||||
nickname,domain,fromPort, \
|
nickname,domain,fromPort, \
|
||||||
messageJson['actor'],federationList,
|
messageJson['actor'],federationList,
|
||||||
|
|
Loading…
Reference in New Issue