mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Implement user-mod
This commit is contained in:
parent
69bc5ad77a
commit
e012e860b4
@ -115,6 +115,15 @@ class Entry:
|
|||||||
r.append((i[0], n))
|
r.append((i[0], n))
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
def toDict(self):
|
||||||
|
"""Convert the attrs and values to a dict. The dict is keyed on the
|
||||||
|
attribute name. The value is either single value or a list of values."""
|
||||||
|
result = ipautil.CIDict(self.data)
|
||||||
|
for i in result.keys():
|
||||||
|
result[i] = ipautil.utf8_encode_values(result[i])
|
||||||
|
result['dn'] = self.dn
|
||||||
|
return result
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Convert the Entry to its LDIF representation"""
|
"""Convert the Entry to its LDIF representation"""
|
||||||
return self.__repr__()
|
return self.__repr__()
|
||||||
|
@ -121,6 +121,22 @@ def is_user_unique(uid):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_user_by_uid (uid, sattrs):
|
||||||
|
"""Get a specific user's entry. Return as a dict of values.
|
||||||
|
Multi-valued fields are represented as lists.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if not isinstance(uid,basestring) or len(uid) == 0:
|
||||||
|
raise SyntaxError("uid is not a string")
|
||||||
|
# raise ipaerror.gen_exception(ipaerror.INPUT_INVALID_PARAMETER)
|
||||||
|
if sattrs is not None and not isinstance(sattrs,list):
|
||||||
|
raise SyntaxError("sattrs is not a list")
|
||||||
|
# raise ipaerror.gen_exception(ipaerror.INPUT_INVALID_PARAMETER)
|
||||||
|
# logging.info("IPA: get_user_by_uid '%s'" % uid)
|
||||||
|
# uid = self.__safe_filter(uid)
|
||||||
|
searchfilter = "(uid=" + uid + ")"
|
||||||
|
return get_sub_entry("cn=accounts," + basedn, searchfilter, sattrs)
|
||||||
|
|
||||||
def uid_too_long(uid):
|
def uid_too_long(uid):
|
||||||
"""Verify that the new uid is within the limits we set. This is a
|
"""Verify that the new uid is within the limits we set. This is a
|
||||||
very narrow test.
|
very narrow test.
|
||||||
@ -143,14 +159,18 @@ def uid_too_long(uid):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def update_entry (oldentry, newentry):
|
def update_entry (entry):
|
||||||
"""Update an LDAP entry
|
"""Update an LDAP entry
|
||||||
|
|
||||||
oldentry is a dict
|
entry is a dict
|
||||||
newentry is a dict
|
|
||||||
|
This refreshes the record from LDAP in order to obtain the list of
|
||||||
|
attributes that has changed.
|
||||||
"""
|
"""
|
||||||
oldentry = convert_scalar_values(oldentry)
|
attrs = entry.keys()
|
||||||
newentry = convert_scalar_values(newentry)
|
o = get_base_entry(entry['dn'], "objectclass=*", attrs)
|
||||||
|
oldentry = convert_scalar_values(o)
|
||||||
|
newentry = convert_scalar_values(entry)
|
||||||
|
|
||||||
# Should be able to get this from either the old or new entry
|
# Should be able to get this from either the old or new entry
|
||||||
# but just in case someone has decided to try changing it, use the
|
# but just in case someone has decided to try changing it, use the
|
||||||
@ -161,8 +181,7 @@ def update_entry (oldentry, newentry):
|
|||||||
# FIXME: return a missing DN error message
|
# FIXME: return a missing DN error message
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
res = context.conn.getConn().updateEntry(moddn, oldentry, newentry)
|
return context.conn.getConn().updateEntry(moddn, oldentry, newentry)
|
||||||
return res
|
|
||||||
|
|
||||||
def add_entry(entry):
|
def add_entry(entry):
|
||||||
"""Add a new entry"""
|
"""Add a new entry"""
|
||||||
|
@ -170,7 +170,7 @@ class user_add(crud.Add):
|
|||||||
def forward(self, *args, **kw):
|
def forward(self, *args, **kw):
|
||||||
result = super(crud.Add, self).forward(*args, **kw)
|
result = super(crud.Add, self).forward(*args, **kw)
|
||||||
if result != False:
|
if result != False:
|
||||||
print result
|
print "User %s added" % args[0]
|
||||||
|
|
||||||
api.register(user_add)
|
api.register(user_add)
|
||||||
|
|
||||||
@ -182,6 +182,25 @@ api.register(user_del)
|
|||||||
|
|
||||||
class user_mod(crud.Mod):
|
class user_mod(crud.Mod):
|
||||||
'Edit an existing user.'
|
'Edit an existing user.'
|
||||||
|
def execute(self, *args, **kw):
|
||||||
|
uid=args[0]
|
||||||
|
result = servercore.get_sub_entry(servercore.basedn, "uid=%s" % uid, ["*"])
|
||||||
|
|
||||||
|
user = kw
|
||||||
|
dn = result.get('dn')
|
||||||
|
del result['dn']
|
||||||
|
entry = ipaldap.Entry((dn, servercore.convert_scalar_values(result)))
|
||||||
|
|
||||||
|
for u in user:
|
||||||
|
entry.setValues(u, user[u])
|
||||||
|
|
||||||
|
result = servercore.update_entry(entry.toDict())
|
||||||
|
|
||||||
|
return result
|
||||||
|
def forward(self, *args, **kw):
|
||||||
|
result = super(crud.Mod, self).forward(*args, **kw)
|
||||||
|
if result != False:
|
||||||
|
print "User %s modified" % args[0]
|
||||||
api.register(user_mod)
|
api.register(user_mod)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user