diff options
author | Alexander Bokovoy <abokovoy@redhat.com> | 2011-07-07 18:58:18 +0300 |
---|---|---|
committer | Alexander Bokovoy <abokovoy@redhat.com> | 2011-07-12 13:36:12 +0300 |
commit | 40ce1cde62113e8091ed8fae6a2acdf03e7b9c9c (patch) | |
tree | 5ead9f82d1e5ce5f45ef664bfc354251c396bc9d /ipalib/plugins/user.py | |
parent | 3229eee074e6b419f64faa9bb701a60fe96da3a6 (diff) | |
download | freeipa-ticket-1259.tar.gz freeipa-ticket-1259.tar.xz freeipa-ticket-1259.zip |
Convert nsaccountlock to always work as bool towards Python codeticket-1259
https://fedorahosted.org/freeipa/ticket/1259
Python code will see nsaccountlock as bool. JavaScript code will also see it as bool.
This allows native boolean operations with the lock field. Passes both CLI and WebUI tests.
Diffstat (limited to 'ipalib/plugins/user.py')
-rw-r--r-- | ipalib/plugins/user.py | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index 1f85238da..7d67bddd5 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -69,11 +69,19 @@ NO_UPG_MAGIC = '__no_upg__' def validate_nsaccountlock(entry_attrs): if 'nsaccountlock' in entry_attrs: - if not isinstance(entry_attrs['nsaccountlock'], basestring): - raise errors.OnlyOneValueAllowed(attr='nsaccountlock') - if entry_attrs['nsaccountlock'].lower() not in ('true','false'): - raise errors.ValidationError(name='nsaccountlock', error='must be TRUE or FALSE') - + nsaccountlock = entry_attrs['nsaccountlock'] + if not isinstance(nsaccountlock, (bool, Bool)): + if not isinstance(nsaccountlock, basestring): + raise errors.OnlyOneValueAllowed(attr='nsaccountlock') + if nsaccountlock.lower() not in ('true','false'): + raise errors.ValidationError(name='nsaccountlock', error='must be TRUE or FALSE') + +def convert_nsaccountlock(entry_attrs): + if not 'nsaccountlock' in entry_attrs: + entry_attrs['nsaccountlock'] = False + else: + nsaccountlock = Bool('temp') + entry_attrs['nsaccountlock'] = nsaccountlock.convert(entry_attrs['nsaccountlock'][0]) class user(LDAPObject): """ @@ -428,8 +436,7 @@ class user_mod(LDAPUpdate): return dn def post_callback(self, ldap, dn, entry_attrs, *keys, **options): - if not 'nsaccountlock' in entry_attrs: - entry_attrs['nsaccountlock'] = [u'False'] + convert_nsaccountlock(entry_attrs) self.obj._convert_manager(entry_attrs, **options) return dn @@ -460,8 +467,7 @@ class user_find(LDAPSearch): for entry in entries: (dn, attrs) = entry self.obj._convert_manager(attrs, **options) - if not 'nsaccountlock' in attrs: - attrs['nsaccountlock'] = [u'False'] + convert_nsaccountlock(attrs) msg_summary = ngettext( '%(count)d user matched', '%(count)d users matched', 0 @@ -475,8 +481,7 @@ class user_show(LDAPRetrieve): Display information about a user. """ def post_callback(self, ldap, dn, entry_attrs, *keys, **options): - if not 'nsaccountlock' in entry_attrs: - entry_attrs['nsaccountlock'] = [u'False'] + convert_nsaccountlock(entry_attrs) self.obj._convert_manager(entry_attrs, **options) return dn |