Commit fc4f5eef authored by Douwe Maan's avatar Douwe Maan

Merge branch 'flevour/gitlab-ce-project-path-insensitive-lookup'

parents 1ca11993 7c7b664c
...@@ -102,6 +102,7 @@ v 8.0.0 ...@@ -102,6 +102,7 @@ v 8.0.0
- Webhook for issue now contains repository field (Jungkook Park) - Webhook for issue now contains repository field (Jungkook Park)
- Add ability to add custom text to the help page (Jeroen van Baarsen) - Add ability to add custom text to the help page (Jeroen van Baarsen)
- Add pg_schema to backup config - Add pg_schema to backup config
- Redirect from incorrectly cased group or project path to correct one (Francesco Levorato)
- Removed API calls from CE to CI - Removed API calls from CE to CI
v 7.14.3 v 7.14.3
......
...@@ -117,9 +117,14 @@ class ApplicationController < ActionController::Base ...@@ -117,9 +117,14 @@ class ApplicationController < ActionController::Base
redirect_to request.original_url.gsub(/\.git\Z/, '') and return redirect_to request.original_url.gsub(/\.git\Z/, '') and return
end end
@project = Project.find_with_namespace("#{namespace}/#{id}") project_path = "#{namespace}/#{id}"
@project = Project.find_with_namespace(project_path)
if @project and can?(current_user, :read_project, @project) if @project and can?(current_user, :read_project, @project)
if @project.path_with_namespace != project_path
redirect_to request.original_url.gsub(project_path, @project.path_with_namespace) and return
end
@project @project
elsif current_user.nil? elsif current_user.nil?
@project = nil @project = nil
......
...@@ -238,10 +238,10 @@ class Project < ActiveRecord::Base ...@@ -238,10 +238,10 @@ class Project < ActiveRecord::Base
return nil unless id.include?('/') return nil unless id.include?('/')
id = id.split('/') id = id.split('/')
namespace = Namespace.find_by(path: id.first) namespace = Namespace.by_path(id.first)
return nil unless namespace return nil unless namespace
where(namespace_id: namespace.id).find_by(path: id.second) where(namespace_id: namespace.id).where("LOWER(projects.path) = :path", path: id.second.downcase).first
end end
def visibility_levels def visibility_levels
......
...@@ -8,28 +8,34 @@ describe Projects::IssuesController do ...@@ -8,28 +8,34 @@ describe Projects::IssuesController do
before do before do
sign_in(user) sign_in(user)
project.team << [user, :developer] project.team << [user, :developer]
controller.instance_variable_set(:@project, project)
end end
describe "GET #index" do describe "GET #index" do
it "returns index" do it "returns index" do
get :index, namespace_id: project.namespace.id, project_id: project.id get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(200) expect(response.status).to eq(200)
end end
it "return 301 if request path doesn't match project path" do
get :index, namespace_id: project.namespace.path, project_id: project.path.upcase
expect(response).to redirect_to(namespace_project_issues_path(project.namespace, project))
end
it "returns 404 when issues are disabled" do it "returns 404 when issues are disabled" do
project.issues_enabled = false project.issues_enabled = false
project.save project.save
get :index, namespace_id: project.namespace.id, project_id: project.id get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
it "returns 404 when external issue tracker is enabled" do it "returns 404 when external issue tracker is enabled" do
controller.instance_variable_set(:@project, project)
allow(project).to receive(:default_issues_tracker?).and_return(false) allow(project).to receive(:default_issues_tracker?).and_return(false)
get :index, namespace_id: project.namespace.id, project_id: project.id get :index, namespace_id: project.namespace.path, project_id: project.path
expect(response.status).to eq(404) expect(response.status).to eq(404)
end end
......
...@@ -21,6 +21,20 @@ describe ProjectsController do ...@@ -21,6 +21,20 @@ describe ProjectsController do
expect(response.body).to include("content='#{content}'") expect(response.body).to include("content='#{content}'")
end end
end end
context "when requested with case sensitive namespace and project path" do
it "redirects to the normalized path for case mismatch" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path.upcase
expect(response).to redirect_to("/#{public_project.path_with_namespace}")
end
it "loads the page if normalized path matches request path" do
get :show, namespace_id: public_project.namespace.path, id: public_project.path
expect(response.status).to eq(200)
end
end
end end
describe "POST #toggle_star" do describe "POST #toggle_star" do
......
...@@ -220,6 +220,7 @@ describe Project do ...@@ -220,6 +220,7 @@ describe Project do
end end
it { expect(Project.find_with_namespace('gitlab/gitlabhq')).to eq(@project) } it { expect(Project.find_with_namespace('gitlab/gitlabhq')).to eq(@project) }
it { expect(Project.find_with_namespace('GitLab/GitlabHQ')).to eq(@project) }
it { expect(Project.find_with_namespace('gitlab-ci')).to be_nil } it { expect(Project.find_with_namespace('gitlab-ci')).to be_nil }
end 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