summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-12-12 12:54:28 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2012-12-12 12:54:28 +0200
commit439d03bbedd2dfcd5ddcb5dc16afe610208188b0 (patch)
treeebfc42cd98e74978bad8a5989b20099c2d3da056 /lib/api/helpers.rb
parent105f5ba3c992cf9c69951a4f9ca877afe803a23d (diff)
downloadgitlab-ce-439d03bbedd2dfcd5ddcb5dc16afe610208188b0.tar.gz
Fix namespace api autocomplete
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index e9305b40836..6bd8111c2b2 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -5,13 +5,18 @@ module Gitlab
end
def user_project
- if @project ||= current_user.projects.find_by_id(params[:id]) ||
- current_user.projects.find_by_path(params[:id])
+ @project ||= find_project
+ @project || not_found!
+ end
+
+ def find_project
+ project = Project.find_by_id(params[:id]) || Project.find_with_namespace(params[:id])
+
+ if project && can?(current_user, :read_project, project)
+ project
else
- not_found!
+ nil
end
-
- @project
end
def paginate(object)
@@ -32,6 +37,10 @@ module Gitlab
end
end
+ def can?(object, action, subject)
+ abilities.allowed?(object, action, subject)
+ end
+
def attributes_for_keys(keys)
attrs = {}
keys.each do |key|