Commit 93a21183 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents 2f4656b5 f4387917
...@@ -3,7 +3,7 @@ class Import::BaseController < ApplicationController ...@@ -3,7 +3,7 @@ class Import::BaseController < ApplicationController
private private
def get_or_create_namespace 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
if existing_namespace.owner == current_user if existing_namespace.owner == current_user
......
...@@ -48,6 +48,11 @@ class Namespace < ActiveRecord::Base ...@@ -48,6 +48,11 @@ class Namespace < ActiveRecord::Base
where('lower(path) = :value', value: path.downcase).first where('lower(path) = :value', value: path.downcase).first
end 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) def self.search(query)
where("name LIKE :query OR path LIKE :query", query: "%#{query}%") where("name LIKE :query OR path LIKE :query", query: "%#{query}%")
end end
......
...@@ -75,4 +75,14 @@ describe Namespace do ...@@ -75,4 +75,14 @@ describe Namespace do
expect(namespace.rm_dir).to be_truthy expect(namespace.rm_dir).to be_truthy
end end
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 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