summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-11-24 14:40:35 +0100
committerRémy Coutable <remy@rymai.me>2016-11-24 14:40:35 +0100
commit4f5ed812325845f263fc9b566651c1179b5c24bc (patch)
tree8d05ddcc43dd0c69d38c37ac9d0fc6e214a8087f /lib/api/helpers.rb
parent304163becba3610a99dfff644c13972a2f54ed3b (diff)
downloadgitlab-ce-4f5ed812325845f263fc9b566651c1179b5c24bc.tar.gz
API: Introduce `#find_project!` which also check access permission
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index 60067758e95..42f4c2ccf9d 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -68,7 +68,7 @@ module API
end
def user_project
- @project ||= find_project(params[:id])
+ @project ||= find_project!(params[:id])
end
def available_labels
@@ -76,12 +76,15 @@ module API
end
def find_project(id)
- project =
- if id =~ /^\d+$/
- Project.find_by(id: id)
- else
- Project.find_with_namespace(id)
- end
+ if id =~ /^\d+$/
+ Project.find_by(id: id)
+ else
+ Project.find_with_namespace(id)
+ end
+ end
+
+ def find_project!(id)
+ project = find_project(id)
if can?(current_user, :read_project, project)
project