summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-17 14:32:04 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-04-17 14:32:04 +0300
commit7266c78b76ab22f873a7907463f0d37642827119 (patch)
treeeb212a59e27e7cc3f3218c71c86a8074212d776c
parent5ba7a8e023befeb093532f25f32dfc7f67429d95 (diff)
parent07c149de7406f0861fde4b1eb39ff95de687ee8f (diff)
downloadgitlab-ce-7266c78b76ab22f873a7907463f0d37642827119.tar.gz
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
-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