Convert nsaccountlock to always work as bool towards Python code

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.
This commit is contained in:
Alexander Bokovoy 2011-07-07 18:58:18 +03:00 committed by Martin Kosek
parent f534445e26
commit b93e0b8bbf
7 changed files with 51 additions and 39 deletions

View File

@ -200,9 +200,16 @@ IPA.user_status_widget = function(spec) {
if (!that.record) return;
var lock_field = 'nsaccountlock';
var locked_field = that.record[lock_field];
var locked = false;
var locked = that.record[lock_field] &&
that.record[lock_field][0].toLowerCase() === 'true';
if (typeof locked_field === 'array') locked_field = locked_field[0];
if (typeof locked_field === 'boolean') {
locked = locked_field;
} else {
locked = locked_field && locked_field.toLowerCase() === 'true';
}
var status;
var action;

View File

@ -904,8 +904,8 @@ class Bool(Param):
# FIXME: This my quick hack to get some UI stuff working, change these defaults
# --jderose 2009-08-28
kwargs = Param.kwargs + (
('truths', frozenset, frozenset([1, u'1', u'true', u'TRUE'])),
('falsehoods', frozenset, frozenset([0, u'0', u'false', u'FALSE'])),
('truths', frozenset, frozenset([1, u'1', True, u'true', u'TRUE'])),
('falsehoods', frozenset, frozenset([0, u'0', False, u'false', u'FALSE'])),
)
def _convert_scalar(self, value, index=None):

View File

@ -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

View File

@ -567,7 +567,7 @@ class IPAdmin(SimpleLDAPObject):
else:
operation = ldap.MOD_ADD
modlist.append((operation, "nsAccountlock", "true"))
modlist.append((operation, "nsAccountlock", "TRUE"))
try:
if sctrl is not None:

View File

@ -83,7 +83,7 @@ class test_attr(Declarative):
gidnumber=[fuzzy_digits],
mail=[u'test@example.com'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -107,7 +107,7 @@ class test_attr(Declarative):
gidnumber=[fuzzy_digits],
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -132,7 +132,7 @@ class test_attr(Declarative):
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
telephonenumber=[u'410-555-1212', u'301-555-1212'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -157,7 +157,7 @@ class test_attr(Declarative):
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
telephonenumber=[u'301-555-1212'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -182,7 +182,7 @@ class test_attr(Declarative):
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
telephonenumber=[u'301-555-1212', u'202-888-9833', u'703-555-1212'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -225,7 +225,7 @@ class test_attr(Declarative):
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
telephonenumber=[u'301-555-1212', u'202-888-9833', u'703-555-1212'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -250,7 +250,7 @@ class test_attr(Declarative):
mail=[u'test@example.com', u'test2@example.com'],
memberof_group=[u'ipausers'],
telephonenumber=[u'301-555-1212', u'202-888-9833', u'703-555-1212'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,

View File

@ -89,7 +89,7 @@ class test_replace(Declarative):
gidnumber=[fuzzy_digits],
mail=[u'test1@example.com', u'test3@example.com'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -113,7 +113,7 @@ class test_replace(Declarative):
gidnumber=[fuzzy_digits],
mail=[u'test4@example.com'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -137,7 +137,7 @@ class test_replace(Declarative):
gidnumber=[fuzzy_digits],
mail=[u'test6@example.com', u'test7@example.com', u'test5@example.com'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -160,7 +160,7 @@ class test_replace(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -184,7 +184,7 @@ class test_replace(Declarative):
gidnumber=[fuzzy_digits],
initials=[u'ABC'],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -207,7 +207,7 @@ class test_replace(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,

View File

@ -129,7 +129,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
value=user1,
summary=None,
@ -161,7 +161,7 @@ class test_user(Declarative):
'ipauniqueid': [fuzzy_uuid],
'mepmanagedentry': [u'cn=%s,cn=groups,cn=accounts,%s' % (user1, api.env.basedn)],
'krbpwdpolicyreference': [u'cn=global_policy,cn=%s,cn=kerberos,%s' % (api.env.realm, api.env.basedn)],
'nsaccountlock': [u'False'],
'nsaccountlock': False,
'displayname': [u'Test User1'],
'cn': [u'Test User1'],
'initials': [u'TU'],
@ -187,7 +187,7 @@ class test_user(Declarative):
loginshell=[u'/bin/sh'],
sn=[u'User1'],
uid=[user1],
nsaccountlock=[u'False'],
nsaccountlock=False,
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
),
@ -212,7 +212,7 @@ class test_user(Declarative):
loginshell=[u'/bin/bash'],
sn=[u'Administrator'],
uid=[u'admin'],
nsaccountlock=[u'False'],
nsaccountlock=False,
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
),
@ -223,7 +223,7 @@ class test_user(Declarative):
loginshell=[u'/bin/sh'],
sn=[u'User1'],
uid=[user1],
nsaccountlock=[u'False'],
nsaccountlock=False,
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
),
@ -248,7 +248,7 @@ class test_user(Declarative):
loginshell=[u'/bin/bash'],
sn=[u'Administrator'],
uid=[u'admin'],
nsaccountlock=[u'False'],
nsaccountlock=False,
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
),
@ -301,7 +301,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "tuser1"',
value=user1,
@ -332,7 +332,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=None,
value=user1,
@ -354,7 +354,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "%s"' % user1,
value=user1,
@ -382,7 +382,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
),
summary=u'Modified user "%s"' % renameduser1,
value=renameduser1,
@ -497,7 +497,7 @@ class test_user(Declarative):
uidnumber=[fuzzy_digits],
gidnumber=[fuzzy_digits],
memberof_group=[u'ipausers'],
nsaccountlock=[u'False'],
nsaccountlock=False,
manager=[user1],
),
summary=u'Modified user "%s"' % user2,