service_params.rb 1.81 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  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,
    :namespace,
    :new_issue_url,
    :notify,
    :notify_only_broken_builds,
    :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
62
  ].freeze
63
64

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

Felipe Artur's avatar
Felipe Artur committed
67
  def service_params
68
    dynamic_params = @service.event_channel_names + @service.event_names
69
    service_params = params.permit(:id, service: ALLOWED_PARAMS_CE + dynamic_params)
70

Felipe Artur's avatar
Felipe Artur committed
71
    if service_params[:service].is_a?(Hash)
72
      FILTER_BLANK_PARAMS.each do |param|
Felipe Artur's avatar
Felipe Artur committed
73
        service_params[:service].delete(param) if service_params[:service][param].blank?
74
75
76
      end
    end

Felipe Artur's avatar
Felipe Artur committed
77
    service_params
78
79
  end
end