From 1d608251383e4842b89c941a76dbd13529558f42 Mon Sep 17 00:00:00 2001 From: Jan Cholasta Date: Thu, 18 Jun 2015 07:20:27 +0000 Subject: User life cycle: change user-del flags to be CLI-specific Rename --permanently to --no-preserve. https://fedorahosted.org/freeipa/ticket/3813 Reviewed-By: Petr Vobornik --- API.txt | 4 ++-- VERSION | 4 ++-- ipalib/plugins/user.py | 32 ++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/API.txt b/API.txt index c7f02b9e6..3bcb3bdd2 100644 --- a/API.txt +++ b/API.txt @@ -5155,8 +5155,8 @@ command: user_del args: 1,4,3 arg: Str('uid', attribute=True, cli_name='login', maxlength=255, multivalue=True, pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?$', primary_key=True, query=True, required=True) option: Flag('continue', autofill=True, cli_name='continue', default=False) -option: Flag('permanently?', autofill=True, cli_name='permanently', default=False) -option: Flag('preserve?', autofill=True, cli_name='preserve', default=False) +option: Flag('no_preserve?', autofill=True, default=False, include='cli') +option: Flag('preserve?', autofill=True, default=False, include='cli') option: Str('version?', exclude='webui') output: Output('result', , None) output: Output('summary', (, ), None) diff --git a/VERSION b/VERSION index f38b49465..f8f398d58 100644 --- a/VERSION +++ b/VERSION @@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000 # # ######################################################## IPA_API_VERSION_MAJOR=2 -IPA_API_VERSION_MINOR=134 -# Last change: jcholast - User life cycle: provide preserved user virtual attribute +IPA_API_VERSION_MINOR=135 +# Last change: jcholast - User life cycle: Make user-del flags CLI-specific diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index f4a8a2c3c..d2404e2ed 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -565,18 +565,32 @@ class user_del(baseuser_del): msg_summary = _('Deleted user "%(value)s"') takes_options = baseuser_del.takes_options + ( + Bool('preserve?', + exclude='cli', + ), Flag('preserve?', + include='cli', doc=_('Delete a user, keeping the entry available for future use'), - cli_name='preserve', - default=False, ), - Flag('permanently?', + Flag('no_preserve?', + include='cli', doc=_('Delete a user'), - cli_name='permanently', - default=False, ), ) + def forward(self, *keys, **options): + if self.api.env.context == 'cli': + if options['no_preserve'] and options['preserve']: + raise errors.MutuallyExclusiveError( + reason=_("preserve and no-preserve cannot be both set")) + elif options['no_preserve']: + options['preserve'] = False + elif not options['preserve']: + del options['preserve'] + del options['no_preserve'] + + return super(user_del, self).forward(*keys, **options) + def pre_callback(self, ldap, dn, *keys, **options): assert isinstance(dn, DN) @@ -606,13 +620,15 @@ class user_del(baseuser_del): dn = self.obj.get_dn(*keys, **options) - if options['permanently'] or dn.endswith(DN(self.obj.delete_container_dn, api.env.basedn)): + if (not options.get('preserve', True) or + dn.endswith(DN(self.obj.delete_container_dn, + self.api.env.basedn))): # We are going to permanent delete or the user is already in the delete container. # So we issue a true DEL on that entry return super(user_del, self).execute(*keys, **options) - # The user to delete is active and there is no 'permanently' option - if options['preserve']: + # The user to delete is active and there is no 'no_preserve' option + if options.get('preserve', False): ldap = self.obj.backend -- cgit