Commit fe800f46 authored by Marc Duez's avatar Marc Duez
Browse files

server: refactor controller

parent 26404f61
# coding: utf8
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def index():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
if not auth.user :
res = {"redirect" : "default/user/login"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -16,22 +14,11 @@ def index():
def add():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('add config'))
#TODO check data
def add_form():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
error =""
if request.vars['config_name'] == "" :
......@@ -61,19 +48,11 @@ def add_form():
def edit():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('edit config'))
def edit_form():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path
error =""
......@@ -103,18 +82,10 @@ def edit_form():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def confirm():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('confirm config deletion'))
def delete():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path
#delete data_file using this config
db(db.data_file.config_id==request.vars["id"]).delete()
......
......@@ -9,6 +9,7 @@
## - call exposes all registered services (none by default)
#########################################################################
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
......@@ -31,8 +32,6 @@ def help():
## add a scheduller task to run vidjil on a specific sequence file
def run_request():
import gluon.contrib.simplejson
error = ""
##TODO check
......@@ -97,7 +96,6 @@ def run_request():
def get_data():
import time
import gluon.contrib.simplejson
from subprocess import Popen, PIPE, STDOUT
error = ""
......@@ -126,8 +124,6 @@ def get_data():
def get_analysis():
import gluon.contrib.simplejson
error = ""
if not "patient_id" in request.vars :
......@@ -178,8 +174,6 @@ def get_analysis():
def save_analysis():
import gluon.contrib.simplejson
error = ""
if not "patient_id" in request.vars :
......@@ -272,7 +266,7 @@ def add_membership():
return dict(form=form)
def upload_file():
import gluon.contrib.simplejson, shutil, os.path
import shutil, os.path
try:
# Get the file from the form
......
# coding: utf8
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def add():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
if auth.has_permission('admin', 'patient', request.vars['id'], auth.user_id):
return dict(message=T('add file'))
else :
......@@ -15,12 +16,7 @@ def add():
#TODO check data
def add_form():
import gluon.contrib.simplejson, shutil, os.path, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path, datetime
error = ""
if request.vars['sampling_date'] != None :
......@@ -47,21 +43,12 @@ def add_form():
def edit():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('edit file'))
#TODO check data
def edit_form():
import gluon.contrib.simplejson, shutil, os.path, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path, datetime
error = ""
if request.vars['id'] == None :
......@@ -87,12 +74,7 @@ def edit_form():
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def upload():
import gluon.contrib.simplejson, shutil, os.path, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path, datetime
error = ""
if request.vars['id'] == None :
......@@ -112,19 +94,11 @@ def upload():
def confirm():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('confirm sequence file deletion'))
def delete():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path
patient_id = db.sequence_file[request.vars["id"]].patient_id
......
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
## return group list
def index():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('group list'))
## return an html form to add a group
def add():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('new group'))
......@@ -24,47 +19,34 @@ def add():
## return a flash error message if error
def add_form():
import gluon.contrib.simplejson, datetime
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
error = ""
if request.vars["group_name"] == "" :
error += "group name needed, "
if error=="" :
id = db.auth_group.insert(role=request.vars["group_name"],
description=request.vars["info"])
user_group = auth.user_group(auth.user.id)
#group creator is a group member
auth.add_membership(id, auth.user.id)
#group creator = group admin
auth.add_permission(user_group, 'admin', db.auth_group, id)
res = {"redirect": "group/index",
"message" : "group created"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "message" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
res2 = {"success" : "false", "message" : "connect error"}
return gluon.contrib.simplejson.dumps(res2, separators=(',',':'))
error = ""
if request.vars["group_name"] == "" :
error += "group name needed, "
if error=="" :
id = db.auth_group.insert(role=request.vars["group_name"],
description=request.vars["info"])
user_group = auth.user_group(auth.user.id)
#group creator is a group member
auth.add_membership(id, auth.user.id)
#group creator = group admin
auth.add_permission(user_group, 'admin', db.auth_group, id)
res = {"redirect": "group/index",
"message" : "group created"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "message" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## confirm page before group deletion
## need ["id"]
def confirm():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('confirm group deletion'))
......@@ -72,12 +54,6 @@ def confirm():
## need ["id"]
## redirect to group list if success
def delete():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
#delete group
db(db.auth_group.id == request.vars["id"]).delete()
......@@ -89,103 +65,69 @@ def delete():
## return list of group member
## need ["id"]
def info():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('group info'))
## return list of group admin
## need ["id"]
def permission():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('permission'))
## remove admin right
## need ["group_id", "user_id"]
def remove_permission():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
error = ""
if request.vars["group_id"] == "" :
error += "missing group_id, "
if request.vars["user_id"] == "" :
error += "missing user_id, "
if error=="":
auth.del_permission(auth.user_group(request.vars["user_id"]), 'admin', db.auth_group, request.vars["group_id"])
res = {"redirect" : "group/permission" ,
"args" : { "id" : request.vars["group_id"]} }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
error = ""
if request.vars["group_id"] == "" :
error += "missing group_id, "
if request.vars["user_id"] == "" :
error += "missing user_id, "
if error=="":
auth.del_permission(auth.user_group(request.vars["user_id"]), 'admin', db.auth_group, request.vars["group_id"])
res = {"redirect" : "group/permission" ,
"args" : { "id" : request.vars["group_id"]} }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## give admin right to a group member
## need ["group_id", "user_id"]
def change_permission():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
auth.add_permission(auth.user_group(request.vars["user_id"]), 'admin', db.auth_group, request.vars["group_id"])
auth.add_permission(auth.user_group(request.vars["user_id"]), 'admin', db.auth_group, request.vars["group_id"])
res = {"redirect" : "group/permission" , "args" : { "id" : request.vars["group_id"]} }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
res = {"redirect" : "group/permission" , "args" : { "id" : request.vars["group_id"]} }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## invite an user to join the group
## need ["group_id", "user_id"]
def invite():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
#check admin
if auth.has_permission('admin', 'auth_group', request.vars["group_id"], auth.user.id):
auth.add_membership(request.vars["group_id"], request.vars["user_id"])
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "user have been invited to join this group"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "you don't have permission to invite people"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
#check admin
if auth.has_permission('admin', 'auth_group', request.vars["group_id"], auth.user.id):
auth.add_membership(request.vars["group_id"], request.vars["user_id"])
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "user have been invited to join this group"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "you don't have permission to invite people"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## revoke membership
## need ["group_id", "user_id"]
def kick():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
#check admin
if auth.has_permission('admin', 'auth_group', request.vars["group_id"], auth.user.id):
auth.del_membership(request.vars["group_id"], request.vars["user_id"])
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "user have been kicked"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "you don't have permission to kick people"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
#check admin
if auth.has_permission('admin', 'auth_group', request.vars["group_id"], auth.user.id):
auth.del_membership(request.vars["group_id"], request.vars["user_id"])
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "user have been kicked"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else:
res = {"redirect" : "group/info" ,
"args" : { "id" : request.vars["group_id"]},
"message" : "you don't have permission to kick people"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
# coding: utf8
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def index():
import gluon.contrib.simplejson
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
if not auth.user :
res = {"redirect" : "default/user/login"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
......@@ -14,19 +13,11 @@ def index():
return dict(message=T('standard_list'))
def add():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('add standard file'))
#TODO check data
def add_form():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path
id = db.standard_file.insert(data_file = request.vars.file )
......@@ -36,49 +27,32 @@ def add_form():
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def edit():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
def edit():
return dict(message=T('edit standard file'))
def edit_form():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
error = ""
if request.vars["standard_name"] == "" :
error += "standard name needed, "
if error=="" :
db.standard_file[request.vars["id"]] = dict(name=request.vars['standard_name'],
info=request.vars['standard_info'])
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "error" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
import shutil, os.path
error = ""
if request.vars["standard_name"] == "" :
error += "standard name needed, "
if error=="" :
db.standard_file[request.vars["id"]] = dict(name=request.vars['standard_name'],
info=request.vars['standard_info'])
res = {"success": "true" }
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
else :
res = {"success" : "false", "error" : error}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def confirm():
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
return dict(message=T('confirm standard deletion'))
def delete():
import gluon.contrib.simplejson, shutil, os.path
if request.env.http_origin:
response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400
import shutil, os.path
query = db( (db.config.standard_id==request.vars["id"])).select()
for row in query :
......