Fix users in group and groups for user exact filters
List users in a group by name and list groups for user by name throws HTTP 500 error in case of exact filters because filter_by query used in case of exact filter is not able to filter using 'name' attribute. This patch fixes this issue by replacing filter_by with filter query in case of exact_filter similar to the inexact_filter query. Closes-Bug: 1521772 Change-Id: Ib44513540370c0701a439f11a49e0dc338601fae
This commit is contained in:
parent
545987e1c4
commit
ee2859a61a
|
@ -290,42 +290,41 @@ def _filter(model, query, hints):
|
|||
satisfied_filters.append(filter_)
|
||||
return query.filter(query_term)
|
||||
|
||||
def exact_filter(model, filter_, cumulative_filter_dict):
|
||||
def exact_filter(model, query, filter_, satisfied_filters):
|
||||
"""Applies an exact filter to a query.
|
||||
|
||||
:param model: the table model in question
|
||||
:param query: query to apply filters to
|
||||
:param dict filter_: describes this filter
|
||||
:param dict cumulative_filter_dict: describes the set of exact filters
|
||||
built up so far
|
||||
|
||||
:param list satisfied_filters: filter_ will be added if it is
|
||||
satisfied.
|
||||
:returns query: query updated to add any exact filters we could
|
||||
satisfy
|
||||
"""
|
||||
key = filter_['name']
|
||||
|
||||
col = getattr(model, key)
|
||||
if isinstance(col.property.columns[0].type, sql.types.Boolean):
|
||||
cumulative_filter_dict[key] = (
|
||||
utils.attr_as_boolean(filter_['value']))
|
||||
filter_val = utils.attr_as_boolean(filter_['value'])
|
||||
else:
|
||||
_WontMatch.check(filter_['value'], col)
|
||||
cumulative_filter_dict[key] = filter_['value']
|
||||
filter_val = filter_['value']
|
||||
|
||||
satisfied_filters.append(filter_)
|
||||
return query.filter(col == filter_val)
|
||||
|
||||
try:
|
||||
filter_dict = {}
|
||||
satisfied_filters = []
|
||||
for filter_ in hints.filters:
|
||||
if filter_['name'] not in model.attributes:
|
||||
continue
|
||||
if filter_['comparator'] == 'equals':
|
||||
exact_filter(model, filter_, filter_dict)
|
||||
satisfied_filters.append(filter_)
|
||||
query = exact_filter(model, query, filter_,
|
||||
satisfied_filters)
|
||||
else:
|
||||
query = inexact_filter(model, query, filter_,
|
||||
satisfied_filters)
|
||||
|
||||
# Apply any exact filters we built up
|
||||
if filter_dict:
|
||||
query = query.filter_by(**filter_dict)
|
||||
|
||||
# Remove satisfied filters, then the caller will know remaining filters
|
||||
for filter_ in satisfied_filters:
|
||||
hints.filters.remove(filter_)
|
||||
|
|
|
@ -6512,7 +6512,6 @@ class FilterTests(filtering.FilterTests):
|
|||
self._delete_test_data('user', user_list)
|
||||
self._delete_test_data('group', group_list)
|
||||
|
||||
@test_utils.wip('Waiting on bug #1521772 to be fixed')
|
||||
def test_groups_for_user_exact_filtered(self):
|
||||
"""Test exact filters doesn't break groups_for_user listing."""
|
||||
group_list, user_list, hints = self._groups_for_user_data()
|
||||
|
@ -6589,7 +6588,6 @@ class FilterTests(filtering.FilterTests):
|
|||
self._delete_test_data('user', user_list)
|
||||
self._delete_entity('group')(group['id'])
|
||||
|
||||
@test_utils.wip('Waiting on bug #1521772 to be fixed')
|
||||
def test_list_users_in_group_exact_filtered(self):
|
||||
user_list, group, hints = self._list_users_in_group_data()
|
||||
hints.add_filter('name', 'Arthur Rimbaud', comparator='equals')
|
||||
|
|
|
@ -3298,7 +3298,3 @@ class LdapFilterTests(test_backend.FilterTests, unit.TestCase):
|
|||
# The LDAP identity driver currently does not support filtering on the
|
||||
# listing users for a given group, so will fail this test.
|
||||
super(LdapFilterTests, self).test_list_users_in_group_exact_filtered()
|
||||
|
||||
@wip('Waiting on bug #1521772 to be fixed')
|
||||
def test_groups_for_user_exact_filtered(self):
|
||||
super(LdapFilterTests, self).test_groups_for_user_exact_filtered()
|
||||
|
|
Loading…
Reference in New Issue