[Freeipa-devel] [PATCH] change add_user to take a user instead of a dict
Kevin McCarthy
kmccarth at redhat.com
Mon Aug 20 19:11:36 UTC 2007
This changes the add_user to take the user object. This makes it
consistent with the find and update methods. It also makes the utf-8
encoding completely hidden in the user object now.
-Kevin
-------------- next part --------------
# HG changeset patch
# User Kevin McCarthy <kmccarth at redhat.com>
# Date 1187637050 25200
# Node ID 0cb522cdbae570405c413bbbda8eea96eae6a6e9
# Parent ad03d68751187008821ae1390ee1daa292791e3f
Convert add_user to take a user instead of a dict.
diff -r ad03d6875118 -r 0cb522cdbae5 ipa-admintools/ipa-adduser
--- a/ipa-admintools/ipa-adduser Mon Aug 20 11:39:04 2007 -0700
+++ b/ipa-admintools/ipa-adduser Mon Aug 20 12:10:50 2007 -0700
@@ -21,6 +21,7 @@ import sys
import sys
from optparse import OptionParser
import ipa
+import ipa.user
import ipa.ipaclient as ipaclient
import ipa.config
@@ -56,23 +57,23 @@ def parse_options():
return options, args
def main():
- user=ldap.cidict.cidict()
+ user=ipa.user.User()
options, args = parse_options()
if len(args) != 2:
usage()
- user['givenname'] = options.gn
- user['sn'] = options.sn
- user['uid'] = args[1]
+ user.setValue('givenname', options.gn)
+ user.setValue('sn', options.sn)
+ user.setValue('uid', args[1])
if options.gecos:
- user['gecos'] = options.gecos
+ user.setValue('gecos', options.gecos)
if options.directory:
- user['homedirectory'] = options.directory
+ user.setValue('homedirectory', options.directory)
if options.shell:
- user['loginshell'] = options.shell
+ user.setValue('loginshell', options.shell)
else:
- user['loginshell'] = "/bin/bash"
+ user.setValue('loginshell', "/bin/bash")
try:
client = ipaclient.IPAClient()
diff -r ad03d6875118 -r 0cb522cdbae5 ipa-python/ipaclient.py
--- a/ipa-python/ipaclient.py Mon Aug 20 11:39:04 2007 -0700
+++ b/ipa-python/ipaclient.py Mon Aug 20 12:10:50 2007 -0700
@@ -61,30 +61,33 @@ class IPAClient:
return user.User(result)
def add_user(self,user):
- """Add a user. user is a cidict() of attribute/value pairs"""
+ """Add a user. user is a ipa.user object"""
realm = config.config.get_realm()
# FIXME: This should be dynamic and can include just about anything
# Let us add in some missing attributes
- if user.get('homedirectory') is None:
- user['homedirectory'] ='/home/%s' % user['uid']
- if user.get('gecos') is None:
- user['gecos'] = user['uid']
+ if user.getValue('homedirectory') is None:
+ user.setValue('homedirectory', '/home/%s' % user.getValue('uid'))
+ if user.getValue('gecos') is None:
+ user.setValue('gecos', user.getValue('uid'))
# FIXME: This can be removed once the DS plugin is installed
- user['uidnumber'] ='501'
+ user.setValue('uidnumber', '501')
# FIXME: What is the default group for users?
- user['gidnumber'] ='501'
- user['krbprincipalname'] = "%s@%s" % (user['uid'], realm)
- user['cn'] = "%s %s" % (user['givenname'], user['sn'])
- if user.get('gn'):
- del user['gn']
+ user.setValue('gidnumber', '501')
+ user.setValue('krbprincipalname', "%s@%s" % (user.getValue('uid'), realm))
+ user.setValue('cn', "%s %s" % (user.getValue('givenname'),
+ user.getValue('sn')))
+ user_dict = user.toDict()
+ if user_dict.get('gn'):
+ del user_dict['gn']
+
+ del user_dict['dn']
# convert to a regular dict before sending
- dict_user = cidict_to_dict(user)
- result = self.transport.add_user(dict_user)
+ result = self.transport.add_user(user_dict)
return result
def get_all_users(self):
diff -r ad03d6875118 -r 0cb522cdbae5 ipa-python/user.py
--- a/ipa-python/user.py Mon Aug 20 11:39:04 2007 -0700
+++ b/ipa-python/user.py Mon Aug 20 12:10:50 2007 -0700
@@ -25,7 +25,7 @@ class User:
data - cidict - case insensitive dict of the attributes and values
orig_data - cidict - case insentiive dict of the original attributes and values"""
- def __init__(self,entrydata):
+ def __init__(self,entrydata=None):
"""data is the raw data returned from the python-ldap result method,
which is a search result entry or a reference or None.
If creating a new empty entry, data is the string DN."""
diff -r ad03d6875118 -r 0cb522cdbae5 ipa-server/ipa-gui/ipagui/controllers.py
--- a/ipa-server/ipa-gui/ipagui/controllers.py Mon Aug 20 11:39:04 2007 -0700
+++ b/ipa-server/ipa-gui/ipagui/controllers.py Mon Aug 20 12:10:50 2007 -0700
@@ -70,12 +70,12 @@ class Root(controllers.RootController):
return dict(form=user_new_form, tg_template='ipagui.templates.usernew')
try:
- new_user = {}
- new_user['uid'] = utf8_encode(kw.get('uid'))
- new_user['givenname'] = utf8_encode(kw.get('givenname'))
- new_user['sn'] = utf8_encode(kw.get('sn'))
- new_user['mail'] = utf8_encode(kw.get('mail'))
- new_user['telephonenumber'] = utf8_encode(kw.get('telephonenumber'))
+ new_user = ipa.user.User()
+ new_user.setValue('uid', kw.get('uid'))
+ new_user.setValue('givenname', kw.get('givenname'))
+ new_user.setValue('sn', kw.get('sn'))
+ new_user.setValue('mail', kw.get('mail'))
+ new_user.setValue('telephonenumber', kw.get('telephonenumber'))
rv = client.add_user(new_user)
turbogears.flash("%s added!" % kw['uid'])
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20070820/6851010f/attachment.bin>
More information about the Freeipa-devel
mailing list