[Freeipa-devel] [PATCH] Fix reporting of errors when validating parameters.

2010-12-21 Thread Pavel Zuna
Print the attribute CLI name instead of its 'real' name. The real name is 
usually the name of the corresponding LDAP attribute, which is confusing to the 
user.


 This way we get:

Invalid 'login': blablabla

instead of:

Invalid 'uid': blablabla


Another example:

Invalid 'hostname': blablabla

instead of:

Invalid 'fqdn': blablabla


Ticket #435

Pavel
From 8c6ef40f575399f3190ef077b26fd38ecb3a1c0e Mon Sep 17 00:00:00 2001
From: Pavel Zuna pz...@redhat.com
Date: Tue, 21 Dec 2010 12:14:38 -0500
Subject: [PATCH 1/2] Fix reporting of errors when validating parameters.

Print the attribute CLI name instead of its 'real' name.
The real name is usually the name of the corresponding LDAP
attribute, which is confusing to the user.

This way we get:
Invalid 'login': blablabla
instead of:
Invalid 'uid': blablabla

Another example:
Invalid 'hostname': blablabla
instead of:
Invalid 'fqdn': blablabla

Ticket #435
---
 ipalib/parameters.py   |5 -
 ipalib/plugins/user.py |8 +++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 955b979..feccd7e 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -748,8 +748,11 @@ class Param(ReadOnly):
 for rule in self.all_rules:
 error = rule(ugettext, value)
 if error is not None:
+name = self.cli_name
+if not name:
+name = self.name
 raise ValidationError(
-name=self.name,
+name=name,
 value=value,
 index=index,
 error=error,
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index f76fbd6..6209754 100644
--- a/ipalib/plugins/user.py
+++ b/ipalib/plugins/user.py
@@ -227,7 +227,13 @@ class user_add(LDAPCreate):
 config = ldap.get_ipa_config()[1]
 if 'ipamaxusernamelength' in config:
 if len(keys[-1])  int(config.get('ipamaxusernamelength')[0]):
-raise errors.ValidationError(name='uid', error=_('can be at most %(len)d characters' % dict(len = int(config.get('ipamaxusernamelength')[0]
+raise errors.ValidationError(
+name=self.obj.primary_key.cli_name, error=_(
+'can be at most %(len)d characters' % dict(
+len = int(config.get('ipamaxusernamelength')[0])
+)
+)
+)
 entry_attrs.setdefault('loginshell', config.get('ipadefaultloginshell'))
 # hack so we can request separate first and last name in CLI
 full_name = '%s %s' % (entry_attrs['givenname'], entry_attrs['sn'])
-- 
1.7.1.1

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Re: [Freeipa-devel] [PATCH] Fix reporting of errors when validating parameters.

2010-12-21 Thread Rob Crittenden

Pavel Zuna wrote:

Print the attribute CLI name instead of its 'real' name. The real name
is usually the name of the corresponding LDAP attribute, which is
confusing to the user.

This way we get:

Invalid 'login': blablabla

instead of:

Invalid 'uid': blablabla


Another example:

Invalid 'hostname': blablabla

instead of:

Invalid 'fqdn': blablabla


Ticket #435

Pavel


ack, pushed to master

___
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel