diff --git a/lib/api.rb b/lib/api.rb index f58b82ff98ebb99cfba84e027e573937ca3c4ca6..3ee56a7f79eb2dbf9cdd24403df913298cad52c6 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 0000000000000000000000000000000000000000..c12605841ab0beecd3fdb3b16f1e9f4f48c2b190 --- /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 +