Handling filters in Generalized Filtering API

This patch handles the following filters :

1) all_tenants : Restoring to previous functionality of ignoring
invalid filters

2) is_public (volume_type): This filter has the 3 valid values,
* True : show only public volume types (valid for non-admins)
* False : show only private volume types (valid for admins)
* None : show both private and public volume types
Since this filter is valid for admins as well as non-admins,
we can pass this through filtering API to lower level code where
this is handled correctly.

3) name (group, group snapshot): 'name' is a valid parameter for
non-admins while showing a group or group snapshot.

Closes-Bug: #1753885

Change-Id: I1545c165087f80a9fdc9f576114a820ac95be5c5
(cherry picked from commit 80e94ac3dc)
This commit is contained in:
whoami-rajat 2019-03-07 21:58:21 +05:30 committed by Rajat Dhasmana
parent 0a45cd5eb9
commit 46363697d9
3 changed files with 8 additions and 7 deletions

View File

@ -427,8 +427,9 @@ def reject_invalid_filters(context, filters, resource,
"%s~" % key in configured_filters):
invalid_filters.append(key)
if invalid_filters:
if (resource == 'volume_type' and len(invalid_filters) == 1
and invalid_filters[0] == 'is_public'):
if 'all_tenants' in invalid_filters:
invalid_filters.remove('all_tenants')
if len(invalid_filters) == 0:
return
raise webob.exc.HTTPBadRequest(
explanation=_('Invalid filters %s are found in query '

View File

@ -415,7 +415,7 @@ class GeneralFiltersTest(test.TestCase):
'resource': 'fake_resource'},
{'filters': {'is_public': True},
'is_admin': False,
'result': {'volume_type': []},
'result': {'volume_type': ["is_public"]},
'expected': {'is_public': True},
'resource': 'volume_type'})
@ddt.unpack
@ -485,7 +485,7 @@ class GeneralFiltersTest(test.TestCase):
'expected': ["name", "status", "volume_id", "metadata",
"availability_zone"]},
{'resource': 'group_snapshot',
'expected': ["status", "group_id"]},
'expected': ["name", "status", "group_id"]},
{'resource': 'attachment',
'expected': ["volume_id", "status", "instance_id",
"attach_status"]},

View File

@ -5,11 +5,11 @@
"backup": ["name", "status", "volume_id"],
"snapshot": ["name", "status", "volume_id", "metadata",
"availability_zone"],
"group": [],
"group_snapshot": ["status", "group_id"],
"group": ["name"],
"group_snapshot": ["name", "status", "group_id"],
"attachment": ["volume_id", "status", "instance_id", "attach_status"],
"message": ["resource_uuid", "resource_type", "event_id",
"request_id", "message_level"],
"pool": ["name", "volume_type"],
"volume_type": []
"volume_type": ["is_public"]
}