summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@gitlab.com>2015-03-03 18:57:49 +0000
committerMarin Jankovski <maxlazio@gmail.com>2015-03-04 10:15:02 -0800
commit520a49d32592bbb8d1bd91e01d53ae94fa1a1850 (patch)
treed665e05fc240532f645ea66ede63c60d499ea2cc
parent63e74ce9d648603d12544ae989b3c56afe8a0e9a (diff)
downloadgitlab-ce-520a49d32592bbb8d1bd91e01d53ae94fa1a1850.tar.gz
Merge branch 'case-sensetivity-import' into 'master'
Fix import check for case sensetive namespaces If you already have namespace `ABc` and you try to import project with namespace `abC` - import will fail with 422 error. cc @valery See merge request !1618
-rw-r--r--app/controllers/import/base_controller.rb2
-rw-r--r--app/models/namespace.rb5
-rw-r--r--spec/models/namespace_spec.rb10
3 files changed, 16 insertions, 1 deletions
diff --git a/app/controllers/import/base_controller.rb b/app/controllers/import/base_controller.rb
index 4df171dbcfe..7dc0cac8d4c 100644
--- a/app/controllers/import/base_controller.rb
+++ b/app/controllers/import/base_controller.rb
@@ -3,7 +3,7 @@ class Import::BaseController < ApplicationController
private
def get_or_create_namespace
- existing_namespace = Namespace.find_by("path = ? OR name = ?", @target_namespace, @target_namespace)
+ existing_namespace = Namespace.find_by_path_or_name(@target_namespace)
if existing_namespace
if existing_namespace.owner == current_user
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 2c7ed376265..35280889a86 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -48,6 +48,11 @@ class Namespace < ActiveRecord::Base
where('lower(path) = :value', value: path.downcase).first
end
+ # Case insensetive search for namespace by path or name
+ def self.find_by_path_or_name(path)
+ find_by("lower(path) = :path OR lower(name) = :path", path: path.downcase)
+ end
+
def self.search(query)
where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
end
diff --git a/spec/models/namespace_spec.rb b/spec/models/namespace_spec.rb
index 4e268f8d8fa..ed6845c82cc 100644
--- a/spec/models/namespace_spec.rb
+++ b/spec/models/namespace_spec.rb
@@ -75,4 +75,14 @@ describe Namespace do
expect(namespace.rm_dir).to be_truthy
end
end
+
+ describe :find_by_path_or_name do
+ before do
+ @namespace = create(:namespace, name: 'WoW', path: 'woW')
+ end
+
+ it { expect(Namespace.find_by_path_or_name('wow')).to eq(@namespace) }
+ it { expect(Namespace.find_by_path_or_name('WOW')).to eq(@namespace) }
+ it { expect(Namespace.find_by_path_or_name('unknown')).to eq(nil) }
+ end
end