Commit cc96b572 authored by Ryan Herbert's avatar Ryan Herbert
Browse files

major refactor to use sample_set_id everywhere.

There were some places where the patient/run/generic id was used (such
as for permissions) but we want to migrate to full-on sample_set
management, so we can display the sample_set id to users.
parent 9cd621a5
......@@ -162,6 +162,7 @@ PatientFormBuilder.prototype.build = function(index) {
var fieldset = this.build_fieldset(this.type);
fieldset.appendChild(this.createCloseButton());
fieldset.appendChild(this.build_input('id', 'text', 'id', 'hidden', this.type));
fieldset.appendChild(this.build_input('sample_set_id', 'text', 'sample_set_id', 'hidden', this.type));
fieldset.appendChild(this.set_id());
fieldset.appendChild(this.build_field('first_name', undefined, undefined, true));
fieldset.appendChild(this.build_field('last_name', undefined, undefined, true));
......@@ -182,6 +183,7 @@ RunFormBuilder.prototype.build = function(index) {
var fieldset = this.build_fieldset(this.type);
fieldset.appendChild(this.createCloseButton());
fieldset.appendChild(this.build_input('id', 'text', 'id', 'hidden', this.type));
fieldset.appendChild(this.build_input('sample_set_id', 'text', 'sample_set_id', 'hidden', this.type));
fieldset.appendChild(this.set_id());
fieldset.appendChild(this.build_field('name', undefined, undefined, true));
fieldset.appendChild(this.build_date('run_date', 'run_date', 'Date'));
......@@ -203,6 +205,7 @@ GenericFormBuilder.prototype.build = function(index) {
var fieldset = this.build_fieldset('set');
fieldset.appendChild(this.createCloseButton());
fieldset.appendChild(this.build_input('id', 'text', 'id', 'hidden', this.type));
fieldset.appendChild(this.build_input('sample_set_id', 'text', 'sample_set_id', 'hidden', this.type));
fieldset.appendChild(this.build_field('name', undefined, undefined, true));
fieldset.appendChild(this.build_info());
return fieldset;
......
......@@ -346,7 +346,7 @@ def get_data():
data["info"] = db.generic[row.id].info
data["generic_id"] = row.id
data["sample_name"] = generic_name
data["group_id"] = get_set_group(defs.SET_TYPE_GENERIC, row.id)
data["group_id"] = get_set_group(row.sample_set_id)
if (sample_set.sample_type == defs.SET_TYPE_PATIENT):
for row in db( db.patient.sample_set_id == request.vars["sample_set_id"] ).select() :
......@@ -356,7 +356,7 @@ def get_data():
data["info"] = db.patient[row.id].info
data["patient_id"] = row.id
data["sample_name"] = patient_name
data["group_id"] = get_set_group(defs.SET_TYPE_PATIENT, row.id)
data["group_id"] = get_set_group(row.sample_set_id)
if (sample_set.sample_type == defs.SET_TYPE_RUN) :
for row in db( db.run.sample_set_id == request.vars["sample_set_id"] ).select() :
......@@ -366,7 +366,7 @@ def get_data():
data["info"] = db.run[row.id].info
data["run_id"] = row.id
data["sample_name"] = run_name
data["group_id"] = get_set_group(defs.SET_TYPE_RUN, row.id)
data["group_id"] = get_set_group(row.sample_set_id)
log_query = db( ( db.user_log.record_id == log_reference_id )
& ( db.user_log.table_name == sample_set.sample_type )
......
......@@ -95,7 +95,7 @@ def validate_sets(myfile, errors):
myfile['sets'].append({'type': set_type, 'id': sid})
set_id = helpers[set_type].parse_id_string(sid)
myfile['id_dict'][set_type].append(set_id)
if not auth.can_modify(set_type, set_id) :
if not auth.can_modify_sample_set(set_id) :
errors.append("missing permission for %s %d" % (set_type, set_id))
except ValueError:
errors.append("Invalid %s %s" % (key, set_ids[set_type]))
......@@ -247,12 +247,10 @@ def submit():
action = "add"
mes = "file (%d) %s %sed" % (f["id"], f["filename"], action)
group_ids = set()
for key in f['id_dict']:
for sid in f['id_dict'][key]:
group_ids.add(get_set_group(key, sid))
for group_id in group_ids:
register_tags(db, 'sequence_file', fid, f["info"], group_id, reset=True)
group_id = get_set_group(sid)
register_tags(db, 'sequence_file', fid, f["info"], group_id, reset=True)
if f['filename'] != "":
if reupload:
......@@ -268,8 +266,7 @@ def submit():
file_data['network'] = True
db.sequence_file[fid] = file_data
id_dict = get_sample_set_ids(f['id_dict'])
link_to_sample_sets(fid, id_dict)
link_to_sample_sets(fid, f['id_dict'])
log.info(mes, extra={'user_id': auth.user.id,\
'record_id': f['id'],\
......
......@@ -387,8 +387,8 @@ def form():
sample_set = db.sample_set[request.vars["id"]]
set_type = sample_set.sample_type
sset = db(db[set_type].sample_set_id == sample_set.id).select().first()
if(auth.can_modify(sample_set.sample_type, sset.id)):
groups = [get_set_group(set_type, sset.id)]
if(auth.can_modify_sample_set(sset.sample_set_id)):
groups = [get_set_group(sset.sample_set_id)]
message = 'edit %s' % set_type
max_group = None
else:
......@@ -452,15 +452,14 @@ def submit():
name = helper.get_name(p)
# edit
if (p['id'] != "" and auth.can_modify(set_type, p['id'])):
if (p['sample_set_id'] != "" and auth.can_modify_sample_set(p['sample_set_id'])):
reset = True
id = p["id"]
sset = db[set_type][id]
db[set_type][id] = p
sset = db(db[set_type].sample_set_id == p['sample_set_id']).select().first()
db[set_type][sset.id] = p
id_sample_set = sset['sample_set_id']
if (sset.info != p['info']):
group_id = get_set_group(set_type, id)
group_id = get_set_group(id_sample_set)
register = True
reset = True
......@@ -480,7 +479,7 @@ def submit():
register = True
#patient creator automaticaly has all rights
auth.add_permission(group_id, PermissionEnum.access.value, db[set_type], p['id'])
auth.add_permission(group_id, PermissionEnum.access.value, 'sample_set', p['sample_set_id'])
action = "add"
......@@ -494,7 +493,7 @@ def submit():
error = True
mes = "%s (%s) %s %sed" % (set_type, id_sample_set, name, action)
log.info(mes, extra={'user_id': auth.user.id, 'record_id': id, 'table_name': 'patient'})
log.info(mes, extra={'user_id': auth.user.id, 'record_id': p['id'], 'table_name': 'patient'})
if register:
register_tags(db, set_type, p["id"], p["info"], group_id, reset=reset)
......@@ -543,10 +542,7 @@ def custom():
qq = (db.sample_set.id == request.vars["id"])
else:
qq = (auth.vidjil_accessible_query(PermissionEnum.read.value, db.patient)
| auth.vidjil_accessible_query(PermissionEnum.read.value, db.run)
| auth.vidjil_accessible_query(PermissionEnum.read.value, db.generic))
qq = (auth.vidjil_accessible_query(PermissionEnum.read.value, db.sample_set))
myGroupBy = db.sequence_file.id|db.patient.id|db.run.id|db.generic.id|db.results_file.config_id
q = (qq
......@@ -761,7 +757,8 @@ def change_permission():
def get_sample_set_list(type):
query = db(
auth.vidjil_accessible_query(PermissionEnum.admin.value, db[type])
(auth.vidjil_accessible_query(PermissionEnum.admin.value, db.sample_set))&
(db[type].sample_set_id == db.sample_set.id)
).select(
db[type].ALL, # sub optimal, use helpers to reduce ?
orderby = ~db[type].id
......
......@@ -154,11 +154,11 @@ def get_sample_name(sample_set_id):
return vidjil_utils.anon_ids(patient_or_run.id)
return patient_or_run.name
def get_set_group(stype, sid):
def get_set_group(sid):
'''
Return the group associated with the set
'''
perm = db((db.auth_permission.table_name == stype) &
perm = db((db.auth_permission.table_name == 'sample_set') &
(db.auth_permission.record_id == sid) &
(db.auth_permission.name == PermissionEnum.access.value)
).select().first()
......
......@@ -23,7 +23,7 @@ class Generic(SampleSet):
def get_id_string(self, data):
name = data['name'] if data['name'] is not None else "Unnamed Sample Set"
return ":s %s (%d)" % (name, data['id'])
return ":s %s (%d)" % (name, data['sample_set_id'])
def validate(self, data):
error = []
......
......@@ -42,7 +42,7 @@ class Patient(SampleSet):
def get_id_string(self, data):
name = self.get_name(data)
ident = "(%d)" % data['id']
ident = "(%d)" % data['sample_set_id']
return ":p %s %s" % (name, ident)
def validate(self, data):
......
......@@ -38,7 +38,7 @@ class Run(SampleSet):
def get_id_string(self, data):
name = data['name']
ident = "(%d)" % data['id']
ident = "(%d)" % data['sample_set_id']
return ":r %s %s" % (name, ident)
def validate(self, data):
......
......@@ -6,7 +6,8 @@ class SampleSetList():
if page is not None and step is not None:
limitby = (page*step, (page+1)*step+1) # one more element to indicate if another page exists
query = (auth.vidjil_accessible_query(PermissionEnum.read.value, db[type]))
query = ((auth.vidjil_accessible_query(PermissionEnum.read.value, db.sample_set)) &
(db[type].sample_set_id == db.sample_set.id))
if (tags is not None and len(tags) > 0):
query = filter_by_tags(query, self.type, tags)
......
<fieldset name="generic{{=i}}">
<legend>Set {{=i+1}}</legend>
<input type="hidden" id="generic_id_{{=i}}" name="generic[{{=i}}][id]" value="{{if set is not None:}}{{=set['id']}}{{pass}}">
<input type="hidden" sample_set_id="generic_sample_set_id_{{=i}}" name="generic[{{=i}}][sample_set_id]" value="{{if set is not None:}}{{=set['sample_set_id']}}{{pass}}">
{{ if set is not None and 'error' in set and len(set['error']) > 0: }}
<div class="error">error: {{=", ".join(set['error'])}}</div>
{{pass}}
......
<fieldset name="patient{{=i}}">
<legend>Patient {{=i+1}}</legend>
<input type="hidden" id="patient_id_{{=i}}" name="patient[{{=i}}][id]" value="{{if set is not None:}}{{=set['id']}}{{pass}}">
<input type="hidden" sample_set_id="patient_sample_set_id_{{=i}}" name="patient[{{=i}}][sample_set_id]" value="{{if set is not None:}}{{=set['sample_set_id']}}{{pass}}">
{{ if set is not None and 'error' in set and len(set['error']) > 0: }}
<div class="error">error: {{=", ".join(set['error'])}}</div>
{{ pass }}
......
<fieldset name="run{{=i}}">
<legend>Run {{=i+1}}</legend>
<input type="hidden" id="run_id_{{=i}}" name="run[{{=i}}][id]" value="{{if set is not None:}}{{=set['id']}}{{pass}}">
<input type="hidden" sample_set_id="run_sample_set_id_{{=i}}" name="run[{{=i}}][sample_set_id]" value="{{if set is not None:}}{{=set['sample_set_id']}}{{pass}}">
{{ if set is not None and 'error' in set and len(set['error']) > 0: }}
<div class="error">error: {{=", ".join(set['error'])}}</div>
{{ pass }}
......
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