mirror of https://gitlab.com/bashrc2/epicyon
Setting roles
parent
bc67385587
commit
50ce56d937
29
person.py
29
person.py
|
@ -105,6 +105,35 @@ def setSkillLevel(baseDir: str,nickname: str,domain: str, \
|
||||||
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def setRole(baseDir: str,nickname: str,domain: str, \
|
||||||
|
project: str,role: str) -> bool:
|
||||||
|
"""Set a person's role within a project
|
||||||
|
Setting the role to an empty string or None will remove it
|
||||||
|
"""
|
||||||
|
# avoid giant strings
|
||||||
|
if len(role)>128 or len(project)>128:
|
||||||
|
return False
|
||||||
|
actorFilename=baseDir+'/accounts/'+nickname+'@'+domain+'.json'
|
||||||
|
if not os.path.isfile(actorFilename):
|
||||||
|
return False
|
||||||
|
with open(actorFilename, 'r') as fp:
|
||||||
|
actorJson=commentjson.load(fp)
|
||||||
|
if role:
|
||||||
|
if actorJson['roles'].get(project):
|
||||||
|
if role not in actorJson['roles'][project]:
|
||||||
|
actorJson['roles'][project].append(role)
|
||||||
|
else:
|
||||||
|
actorJson['roles'][project]=[role]
|
||||||
|
else:
|
||||||
|
if actorJson['roles'].get(project):
|
||||||
|
actorJson['roles'][project].remove(role)
|
||||||
|
# if the project contains no roles then remove it
|
||||||
|
if len(actorJson['roles'][project])==0:
|
||||||
|
del actorJson['roles'][project]
|
||||||
|
with open(actorFilename, 'w') as fp:
|
||||||
|
commentjson.dump(actorJson, fp, indent=4, sort_keys=False)
|
||||||
|
return True
|
||||||
|
|
||||||
def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
|
def createPersonBase(baseDir: str,nickname: str,domain: str,port: int, \
|
||||||
httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}):
|
httpPrefix: str, saveToFile: bool,password=None) -> (str,str,{},{}):
|
||||||
"""Returns the private key, public key, actor and webfinger endpoint
|
"""Returns the private key, public key, actor and webfinger endpoint
|
||||||
|
|
4
tests.py
4
tests.py
|
@ -41,6 +41,7 @@ from person import createPerson
|
||||||
from person import setPreferredNickname
|
from person import setPreferredNickname
|
||||||
from person import setBio
|
from person import setBio
|
||||||
from person import setSkillLevel
|
from person import setSkillLevel
|
||||||
|
from person import setRole
|
||||||
from auth import createBasicAuthHeader
|
from auth import createBasicAuthHeader
|
||||||
from auth import authorizeBasic
|
from auth import authorizeBasic
|
||||||
from auth import storeBasicCredentials
|
from auth import storeBasicCredentials
|
||||||
|
@ -149,6 +150,7 @@ def createServerAlice(path: str,domain: str,port: int,federationList: [], \
|
||||||
deleteAllPosts(path,nickname,domain,'inbox')
|
deleteAllPosts(path,nickname,domain,'inbox')
|
||||||
deleteAllPosts(path,nickname,domain,'outbox')
|
deleteAllPosts(path,nickname,domain,'outbox')
|
||||||
assert setSkillLevel(path,nickname,domain,'hacking',90)
|
assert setSkillLevel(path,nickname,domain,'hacking',90)
|
||||||
|
assert setRole(path,nickname,domain,'someproject','guru')
|
||||||
if hasFollows:
|
if hasFollows:
|
||||||
followPerson(path,nickname,domain,'bob','127.0.0.100:61936', \
|
followPerson(path,nickname,domain,'bob','127.0.0.100:61936', \
|
||||||
federationList,True)
|
federationList,True)
|
||||||
|
@ -194,6 +196,8 @@ def createServerBob(path: str,domain: str,port: int,federationList: [], \
|
||||||
createPerson(path,nickname,domain,port,httpPrefix,True,password)
|
createPerson(path,nickname,domain,port,httpPrefix,True,password)
|
||||||
deleteAllPosts(path,nickname,domain,'inbox')
|
deleteAllPosts(path,nickname,domain,'inbox')
|
||||||
deleteAllPosts(path,nickname,domain,'outbox')
|
deleteAllPosts(path,nickname,domain,'outbox')
|
||||||
|
assert setRole(path,nickname,domain,'bandname','bass player')
|
||||||
|
assert setRole(path,nickname,domain,'bandname','publicist')
|
||||||
if hasFollows:
|
if hasFollows:
|
||||||
followPerson(path,nickname,domain, \
|
followPerson(path,nickname,domain, \
|
||||||
'alice','127.0.0.50:61935',federationList,True)
|
'alice','127.0.0.50:61935',federationList,True)
|
||||||
|
|
Loading…
Reference in New Issue