Commit e80b8c74 authored by Marc Duez's avatar Marc Duez

default.py: impersonate

parent 3ed2da83
......@@ -89,6 +89,7 @@ def init_db(force=False):
auth.add_permission(id_admin_group, 'create', db.patient, 0)
auth.add_permission(id_admin_group, 'create', db.auth_group, 0)
auth.add_permission(id_admin_group, 'create', db.config, 0)
auth.add_permission(id_admin_group, 'impersonate', db.auth_user, 0)
def init_from_csv():
if db(db.auth_user.id > 0).count() == 0:
......@@ -463,6 +464,26 @@ def user():
return dict(form=auth())
def impersonate() :
if auth.is_impersonating() :
stop_impersonate()
if request.vars["id"] != 0 :
auth.impersonate(request.vars["id"])
res = {"redirect": "reload"}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
def stop_impersonate() :
import time
if auth.is_impersonating() :
auth.impersonate(0)
# force clean login (default impersonate don't restore everything :/ )
auth.login_user(db.auth_user(auth.user.id))
res = {"redirect" : URL('patient', 'index', scheme=True, host=True)}
return gluon.contrib.simplejson.dumps(res, separators=(',',':'))
## TODO make custom download for .data et .analysis
@cache.action()
def download():
......
......@@ -14,8 +14,41 @@
<div id="db_auth">
{{if auth.user:}}
{{=auth.user.first_name}} {{=auth.user.last_name}}
<a class="button" onclick="db.request('default/user/logout');">(logout)</a>
{{if auth.is_impersonating() :}}
impersonate
<span>
<select id="choose_user" name="user" onchange="db.call('default/impersonate', {'id' : this.value})">
<option value="0" selected> --- </option>
{{for row in db(db.auth_user.id >1).select() :}}
<option value="{{=row.id }}" {{if row.id==auth.user_id:}}selected {{pass}}>{{=row.first_name}} {{=row.last_name}} </option> {{pass}}
</select>
</span>{{pass}}
{{if auth.is_admin():}}
{{if not auth.is_impersonating() :}}
impersonate
<span>
<select id="choose_user" name="user" onchange="db.call('default/impersonate', {'id' : this.value})">
<option value="0" selected> --- </option>
{{for row in db(db.auth_user.id >1).select() :}}
<option value="{{=row.id }}">{{=row.first_name}} {{=row.last_name}}</option> {{pass}}
</select>
</span>
{{pass}}
{{pass}}
{{if not auth.is_impersonating() :}}
{{=auth.user.first_name}} {{=auth.user.last_name}}
{{pass}}
<a class="button" onclick="db.request('default/user/logout');">(logout)</a>
{{pass}}
</div>
......
......@@ -11,10 +11,10 @@
{{else:}}
{{form['_id'] ="login_form"}}
{{=form}}
{{if 'form' in locals():}}
{{form['_id'] ="login_form"}}
{{=form}}
{{pass}}
{{if request.args(0)=='login':}}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment