summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-12-23 01:03:57 +0100
commitdb2c15369c365340aeaf4e431e8838714b40396b (patch)
tree26ca045a337132370b67cc8f2ed4010e3087dfa5 /lib/api/helpers.rb
parentb47173da6a0fea0982d009f91e2c4d042f9b5c37 (diff)
parent68c43d59f09a66cca0da1b9a50c11421d52eac9a (diff)
downloadgitlab-ce-db2c15369c365340aeaf4e431e8838714b40396b.tar.gz
Merge branch 'master' into discussions
Conflicts: app/assets/stylesheets/main.scss app/models/project.rb app/views/notes/_common_form.html.haml app/views/notes/_per_line_form.html.haml lib/gitlab/markdown.rb spec/models/note_spec.rb
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|