Move follow approval functions

master
Bob Mottram 2019-07-20 18:00:23 +01:00
parent 5cd0390234
commit c9a0167d55
2 changed files with 37 additions and 25 deletions

View File

@ -193,3 +193,36 @@ def receiveAcceptReject(session,baseDir: str, \
if debug: if debug:
print('DEBUG: Uh, '+messageJson['type']+', I guess') print('DEBUG: Uh, '+messageJson['type']+', I guess')
return True return True
def manualDenyFollowRequest(baseDir: str,nickname: str,domain: str,denyHandle: str) -> None:
"""Manually deny a follow request
"""
handle=args.nickname+'@'+domain
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountDir+'/followrequests.txt'
if handle in open(approveFollowsFilename).read():
with open(approveFollowsFilename+'.new', 'w') as approvefilenew:
with open(approveFollowsFilename, 'r') as approvefile:
for approveHandle in approvefile:
if not approveHandle.startswith(denyHandle):
approvefilenew.write(approveHandle)
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
print('Follow request from '+denyHandle+' was denied.')
def manualApproveFollowRequest(baseDir: str,nickname: str,domain: str,approveHandle: str):
"""Manually approve a follow request
"""
handle=nickname+'@'+domain
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountDir+'/followrequests.txt'
if handle in open(approveFollowsFilename).read():
with open(approveFollowsFilename+'.new', 'w') as approvefilenew:
with open(approveFollowsFilename, 'r') as approvefile:
for handle in approvefile:
if handle.startswith(approveHandle):
if ':' in handle:
port=int(handle.split(':')[1].replace('\n',''))
# TODO approve follow for handle/port
else:
approvefilenew.write(handle)
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)

View File

@ -70,6 +70,8 @@ from roles import sendRoleViaServer
from skills import sendSkillViaServer from skills import sendSkillViaServer
from availability import setAvailability from availability import setAvailability
from availability import sendAvailabilityViaServer from availability import sendAvailabilityViaServer
from acceptreject import manualDenyFollowRequest
from acceptreject import manualApproveFollowRequest
import argparse import argparse
def str2bool(v): def str2bool(v):
@ -334,20 +336,7 @@ if args.approve:
if '@' not in args.approve: if '@' not in args.approve:
print('syntax: --approve nick@domain') print('syntax: --approve nick@domain')
sys.exit() sys.exit()
handle=args.nickname+'@'+domain manualApproveFollowRequest(baseDir,args.nickname,domain,args.approve)
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountDir+'/followrequests.txt'
if handle in open(approveFollowsFilename).read():
with open(approveFollowsFilename+'.new', 'w') as approvefilenew:
with open(approveFollowsFilename, 'r') as approvefile:
for approveHandle in approvefile:
if approveHandle.startswith(args.approve):
if ':' in approveHandle:
port=int(approveHandle.split(':')[1].replace('\n',''))
# TODO approve follow for handle/port
else:
approvefilenew.write(approveHandle)
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
sys.exit() sys.exit()
if args.deny: if args.deny:
@ -357,17 +346,7 @@ if args.deny:
if '@' not in args.deny: if '@' not in args.deny:
print('syntax: --deny nick@domain') print('syntax: --deny nick@domain')
sys.exit() sys.exit()
handle=args.nickname+'@'+domain manualDenyFollowRequest(baseDir,args.nickname,domain,args.deny)
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountDir+'/followrequests.txt'
if handle in open(approveFollowsFilename).read():
with open(approveFollowsFilename+'.new', 'w') as approvefilenew:
with open(approveFollowsFilename, 'r') as approvefile:
for approveHandle in approvefile:
if not approveHandle.startswith(args.deny):
approvefilenew.write(approveHandle)
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
print('Follow request from '+args.deny+' was denied.')
sys.exit() sys.exit()
if args.followerspending: if args.followerspending: