mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Convert add_user to take a user instead of a dict.
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
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()
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user