File tree Expand file tree Collapse file tree 5 files changed +85
-3
lines changed
Expand file tree Collapse file tree 5 files changed +85
-3
lines changed Original file line number Diff line number Diff line change @@ -239,6 +239,20 @@ def get_parser(self, prog_name):
239239 'keys and directions.'
240240 ),
241241 )
242+ parser .add_argument (
243+ '--enabled' ,
244+ action = 'store_true' ,
245+ dest = 'is_enabled' ,
246+ default = None ,
247+ help = _ ('List only enabled projects' ),
248+ )
249+ parser .add_argument (
250+ '--disabled' ,
251+ action = 'store_false' ,
252+ dest = 'is_enabled' ,
253+ default = None ,
254+ help = _ ('List only disabled projects' ),
255+ )
242256 tag .add_tag_filtering_option_to_parser (parser , _ ('projects' ))
243257 return parser
244258
@@ -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 :
Original file line number Diff line number Diff line change @@ -411,6 +411,24 @@ def get_parser(self, prog_name):
411411 default = False ,
412412 help = _ ('List additional fields in output' ),
413413 )
414+ parser .add_argument (
415+ '--enabled' ,
416+ action = 'store_true' ,
417+ dest = 'is_enabled' ,
418+ default = None ,
419+ help = _ (
420+ 'List only enabled users, does nothing with --project and --group'
421+ ),
422+ )
423+ parser .add_argument (
424+ '--disabled' ,
425+ action = 'store_false' ,
426+ dest = 'is_enabled' ,
427+ default = None ,
428+ help = _ (
429+ 'List only disabled users, does nothing with --project and --group'
430+ ),
431+ )
414432 return parser
415433
416434 def take_action (self , parsed_args ):
@@ -430,6 +448,9 @@ def take_action(self, parsed_args):
430448 ignore_missing = False ,
431449 ).id
432450
451+ if parsed_args .is_enabled is not None :
452+ enabled = parsed_args .is_enabled
453+
433454 if parsed_args .project :
434455 if domain is not None :
435456 project = identity_client .find_project (
@@ -468,9 +489,15 @@ def take_action(self, parsed_args):
468489 group = group ,
469490 )
470491 else :
471- data = identity_client .users (
472- domain_id = domain ,
473- )
492+ if parsed_args .is_enabled is not None :
493+ data = identity_client .users (
494+ domain_id = domain ,
495+ is_enabled = enabled ,
496+ )
497+ else :
498+ data = identity_client .users (
499+ domain_id = domain ,
500+ )
474501
475502 # Column handling
476503 if parsed_args .long :
Original file line number Diff line number Diff 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
945961class TestProjectSet (TestProject ):
946962 domain = identity_fakes .FakeDomain .create_one_domain ()
Original file line number Diff line number Diff line change @@ -988,6 +988,24 @@ def test_user_list_project(self):
988988 self .assertEqual (self .columns , columns )
989989 self .assertEqual (self .datalist , tuple (data ))
990990
991+ def test_user_list_with_option_enabled (self ):
992+ arglist = ['--enabled' ]
993+ verifylist = [('is_enabled' , True )]
994+ parsed_args = self .check_parser (self .cmd , arglist , verifylist )
995+
996+ # In base command class Lister in cliff, abstract method take_action()
997+ # returns a tuple containing the column names and an iterable
998+ # containing the data to be listed.
999+ columns , data = self .cmd .take_action (parsed_args )
1000+
1001+ kwargs = {'domain_id' : None , 'is_enabled' : True }
1002+ self .identity_sdk_client .users .assert_called_with (** kwargs )
1003+ self .identity_sdk_client .find_user .assert_not_called ()
1004+ self .identity_sdk_client .group_users .assert_not_called ()
1005+
1006+ self .assertEqual (self .columns , columns )
1007+ self .assertEqual (self .datalist , tuple (data ))
1008+
9911009
9921010class TestUserSet (identity_fakes .TestIdentityv3 ):
9931011 project = sdk_fakes .generate_fake_resource (_project .Project )
Original file line number Diff line number Diff line change 1+ ---
2+ features :
3+ - |
4+ Add filters to search for enabled and disabled users and projects.
You can’t perform that action at this time.
0 commit comments