Skip to content

Commit c7e282c

Browse files
authored
Merge pull request #1053 from scitran/analysis-info
Add standard info editing for analyses
2 parents 847a20f + 8ea879a commit c7e282c

File tree

3 files changed

+83
-2
lines changed

3 files changed

+83
-2
lines changed

api/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ def prefix(path, routes):
245245
prefix( '/analyses/<_id:{cid}>', [
246246
route('/files', AnalysesHandler, h='download', m=['GET']),
247247
route('/files/<filename:{fname}>', AnalysesHandler, h='download', m=['GET']),
248+
route( '/info', AnalysesHandler, h='modify_info', m=['POST']),
248249
]),
249250
prefix('/<:{cname}>/<:{cid}>/<cont_name:analyses>/<cid:{cid}>', [
250251
route('/<list_name:notes>', NotesListHandler, m=['POST']),

api/handlers/refererhandler.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ def post(self, cont_name, cid):
7979
permchecker(noop)('POST')
8080

8181
if self.is_true('job'):
82-
if cont_name != 'sessions':
83-
self.abort(400, 'Analysis created via a job must be at the session level')
8482

8583
payload = self.request.json_body
8684
analysis = payload.get('analysis')
@@ -126,6 +124,22 @@ def put(self, cont_name, **kwargs):
126124
else:
127125
self.abort(404, 'Element not updated in container {} {}'.format(self.storage.cont_name, _id))
128126

127+
@validators.verify_payload_exists
128+
def modify_info(self, **kwargs):
129+
_id = kwargs.get('_id')
130+
131+
analysis = self.storage.get_container(_id)
132+
parent = self.storage.get_parent(analysis['parent']['type'], analysis['parent']['id'])
133+
permchecker = self.get_permchecker(parent)
134+
permchecker(noop)('PUT')
135+
136+
payload = self.request.json_body
137+
validators.validate_data(payload, 'info_update.json', 'input', 'POST')
138+
139+
self.storage.modify_info(_id, payload)
140+
141+
return
142+
129143
def get(self, **kwargs):
130144
_id = kwargs.get('_id')
131145
analysis = self.storage.get_container(_id)

tests/integration_tests/python/test_containers.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,6 +1065,72 @@ def test_edit_subject_info(data_builder, as_admin, as_user):
10651065
assert r.json()['info'] == {}
10661066

10671067

1068+
def test_edit_analysis_info(data_builder, default_payload, file_form, as_admin, as_user):
1069+
"""
1070+
Abridged version since it uses same storage layer as container info
1071+
"""
1072+
1073+
gear_doc = default_payload['gear']['gear']
1074+
gear_doc['inputs'] = {'csv': {'base': 'file'}}
1075+
gear = data_builder.create_gear(gear=gear_doc)
1076+
project = data_builder.create_project()
1077+
1078+
assert as_admin.post('/projects/' + project + '/files', files=file_form('test.csv')).ok
1079+
r = as_admin.post('/projects/' + project + '/analyses', params={'job': 'true'}, json={
1080+
'analysis': {'label': 'with-job'},
1081+
'job': {
1082+
'gear_id': gear,
1083+
'inputs': {'csv': {'type': 'project', 'id': project, 'name': 'test.csv'}}
1084+
}
1085+
})
1086+
assert r.ok
1087+
analysis = r.json()['_id']
1088+
1089+
1090+
r = as_admin.get('/analyses/' + analysis)
1091+
assert r.ok
1092+
assert not r.json().get('info')
1093+
1094+
# Send improper payload
1095+
r = as_admin.post('/analyses/' + analysis + '/info', json={
1096+
'delete': ['map'],
1097+
'replace': {'not_going': 'to_happen'}
1098+
})
1099+
assert r.status_code == 400
1100+
1101+
# Send improper payload
1102+
r = as_admin.post('/analyses/' + analysis + '/info', json={
1103+
'delete': {'a': 'map'},
1104+
})
1105+
assert r.status_code == 400
1106+
1107+
# Send improper payload
1108+
r = as_admin.post('/analyses/' + analysis + '/info', json={
1109+
'set': 'cannot do this',
1110+
})
1111+
assert r.status_code == 400
1112+
1113+
# Attempt full replace of info
1114+
analysis_info = {
1115+
'a': 'b',
1116+
'test': 123,
1117+
'map': {
1118+
'a': 'b'
1119+
},
1120+
'list': [1,2,3]
1121+
}
1122+
1123+
1124+
r = as_admin.post('/analyses/' + analysis + '/info', json={
1125+
'replace': analysis_info
1126+
})
1127+
assert r.ok
1128+
1129+
r = as_admin.get('/analyses/' + analysis)
1130+
assert r.ok
1131+
assert r.json()['info'] == analysis_info
1132+
1133+
10681134
def test_fields_list_requests(data_builder, file_form, as_admin):
10691135
# Ensure sensitive keys are not returned on list endpoints
10701136
# Project: info and files.info

0 commit comments

Comments
 (0)