Merge pull request #190 from eReuse/bugfix/#2559

Bugfix/#2559
This commit is contained in:
cayop 2021-12-21 10:49:11 +01:00 committed by GitHub
commit 2c2e93eb3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 11 deletions

View File

@ -61,23 +61,48 @@ class DocumentView(DeviceView):
args = self.QUERY_PARSER.parse(self.find_args, args = self.QUERY_PARSER.parse(self.find_args,
flask.request, flask.request,
locations=('querystring',)) locations=('querystring',))
ids = []
if 'filter' in request.args:
filters = json.loads(request.args.get('filter', {}))
ids = filters.get('ids', [])
if not ids and not id:
msg = 'Document must be an ID or UUID.'
raise teal.marshmallow.ValidationError(msg)
if id: if id:
# todo we assume we can pass both device id and action id
# for certificates... how is it going to end up being?
try: try:
id = uuid.UUID(id) id = uuid.UUID(id)
except ValueError: except ValueError:
try: try:
id = int(id) ids.append(int(id))
except ValueError: except ValueError:
raise teal.marshmallow.ValidationError('Document must be an ID or UUID.') msg = 'Document must be an ID or UUID.'
raise teal.marshmallow.ValidationError(msg)
else: else:
query = devs.Device.query.filter_by(id=id) query = devs.Device.query.filter(Device.id.in_(ids))
else: else:
query = evs.Action.query.filter_by(id=id) query = evs.Action.query.filter_by(id=id)
else: else:
flask.current_app.auth.requires_auth(lambda: None)() # todo not nice query = devs.Device.query.filter(Device.id.in_(ids))
query = self.query(args)
# if id:
# # todo we assume we can pass both device id and action id
# # for certificates... how is it going to end up being?
# try:
# id = uuid.UUID(id)
# except ValueError:
# try:
# id = int(id)
# except ValueError:
# raise teal.marshmallow.ValidationError('Document must be an ID or UUID.')
# else:
# query = devs.Device.query.filter_by(id=id)
# else:
# query = evs.Action.query.filter_by(id=id)
# else:
# flask.current_app.auth.requires_auth(lambda: None)() # todo not nice
# query = self.query(args)
type = urlutils.URL(flask.request.url).path_parts[-2] type = urlutils.URL(flask.request.url).path_parts[-2]
if type == 'erasures': if type == 'erasures':

View File

@ -70,7 +70,7 @@ def test_erasure_certificate_private_query(user: UserClient):
doc, response = user.get(res=documents.DocumentDef.t, doc, response = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[ query=[
('filter', {'id': [snapshot['device']['id']]})], ('filter', {'ids': [snapshot['device']['id']]})],
accept=ANY) accept=ANY)
assert 'html' in response.content_type assert 'html' in response.content_type
assert '<html' in doc assert '<html' in doc
@ -80,7 +80,7 @@ def test_erasure_certificate_private_query(user: UserClient):
item='erasures/', item='erasures/',
query=[ query=[
('filter', { ('filter', {
'id': [snapshot['device']['id']]}), 'ids': [snapshot['device']['id']]}),
('format', 'PDF') ('format', 'PDF')
], ],
accept='application/pdf') accept='application/pdf')
@ -601,7 +601,7 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client):
doc, _ = user.get(res=documents.DocumentDef.t, doc, _ = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[('filter', {'id': [snapshot['device']['id']]})], query=[('filter', {'ids': [snapshot['device']['id']]})],
accept=ANY) accept=ANY)
response, _ = client.post(res=documents.DocumentDef.t, response, _ = client.post(res=documents.DocumentDef.t,
@ -616,7 +616,7 @@ def test_verify_stamp_erasure_certificate(user: UserClient, client: Client):
doc, _ = user.get(res=documents.DocumentDef.t, doc, _ = user.get(res=documents.DocumentDef.t,
item='erasures/', item='erasures/',
query=[ query=[
('filter', {'id': [snapshot['device']['id']]}), ('filter', {'ids': [snapshot['device']['id']]}),
('format', 'PDF') ('format', 'PDF')
], ],
accept='application/pdf') accept='application/pdf')