Commit 18fd644a authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Fixed edit api with empty with_embargo action. #530

parent 44e44caf
......@@ -607,7 +607,22 @@ class EditRepoCalcsResource(Resource):
action_value = action.get('value')
action_value = action_value if action_value is None else action_value.strip()
if action_value is None:
if action_quantity_name == 'with_embargo':
# ignore the actual value ... just lift the embargo
mongo_value = False
lift_embargo = True
# check if necessary
search_request = search.SearchRequest()
apply_search_parameters(search_request, parsed_query)
search_request.q = search_request.q & Q('term', with_embargo=True)
if search_request.execute()['total'] == 0:
action['success'] = False
has_error = True
action['message'] = 'There is no embargo to lift'
continue
elif action_value is None:
mongo_value = None
elif action_value == '':
......@@ -644,20 +659,6 @@ class EditRepoCalcsResource(Resource):
dataset.a_mongo.create()
mongo_value = dataset.dataset_id
elif action_quantity_name == 'with_embargo':
# ignore the actual value ... just lift the embargo
mongo_value = False
lift_embargo = True
# check if necessary
search_request = search.SearchRequest()
apply_search_parameters(search_request, parsed_query)
search_request.q = search_request.q & Q('term', with_embargo=True)
if search_request.execute()['total'] == 0:
action['success'] = False
has_error = True
action['message'] = 'There is no embargo to lift'
continue
else:
mongo_value = action_value
......
......@@ -1750,19 +1750,30 @@ class TestEditRepo():
def test_edit_lift_embargo(api, published, other_test_user_auth):
example_calc = Calc.objects(upload_id=published.upload_id).first()
assert example_calc.metadata['with_embargo']
elastic_calc = next(
search.SearchRequest().search_parameters(calc_id=example_calc.calc_id).execute_scan())
assert elastic_calc['with_embargo'] is True
with pytest.raises(files.Restricted):
with files.UploadFiles.get(published.upload_id).read_archive(example_calc.calc_id) as archive:
archive[example_calc.calc_id].to_dict()
rv = api.post(
'/repo/edit', headers=other_test_user_auth, content_type='application/json',
data=json.dumps({
'actions': {
'with_embargo': {
'value': 'lift'
}
'with_embargo': {}
}
}))
assert rv.status_code == 200, rv.data
assert not Calc.objects(calc_id=example_calc.calc_id).first().metadata['with_embargo']
Upload.get(published.upload_id).block_until_complete()
elastic_calc = next(
search.SearchRequest().search_parameters(calc_id=example_calc.calc_id).execute_scan())
assert elastic_calc['with_embargo'] is False
# should not raise Restricted anymore
with files.UploadFiles.get(published.upload_id).read_archive(example_calc.calc_id) as archive:
archive[example_calc.calc_id].to_dict()
......
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