[ckan-changes] [okfn/ckan] 8aeee0: name_validator() exception for preexisting user na...
GitHub
noreply at github.com
Fri Apr 13 13:18:30 UTC 2012
Branch: refs/heads/name-validator-exception-for-preexisting-usernames
Home: https://github.com/okfn/ckan
Commit: 8aeee0021caa9f828770c034bcd926c5377e023c
https://github.com/okfn/ckan/commit/8aeee0021caa9f828770c034bcd926c5377e023c
Author: Sean Hammond <seanhammond at lavabit.com>
Date: 2012-04-13 (Fri, 13 Apr 2012)
Changed paths:
M ckan/logic/validators.py
Log Message:
-----------
name_validator() exception for preexisting user names
If the user is e.g. editing her profile and she has not changed her user
name, then skip the usual user name validation. This fixes problems for
preexisting user accounts with user names that don't pass CKAN's current
user name validation.
diff --git a/ckan/logic/validators.py b/ckan/logic/validators.py
index 58c69ee..a9d3774 100644
--- a/ckan/logic/validators.py
+++ b/ckan/logic/validators.py
@@ -176,7 +176,16 @@ def extras_unicode_convert(extras, context):
return extras
name_match = re.compile('[a-z0-9_\-]*$')
-def name_validator(val, context):
+def name_validator(key, data, errors, context):
+ val = data[key]
+ model = context['model']
+
+ if data.has_key(('id',)):
+ userid = data[('id',)]
+ userobj = model.User.get(userid)
+ if userobj and val == userobj.name:
+ return val
+
# check basic textual rules
if val in ['new', 'edit', 'search']:
raise Invalid(_('That name cannot be used'))
================================================================
More information about the ckan-changes
mailing list