From 935b6ae6534e77f2b9e84bcb686aeeda88089122 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 4 Feb 2013 17:53:43 +0200 Subject: [PATCH] Internal API --- lib/api.rb | 1 + lib/api/internal.rb | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 lib/api/internal.rb diff --git a/lib/api.rb b/lib/api.rb index f58b82ff98e..3ee56a7f79e 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -19,5 +19,6 @@ module Gitlab mount Session mount MergeRequests mount Notes + mount Internal end end diff --git a/lib/api/internal.rb b/lib/api/internal.rb new file mode 100644 index 00000000000..c12605841ab --- /dev/null +++ b/lib/api/internal.rb @@ -0,0 +1,24 @@ +module Gitlab + # Access API + class Internal < Grape::API + + get "/allowed" do + user = User.find_by_username(params[:username]) + project = Project.find_with_namespace(params[:project]) + action = case params[:action] + when 'git-upload-pack' + then :download_code + when 'git-receive-pack' + then + if project.protected_branch?(params[:ref]) + :push_code_to_protected_branches + else + :push_code + end + end + + user.can?(action, project) + end + end +end + -- GitLab