Skip to content

Commit

Permalink
allow multiple status params for update list views
Browse files Browse the repository at this point in the history
Previously, when querying a list of updates, only a
single status parameter could be specified, e.g.:

https://bodhi.fedoraproject.org/updates/?user=churchyard&status=testing

this commit changes that so multiple status parameters
can be supplied, for example:

https://bodhi.fedoraproject.org/updates/?user=churchyard&status=testing&status=pending

Related: fedora-infra#3429
Signed-off-by: Ryan Lerch <rlerch@redhat.com>
  • Loading branch information
ryanlerch committed Aug 14, 2019
1 parent 62cf4c1 commit 8d7fe01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions bodhi/server/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ class Updates(colander.SequenceSchema):
update = colander.SchemaNode(colander.String())


class Status(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Update status objects."""

status = colander.SchemaNode(colander.String(),
validator=colander.OneOf(list(UpdateStatus.values())))


class Tests(colander.SequenceSchema):
"""A SequenceSchema to validate a list of Test objects."""

Expand Down Expand Up @@ -575,11 +582,11 @@ class ListUpdateSchema(PaginatedSchema, SearchableSchema, Cosmetics):
validator=colander.OneOf(list(UpdateSeverity.values())),
)

status = colander.SchemaNode(
colander.String(),
status = Status(
colander.Sequence(accept_scalar=True),
location="querystring",
missing=None,
validator=colander.OneOf(list(UpdateStatus.values())),
preparer=[util.splitter],
)

submitted_since = colander.SchemaNode(
Expand Down
2 changes: 1 addition & 1 deletion bodhi/server/services/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def query_updates(request):

status = data.get('status')
if status is not None:
query = query.filter(Update.status == status)
query = query.filter(or_(*[Update.status == s for s in status]))

submitted_since = data.get('submitted_since')
if submitted_since is not None:
Expand Down
7 changes: 6 additions & 1 deletion bodhi/server/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,12 @@ def validate_enums(request, **kwargs):
if value is None:
continue

request.validated[param] = enum.from_string(value)
if isinstance(value, str):
request.validated[param] = enum.from_string(value)
else:
for index, item in enumerate(value):
value[index] = enum.from_string(item)
request.validated[param] = value


@postschema_validator
Expand Down

0 comments on commit 8d7fe01

Please sign in to comment.