service_params.rb 1.83 KB
Newer Older
1 2 3
module ServiceParams
  extend ActiveSupport::Concern

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  ALLOWED_PARAMS_CE = [
    :active,
    :add_pusher,
    :api_key,
    :api_url,
    :api_version,
    :bamboo_url,
    :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,
    :merge_requests_events,
36
    :mock_service_url,
37 38 39 40
    :namespace,
    :new_issue_url,
    :notify,
    :notify_only_broken_pipelines,
41
    :notify_only_default_branch,
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    :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
63
  ].freeze
64 65

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

68
  def service_params
69
    dynamic_params = @service.event_channel_names + @service.event_names
70
    service_params = params.permit(:id, service: ALLOWED_PARAMS_CE + dynamic_params)
71

72
    if service_params[:service].is_a?(Hash)
73
      FILTER_BLANK_PARAMS.each do |param|
74
        service_params[:service].delete(param) if service_params[:service][param].blank?
75 76 77
      end
    end

78
    service_params
79 80
  end
end