Port user-mod to use ldap update() method
This commit is contained in:
1 parent
e7937f2944
commit
789a248daa
2 files changed
+33
-20
No files matched your search
@@ -48,8 +48,7 @@ class ldap(CrudBackend):
|
||||
self.api.env.basedn,
|
||||
)
|
||||
|
||||
def find_entry_dn(self, key_attribute, primary_key, attributes=None,
|
||||
object_type=None):
|
||||
def find_entry_dn(self, key_attribute, primary_key, object_type=None):
|
||||
"""
|
||||
Find an existing entry's dn from an attribute
|
||||
"""
|
||||
@@ -73,7 +72,7 @@ class ldap(CrudBackend):
|
||||
|
||||
search_base = "%s, %s" % (self.api.env.container_accounts, self.api.env.basedn)
|
||||
|
||||
entry = servercore.get_sub_entry(search_base, filter, attributes)
|
||||
entry = servercore.get_sub_entry(search_base, filter, ['dn', 'objectclass'])
|
||||
|
||||
return entry['dn']
|
||||
|
||||
@@ -95,6 +94,16 @@ class ldap(CrudBackend):
|
||||
def retrieve(self, dn, attributes=None):
|
||||
return servercore.get_entry_by_dn(dn, attributes)
|
||||
|
||||
def update(self, dn, **kw):
|
||||
result = self.retrieve(dn, ["*"])
|
||||
|
||||
entry = ipaldap.Entry((dn, servercore.convert_scalar_values(result)))
|
||||
|
||||
for k in kw:
|
||||
entry.setValues(k, kw[k])
|
||||
|
||||
return servercore.update_entry(entry.toDict())
|
||||
|
||||
def delete(self, dn):
|
||||
return servercore.delete_entry(dn)
|
||||
|
||||
|
||||
+21
-17
@@ -205,27 +205,31 @@ api.register(user_del)
|
||||
|
||||
class user_mod(crud.Mod):
|
||||
'Edit an existing user.'
|
||||
def execute(self, *args, **kw):
|
||||
uid=args[0]
|
||||
def execute(self, uid, **kw):
|
||||
"""
|
||||
Execute the user-mod operation.
|
||||
|
||||
# Get the existing user entry
|
||||
result = servercore.get_sub_entry("cn=accounts," + servercore.basedn, "uid=%s" % uid, ["*"])
|
||||
The dn should not be passed as a keyword argument as it is constructed
|
||||
by this method.
|
||||
|
||||
user = kw
|
||||
dn = result.get('dn')
|
||||
del result['dn']
|
||||
entry = ipaldap.Entry((dn, servercore.convert_scalar_values(result)))
|
||||
Returns the entry
|
||||
|
||||
for u in user:
|
||||
entry.setValues(u, user[u])
|
||||
:param uid: The login name of the user to retrieve.
|
||||
:param kw: Keyword arguments for the other LDAP attributes.
|
||||
"""
|
||||
assert 'uid' not in kw
|
||||
assert 'dn' not in kw
|
||||
ldap = self.api.Backend.ldap
|
||||
dn = ldap.find_entry_dn("uid", uid, "posixAccount")
|
||||
return ldap.update(dn, **kw)
|
||||
|
||||
result = servercore.update_entry(entry.toDict())
|
||||
def output_for_cli(self, ret):
|
||||
"""
|
||||
Output result of this command to command line interface.
|
||||
"""
|
||||
if ret:
|
||||
print "User updated"
|
||||
|
||||
return result
|
||||
def forward(self, *args, **kw):
|
||||
result = super(crud.Mod, self).forward(*args, **kw)
|
||||
if result:
|
||||
print "User %s modified" % args[0]
|
||||
api.register(user_mod)
|
||||
|
||||
|
||||
@@ -269,7 +273,7 @@ class user_show(crud.Get):
|
||||
:param kw: Not used.
|
||||
"""
|
||||
ldap = self.api.Backend.ldap
|
||||
dn = ldap.find_entry_dn("uid", uid, ["*"], "posixAccount")
|
||||
dn = ldap.find_entry_dn("uid", uid, "posixAccount")
|
||||
# FIXME: should kw contain the list of attributes?
|
||||
return ldap.retrieve(dn)
|
||||
|
||||
|
||||
Reference in new issue
Block a user