Commit 05d42257 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Enable multi ids in queries for edit and download.

parent ec7b8701
......@@ -481,7 +481,7 @@ class EditUserMetadataDialogUnstyled extends React.Component {
const { classes, buttonProps, total, api, user, example, disabled } = this.props
const { open, actions, verified, submitting } = this.state
const dialogEnabled = user && example.uploader.user_id === user.sub && !disabled
const dialogEnabled = user && example.uploader && example.uploader.user_id === user.sub && !disabled
const submitEnabled = Object.keys(actions).length && !submitting && verified
const listTextInputProps = (key, verify) => {
......
......@@ -138,12 +138,13 @@ def add_query(search_request: search.SearchRequest, args: Dict[str, Any]):
args = {key: value for key, value in args.items() if value is not None}
# owner
owner = args.get('owner', 'all')
try:
search_request.owner(
args.get('owner', 'all'),
owner,
g.user.user_id if g.user is not None else None)
except ValueError as e:
abort(401, getattr(e, 'message', 'Invalid owner parameter'))
abort(401, getattr(e, 'message', 'Invalid owner parameter: %s' % owner))
except Exception as e:
abort(400, getattr(e, 'message', 'Invalid owner parameter'))
......@@ -298,7 +299,7 @@ query_model_parameters = {
}
for quantity in search.quantities.values():
if quantity.multi:
if quantity.multi and quantity.argparse_action is None:
def field(**kwargs):
return fields.List(fields.String(**kwargs))
else:
......@@ -434,8 +435,16 @@ class EditRepoCalcsResource(Resource):
return json_data, 400
# get all calculations that have to change
parsed_query = {}
for quantity_name, quantity in search.quantities.items():
if quantity_name in query:
value = query[quantity_name]
if quantity.multi and quantity.argparse_action == 'split' and not isinstance(value, list):
value = value.split(',')
parsed_query[quantity_name] = value
search_request = search.SearchRequest()
add_query(search_request, query)
add_query(search_request, parsed_query)
calc_ids = list(hit['calc_id'] for hit in search_request.execute_scan())
# perform the update on the mongo db
......
......@@ -303,11 +303,21 @@ class Domain:
quantities=DomainQuantity(
multi=True,
description='Search for the existence of a certain meta-info quantity'),
upload_id=DomainQuantity(description='Search for the upload_id.'),
calc_id=DomainQuantity(description='Search for the calc_id.'),
pid=DomainQuantity(description='Search for the pid.'),
raw_id=DomainQuantity(description='Search for the raw_id.'),
mainfile=DomainQuantity(description='Search for the mainfile.'),
upload_id=DomainQuantity(
description='Search for the upload_id.',
multi=True, argparse_action='split', elastic_search_type='terms'),
calc_id=DomainQuantity(
description='Search for the calc_id.',
multi=True, argparse_action='split', elastic_search_type='terms'),
pid=DomainQuantity(
description='Search for the pid.',
multi=True, argparse_action='split', elastic_search_type='terms'),
raw_id=DomainQuantity(
description='Search for the raw_id.',
multi=True, argparse_action='split', elastic_search_type='terms'),
mainfile=DomainQuantity(
description='Search for the mainfile.',
multi=True, argparse_action='append', elastic_search_type='terms'),
external_id=DomainQuantity(
description='External user provided id. Does not have to be unique necessarily.',
multi=True, argparse_action='split', elastic_search_type='terms'),
......
......@@ -1114,6 +1114,14 @@ class TestEditRepo():
assert not self.mongo(4, comment='test_edit_all')
assert not self.elastic(4, comment='test_edit_all')
def test_edit_multi(self):
rv = self.perform_edit(comment='test_edit_multi', query=dict(upload_id='upload_1,upload_3'))
self.assert_edit(rv, quantity='comment', success=True, message=False)
assert self.mongo(1, 4, comment='test_edit_multi')
assert self.elastic(1, 4, comment='test_edit_multi')
assert not self.mongo(2, 3, comment='test_edit_multi')
assert not self.elastic(2, 3, comment='test_edit_multi')
def test_edit_some(self):
rv = self.perform_edit(comment='test_edit_some', query=dict(upload_id='upload_1'))
self.assert_edit(rv, quantity='comment', success=True, message=False)
......
Supports Markdown
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