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

Improve Project Lookup

Fixes #1080
This commit is contained in:
Dmitriy Zaporozhets 2014-03-15 06:27:15 +00:00
commit 66a484c9cd
2 changed files with 7 additions and 9 deletions

View File

@ -177,15 +177,13 @@ class Project < ActiveRecord::Base
end
def find_with_namespace(id)
if id.include?("/")
id = id.split("/")
namespace = Namespace.find_by(path: id.first)
return nil unless namespace
return nil unless id.include?("/")
where(namespace_id: namespace.id).find_by(path: id.second)
else
where(path: id, namespace_id: nil).last
end
id = id.split("/")
namespace = Namespace.find_by(path: id.first)
return nil unless namespace
where(namespace_id: namespace.id).find_by(path: id.second)
end
def visibility_levels

View File

@ -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