TG-124 : Modifications de la Base et adapation du code
This commit is contained in:
@ -24,7 +24,7 @@ class GroupAPI(Resource):
|
||||
department = args['department']
|
||||
resp_id = args['resp_id']
|
||||
sec_id = args['sec_id']
|
||||
res_dir = app.config['BASE_RESSOURCES_DIR'] + name + "/"
|
||||
res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
|
||||
|
||||
group = getGroup(name=name)
|
||||
if group is not None:
|
||||
@ -34,6 +34,18 @@ class GroupAPI(Resource):
|
||||
if user is None:
|
||||
return {"ERROR": "The user with id " + str(resp_id) + " does not exists !"}, 400
|
||||
else:
|
||||
query = USER.select(USER.c.id == user["id"])
|
||||
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"],
|
||||
"URL": getParam('OLA_URL') + "registration/"
|
||||
+ res.hash})
|
||||
else:
|
||||
mail = mailsModels.getMailContent("RESP_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL')})
|
||||
|
||||
send_mail(mail[0], user["email"], mail[1])
|
||||
if "2" not in user['role'].split('-'):
|
||||
role = user['role'] + "-2"
|
||||
query = USER.update().values(role=role).where(USER.c.id == resp_id)
|
||||
@ -43,6 +55,18 @@ class GroupAPI(Resource):
|
||||
if user is None:
|
||||
return {"ERROR": "The user with id " + str(sec_id) + " does not exists !"}, 400
|
||||
else:
|
||||
query = USER.select(USER.c.id == user["id"])
|
||||
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"],
|
||||
"URL": getParam('OLA_URL') + "registration/"
|
||||
+ res.hash})
|
||||
else:
|
||||
mail = mailsModels.getMailContent("SEC_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL')})
|
||||
|
||||
send_mail(mail[0], user["email"], mail[1])
|
||||
if "1" not in user['role'].split('-'):
|
||||
role = user['role'] + "-1"
|
||||
query = USER.update().values(role=role).where(USER.c.id == sec_id)
|
||||
@ -59,14 +83,14 @@ class GroupAPI(Resource):
|
||||
if not checkParams(['name', 'year', 'class_short', 'class_long', 'department', 'resp_id', 'sec_id'], args):
|
||||
return {"ERROR": "One or more parameters are missing !"}, 400
|
||||
|
||||
name = args['name']
|
||||
name = args['name'].replace(" ", "_").replace("/", "-")
|
||||
year = args['year']
|
||||
class_short = args['class_short']
|
||||
class_long = args['class_long']
|
||||
department = args['department']
|
||||
resp_id = args['resp_id']
|
||||
sec_id = args['sec_id']
|
||||
res_dir = app.config['BASE_RESSOURCES_DIR'] + name + "/"
|
||||
res_dir = getParam('URL_BASE_DIRECTORY') + name + "/"
|
||||
|
||||
group = getGroup(gid=gid)
|
||||
if group is None:
|
||||
@ -80,6 +104,18 @@ class GroupAPI(Resource):
|
||||
if user is None:
|
||||
return {"ERROR": "The user with id " + str(resp_id) + " does not exists !"}, 400
|
||||
else:
|
||||
query = USER.select(USER.c.id == user["id"])
|
||||
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"],
|
||||
"URL": getParam('OLA_URL') + "registration/"
|
||||
+ res.hash})
|
||||
else:
|
||||
mail = mailsModels.getMailContent("RESP_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL')})
|
||||
|
||||
send_mail(mail[0], user["email"], mail[1])
|
||||
if "2" not in user['role'].split('-'):
|
||||
role = user['role'] + "-2"
|
||||
query = USER.update().values(role=role).where(USER.c.id == resp_id)
|
||||
@ -89,6 +125,18 @@ class GroupAPI(Resource):
|
||||
if user is None:
|
||||
return {"ERROR": "The user with id " + str(sec_id) + " does not exists !"}, 400
|
||||
else:
|
||||
query = USER.select(USER.c.id == user["id"])
|
||||
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"],
|
||||
"URL": getParam('OLA_URL') + "registration/"
|
||||
+ res.hash})
|
||||
else:
|
||||
mail = mailsModels.getMailContent("SEC_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL')})
|
||||
|
||||
send_mail(mail[0], user["email"], mail[1])
|
||||
if "1" not in user['role'].split('-'):
|
||||
role = user['role'] + "-1"
|
||||
query = USER.update().values(role=role).where(USER.c.id == sec_id)
|
||||
@ -143,9 +191,18 @@ class GroupAPI(Resource):
|
||||
|
||||
query = TUTORSHIP.insert().values(group_id=gid, student_id=p[0], ptutor_id=p[1])
|
||||
query.execute()
|
||||
mail = mailsModels.getMailContent("NEW_TO_GROUP", {"GROUP": group["name"],
|
||||
"URL": "ola.univ-tlse2.fr/registration/"
|
||||
+ get_random_string()})
|
||||
|
||||
query = USER.select(USER.c.id == stud["id"])
|
||||
rows = query.execute()
|
||||
res = rows.first()
|
||||
if res.hash is not None and len(res.hash) > 0:
|
||||
mail = mailsModels.getMailContent("NEW_STUD_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL') + "registration/"
|
||||
+ res.hash})
|
||||
else:
|
||||
mail = mailsModels.getMailContent("STUD_OF_GROUP", {"GROUP": group["name"],
|
||||
"URL": getParam('OLA_URL')})
|
||||
|
||||
send_mail(mail[0], stud["email"], mail[1])
|
||||
|
||||
return {"RESULT": "Pairs added successfully"}, 200
|
||||
|
@ -1,7 +1,9 @@
|
||||
from hashlib import sha256
|
||||
|
||||
from flask_restful import Resource, request
|
||||
|
||||
from app.model import *
|
||||
from app.utils import checkParams
|
||||
from app.utils import checkParams, get_random_string
|
||||
|
||||
|
||||
class UserAPI(Resource):
|
||||
@ -11,55 +13,54 @@ class UserAPI(Resource):
|
||||
|
||||
def post(self):
|
||||
args = request.get_json(cache=False, force=True)
|
||||
if not checkParams(['CASid', 'role'], args):
|
||||
if not checkParams(['role', 'email', 'name'], args):
|
||||
return {"ERROR": "One or more parameters are missing !"}, 400
|
||||
|
||||
CASid = args['CASid']
|
||||
role = args['role']
|
||||
email = self.getEmailFromCAS(CASid)
|
||||
email = args['email']
|
||||
name = args['name']
|
||||
phone = None
|
||||
user = getUser(login=CASid)
|
||||
user = getUser(email=email)
|
||||
hashpass = get_random_string()
|
||||
while hashExists(hashpass):
|
||||
hashpass = get_random_string()
|
||||
|
||||
if user is not None:
|
||||
return {"UID": user["id"]}, 200
|
||||
|
||||
if getUser(email=email) is not None:
|
||||
return {"ERROR": "A user with this email (" + email + ") already exists !"}, 405
|
||||
|
||||
query = USER.insert().values(login=CASid, email=email, role=role, phone=phone)
|
||||
query = USER.insert().values(email=email, role=role, phone=phone, name=name, hash=hashpass)
|
||||
res = query.execute()
|
||||
return {"UID": res.lastrowid}, 201
|
||||
|
||||
def put(self, uid):
|
||||
args = request.get_json(cache=False, force=True)
|
||||
if not checkParams(['CASid', 'role', 'email', 'phone'], args):
|
||||
if not checkParams(['role', 'email', 'phone', 'name', 'password'], args):
|
||||
return {"ERROR": "One or more parameters are missing !"}, 400
|
||||
|
||||
CASid = args['CASid']
|
||||
role = args['role']
|
||||
email = args['email']
|
||||
phone = args['phone']
|
||||
name = args['name']
|
||||
psw = args['password']
|
||||
|
||||
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()
|
||||
|
||||
if getUser(uid=uid) is None:
|
||||
return {"ERROR": "This user doesn't exists !"}, 405
|
||||
|
||||
if getUser(login=CASid) is not None:
|
||||
return {"ERROR": "A user with this CASid (login) already exists !"}, 405
|
||||
|
||||
if getUser(email=email) is not None:
|
||||
return {"ERROR": "A user with this email already exists !"}, 405
|
||||
|
||||
query = USER.update().values(login=CASid, email=email, role=role, phone=phone).where(USER.c.id == uid)
|
||||
query = USER.update().values(email=email, role=role, phone=phone, name=name, psw=password, hash=None) \
|
||||
.where(USER.c.id == uid)
|
||||
query.execute()
|
||||
return {"UID": uid}, 200
|
||||
|
||||
def get(self, uid=0, login="", email=""):
|
||||
def get(self, uid=0, email=""):
|
||||
if uid > 0:
|
||||
return {'USER': getUser(uid=uid)}, 200
|
||||
elif login != "":
|
||||
return {'USER': getUser(login=login)}, 200
|
||||
elif email != "":
|
||||
return {'USER': getUser(email=email)}, 200
|
||||
|
||||
@staticmethod
|
||||
def getEmailFromCAS(CASid):
|
||||
return CASid + "@ola.com"
|
||||
|
@ -1,13 +1,53 @@
|
||||
_NEW_USER = ("Votre compte OLA a été créé !", "Bonjour,<br/><p>Votre compte vient d'être créé dans l'Outil du "
|
||||
"Livret de l'Alternant dans le groupe #GROUPE. Vous pouvez dès "
|
||||
_NEW_STUD_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,<br/><p>Votre compte vient d'être créé dans l'Outil du "
|
||||
"Livret de l'Alternant dans le groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant l'activer, puis créer un livret en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
_STUD_OF_GROUP = (
|
||||
"Vous avez été ajouté à un groupe OLA !", "Bonjour,<br/><p>Votre compte vient d'être ajouté dans l'Outil du "
|
||||
"Livret de l'Alternant au groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant créer un livret en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
_NEW_RESP_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,<br/><p>Votre compte vient d'être créé dans l'Outil du "
|
||||
"Livret de l'Alternant en tant que responsable du groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant l'activer, en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
_RESP_OF_GROUP = (
|
||||
"Vous avez été ajouté à un groupe OLA !", "Bonjour,<br/><p>Votre compte vient d'être ajouté dans l'Outil du "
|
||||
"Livret de l'Alternant en tant que responsable du groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant y accéder en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
_NEW_SEC_OF_GROUP = ("Votre compte OLA a été créé !", "Bonjour,<br/><p>Votre compte vient d'être créé dans l'Outil du "
|
||||
"Livret de l'Alternant en tant que secrétaire du groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant l'activer, en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
_SEC_OF_GROUP = (
|
||||
"Vous avez été ajouté à un groupe OLA !", "Bonjour,<br/><p>Votre compte vient d'être ajouté dans l'Outil du "
|
||||
"Livret de l'Alternant en tant que secrétaire du groupe <b>#GROUPE</b>. Vous pouvez dès "
|
||||
"maintenant y accéder en vous rendant à l'adresse : <br/>"
|
||||
"<a href='#URL'>#URL</a></p><p>Bonne journée !</p>")
|
||||
|
||||
|
||||
def getMailContent(mail_type, args):
|
||||
mail = None
|
||||
if mail_type == "NEW_USER":
|
||||
mail = _NEW_USER
|
||||
for key, value in args:
|
||||
mail[1].replace("#" + key, value)
|
||||
if mail_type == "NEW_STUD_OF_GROUP":
|
||||
mail = _NEW_STUD_OF_GROUP
|
||||
elif mail_type == "STUD_OF_GROUP":
|
||||
mail = _STUD_OF_GROUP
|
||||
elif mail_type == "NEW_RESP_OF_GROUP":
|
||||
mail = _NEW_RESP_OF_GROUP
|
||||
elif mail_type == "RESP_OF_GROUP":
|
||||
mail = _RESP_OF_GROUP
|
||||
elif mail_type == "NEW_SEC_OF_GROUP":
|
||||
mail = _NEW_SEC_OF_GROUP
|
||||
elif mail_type == "SEC_OF_GROUP":
|
||||
mail = _SEC_OF_GROUP
|
||||
else:
|
||||
raise Exception("Unknown mail type !")
|
||||
|
||||
for key, value in args:
|
||||
mail[1].replace("#" + key, value)
|
||||
return mail
|
||||
|
Reference in New Issue
Block a user