Skip to content

Commit 485695f

Browse files
authored
Merge pull request #1050 from scitran/group-delete
Fix bug when deleting empty group
2 parents 8bd473b + 8d0989b commit 485695f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

api/dao/consistencychecker.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ def get_container_storage_checker(action, cont_name):
2323
return field_on_container('acquisition', 'acquisitions')
2424
elif cont_name == 'groups' and action == 'DELETE':
2525
return check_children('group', 'projects')
26-
elif cont_name == 'projects' and action == 'DELETE':
27-
return check_children('project', 'sessions')
28-
elif cont_name == 'sessions' and action == 'DELETE':
29-
return check_children('session', 'acquisitions')
3026
return noop
3127

3228
def user_on_permission(data_op, **kwargs): # pylint: disable=unused-argument
@@ -64,7 +60,7 @@ def check_children(foreign_key_field, container_name):
6460
APIConsistencyException: Child document found
6561
"""
6662
def f(data_op, **kwargs): # pylint: disable=unused-argument
67-
if config.db[container_name].find_one({foreign_key_field: data_op['_id']}):
63+
if config.db[container_name].find_one({foreign_key_field: data_op['_id'], 'deleted' :{'$exists': False}}):
6864
raise APIConsistencyException(
6965
'DELETE not allowed. Children {} found for {}'.format(container_name, data_op['_id'])
7066
)

tests/integration_tests/python/test_containers.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1169,10 +1169,11 @@ def test_fields_list_requests(data_builder, file_form, as_admin):
11691169
assert not a['files'][0].get('info')
11701170

11711171

1172-
def test_container_delete_tag(data_builder, default_payload, as_admin, as_user, file_form, api_db):
1172+
def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, as_user, file_form, api_db):
11731173
gear_doc = default_payload['gear']['gear']
11741174
gear_doc['inputs'] = {'csv': {'base': 'file'}}
11751175
gear = data_builder.create_gear(gear=gear_doc)
1176+
group = data_builder.create_group()
11761177
project = data_builder.create_project()
11771178
session = data_builder.create_session()
11781179
acquisition = data_builder.create_acquisition()
@@ -1192,6 +1193,10 @@ def test_container_delete_tag(data_builder, default_payload, as_admin, as_user,
11921193
})
11931194
assert r.ok
11941195

1196+
# try to delete group with project
1197+
r = as_root.delete('/groups/' + group)
1198+
assert r.status_code == 400
1199+
11951200
# try to delete project without admin perms
11961201
r = as_user.delete('/projects/' + project)
11971202
assert r.status_code == 403
@@ -1256,3 +1261,7 @@ def test_container_delete_tag(data_builder, default_payload, as_admin, as_user,
12561261
assert as_admin.get('/sessions').json() == []
12571262
assert as_admin.get('/acquisitions').json() == []
12581263
assert as_admin.get('/collections').json() == []
1264+
1265+
# test that the (now) empty group can be deleted
1266+
assert as_root.delete('/groups/' + group).ok
1267+

0 commit comments

Comments
 (0)