TG-124 : Remise a niveau des TU

This commit is contained in:
Clément ARNAUDEAU
2017-03-24 15:37:21 +01:00
parent 1b8c71945a
commit 59f1fca610
5 changed files with 45 additions and 36 deletions

View File

@ -25,6 +25,7 @@ class GroupAPI(Resource):
resp_id = args['resp_id']
sec_id = args['sec_id']
res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
mails = []
group = getGroup(name=name)
if group is not None:
@ -38,14 +39,14 @@ class GroupAPI(Resource):
rows = query.execute()
res = rows.first()
if res.hash is not None and len(res.hash) > 0:
mail = mailsModels.getMailContent("NEW_RESP_OF_GROUP", {"GROUP": group["name"],
mail = mailsModels.getMailContent("NEW_RESP_OF_GROUP", {"GROUP": name,
"URL": getParam('OLA_URL') + "registration/"
+ res.hash})
else:
mail = mailsModels.getMailContent("RESP_OF_GROUP", {"GROUP": group["name"],
mail = mailsModels.getMailContent("RESP_OF_GROUP", {"GROUP": name,
"URL": getParam('OLA_URL')})
send_mail(mail[0], user["email"], mail[1])
mails.append((user["email"], mail))
if "2" not in user['role'].split('-'):
role = user['role'] + "-2"
query = USER.update().values(role=role).where(USER.c.id == resp_id)
@ -59,14 +60,14 @@ class GroupAPI(Resource):
rows = query.execute()
res = rows.first()
if res.hash is not None and len(res.hash) > 0:
mail = mailsModels.getMailContent("NEW_SEC_OF_GROUP", {"GROUP": group["name"],
mail = mailsModels.getMailContent("NEW_SEC_OF_GROUP", {"GROUP": name,
"URL": getParam('OLA_URL') + "registration/"
+ res.hash})
else:
mail = mailsModels.getMailContent("SEC_OF_GROUP", {"GROUP": group["name"],
mail = mailsModels.getMailContent("SEC_OF_GROUP", {"GROUP": name,
"URL": getParam('OLA_URL')})
send_mail(mail[0], user["email"], mail[1])
mails.append((user["email"], mail))
if "1" not in user['role'].split('-'):
role = user['role'] + "-1"
query = USER.update().values(role=role).where(USER.c.id == sec_id)
@ -76,6 +77,12 @@ class GroupAPI(Resource):
department=department, resp_id=resp_id, sec_id=sec_id, ressources_dir=res_dir)
res = query.execute()
os.mkdir(res_dir)
for m in mails:
addr = m[0]
mail = m[1]
send_mail(mail[0], addr, mail[1])
return {"GID": res.lastrowid}, 201
def put(self, gid):
@ -91,6 +98,7 @@ class GroupAPI(Resource):
resp_id = args['resp_id']
sec_id = args['sec_id']
res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
mails = []
group = getGroup(gid=gid)
if group is None:
@ -115,7 +123,7 @@ class GroupAPI(Resource):
mail = mailsModels.getMailContent("RESP_OF_GROUP", {"GROUP": group["name"],
"URL": getParam('OLA_URL')})
send_mail(mail[0], user["email"], mail[1])
mails.append((user["email"], mail))
if "2" not in user['role'].split('-'):
role = user['role'] + "-2"
query = USER.update().values(role=role).where(USER.c.id == resp_id)
@ -136,7 +144,7 @@ class GroupAPI(Resource):
mail = mailsModels.getMailContent("SEC_OF_GROUP", {"GROUP": group["name"],
"URL": getParam('OLA_URL')})
send_mail(mail[0], user["email"], mail[1])
mails.append((user["email"], mail))
if "1" not in user['role'].split('-'):
role = user['role'] + "-1"
query = USER.update().values(role=role).where(USER.c.id == sec_id)
@ -150,6 +158,11 @@ class GroupAPI(Resource):
if group["ressources_dir"] != res_dir:
os.rename(group["ressources_dir"], res_dir)
for m in mails:
addr = m[0]
mail = m[1]
send_mail(mail[0], addr, mail[1])
return {"GID": gid}, 200
def get(self, gid=0, name=""):

View File

@ -46,7 +46,7 @@ class UserAPI(Resource):
if psw is None or len(psw) < 8:
return {"ERROR": "Password can't be empty or less than 8 characters !"}, 400
password = sha256(psw).hexdigest()
password = sha256(psw.encode('utf-8')).hexdigest()
if getUser(uid=uid) is None:
return {"ERROR": "This user doesn't exists !"}, 405

View File

@ -48,6 +48,6 @@ def getMailContent(mail_type, args):
else:
raise Exception("Unknown mail type !")
for key, value in args:
for key, value in args.items():
mail[1].replace("#" + key, value)
return mail