mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Do uniqueness check on phone numbers and cn entered via the UI.
445286
This commit is contained in:
@@ -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'),
|
||||
|
||||
65
ipa-server/ipa-gui/ipagui/helpers/validators.py
Normal file
65
ipa-server/ipa-gui/ipagui/helpers/validators.py
Normal file
@@ -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)
|
||||
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user