summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2008-05-20 11:38:35 -0400
committerRob Crittenden <rcritten@redhat.com>2008-05-20 14:58:50 -0400
commit099cd00950f32581f3187910ad07f8e60e42e9c1 (patch)
tree4a958160feb7e0f3c976e1721d1a8391bb7161f8
parent649dcf6c445d99f13151eef4c518635e03d496a5 (diff)
downloadfreeipa-099cd00950f32581f3187910ad07f8e60e42e9c1.tar.gz
freeipa-099cd00950f32581f3187910ad07f8e60e42e9c1.tar.xz
freeipa-099cd00950f32581f3187910ad07f8e60e42e9c1.zip
Do uniqueness check on phone numbers and cn entered via the UI.
445286
-rw-r--r--ipa-server/ipa-gui/ipagui/forms/user.py15
-rw-r--r--ipa-server/ipa-gui/ipagui/helpers/validators.py65
-rw-r--r--ipa-server/ipa-gui/ipagui/subcontrollers/user.py4
3 files changed, 80 insertions, 4 deletions
diff --git a/ipa-server/ipa-gui/ipagui/forms/user.py b/ipa-server/ipa-gui/ipagui/forms/user.py
index a149dc47..2c10eeac 100644
--- a/ipa-server/ipa-gui/ipagui/forms/user.py
+++ b/ipa-server/ipa-gui/ipagui/forms/user.py
@@ -18,6 +18,7 @@
import turbogears
from turbogears import validators, widgets
from tg_expanding_form_widget.tg_expanding_form_widget import ExpandingForm
+from ipagui.helpers.validators import *
class UserFields(object):
givenname = widgets.TextField(name="givenname", label="First Name")
@@ -89,8 +90,13 @@ class UserNewValidator(validators.Schema):
krbprincipalkey_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
sn = validators.String(not_empty=True)
- cn = validators.ForEach(validators.String(not_empty=True))
+ cn = UniqueList(not_empty=True)
mail = validators.Email(not_empty=False)
+ telephonenumber = UniqueList(not_empty=False)
+ facsimiletelephonenumber = UniqueList(not_empty=False)
+ mobile = UniqueList(not_empty=False)
+ pager = UniqueList(not_empty=False)
+ homephone = UniqueList(not_empty=False)
chained_validators = [
validators.FieldsMatch('krbprincipalkey', 'krbprincipalkey_confirm')
@@ -125,10 +131,15 @@ class UserEditValidator(validators.Schema):
krbprincipalkey_confirm = validators.String(not_empty=False)
givenname = validators.String(not_empty=True)
sn = validators.String(not_empty=True)
- cn = validators.ForEach(validators.String(not_empty=True))
+ cn = UniqueList(not_empty=True)
mail = validators.Email(not_empty=False)
uidnumber = validators.Int(not_empty=False)
gidnumber = validators.Int(not_empty=False)
+ telephonenumber = UniqueList(not_empty=False)
+ facsimiletelephonenumber = UniqueList(not_empty=False)
+ mobile = UniqueList(not_empty=False)
+ pager = UniqueList(not_empty=False)
+ homephone = UniqueList(not_empty=False)
pre_validators = [
validators.RequireIfPresent(required='uid', present='editprotected'),
diff --git a/ipa-server/ipa-gui/ipagui/helpers/validators.py b/ipa-server/ipa-gui/ipagui/helpers/validators.py
new file mode 100644
index 00000000..6e78781a
--- /dev/null
+++ b/ipa-server/ipa-gui/ipagui/helpers/validators.py
@@ -0,0 +1,65 @@
+# Copyright (C) 2007-2008 Red Hat
+# see file 'COPYING' for use and warranty information
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; version 2 only
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+
+from formencode.validators import *
+from formencode.compound import *
+from formencode.api import Invalid, NoDefault
+from formencode.schema import Schema
+from formencode import ForEach
+
+def _(s): return s # dummy
+
+class UniqueList(FancyValidator):
+ """
+ Given a list, ensure that all of the values in it are unique.
+
+ >>> x = UniqueList()
+ >>> x.validate_python(['1','1'],'')
+ Traceback (most recent call last):
+ ...
+ formencode.api.Invalid: Duplicate values are not allowed
+ >>> x.validate_python(['1','2'],'')
+ >>>
+ """
+
+ not_empty = None
+
+ messages = {
+ 'notunique': _('Duplicate values are not allowed'),
+ 'empty': _('Empty values not allowed'),
+ }
+
+ def __initargs__(self, new_attrs):
+ if self.not_empty is None:
+ self.not_empty = True
+
+ def validate_python(self, value, state):
+ if not isinstance(value, list):
+ return # just punt for now
+
+ if self.not_empty:
+ for v in value:
+ if v is None or len(v) == 0:
+ raise Invalid(self.message('empty', state),
+ value, state)
+
+ orig = len(value)
+ check = len(set(value))
+
+ if orig > check:
+ raise Invalid(self.message('notunique', state),
+ value, state)
diff --git a/ipa-server/ipa-gui/ipagui/subcontrollers/user.py b/ipa-server/ipa-gui/ipagui/subcontrollers/user.py
index 9232f305..734d867f 100644
--- a/ipa-server/ipa-gui/ipagui/subcontrollers/user.py
+++ b/ipa-server/ipa-gui/ipagui/subcontrollers/user.py
@@ -165,8 +165,6 @@ class UserController(IPAController):
turbogears.flash("Add user cancelled")
raise turbogears.redirect('/user/list')
- tg_errors, kw = self.usercreatevalidate(**kw)
-
# Fix incoming multi-valued fields we created for the form
kw = ipahelper.fix_incoming_fields(kw, 'cn', 'cns')
kw = ipahelper.fix_incoming_fields(kw, 'telephonenumber', 'telephonenumbers')
@@ -175,6 +173,8 @@ class UserController(IPAController):
kw = ipahelper.fix_incoming_fields(kw, 'pager', 'pagers')
kw = ipahelper.fix_incoming_fields(kw, 'homephone', 'homephones')
+ tg_errors, kw = self.usercreatevalidate(**kw)
+
if tg_errors:
turbogears.flash("There were validation errors.<br/>" +
"Please see the messages below for details.")