service_params.rb 2.07 KB
Newer Older
1 2
# frozen_string_literal: true

3 4
module ServiceParams
  extend ActiveSupport::Concern
5

6 7 8 9 10 11 12
  ALLOWED_PARAMS_CE = [
    :active,
    :add_pusher,
    :api_key,
    :api_url,
    :api_version,
    :bamboo_url,
13
    :branches_to_be_notified,
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    :build_key,
    :build_type,
    :ca_pem,
    :channel,
    :channels,
    :color,
    :colorize_messages,
    :confidential_issues_events,
    :default_irc_uri,
    :description,
    :device,
    :disable_diffs,
    :drone_url,
    :enable_ssl_verification,
    :external_wiki_url,
    # We're using `issues_events` and `merge_requests_events`
    # in the view so we still need to explicitly state them
    # here. `Service#event_names` would only give
    # `issue_events` and `merge_request_events` (singular!)
    # See app/helpers/services_helper.rb for how we
    # make those event names plural as special case.
    :issues_events,
    :issues_url,
    :jira_issue_transition_id,
38
    :manual_configuration,
39
    :merge_requests_events,
40
    :mock_service_url,
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    :namespace,
    :new_issue_url,
    :notify,
    :notify_only_broken_pipelines,
    :password,
    :priority,
    :project_key,
    :project_url,
    :recipients,
    :restrict_to_branch,
    :room,
    :send_from_committer_email,
    :server,
    :server_host,
    :server_port,
    :sound,
    :subdomain,
    :teamcity_url,
    :title,
    :token,
    :type,
    :url,
    :user_key,
    :username,
    :webhook
Douwe Maan's avatar
Douwe Maan committed
66
  ].freeze
67

68
  # Parameters to ignore if no value is specified
Douwe Maan's avatar
Douwe Maan committed
69
  FILTER_BLANK_PARAMS = [:password].freeze
70

71
  def service_params
72
    dynamic_params = @service.event_channel_names + @service.event_names # rubocop:disable Gitlab/ModuleWithInstanceVariables
73
    service_params = params.permit(:id, service: allowed_service_params + dynamic_params)
74

75
    if service_params[:service].is_a?(ActionController::Parameters)
76
      FILTER_BLANK_PARAMS.each do |param|
77
        service_params[:service].delete(param) if service_params[:service][param].blank?
78 79 80
      end
    end

81
    service_params
82
  end
83 84 85 86

  def allowed_service_params
    ALLOWED_PARAMS_CE
  end
87
end
88

89
ServiceParams.prepend_if_ee('EE::ServiceParams')