Skip to content

Commit 5f2145d

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add filters to search for enabled/disabled users and projects"
2 parents 51305d0 + 3483117 commit 5f2145d

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

openstackclient/identity/v3/project.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,20 @@ def get_parser(self, prog_name):
240240
'keys and directions.'
241241
),
242242
)
243+
parser.add_argument(
244+
'--enabled',
245+
action='store_true',
246+
dest='is_enabled',
247+
default=None,
248+
help=_('List only enabled projects'),
249+
)
250+
parser.add_argument(
251+
'--disabled',
252+
action='store_false',
253+
dest='is_enabled',
254+
default=None,
255+
help=_('List only disabled projects'),
256+
)
243257
tag.add_tag_filtering_option_to_parser(parser, _('projects'))
244258
return parser
245259

@@ -277,6 +291,9 @@ def take_action(self, parsed_args):
277291

278292
kwargs['user'] = user_id
279293

294+
if parsed_args.is_enabled is not None:
295+
kwargs['is_enabled'] = parsed_args.is_enabled
296+
280297
tag.get_tag_filtering_args(parsed_args, kwargs)
281298

282299
if parsed_args.my_projects:

openstackclient/identity/v3/user.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,24 @@ def get_parser(self, prog_name):
412412
default=False,
413413
help=_('List additional fields in output'),
414414
)
415+
parser.add_argument(
416+
'--enabled',
417+
action='store_true',
418+
dest='is_enabled',
419+
default=None,
420+
help=_(
421+
'List only enabled users, does nothing with --project and --group'
422+
),
423+
)
424+
parser.add_argument(
425+
'--disabled',
426+
action='store_false',
427+
dest='is_enabled',
428+
default=None,
429+
help=_(
430+
'List only disabled users, does nothing with --project and --group'
431+
),
432+
)
415433
return parser
416434

417435
def take_action(self, parsed_args):
@@ -431,6 +449,9 @@ def take_action(self, parsed_args):
431449
ignore_missing=False,
432450
).id
433451

452+
if parsed_args.is_enabled is not None:
453+
enabled = parsed_args.is_enabled
454+
434455
if parsed_args.project:
435456
if domain is not None:
436457
project = identity_client.find_project(
@@ -469,9 +490,15 @@ def take_action(self, parsed_args):
469490
group=group,
470491
)
471492
else:
472-
data = identity_client.users(
473-
domain_id=domain,
474-
)
493+
if parsed_args.is_enabled is not None:
494+
data = identity_client.users(
495+
domain_id=domain,
496+
is_enabled=enabled,
497+
)
498+
else:
499+
data = identity_client.users(
500+
domain_id=domain,
501+
)
475502

476503
# Column handling
477504
if parsed_args.long:

openstackclient/tests/unit/identity/v3/test_project.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,22 @@ def test_project_list_my_projects(self):
941941
)
942942
self.assertEqual(datalist, tuple(data))
943943

944+
def test_project_list_with_option_enabled(self):
945+
arglist = ['--enabled']
946+
verifylist = [('is_enabled', True)]
947+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
948+
949+
# In base command class Lister in cliff, abstract method take_action()
950+
# returns a tuple containing the column names and an iterable
951+
# containing the data to be listed.
952+
columns, data = self.cmd.take_action(parsed_args)
953+
954+
kwargs = {'is_enabled': True}
955+
self.projects_mock.list.assert_called_with(**kwargs)
956+
957+
self.assertEqual(self.columns, columns)
958+
self.assertEqual(self.datalist, tuple(data))
959+
944960

945961
class TestProjectSet(TestProject):
946962
domain = identity_fakes.FakeDomain.create_one_domain()

openstackclient/tests/unit/identity/v3/test_user.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,24 @@ def test_user_list_project(self):
10351035
self.assertEqual(self.columns, columns)
10361036
self.assertEqual(self.datalist, tuple(data))
10371037

1038+
def test_user_list_with_option_enabled(self):
1039+
arglist = ['--enabled']
1040+
verifylist = [('is_enabled', True)]
1041+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1042+
1043+
# In base command class Lister in cliff, abstract method take_action()
1044+
# returns a tuple containing the column names and an iterable
1045+
# containing the data to be listed.
1046+
columns, data = self.cmd.take_action(parsed_args)
1047+
1048+
kwargs = {'domain_id': None, 'is_enabled': True}
1049+
self.identity_sdk_client.users.assert_called_with(**kwargs)
1050+
self.identity_sdk_client.find_user.assert_not_called()
1051+
self.identity_sdk_client.group_users.assert_not_called()
1052+
1053+
self.assertEqual(self.columns, columns)
1054+
self.assertEqual(self.datalist, tuple(data))
1055+
10381056

10391057
class TestUserSet(identity_fakes.TestIdentityv3):
10401058
project = sdk_fakes.generate_fake_resource(_project.Project)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
features:
3+
- |
4+
Add filters to search for enabled and disabled users and projects.

0 commit comments

Comments
 (0)