2014-09-02 18:07:02 +05:30
|
|
|
class Projects::ServicesController < Projects::ApplicationController
|
2016-08-24 12:49:21 +05:30
|
|
|
include ServiceParams
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Authorize
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_admin_project!
|
|
|
|
before_action :service, only: [:edit, :update, :test]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
|
|
|
def index
|
|
|
|
@project.build_missing_services
|
2015-04-26 12:48:37 +05:30
|
|
|
@services = @project.services.visible.reload
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-08-24 12:49:21 +05:30
|
|
|
if @service.update_attributes(service_params[:service])
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to(
|
2016-09-29 09:46:39 +05:30
|
|
|
edit_namespace_project_service_path(@project.namespace, @project, @service.to_param),
|
|
|
|
notice: 'Successfully updated.'
|
2015-04-26 12:48:37 +05:30
|
|
|
)
|
2014-09-02 18:07:02 +05:30
|
|
|
else
|
|
|
|
render 'edit'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2016-08-24 12:49:21 +05:30
|
|
|
data = @service.test_data(project, current_user)
|
2015-09-11 14:41:01 +05:30
|
|
|
outcome = @service.test(data)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
if outcome[:success]
|
2015-04-26 12:48:37 +05:30
|
|
|
message = { notice: 'We sent a request to the provided URL' }
|
|
|
|
else
|
2015-09-11 14:41:01 +05:30
|
|
|
error_message = "We tried to send a request to the provided URL but an error occurred"
|
|
|
|
error_message << ": #{outcome[:result]}" if outcome[:result].present?
|
|
|
|
message = { alert: error_message }
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
redirect_back_or_default(options: message)
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def service
|
|
|
|
@service ||= @project.services.find { |service| service.to_param == params[:id] }
|
|
|
|
end
|
|
|
|
end
|