This started as a problem in allowing leading/trailing whitespaces on
primary keys. In nearly every command other than add query is True so
all rules were ignored on the primary key. This meant that to enforce
whitespace we would need to define a validator for each one.
I decided instead to set self.all_rules to just the class rules if query
== True. So the minimum set of validators will be executed against each
type but param-specific validators will only run on add.
I talked to Martin about this a bit this morning. My original intention
was to make some pretty invasive changes related to query and he talked
me out of them. He felt that in anything other than an add the
validators shouldn't be run. We compromised on letting Paramter-specific
validators be run.
This has pretty big implications on primary keys so test carefully.
https://fedorahosted.org/freeipa/ticket/1285
https://fedorahosted.org/freeipa/ticket/1286
https://fedorahosted.org/freeipa/ticket/1287
rob
>From 799b187b9819730c12accd2c699a6f1d4eb89a43 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <[email protected]>
Date: Fri, 24 Jun 2011 14:32:57 -0400
Subject: [PATCH] Enforce class rules when query=True, continue to not run validators.
This started as a problem in allowing leading/trailing whitespaces
on primary keys. In nearly every command other than add query is True
so all rules were ignored on the primary key. This meant that to
enforce whitespace we would need to define a validator for each one.
I decided instead to set self.all_rules to just the class rules if
query == True. So the minimum set of validators will be executed
against each type but param-specific validators will only run on add.
https://fedorahosted.org/freeipa/ticket/1285
https://fedorahosted.org/freeipa/ticket/1286
https://fedorahosted.org/freeipa/ticket/1287
---
ipalib/parameters.py | 20 ++++++++++++++++----
1 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 3ff0456..4d2e0a7 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -432,7 +432,10 @@ class Param(ReadOnly):
# Check that all the rules are callable
self.class_rules = tuple(class_rules)
self.rules = rules
- self.all_rules = self.class_rules + self.rules
+ if self.query:
+ self.all_rules = self.class_rules
+ else:
+ self.all_rules = self.class_rules + self.rules
for rule in self.all_rules:
if not callable(rule):
raise TypeError(
@@ -727,8 +730,6 @@ class Param(ReadOnly):
else:
raise RequirementError(name=self.name)
return
- if self.query:
- return
if self.multivalue:
if type(value) is not tuple:
raise TypeError(
@@ -1124,8 +1125,9 @@ class Data(Param):
('length', int, None),
('pattern', (basestring,), None),
('pattern_errmsg', (basestring,), None),
+ ('noextrawhitespace', bool, True),
)
-
+
re = None
re_errmsg = None
@@ -1268,6 +1270,16 @@ class Str(Data):
error=ugettext(self.type_error),
)
+ def _rule_noextrawhitespace(self, _, value):
+ """
+ Do not allow leading/trailing spaces.
+ """
+ assert type(value) is unicode
+ if self.noextrawhitespace is False:
+ return
+ if len(value) != len(value.strip()):
+ return _('Leading and trailing spaces are not allowed')
+
def _rule_minlength(self, _, value):
"""
Check minlength constraint.
--
1.7.4
_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel