summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2018-02-24 03:18:14 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2018-03-07 17:50:11 +0000
commitef15668d8214e8cce5732525c872d5b8f57e337a (patch)
treeb76633818d52f91567971a45d34a4a7b84e91142 /app
parent6253d4456a98613b419d766a03af7ff9b9fcf2af (diff)
downloadgitlab-ce-ef15668d8214e8cce5732525c872d5b8f57e337a.tar.gz
Service integration displays validation errors on test fail
Fixes attempts to update a service integration which had `can_test?` set to true but validations were causing the "Test and save changes" button to return "Something went wrong on our end." Removes references to index action left from 0af99433143727088b6a0a1b2163751c05d80ce6
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/services_controller.rb28
1 files changed, 16 insertions, 12 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb
index b0da0d4dac5..f14cb5f6a9f 100644
--- a/app/controllers/projects/services_controller.rb
+++ b/app/controllers/projects/services_controller.rb
@@ -4,7 +4,7 @@ class Projects::ServicesController < Projects::ApplicationController
# Authorize
before_action :authorize_admin_project!
before_action :ensure_service_enabled
- before_action :service, only: [:edit, :update, :test]
+ before_action :service
respond_to :html
@@ -24,26 +24,30 @@ class Projects::ServicesController < Projects::ApplicationController
end
def test
- message = {}
+ if @service.can_test?
+ render json: service_test_response, status: :ok
+ else
+ render json: {}, status: :not_found
+ end
+ end
+
+ private
- if @service.can_test? && @service.update_attributes(service_params[:service])
+ def service_test_response
+ if @service.update_attributes(service_params[:service])
data = @service.test_data(project, current_user)
outcome = @service.test(data)
- unless outcome[:success]
- message = { error: true, message: 'Test failed.', service_response: outcome[:result].to_s }
+ if outcome[:success]
+ {}
+ else
+ { error: true, message: 'Test failed.', service_response: outcome[:result].to_s }
end
-
- status = :ok
else
- status = :not_found
+ { error: true, message: 'Validations failed.', service_response: @service.errors.full_messages.join(',') }
end
-
- render json: message, status: status
end
- private
-
def success_message
if @service.active?
"#{@service.title} activated."