diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2016-11-14 15:10:35 +0100 |
---|---|---|
committer | Z.J. van de Weg <git@zjvandeweg.nl> | 2016-11-17 21:34:23 +0100 |
commit | 53271b486d296fae2e290d6948a05aeb47dbea89 (patch) | |
tree | 8ee12e07be37d1bf7251d570996a2575c93538b9 /lib/api/services.rb | |
parent | 4762198959fbc2bc22981749313955b65c6d6026 (diff) | |
download | gitlab-ce-53271b486d296fae2e290d6948a05aeb47dbea89.tar.gz |
Make chat authorization to work [ci skip]
Diffstat (limited to 'lib/api/services.rb')
-rw-r--r-- | lib/api/services.rb | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/lib/api/services.rb b/lib/api/services.rb index fc8598daa32..b4b3bb6e41a 100644 --- a/lib/api/services.rb +++ b/lib/api/services.rb @@ -1,10 +1,10 @@ module API # Projects API class Services < Grape::API - before { authenticate! } - before { authorize_admin_project } - resource :projects do + before { authenticate! } + before { authorize_admin_project } + # Set <service_slug> service for project # # Example Request: @@ -59,5 +59,28 @@ module API present project_service, with: Entities::ProjectService, include_passwords: current_user.is_admin? end end + + resource :projects do + post ':id/services/:service_slug/trigger' do + project = Project.find_with_namespace(params[:id]) || Project.find_by(id: params[:id]) + + underscored_service = params[:service_slug].underscore + + not_found!('Service') unless Service.available_services_names.include?(underscored_service) + service_method = "#{underscored_service}_service" + + service = project.public_send(service_method) + + result = if service.try(:active?) && service.respond_to?(:trigger) + service.trigger(params) + end + + if result + present result, status: result[:status] || 200 + else + not_found!('Service') + end + end + end end end |