BigW Consortium Gitlab

Commit 07c149de by Dmitriy Zaporozhets

Merge branch 'fix-username-period-migration' into 'master'

Fix username period migration to preserve uniqueness of names and paths. See merge request !534
parents 5456b00f 46524ecb
...@@ -59,6 +59,7 @@ class Namespace < ActiveRecord::Base ...@@ -59,6 +59,7 @@ class Namespace < ActiveRecord::Base
end end
def clean_path(path) def clean_path(path)
path = path.dup
path.gsub!(/@.*\z/, "") path.gsub!(/@.*\z/, "")
path.gsub!(/\.git\z/, "") path.gsub!(/\.git\z/, "")
path.gsub!(/\A-+/, "") path.gsub!(/\A-+/, "")
......
...@@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration ...@@ -3,21 +3,21 @@ class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration
class Namespace < ActiveRecord::Base class Namespace < ActiveRecord::Base
class << self class << self
def by_path(path) def find_by_path_or_name(path)
where('lower(path) = :value', value: path.downcase).first find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
end end
def clean_path(path) def clean_path(path)
path = path.dup path = path.dup
path.gsub!(/@.*\z/, "") path.gsub!(/@.*\z/, "")
path.gsub!(/\.git\z/, "") path.gsub!(/\.git\z/, "")
path.gsub!(/\A-/, "") path.gsub!(/\A-+/, "")
path.gsub!(/.\z/, "") path.gsub!(/\.+\z/, "")
path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") path.gsub!(/[^a-zA-Z0-9_\-\.]/, "")
counter = 0 counter = 0
base = path base = path
while Namespace.by_path(path).present? while Namespace.find_by_path_or_name(path)
counter += 1 counter += 1
path = "#{base}#{counter}" path = "#{base}#{counter}"
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment