Commit 935b6ae6534e77f2b9e84bcb686aeeda88089122

Authored by Dmitriy Zaporozhets
1 parent 6f7ccea6

Internal API

Showing 2 changed files with 25 additions and 0 deletions   Show diff stats
lib/api.rb
... ... @@ -19,5 +19,6 @@ module Gitlab
19 19 mount Session
20 20 mount MergeRequests
21 21 mount Notes
  22 + mount Internal
22 23 end
23 24 end
... ...
lib/api/internal.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +module Gitlab
  2 + # Access API
  3 + class Internal < Grape::API
  4 +
  5 + get "/allowed" do
  6 + user = User.find_by_username(params[:username])
  7 + project = Project.find_with_namespace(params[:project])
  8 + action = case params[:action]
  9 + when 'git-upload-pack'
  10 + then :download_code
  11 + when 'git-receive-pack'
  12 + then
  13 + if project.protected_branch?(params[:ref])
  14 + :push_code_to_protected_branches
  15 + else
  16 + :push_code
  17 + end
  18 + end
  19 +
  20 + user.can?(action, project)
  21 + end
  22 + end
  23 +end
  24 +
... ...