Option to deactivate account

main2
Bob Mottram 2019-11-05 10:37:37 +00:00
parent 157ec0de71
commit 7d9df1445a
2 changed files with 16 additions and 2 deletions

View File

@ -14,6 +14,7 @@ from person import setDisplayNickname
from person import setBio
from person import setProfileImage
from person import removeAccount
from person import deactivateAccount
from skills import setSkillLevel
from roles import setRole
from person import setOrganizationScheme
@ -112,6 +113,9 @@ parser.add_argument('-a','--addaccount', dest='addaccount', \
parser.add_argument('-g','--addgroup', dest='addgroup', \
type=str,default=None, \
help='Adds a new group')
parser.add_argument('--deactivate', dest='deactivate', \
type=str,default=None, \
help='Deactivate an account')
parser.add_argument('-r','--rmaccount', dest='rmaccount', \
type=str,default=None, \
help='Remove an account')
@ -985,6 +989,9 @@ if args.addgroup:
if args.rmgroup:
args.rmaccount=args.rmgroup
if args.deactivate:
args.rmaccount=args.deactivate
if args.rmaccount:
if '@' in args.rmaccount:
nickname=args.rmaccount.split('@')[0]
@ -994,6 +1001,12 @@ if args.rmaccount:
if not args.domain or not getConfigParam(baseDir,'domain'):
print('Use the --domain option to set the domain name')
sys.exit()
if args.deactivate:
if deactivateAccount(baseDir,nickname,domain):
print('Account for '+handle+' was deactivated')
else:
print('Account for '+handle+' was not found')
sys.exit()
if removeAccount(baseDir,nickname,domain,port):
if not args.rmgroup:
print('Account for '+handle+' was removed')

View File

@ -699,16 +699,17 @@ def removeAccount(baseDir: str,nickname: str,domain: str,port: int) -> bool:
shutil.rmtree(baseDir+'/sharefiles/'+nickname)
return True
def deactivateAccount(baseDir: str,nickname: str,domain: str) -> None:
def deactivateAccount(baseDir: str,nickname: str,domain: str) -> bool:
"""Makes an account temporarily unavailable
"""
accountDir=baseDir+'/accounts/'+nickname+'@'+domain
if not os.path.isdir(accountDir):
return
return False
deactivatedDir=baseDir+'/deactivated'
if not os.path.isdir(deactivatedDir):
os.mkdir(deactivatedDir)
shutil.move(accountDir,deactivatedDir+'/'+nickname+'@'+domain)
return os.path.isdir(deactivatedDir+'/'+nickname+'@'+domain)
def activateAccount(baseDir: str,nickname: str,domain: str) -> None:
"""Makes a deactivated account available