Fix broken User link_name validations. Changes in r1014 still caused some problems so I came out with new idea to compare User accounts (previously called "id").
Patch by: Pawel Solyga
--- a/app/soc/views/models/user.py Sat Nov 15 16:17:11 2008 +0000
+++ b/app/soc/views/models/user.py Sat Nov 15 21:46:23 2008 +0000
@@ -68,8 +68,15 @@
properties = {'link_name': link_name}
user = soc.logic.models.user.logic.getForFields(properties, unique=True)
- if user and user.link_name == link_name:
- raise forms.ValidationError("This link name is already in use.")
+ link_name_user = soc.logic.models.user.logic.getForFields(properties, unique=True)
+
+ key_name = self.data.get('key_name')
+ if key_name:
+ key_name_user = user_logic.logic.getFromKeyName(key_name)
+
+ if link_name_user and key_name_user and \
+ link_name_user.account != key_name_user.account:
+ raise forms.ValidationError("This link name is already in use.")
return link_name
--- a/app/soc/views/site/user/profile.py Sat Nov 15 16:17:11 2008 +0000
+++ b/app/soc/views/site/user/profile.py Sat Nov 15 21:46:23 2008 +0000
@@ -236,13 +236,12 @@
raise forms.ValidationError("This link name is in wrong format.")
key_name = self.data.get('key_name')
- user = models.user.logic.getFromKeyName(key_name)
-
- linkname_user_exist = models.user.logic.getForFields(
- {'link_name': link_name}, unique=True)
-
- if (user and user.link_name != link_name) and linkname_user_exist:
- raise forms.ValidationError("This link name is already in use.")
+ if key_name:
+ key_name_user = user_logic.logic.getFromKeyName(key_name)
+
+ if link_name_user and key_name_user and \
+ link_name_user.account != key_name_user.account:
+ raise forms.ValidationError("This link name is already in use.")
return link_name
--- a/app/soc/views/user/profile.py Sat Nov 15 16:17:11 2008 +0000
+++ b/app/soc/views/user/profile.py Sat Nov 15 21:46:23 2008 +0000
@@ -62,8 +62,13 @@
user = models.user.logic.getForFields({'link_name': link_name},
unique=True)
+
+ # Get the currently logged in user account
+ current_account = users.get_current_user()
+
if user:
- raise forms.ValidationError("This link name is already in use.")
+ if current_account != user.account:
+ raise forms.ValidationError("This link name is already in use.")
return link_name