Commit 8ae1d812dc9c8099b691e164e7119ede7eb21c61

Authored by Dmitriy Zaporozhets
1 parent 48628d31

deploy keys support for gitlab-shell api

Showing 1 changed file with 18 additions and 13 deletions   Show diff stats
lib/api/internal.rb
... ... @@ -7,22 +7,27 @@ module Gitlab
7 7 #
8 8 get "/allowed" do
9 9 key = Key.find(params[:key_id])
10   - user = key.user
11   -
12 10 project = Project.find_with_namespace(params[:project])
13   - action = case params[:action]
14   - when 'git-upload-pack'
15   - then :download_code
16   - when 'git-receive-pack'
17   - then
18   - if project.protected_branch?(params[:ref])
19   - :push_code_to_protected_branches
20   - else
21   - :push_code
  11 + git_cmd = params[:action]
  12 +
  13 + if key.is_deploy_key
  14 + project == key.project && git_cmd == 'git-upload-pack'
  15 + else
  16 + user = key.user
  17 + action = case git_cmd
  18 + when 'git-upload-pack'
  19 + then :download_code
  20 + when 'git-receive-pack'
  21 + then
  22 + if project.protected_branch?(params[:ref])
  23 + :push_code_to_protected_branches
  24 + else
  25 + :push_code
  26 + end
22 27 end
23   - end
24 28  
25   - user.can?(action, project)
  29 + user.can?(action, project)
  30 + end
26 31 end
27 32  
28 33 #
... ...