Commit 66a484c9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'improve-project-lookup' into 'master'

Improve Project Lookup

Fixes #1080
parents 7c5320d2 a9f2903e
......@@ -177,15 +177,13 @@ class Project < ActiveRecord::Base
end
def find_with_namespace(id)
if id.include?("/")
return nil unless id.include?("/")
id = id.split("/")
namespace = Namespace.find_by(path: id.first)
return nil unless namespace
where(namespace_id: namespace.id).find_by(path: id.second)
else
where(path: id, namespace_id: nil).last
end
end
def visibility_levels
......
......@@ -47,7 +47,7 @@ module API
end
def find_project(id)
project = Project.find_by(id: id) || Project.find_with_namespace(id)
project = Project.find_with_namespace(id) || Project.find_by(id: id)
if project && can?(current_user, :read_project, project)
project
......
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