Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions api/dao/consistencychecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ def get_container_storage_checker(action, cont_name):
return field_on_container('acquisition', 'acquisitions')
elif cont_name == 'groups' and action == 'DELETE':
return check_children('group', 'projects')
elif cont_name == 'projects' and action == 'DELETE':
return check_children('project', 'sessions')
elif cont_name == 'sessions' and action == 'DELETE':
return check_children('session', 'acquisitions')
return noop

def user_on_permission(data_op, **kwargs): # pylint: disable=unused-argument
Expand Down Expand Up @@ -64,7 +60,7 @@ def check_children(foreign_key_field, container_name):
APIConsistencyException: Child document found
"""
def f(data_op, **kwargs): # pylint: disable=unused-argument
if config.db[container_name].find_one({foreign_key_field: data_op['_id']}):
if config.db[container_name].find_one({foreign_key_field: data_op['_id'], 'deleted' :{'$exists': False}}):
raise APIConsistencyException(
'DELETE not allowed. Children {} found for {}'.format(container_name, data_op['_id'])
)
Expand Down
11 changes: 10 additions & 1 deletion tests/integration_tests/python/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1169,10 +1169,11 @@ def test_fields_list_requests(data_builder, file_form, as_admin):
assert not a['files'][0].get('info')


def test_container_delete_tag(data_builder, default_payload, as_admin, as_user, file_form, api_db):
def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, as_user, file_form, api_db):
gear_doc = default_payload['gear']['gear']
gear_doc['inputs'] = {'csv': {'base': 'file'}}
gear = data_builder.create_gear(gear=gear_doc)
group = data_builder.create_group()
project = data_builder.create_project()
session = data_builder.create_session()
acquisition = data_builder.create_acquisition()
Expand All @@ -1192,6 +1193,10 @@ def test_container_delete_tag(data_builder, default_payload, as_admin, as_user,
})
assert r.ok

# try to delete group with project
r = as_root.delete('/groups/' + group)
assert r.status_code == 400

# try to delete project without admin perms
r = as_user.delete('/projects/' + project)
assert r.status_code == 403
Expand Down Expand Up @@ -1256,3 +1261,7 @@ def test_container_delete_tag(data_builder, default_payload, as_admin, as_user,
assert as_admin.get('/sessions').json() == []
assert as_admin.get('/acquisitions').json() == []
assert as_admin.get('/collections').json() == []

# test that the (now) empty group can be deleted
assert as_root.delete('/groups/' + group).ok