summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-17 12:03:54 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-17 14:33:34 +0300
commitb6d01abc026f0750db53121619b663867f95ac3d (patch)
tree6e6f9343a927dfe63e8c1b39fb45bc53a18c8478
parent743f3ed60c9a8545bf7bc038bb561ca468485780 (diff)
downloadgitlab-ce-b6d01abc026f0750db53121619b663867f95ac3d.tar.gz
Fix username period migration to preserve uniqueness of names and paths.
-rw-r--r--app/models/namespace.rb1
-rw-r--r--db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb10
2 files changed, 6 insertions, 5 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index a0d79d7e5c0..e1de114375e 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -59,6 +59,7 @@ class Namespace < ActiveRecord::Base
end
def clean_path(path)
+ path = path.dup
path.gsub!(/@.*\z/, "")
path.gsub!(/\.git\z/, "")
path.gsub!(/\A-+/, "")
diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
index 7ce53c2a0d6..dc38b0eceb7 100644
--- a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
+++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb
@@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
class Namespace < ActiveRecord::Base
class << self
- def by_path(path)
- where('lower(path) = :value', value: path.downcase).first
+ def find_by_path_or_name(path)
+ find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
end
def clean_path(path)
path = path.dup
path.gsub!(/@.*\z/, "")
path.gsub!(/\.git\z/, "")
- path.gsub!(/\A-/, "")
- path.gsub!(/.\z/, "")
+ path.gsub!(/\A-+/, "")
+ path.gsub!(/\.+\z/, "")
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
counter = 0
base = path
- while Namespace.by_path(path).present?
+ while Namespace.find_by_path_or_name(path)
counter += 1
path = "#{base}#{counter}"
end