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

services_controller.rb 2.52 KB
Newer Older
1
class Projects::ServicesController < Projects::ApplicationController
Drew Blessing's avatar
Drew Blessing committed
2
  ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :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,
Drew Blessing's avatar
Drew Blessing committed
13 14
                    :server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
                    :jira_issue_transition_id]
15 16 17

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

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

  respond_to :html

25 26
  layout "project_settings"

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

  def edit
  end

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

  def test
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
48
    data = Gitlab::PushDataBuilder.build_sample(project, current_user)
49 50
    outcome = @service.test(data)
    if outcome[:success]
51 52
      message = { notice: 'We sent a request to the provided URL' }
    else
53 54 55
      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 }
56
    end
57

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

  private

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

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