]> source.dussan.org Git - redmine.git/commitdiff
Fixed that users with different case logins cannot update their accounts (#10711).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 19 Apr 2012 08:42:07 +0000 (08:42 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 19 Apr 2012 08:42:07 +0000 (08:42 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9449 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/user.rb
test/unit/user_test.rb

index 6e7e94cf6d4c1215d512e38a218b19f5260f6896..b11d918075e05b4b215c6da66bba0772e8e4888d 100644 (file)
@@ -68,7 +68,7 @@ class User < Principal
   MAIL_LENGTH_LIMIT = 60
 
   validates_presence_of :login, :firstname, :lastname, :mail, :if => Proc.new { |user| !user.is_a?(AnonymousUser) }
-  validates_uniqueness_of :login, :if => Proc.new { |user| !user.login.blank? }, :case_sensitive => false
+  validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, :case_sensitive => false
   validates_uniqueness_of :mail, :if => Proc.new { |user| !user.mail.blank? }, :case_sensitive => false
   # Login must contain lettres, numbers, underscores only
   validates_format_of :login, :with => /^[a-z0-9_\-@\.]*$/i
index a85d56adb5408efe2396fccb2a8b7b1e2c710022..cf21298f0a9d9813840052c671e45c0ad2c64623 100644 (file)
@@ -134,6 +134,20 @@ class UserTest < ActiveSupport::TestCase
     assert_equal "john", @admin.login
   end
 
+  def test_update_should_not_fail_for_legacy_user_with_different_case_logins
+    u1 = User.new(:firstname => "new", :lastname => "user", :mail => "newuser1@somenet.foo")
+    u1.login = 'newuser1'
+    assert u1.save
+
+    u2 = User.new(:firstname => "new", :lastname => "user", :mail => "newuser2@somenet.foo")
+    u2.login = 'newuser1'
+    assert u2.save(false)
+
+    user = User.find(u2.id)
+    user.firstname = "firstname"
+    assert user.save, "Save failed"
+  end
+
   def test_destroy_should_delete_members_and_roles
     members = Member.find_all_by_user_id(2)
     ms = members.size