Improve manual follow approval

merge-requests/6/head
Bob Mottram 2019-12-29 12:59:13 +00:00
parent 4594a92508
commit 10fde1cb21
3 changed files with 35 additions and 20 deletions

View File

@ -395,7 +395,7 @@ def storeFollowRequest(baseDir: str, \
if debug: if debug:
print('DEBUG: '+approveHandle+' is already awaiting approval') print('DEBUG: '+approveHandle+' is already awaiting approval')
else: else:
with open(approveFollowsFilename, "w") as fp: with open(approveFollowsFilename, "w+") as fp:
fp.write(approveHandle+'\n') fp.write(approveHandle+'\n')
# store the follow request in its own directory # store the follow request in its own directory

View File

@ -72,30 +72,32 @@ def manualApproveFollowRequest(session,baseDir: str, \
projectVersion: str) -> None: projectVersion: str) -> None:
"""Manually approve a follow request """Manually approve a follow request
""" """
print('Manually approving follow request from '+approveHandle)
handle=nickname+'@'+domain handle=nickname+'@'+domain
accountsDir=baseDir+'/accounts/'+handle print('Manual follow accept: '+handle+' approving follow request from '+approveHandle)
approveFollowsFilename=accountsDir+'/followrequests.txt' accountDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountDir+'/followrequests.txt'
if not os.path.isfile(approveFollowsFilename): if not os.path.isfile(approveFollowsFilename):
if debug: if debug:
print('WARN: Follow requests file '+approveFollowsFilename+' not found') print('Manual follow accept: follow requests file '+approveFollowsFilename+' not found')
return return
# is the handle in the requests file?
if approveHandle not in open(approveFollowsFilename).read(): if approveHandle not in open(approveFollowsFilename).read():
if debug: if debug:
print(handle+' not in '+approveFollowsFilename) print('Manual follow accept: '+approveHandle+' not in requests file '+approveFollowsFilename)
return return
approvefilenew = open(approveFollowsFilename+'.new', 'w+') approvefilenew = open(approveFollowsFilename+'.new', 'w+')
updateApprovedFollowers=False updateApprovedFollowers=False
with open(approveFollowsFilename, 'r') as approvefile: with open(approveFollowsFilename, 'r') as approvefile:
for handle in approvefile: for handleOfFollowRequester in approvefile:
if handle.startswith(approveHandle): # is this the approved follow?
handle=handle.replace('\n','') if handleOfFollowRequester.startswith(approveHandle):
handleOfFollowRequester=handleOfFollowRequester.replace('\n','')
port2=port port2=port
if ':' in handle: if ':' in handleOfFollowRequester:
port2=int(handle.split(':')[1]) port2=int(handleOfFollowRequester.split(':')[1])
requestsDir=accountsDir+'/requests' requestsDir=accountDir+'/requests'
followActivityfilename=requestsDir+'/'+handle+'.follow' followActivityfilename=requestsDir+'/'+handleOfFollowRequester+'.follow'
if os.path.isfile(followActivityfilename): if os.path.isfile(followActivityfilename):
followJson=loadJson(followActivityfilename) followJson=loadJson(followActivityfilename)
if followJson: if followJson:
@ -105,7 +107,7 @@ def manualApproveFollowRequest(session,baseDir: str, \
if ':' in approveDomain: if ':' in approveDomain:
approvePort=approveDomain.split(':')[1] approvePort=approveDomain.split(':')[1]
approveDomain=approveDomain.split(':')[0] approveDomain=approveDomain.split(':')[0]
print('Sending Accept for '+handle+' follow request from '+approveHandle) print('Manual follow accept: Sending Accept for '+handle+' follow request from '+approveNickname+'@'+approveDomain)
followedAccountAccepts(session,baseDir,httpPrefix, \ followedAccountAccepts(session,baseDir,httpPrefix, \
nickname,domain,port, \ nickname,domain,port, \
approveNickname,approveDomain,approvePort, \ approveNickname,approveDomain,approvePort, \
@ -116,13 +118,15 @@ def manualApproveFollowRequest(session,baseDir: str, \
debug,projectVersion) debug,projectVersion)
updateApprovedFollowers=True updateApprovedFollowers=True
else: else:
approvefilenew.write(handle) # this isn't the approved follow so it will remain
# in the requests file
approvefilenew.write(handleOfFollowRequester)
approvefilenew.close() approvefilenew.close()
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
followersFilename=accountDir+'/followers.txt'
if updateApprovedFollowers: if updateApprovedFollowers:
# update the followers # update the followers
followersFilename=accountsDir+'/followers.txt' print('Manual follow accept: updating '+followersFilename)
if os.path.isfile(followersFilename): if os.path.isfile(followersFilename):
if approveHandle not in open(followersFilename).read(): if approveHandle not in open(followersFilename).read():
try: try:
@ -131,8 +135,19 @@ def manualApproveFollowRequest(session,baseDir: str, \
followersFile.seek(0, 0) followersFile.seek(0, 0)
followersFile.write(approveHandle+'\n'+content) followersFile.write(approveHandle+'\n'+content)
except Exception as e: except Exception as e:
print('WARN: Failed to write entry to followers file '+str(e)) print('WARN: Manual follow accept. Failed to write entry to followers file '+str(e))
else:
print('WARN: Manual follow accept: '+approveHandle+' already exists in '+followersFilename)
else: else:
print('Manual follow accept: first follower accepted for '+handle+' is '+approveHandle)
followersFile=open(followersFilename, "w+") followersFile=open(followersFilename, "w+")
followersFile.write(approveHandle+'\n') followersFile.write(approveHandle+'\n')
followersFile.close() followersFile.close()
# only update the follow requests file if the follow is confirmed to be
# in followers.txt
if approveHandle in open(followersFilename).read():
# update the follow requests with the handles not yet approved
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
else:
os.remove(approveFollowsFilename+'.new')

View File

@ -488,10 +488,10 @@ def getCachedPostFilename(baseDir: str,nickname: str,domain: str, \
""" """
cachedPostDir=getCachedPostDirectory(baseDir,nickname,domain) cachedPostDir=getCachedPostDirectory(baseDir,nickname,domain)
if not os.path.isdir(cachedPostDir): if not os.path.isdir(cachedPostDir):
print('ERROR: invalid html cache directory '+cachedPostDir) #print('ERROR: invalid html cache directory '+cachedPostDir)
return None return None
if '@' not in cachedPostDir: if '@' not in cachedPostDir:
print('ERROR: invalid html cache directory '+cachedPostDir) #print('ERROR: invalid html cache directory '+cachedPostDir)
return None return None
cachedPostFilename= \ cachedPostFilename= \
cachedPostDir+ \ cachedPostDir+ \