Add account deactivation checkbox.

Fix genModList to lowercase all keys and use CIDict.
This commit is contained in:
Kevin McCarthy 2007-08-31 10:59:26 -07:00
parent c85c8eede3
commit 00e299467c
8 changed files with 59 additions and 7 deletions

View File

@ -28,6 +28,8 @@ password_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
client = ipa.ipaclient.IPAClient(True) client = ipa.ipaclient.IPAClient(True)
client.set_principal("test@FREEIPA.ORG") client.set_principal("test@FREEIPA.ORG")
user_fields = ['*', 'nsAccountLock']
def restrict_post(): def restrict_post():
if cherrypy.request.method != "POST": if cherrypy.request.method != "POST":
turbogears.flash("This method only accepts posts") turbogears.flash("This method only accepts posts")
@ -77,6 +79,8 @@ class Root(controllers.RootController):
new_user.setValue('sn', kw.get('sn')) new_user.setValue('sn', kw.get('sn'))
new_user.setValue('mail', kw.get('mail')) new_user.setValue('mail', kw.get('mail'))
new_user.setValue('telephonenumber', kw.get('telephonenumber')) new_user.setValue('telephonenumber', kw.get('telephonenumber'))
if kw.get('nsAccountLock'):
new_user.setValue('nsAccountLock', 'true')
rv = client.add_user(new_user) rv = client.add_user(new_user)
turbogears.flash("%s added!" % kw['uid']) turbogears.flash("%s added!" % kw['uid'])
@ -92,7 +96,7 @@ class Root(controllers.RootController):
if tg_errors: if tg_errors:
turbogears.flash("There was a problem with the form!") turbogears.flash("There was a problem with the form!")
user = client.get_user_by_uid(uid) user = client.get_user_by_uid(uid, user_fields)
user_dict = user.toDict() user_dict = user.toDict()
# store a copy of the original user for the update later # store a copy of the original user for the update later
user_data = b64encode(dumps(user_dict)) user_data = b64encode(dumps(user_dict))
@ -120,6 +124,11 @@ class Root(controllers.RootController):
new_user.setValue('sn', kw.get('sn')) new_user.setValue('sn', kw.get('sn'))
new_user.setValue('mail', kw.get('mail')) new_user.setValue('mail', kw.get('mail'))
new_user.setValue('telephonenumber', kw.get('telephonenumber')) new_user.setValue('telephonenumber', kw.get('telephonenumber'))
if kw.get('nsAccountLock'):
new_user.setValue('nsAccountLock', 'true')
else:
new_user.setValue('nsAccountLock', None)
# #
# this is a hack until we decide on the policy for names/cn/sn/givenName # this is a hack until we decide on the policy for names/cn/sn/givenName
# #
@ -161,7 +170,7 @@ class Root(controllers.RootController):
def usershow(self, uid): def usershow(self, uid):
"""Retrieve a single user for display""" """Retrieve a single user for display"""
try: try:
user = client.get_user_by_uid(uid) user = client.get_user_by_uid(uid, user_fields)
return dict(user=user.toDict(), fields=forms.user.UserFields()) return dict(user=user.toDict(), fields=forms.user.UserFields())
except ipaerror.IPAError, e: except ipaerror.IPAError, e:
turbogears.flash("User show failed: " + str(e)) turbogears.flash("User show failed: " + str(e))

View File

@ -10,6 +10,7 @@ class UserFields():
sn = widgets.TextField(name="sn", label="Last name") sn = widgets.TextField(name="sn", label="Last name")
mail = widgets.TextField(name="mail", label="E-mail address") mail = widgets.TextField(name="mail", label="E-mail address")
telephonenumber = widgets.TextField(name="telephonenumber", label="Phone") telephonenumber = widgets.TextField(name="telephonenumber", label="Phone")
nsAccountLock = widgets.CheckBox(name="nsAccountLock", label="Account Deactivated")
uid.validator = validators.PlainText(not_empty=True) uid.validator = validators.PlainText(not_empty=True)
userpassword.validator = validators.String(not_empty=True) userpassword.validator = validators.String(not_empty=True)

View File

@ -122,7 +122,7 @@ body {
} }
.formtable th { .formtable th {
width: 15%; width: 20%;
text-align: right; text-align: right;
} }

View File

@ -139,6 +139,21 @@
</tr> </tr>
</table> </table>
<div class="formsection">Account Status</div>
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr>
<th>
<label class="fieldlabel" for="${user.nsAccountLock.field_id}"
py:content="user.nsAccountLock.label" />:
</th>
<td>
<span py:replace="user.nsAccountLock.display(value_for(user.nsAccountLock))" />
<span py:if="tg.errors.get('nsAccountLock')" class="fielderror"
py:content="tg.errors.get('nsAccountLock')" />
</td>
</tr>
</table>
<table class="formtable" cellpadding="2" cellspacing="0" border="0"> <table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr> <tr>
<th> <th>

View File

@ -150,6 +150,21 @@
</tr> </tr>
</table> </table>
<div class="formsection">Account Status</div>
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr>
<th>
<label class="fieldlabel" for="${user.nsAccountLock.field_id}"
py:content="user.nsAccountLock.label" />:
</th>
<td>
<span py:replace="user.nsAccountLock.display(value_for(user.nsAccountLock))" />
<span py:if="tg.errors.get('nsAccountLock')" class="fielderror"
py:content="tg.errors.get('nsAccountLock')" />
</td>
</tr>
</table>
<table class="formtable" cellpadding="2" cellspacing="0" border="0"> <table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr> <tr>
<th> <th>

View File

@ -62,6 +62,16 @@
</tr> </tr>
</table> </table>
<div class="formsection">Account Status</div>
<table class="formtable" cellpadding="2" cellspacing="0" border="0">
<tr>
<th>
<label class="fieldlabel" py:content="fields.nsAccountLock.label" />:
</th>
<td>${user.get("nsAccountLock")}</td>
</tr>
</table>
<a href="${tg.url('/useredit', uid=user.get('uid'))}">edit</a> <a href="${tg.url('/useredit', uid=user.get('uid'))}">edit</a>
</body> </body>

View File

@ -29,6 +29,7 @@ import urllib2
import socket import socket
import ldif import ldif
import re import re
import string
import ldap import ldap
import cStringIO import cStringIO
import time import time
@ -382,8 +383,11 @@ class IPAdmin(SimpleLDAPObject):
REPLACE operations, to deal with multi-user updates more properly.""" REPLACE operations, to deal with multi-user updates more properly."""
modlist = [] modlist = []
keys = set(old_entry.keys()) old_entry = ipautil.CIDict(old_entry)
keys.update(new_entry.keys()) new_entry = ipautil.CIDict(new_entry)
keys = set(map(string.lower, old_entry.keys()))
keys.update(map(string.lower, new_entry.keys()))
for key in keys: for key in keys:
new_values = new_entry.get(key, []) new_values = new_entry.get(key, [])

View File

@ -270,8 +270,6 @@ class IPAServer:
if user.get('gn'): if user.get('gn'):
del user['gn'] del user['gn']
if user.get('givenname'):
del user['givenname']
# some required objectclasses # some required objectclasses
entry.setValues('objectClass', 'top', 'posixAccount', 'shadowAccount', 'account', 'person', 'inetOrgPerson', 'organizationalPerson', 'krbPrincipalAux', 'krbTicketPolicyAux') entry.setValues('objectClass', 'top', 'posixAccount', 'shadowAccount', 'account', 'person', 'inetOrgPerson', 'organizationalPerson', 'krbPrincipalAux', 'krbTicketPolicyAux')