GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

services_controller.rb 2.46 KB
Newer Older
1
class Projects::ServicesController < Projects::ApplicationController
2
  ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_version, :subdomain,
3 4
                    :room, :recipients, :project_url, :webhook,
                    :user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
Kirilll Zaitsev's avatar
Kirilll Zaitsev committed
5
                    :build_key, :server, :teamcity_url, :drone_url, :build_type,
6 7 8
                    :description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
                    :colorize_messages, :channels,
                    :push_events, :issues_events, :merge_requests_events, :tag_push_events,
9 10 11
                    :note_events, :build_events,
                    :notify_only_broken_builds, :add_pusher,
                    :send_from_committer_email, :disable_diffs, :external_wiki_url,
12
                    :notify, :color,
13
                    :server_host, :server_port, :default_irc_uri, :enable_ssl_verification]
14 15 16

  # Parameters to ignore if no value is specified
  FILTER_BLANK_PARAMS = [:password]
17

18
  # Authorize
19 20
  before_action :authorize_admin_project!
  before_action :service, only: [:edit, :update, :test]
21 22 23

  respond_to :html

24 25
  layout "project_settings"

26
  def index
27
    @project.build_missing_services
28
    @services = @project.services.visible.reload
29 30 31 32 33 34
  end

  def edit
  end

  def update
35
    if @service.update_attributes(service_params)
Vinnie Okada's avatar
Vinnie Okada committed
36 37 38 39 40
      redirect_to(
        edit_namespace_project_service_path(@project.namespace, @project,
                                            @service.to_param, notice:
                                            'Successfully updated.')
      )
41 42 43 44 45 46
    else
      render 'edit'
    end
  end

  def test
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
47
    data = Gitlab::PushDataBuilder.build_sample(project, current_user)
48 49
    outcome = @service.test(data)
    if outcome[:success]
50 51
      message = { notice: 'We sent a request to the provided URL' }
    else
52 53 54
      error_message = "We tried to send a request to the provided URL but an error occurred"
      error_message << ": #{outcome[:result]}" if outcome[:result].present?
      message = { alert: error_message }
55
    end
56

57
    redirect_back_or_default(options: message)
58
  end
59 60 61 62 63 64

  private

  def service
    @service ||= @project.services.find { |service| service.to_param == params[:id] }
  end
65 66

  def service_params
67
    service_params = params.require(:service).permit(ALLOWED_PARAMS)
68 69 70
    FILTER_BLANK_PARAMS.each do |param|
      service_params.delete(param) if service_params[param].blank?
    end
71
    service_params
72
  end
73
end