Commit 63efc5b2 authored by HERBERT Ryan's avatar HERBERT Ryan Committed by Mathieu Giraud
Browse files

user_group.py, run.py patient.py owner group refactoring

Refactored the selection of the owner group when adding a patient and a
run since the process is the same, but there was a duplication in the
code and the two versions had diverged, creating a bug.
parent 48984437
......@@ -252,35 +252,9 @@ def index():
## return form to create new patient
def add():
if (auth.can_create_patient()):
max_group = auth.user_group()
group_dict = {}
if (auth.is_admin()):
group_list = db(db.auth_group).select(db.auth_group.id, db.auth_group.role)
else:
group_list = db((db.auth_group.id == db.auth_membership.group_id) &
(db.auth_membership.user_id == auth.user_id) &
(db.auth_group.role != 'public')
).select(db.auth_group.id, db.auth_group.role)
max_elements = 0
for group in group_list:
if (auth.is_admin()
or auth.has_permission(PermissionEnum.create.value, 'sample_set', 0, group_id = group.id)):
parents = auth.get_group_parent(group.id)
if (len(parents) > 0):
tgt_group = parents[0]
else:
tgt_group = group
group_dict[tgt_group.id] = {'id': tgt_group.id,
'name': 'Personnal Group' if tgt_group.id == auth.user_group() else tgt_group.role}
elements = db(
(db.auth_permission.group_id == tgt_group.id) &
(db.auth_permission.table_name.belongs('patient', 'run', 'sample_set')) &
(db.auth_permission.record_id > 0)
).count()
if (elements >= max_elements and tgt_group.id != auth.user_group()):
max_elements = elements
max_group = tgt_group.id
groups = [{'id': group_dict[key]['id'], 'name': group_dict[key]['name']} for key in group_dict]
creation_group_tuple = get_default_creation_group(auth)
groups = creation_group_tuple[0]
max_group = creation_group_tuple[1]
return dict(message=T('add patient'), groups=groups, master_group=max_group)
else :
res = {"message": ACCESS_DENIED}
......
......@@ -178,24 +178,9 @@ def add():
distinct=True
)
max_group = db.auth_group[auth.user_group()]
groups = []
if (auth.is_admin()):
group_list = db(db.auth_group).select(db.auth_group.id, db.auth_group.role)
else:
groups.append({'name': 'Personnal Group', 'id': auth.user_group()})
group_list = auth.get_user_group_parents()
max_elements = 0
for group in group_list:
groups.append({'id': group.id, 'name': group.role})
elements = db(
(db.auth_permission.group_id == group.id) &
(db.auth_permission.table_name.belongs('patient', 'run', 'sample_set')) &
(db.auth_permission.record_id > 0)
).count()
if (elements > max_elements):
max_elements = elements
max_group = group.id
creation_group_tuple = get_default_creation_group(auth)
groups = creation_group_tuple[0]
max_group = creation_group_tuple[1]
return dict(message=T('add run'),
sequencer_list = sequencer_list,
......
from gluon import current
def get_default_creation_group(auth):
db = auth.db
max_group = auth.user_group()
group_dict = {}
if (auth.is_admin()):
group_list = db(db.auth_group).select(db.auth_group.id, db.auth_group.role)
else:
group_list = db((db.auth_group.id == db.auth_membership.group_id) &
(db.auth_membership.user_id == auth.user_id) &
(db.auth_group.role != 'public')
).select(db.auth_group.id, db.auth_group.role)
max_elements = 0
for group in group_list:
if (auth.is_admin()
or auth.has_permission(PermissionEnum.create.value, 'sample_set', 0, group_id = group.id)):
parents = auth.get_group_parent(group.id)
if (len(parents) > 0):
tgt_group = parents[0]
else:
tgt_group = group
group_dict[tgt_group.id] = {'id': tgt_group.id,
'name': 'Personnal Group' if tgt_group.id == auth.user_group() else tgt_group.role}
elements = db(
(db.auth_permission.group_id == tgt_group.id) &
(db.auth_permission.table_name.belongs('patient', 'run', 'sample_set')) &
(db.auth_permission.record_id > 0)
).count()
if (elements >= max_elements and tgt_group.id != auth.user_group()):
max_elements = elements
max_group = tgt_group.id
groups = [{'id': group_dict[key]['id'], 'name': group_dict[key]['name']} for key in group_dict]
return (groups, max_group)
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