summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorAdam Young <ayoung@redhat.com>2010-08-13 16:20:41 -0400
committerAdam Young <ayoung@redhat.com>2010-08-13 16:20:41 -0400
commit030b5dab93971495d8656f7886c29136e118a9e6 (patch)
treecb3bf3ca3fed61c777bedb713054954bbfb2abeb /ipalib
parentf15758dbea6be0894cdc2fcc19ec9d2428c797f1 (diff)
downloadfreeipa-030b5dab93971495d8656f7886c29136e118a9e6.tar.gz
freeipa-030b5dab93971495d8656f7886c29136e118a9e6.tar.xz
freeipa-030b5dab93971495d8656f7886c29136e118a9e6.zip
Change the behaviour of addattr/setattr parameters.
setattr and addattr can now be used both to set all values of ANY attribute. the last setattr always resets the attribute to the specified value and all addattr append to it. Examples: user-mod testuser --setattr=title=msc title: msc user-mod testuser --setattr=title=msb title: msb user-mod testuser --addattr=title=msc title: msb, msc user-mod testuser --setattr=title= title: user-mod testuser --setattr=title=msc --addattr=msb title: msc, msb user-mod testuser --setattr=title=ing --addattr=bc title: ing, bc user-mod testuser --setattr=title=doc title: doc It's not very user friendly, but it's going to be used very very rarely in special conditions in the CLI and we can use it to save lots of JSON-RPC roundtrips in the webUI. This version includes calling the validation of Params during the setting of the attrs.
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/frontend.py17
-rw-r--r--ipalib/plugins/baseldap.py58
2 files changed, 40 insertions, 35 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index d320f02e0..1c4fea8cb 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -519,11 +519,12 @@ class Command(HasParam):
if len(value) == 0:
# None means "delete this attribute"
value = None
- if attr not in self.params:
- if append and attr in newdict:
- newdict[attr].append(value)
- else:
- newdict[attr] = [value]
+ if attr in self.params:
+ value = self.params[attr](value)
+ if append and attr in newdict:
+ newdict[attr].append(value)
+ else:
+ newdict[attr] = [value]
return newdict
def __attributes_2_entry(self, kw):
@@ -540,7 +541,11 @@ class Command(HasParam):
adddict = self.__convert_2_dict(kw['setattr'], append=False)
if kw.get('addattr'):
- adddict.update(self.__convert_2_dict(kw['addattr']))
+ for (k, v) in self.__convert_2_dict(kw['addattr']).iteritems():
+ if k in adddict:
+ adddict[k] += v
+ else:
+ adddict[k] = v
for name in adddict:
value = adddict[name]
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 43fafe32a..f3e5b0fe2 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -419,6 +419,35 @@ class LDAPUpdate(LDAPQuery, crud.Update):
entry_attrs = self.args_options_2_entry(**options)
+ """
+ Some special handling is needed because we need to update the
+ values here rather than letting ldap.update_entry() do the work. We
+ have to do the work of adding new values to an existing attribute
+ because if we pass just what is addded only the new values get
+ set.
+ """
+ if 'addattr' in options:
+ setset = set(get_attributes(options.get('setattr', [])))
+ addset = set(get_attributes(options.get('addattr', [])))
+ difflist = list(addset.difference(setset))
+ if difflist:
+ try:
+ (dn, old_entry) = ldap.get_entry(
+ dn, difflist, normalize=self.obj.normalize_dn
+ )
+ except errors.ExecutionError, e:
+ try:
+ (dn, old_entry) = self._call_exc_callbacks(
+ keys, options, e, ldap.get_entry, dn, attrs_list,
+ normalize=self.obj.normalize_dn
+ )
+ except errors.NotFound:
+ self.obj.handle_not_found(*keys)
+ for a in old_entry:
+ if not isinstance(entry_attrs[a], (list, tuple)):
+ entry_attrs[a] = [entry_attrs[a]]
+ entry_attrs[a] += old_entry[a]
+
if options.get('all', False):
attrs_list = ['*']
else:
@@ -436,35 +465,6 @@ class LDAPUpdate(LDAPQuery, crud.Update):
self, ldap, dn, entry_attrs, attrs_list, *keys, **options
)
- """
- Some special handling is needed because we need to update the
- values here rather than letting ldap.update_entry() do the work. We
- have to do the work of adding new values to an existing attribute
- because if we pass just what is addded only the new values get
- set.
- """
- if 'addattr' in options:
- try:
- (dn, old_entry) = ldap.get_entry(
- dn, attrs_list, normalize=self.obj.normalize_dn
- )
- except errors.ExecutionError, e:
- try:
- (dn, old_entry) = self._call_exc_callbacks(
- keys, options, e, ldap.get_entry, dn, attrs_list,
- normalize=self.obj.normalize_dn
- )
- except errors.NotFound:
- self.obj.handle_not_found(*keys)
- attrlist = get_attributes(options['addattr'])
- for attr in attrlist:
- if attr in old_entry:
- if type(entry_attrs[attr]) in (tuple,list):
- entry_attrs[attr] = old_entry[attr] + entry_attrs[attr]
- else:
- old_entry[attr].append(entry_attrs[attr])
- entry_attrs[attr] = old_entry[attr]
-
try:
ldap.update_entry(dn, entry_attrs, normalize=self.obj.normalize_dn)
except errors.ExecutionError, e: