TG-60 : TU sur GroupAPI + corrections

This commit is contained in:
Clément ARNAUDEAU
2017-03-17 13:43:53 +01:00
parent 2e21619ff5
commit 793544e300
4 changed files with 120 additions and 8 deletions

View File

@ -2,7 +2,6 @@ import os
from flask_restful import Resource, request
from app.config import Config
from app.core import app
from app.model import *
from app.utils import checkParams
@ -25,7 +24,7 @@ class GroupAPI(Resource):
department = args['department']
resp_id = args['resp_id']
sec_id = args['sec_id']
res_dir = Config.BASE_RESSOURCES_DIR + name + "/"
res_dir = app.config['BASE_RESSOURCES_DIR'] + name + "/"
group = getGroup(name=name)
if group is not None:
@ -73,8 +72,8 @@ class GroupAPI(Resource):
if group is None:
return {"ERROR": "This group does not exists !"}, 405
group = getGroup(name=name)
if group is not None:
group2 = getGroup(name=name)
if group2 is not None:
return {"ERROR": "A group with this name already exists !"}, 405
user = getUser(uid=resp_id)
@ -99,7 +98,10 @@ class GroupAPI(Resource):
department=department, resp_id=resp_id, sec_id=sec_id, ressources_dir=res_dir) \
.where(GROUP.c.id == gid)
res = query.execute()
os.mkdir(res_dir)
if group["ressources_dir"] != res_dir:
os.rename(group["ressources_dir"], res_dir)
return {"GID": gid}, 200
def get(self, gid=0, name=""):

View File

@ -27,7 +27,9 @@ def getUser(uid=0, login="", email=""):
raise Exception("getUser must be called with one argument !")
else:
if uid != 0:
res = db.session.query(user_class).get(uid)
query = USER.select(USER.c.id == uid)
rows = query.execute()
res = rows.first()
elif login != "":
query = USER.select(USER.c.login == login)
@ -59,7 +61,9 @@ def getGroup(gid=0, name=""):
raise Exception("getUser must be called with one argument !")
else:
if gid != 0:
res = db.session.query(group_class).get(gid)
query = GROUP.select(GROUP.c.id == gid)
rows = query.execute()
res = rows.first()
elif name != "":
query = GROUP.select(GROUP.c.name == name)