Commit 66a484c9cdb6b35801aa09a95e7295043e0d52ac

Authored by Dmitriy Zaporozhets
2 parents 7c5320d2 a9f2903e

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

Improve Project Lookup

Fixes #1080
Showing 2 changed files with 8 additions and 10 deletions   Show diff stats
app/models/project.rb
@@ -177,15 +177,13 @@ class Project < ActiveRecord::Base @@ -177,15 +177,13 @@ class Project < ActiveRecord::Base
177 end 177 end
178 178
179 def find_with_namespace(id) 179 def find_with_namespace(id)
180 - if id.include?("/")  
181 - id = id.split("/")  
182 - namespace = Namespace.find_by(path: id.first)  
183 - return nil unless namespace  
184 -  
185 - where(namespace_id: namespace.id).find_by(path: id.second)  
186 - else  
187 - where(path: id, namespace_id: nil).last  
188 - end 180 + return nil unless id.include?("/")
  181 +
  182 + id = id.split("/")
  183 + namespace = Namespace.find_by(path: id.first)
  184 + return nil unless namespace
  185 +
  186 + where(namespace_id: namespace.id).find_by(path: id.second)
189 end 187 end
190 188
191 def visibility_levels 189 def visibility_levels
lib/api/helpers.rb
@@ -47,7 +47,7 @@ module API @@ -47,7 +47,7 @@ module API
47 end 47 end
48 48
49 def find_project(id) 49 def find_project(id)
50 - project = Project.find_by(id: id) || Project.find_with_namespace(id) 50 + project = Project.find_with_namespace(id) || Project.find_by(id: id)
51 51
52 if project && can?(current_user, :read_project, project) 52 if project && can?(current_user, :read_project, project)
53 project 53 project