OSDN Git Service

Merge branch 'easy-to-find-commit-on-network-graph' of https://github.com/hiroponz...
[wvm/gitlab.git] / lib / api / internal.rb
1 module Gitlab
2   # Internal access API
3   class Internal < Grape::API
4     namespace 'internal' do
5       #
6       # Check if ssh key has access to project code
7       #
8       get "/allowed" do
9         key = Key.find(params[:key_id])
10         project = Project.find_with_namespace(params[:project])
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
27                    end
28
29           user.can?(action, project)
30         end
31       end
32
33       #
34       # Discover user by ssh key
35       #
36       get "/discover" do
37         key = Key.find(params[:key_id])
38         present key.user, with: Entities::User
39       end
40
41       get "/check" do
42         {
43           api_version: '3'
44         }
45       end
46     end
47   end
48 end
49