Commit c77047b8 authored by Alex Kalderimis's avatar Alex Kalderimis

Rename ServiceParams to IntegrationParams

parent af91d563
# frozen_string_literal: true # frozen_string_literal: true
class Admin::ServicesController < Admin::ApplicationController class Admin::ServicesController < Admin::ApplicationController
include ServiceParams include IntegrationParams
before_action :service, only: [:edit, :update] before_action :service, only: [:edit, :update]
before_action :disable_query_limiting, only: [:index] before_action :disable_query_limiting, only: [:index]
...@@ -21,7 +21,7 @@ class Admin::ServicesController < Admin::ApplicationController ...@@ -21,7 +21,7 @@ class Admin::ServicesController < Admin::ApplicationController
end end
def update def update
if service.update(service_params[:service]) if service.update(integration_params[:integration])
PropagateServiceTemplateWorker.perform_async(service.id) if service.active? # rubocop:disable CodeReuse/Worker PropagateServiceTemplateWorker.perform_async(service.id) if service.active? # rubocop:disable CodeReuse/Worker
redirect_to admin_application_settings_services_path, redirect_to admin_application_settings_services_path,
......
# frozen_string_literal: true # frozen_string_literal: true
module ServiceParams module IntegrationParams
extend ActiveSupport::Concern extend ActiveSupport::Concern
ALLOWED_PARAMS_CE = [ ALLOWED_PARAMS_CE = [
...@@ -79,22 +79,23 @@ module ServiceParams ...@@ -79,22 +79,23 @@ module ServiceParams
# Parameters to ignore if no value is specified # Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password].freeze FILTER_BLANK_PARAMS = [:password].freeze
def service_params def integration_params
dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables
service_params = params.permit(:id, service: allowed_service_params + dynamic_params) return_value = params.permit(:id, integration: allowed_integration_params + dynamic_params)
param_values = return_value[:integration]
if service_params[:service].is_a?(ActionController::Parameters) if param_values.is_a?(ActionController::Parameters)
FILTER_BLANK_PARAMS.each do |param| FILTER_BLANK_PARAMS.each do |param|
service_params[:service].delete(param) if service_params[:service][param].blank? param_values.delete(param) if param_values[param].blank?
end end
end end
service_params return_value
end end
def allowed_service_params def allowed_integration_params
ALLOWED_PARAMS_CE ALLOWED_PARAMS_CE
end end
end end
ServiceParams.prepend_if_ee('EE::ServiceParams') IntegrationParams.prepend_if_ee('EE::IntegrationParams')
...@@ -4,7 +4,7 @@ module IntegrationsActions ...@@ -4,7 +4,7 @@ module IntegrationsActions
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
include ServiceParams include IntegrationParams
before_action :integration, only: [:edit, :update, :test] before_action :integration, only: [:edit, :update, :test]
end end
...@@ -14,7 +14,7 @@ module IntegrationsActions ...@@ -14,7 +14,7 @@ module IntegrationsActions
end end
def update def update
saved = integration.update(service_params[:service]) saved = integration.update(integration_params[:integration])
respond_to do |format| respond_to do |format|
format.html do format.html do
...@@ -49,7 +49,8 @@ module IntegrationsActions ...@@ -49,7 +49,8 @@ module IntegrationsActions
private private
def integration def integration
# Using instance variable `@service` still required as it's used in ServiceParams. # Using instance variable `@service` still required as it's used in
# IntegrationParams.
# Should be removed once that is refactored to use `@integration`. # Should be removed once that is refactored to use `@integration`.
@integration = @service ||= find_or_initialize_non_project_specific_integration(params[:id]) # rubocop:disable Gitlab/ModuleWithInstanceVariables @integration = @service ||= find_or_initialize_non_project_specific_integration(params[:id]) # rubocop:disable Gitlab/ModuleWithInstanceVariables
end end
......
# frozen_string_literal: true # frozen_string_literal: true
class Projects::ServicesController < Projects::ApplicationController class Projects::ServicesController < Projects::ApplicationController
include ServiceParams include IntegrationParams
include InternalRedirect include InternalRedirect
# Authorize # Authorize
...@@ -26,8 +26,8 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -26,8 +26,8 @@ class Projects::ServicesController < Projects::ApplicationController
end end
def update def update
@service.attributes = service_params[:service] @service.attributes = integration_params[:integration]
@service.inherit_from_id = nil if service_params[:service][:inherit_from_id].blank? @service.inherit_from_id = nil if integration_params[:integration][:inherit_from_id].blank?
saved = @service.save(context: :manual_change) saved = @service.save(context: :manual_change)
...@@ -60,7 +60,7 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -60,7 +60,7 @@ class Projects::ServicesController < Projects::ApplicationController
private private
def service_test_response def service_test_response
unless @service.update(service_params[:service]) unless @service.update(integration_params[:integration])
return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false } return { error: true, message: _('Validations failed.'), service_response: @service.errors.full_messages.join(','), test_failed: false }
end end
......
# frozen_string_literal: true # frozen_string_literal: true
module EE module EE
module ServiceParams module IntegrationParams
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
ALLOWED_PARAMS_EE = [ ALLOWED_PARAMS_EE = [
...@@ -14,8 +14,8 @@ module EE ...@@ -14,8 +14,8 @@ module EE
:vulnerabilities_issuetype :vulnerabilities_issuetype
].freeze ].freeze
override :allowed_service_params override :allowed_integration_params
def allowed_service_params def allowed_integration_params
super + ALLOWED_PARAMS_EE super + ALLOWED_PARAMS_EE
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment