Commit 7736f622 authored by HERBERT Ryan's avatar HERBERT Ryan
Browse files

log.py patient/run and user names in logs

Added patient and run names as well as usernames in log views
parent b8c33ebb
...@@ -5,12 +5,30 @@ if request.env.http_origin: ...@@ -5,12 +5,30 @@ if request.env.http_origin:
response.headers['Access-Control-Allow-Credentials'] = 'true' response.headers['Access-Control-Allow-Credentials'] = 'true'
response.headers['Access-Control-Max-Age'] = 86400 response.headers['Access-Control-Max-Age'] = 86400
def anon_names(data):
for row in data:
if not auth.can_view_patient_info(row.id):
row.name = vidjil_utils.anon_ids(row.id)
return data
def get_data_list(table):
data = db(auth.vidjil_accessible_query(PermissionEnum.read.value, table)).select()
log.debug(data)
if table == 'patient':
data = anon_names(data)
data_list = [(row.id, row.name) for row in data]
data_list.sort(key=lambda tup: tup[1])
return data_list
def index(): def index():
user_log = db.user_log user_log = db.user_log
id_list = [] data_list = []
groups = [] groups = []
table_name = 'all' table_name = 'all'
id_value = 0 id_value = 0
auth.load_permissions(PermissionEnum.anon.value, 'patient')
if auth.is_admin(): if auth.is_admin():
query = (user_log.id > 0) query = (user_log.id > 0)
else: else:
...@@ -28,22 +46,25 @@ def index(): ...@@ -28,22 +46,25 @@ def index():
table_name = request.vars['table'] table_name = request.vars['table']
table = db[table_name] table = db[table_name]
query &= user_log.table_name == table_name query &= user_log.table_name == table_name
if auth.is_admin(): data_list = get_data_list(table_name)
ids = db(table).select(table.id, orderby=table.id)
else:
ids = db(
(table.id == user_log.record_id) &
(table_name == user_log.table_name) &
(db.auth_permission.record_id == user_log.record_id) &
(db.auth_permission.name == PermissionEnum.access.value) &
(db.auth_permission.group_id.belongs(groups))
).select(table.id, orderby=table.id)
id_list = [row.id for row in ids]
if 'id' in request.vars and request.vars['id'] != 0: if 'id' in request.vars and request.vars['id'] != 0:
id_value = request.vars['id'] id_value = request.vars['id']
query &= user_log.record_id == request.vars['id'] query &= user_log.record_id == request.vars['id']
return dict(query=db(query).select(user_log.ALL, orderby=~db.user_log.created),
id_list=id_list, query &= (db.auth_user.id == user_log.user_id)
query = db(query).select(user_log.ALL, db.auth_user.first_name, db.auth_user.last_name, db.patient.first_name, db.patient.last_name, db.run.name,
left = [
db.patient.on((db.patient.id == db.user_log.record_id) & (db.user_log.table_name == 'patient')),
db.run.on((db.run.id == db.user_log.record_id) & (db.user_log.table_name == 'run'))
],
orderby=~db.user_log.created)
for row in query:
if row.patient.first_name is not None:
row.names = vidjil_utils.anon_ids(row.user_log.record_id)
else:
row.names = row.run.name
return dict(query=query,
data_list=data_list,
stable=table_name, stable=table_name,
sid=id_value) sid=id_value)
...@@ -7,26 +7,26 @@ ...@@ -7,26 +7,26 @@
table: table:
{{=SELECT(*[OPTION(elem) for elem in ['all', 'patient', 'run']], _id="table_selector", _name="table", _onchange="db.call('log/index', {'table': this.value})", value=stable)}} {{=SELECT(*[OPTION(elem) for elem in ['all', 'patient', 'run']], _id="table_selector", _name="table", _onchange="db.call('log/index', {'table': this.value})", value=stable)}}
id: id:
{{=SELECT(*[OPTION(id) for id in ([0] + id_list)], _id="id_selector", _name="id", _onchange="db.call('log/index', {'table': $('#table_selector').val(), 'id': this.value})", value=sid)}} {{=SELECT(*[OPTION(tup[1], _value=tup[0]) for tup in ([(0, 'None')] + data_list)], _id="id_selector", _name="id", _onchange="db.call('log/index', {'table': $('#table_selector').val(), 'id': this.value})", value=sid)}}
</div> </div>
<div id="db_table_container"> <div id="db_table_container">
<table class="db_table" id="table"> <table class="db_table" id="table">
<thead> <thead>
<tr> <tr>
<td class='column_100 pointer'>user</td> <td class='column_200 pointer'>user</td>
<td class='column_100 pointer'>table</td> <td class='column_100 pointer'>table</td>
<td class='column_100 pointer'>message</td> <td class='pointer'>message</td>
<td class='column_100 pointer'>record</td> <td class='column_100 pointer'>name</td>
<td class='column_100 pointer'>created</td> <td class='column_200 pointer'>created</td>
</tr> </tr>
</thead> </thead>
{{ for row in query: }} {{ for row in query: }}
<tr> <tr>
<td>{{=row.user_id}}</td> <td>{{="%s %s" % (row.auth_user.first_name, row.auth_user.last_name)}}</td>
<td>{{=row.table_name}}</td> <td>{{=row.user_log.table_name}}</td>
<td>{{=row.msg}}</td> <td>{{=row.user_log.msg}}</td>
<td>{{=row.record_id}}</td> <td>{{=row.names}}</td>
<td>{{=row.created}}</td> <td>{{=row.user_log.created}}</td>
</tr> </tr>
{{ pass }} {{ pass }}
</table> </table>
......
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