delegate option

master
Bob Mottram 2019-07-18 17:33:36 +01:00
parent 4f6e9eb87f
commit 05da296cdb
2 changed files with 55 additions and 16 deletions

View File

@ -213,6 +213,8 @@ parser.add_argument('--block', dest='block', type=str,default=None, \
help='Block a particular address') help='Block a particular address')
parser.add_argument('--unblock', dest='unblock', type=str,default=None, \ parser.add_argument('--unblock', dest='unblock', type=str,default=None, \
help='Remove a block on a particular address') help='Remove a block on a particular address')
parser.add_argument('--delegate', dest='delegate', type=str,default=None, \
help='Address of an account to delegate a role to')
parser.add_argument('--filter', dest='filterStr', type=str,default=None, \ parser.add_argument('--filter', dest='filterStr', type=str,default=None, \
help='Adds a word or phrase which if present will cause a message to be ignored') help='Adds a word or phrase which if present will cause a message to be ignored')
parser.add_argument('--unfilter', dest='unfilterStr', type=str,default=None, \ parser.add_argument('--unfilter', dest='unfilterStr', type=str,default=None, \
@ -729,23 +731,24 @@ if args.availability:
if setAvailability(baseDir,nickname,domain,args.availability): if setAvailability(baseDir,nickname,domain,args.availability):
print('Availablity set to '+args.availability) print('Availablity set to '+args.availability)
sys.exit() sys.exit()
if args.project: if args.project:
if not nickname: if not args.delegate:
print('No nickname given') if not nickname:
sys.exit() print('No nickname given')
sys.exit()
if args.role.lower()=='none' or \ if args.role.lower()=='none' or \
args.role.lower()=='remove' or \ args.role.lower()=='remove' or \
args.role.lower()=='delete': args.role.lower()=='delete':
args.role=None args.role=None
if args.role: if args.role:
if setRole(baseDir,nickname,domain,args.project,args.role): if setRole(baseDir,nickname,domain,args.project,args.role):
print('Role within '+args.project+' set to '+args.role) print('Role within '+args.project+' set to '+args.role)
else: else:
if setRole(baseDir,nickname,domain,args.project,None): if setRole(baseDir,nickname,domain,args.project,None):
print('Left '+args.project) print('Left '+args.project)
sys.exit() sys.exit()
if args.skill: if args.skill:
if args.skillLevelPercent==0: if args.skillLevelPercent==0:
@ -802,6 +805,43 @@ if args.block:
time.sleep(1) time.sleep(1)
sys.exit() sys.exit()
if args.delegate:
if not nickname:
print('Specify a nickname with the --nickname option')
sys.exit()
if not args.password:
print('Specify a password with the --password option')
sys.exit()
if not args.project:
print('Specify a project with the --project option')
sys.exit()
if not args.role:
print('Specify a role with the --role option')
sys.exit()
if '@' in args.delegate:
delegatedNickname=args.delegate.split('@')[0]
args.delegate=blockedActor
session = createSession(domain,port,useTor)
personCache={}
cachedWebfingers={}
print('Sending delegation for '+args.delegate+' with role '+args.role+' in project '+args.project)
sendRoleViaServer(session,nickname,args.password,
domain,port, \
httpPrefix,args.delegate, \
args.project,args.role, \
cachedWebfingers,personCache, \
True)
for i in range(10):
# TODO detect send success/fail
time.sleep(1)
sys.exit()
if args.unblock: if args.unblock:
if not nickname: if not nickname:
print('Specify a nickname with the --nickname option') print('Specify a nickname with the --nickname option')

View File

@ -999,7 +999,6 @@ def testDelegateRoles():
assert outboxDelegate(baseDir,newRoleJson,False)==False assert outboxDelegate(baseDir,newRoleJson,False)==False
assert '"otherrole"' not in open(baseDir+'/accounts/'+nickname+'@'+domain+'.json').read() assert '"otherrole"' not in open(baseDir+'/accounts/'+nickname+'@'+domain+'.json').read()
assert False
os.chdir(currDir) os.chdir(currDir)
shutil.rmtree(baseDir) shutil.rmtree(baseDir)