debian-mirror-gitlab/app/controllers/projects/services_controller.rb

75 lines
2.5 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class Projects::ServicesController < Projects::ApplicationController
2015-12-23 02:04:40 +05:30
ALLOWED_PARAMS = [:title, :token, :type, :active, :api_key, :api_url, :api_version, :subdomain,
2015-09-11 14:41:01 +05:30
:room, :recipients, :project_url, :webhook,
:user_key, :device, :priority, :sound, :bamboo_url, :username, :password,
2015-09-25 12:07:36 +05:30
:build_key, :server, :teamcity_url, :drone_url, :build_type,
2015-09-11 14:41:01 +05:30
:description, :issues_url, :new_issue_url, :restrict_to_branch, :channel,
:colorize_messages, :channels,
:push_events, :issues_events, :merge_requests_events, :tag_push_events,
2016-06-02 11:05:42 +05:30
:note_events, :build_events, :wiki_page_events,
2015-12-23 02:04:40 +05:30
:notify_only_broken_builds, :add_pusher,
:send_from_committer_email, :disable_diffs, :external_wiki_url,
2015-09-11 14:41:01 +05:30
:notify, :color,
2015-12-23 02:04:40 +05:30
:server_host, :server_port, :default_irc_uri, :enable_ssl_verification,
:jira_issue_transition_id]
2015-10-24 18:46:33 +05:30
# Parameters to ignore if no value is specified
FILTER_BLANK_PARAMS = [:password]
2014-09-02 18:07:02 +05:30
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!
before_action :service, only: [:edit, :update, :test]
2014-09-02 18:07:02 +05:30
respond_to :html
layout "project_settings"
def index
@project.build_missing_services
2015-04-26 12:48:37 +05:30
@services = @project.services.visible.reload
2014-09-02 18:07:02 +05:30
end
def edit
end
def update
if @service.update_attributes(service_params)
2015-04-26 12:48:37 +05:30
redirect_to(
edit_namespace_project_service_path(@project.namespace, @project,
@service.to_param, notice:
'Successfully updated.')
)
2014-09-02 18:07:02 +05:30
else
render 'edit'
end
end
def test
2015-04-26 12:48:37 +05:30
data = Gitlab::PushDataBuilder.build_sample(project, current_user)
2015-09-11 14:41:01 +05:30
outcome = @service.test(data)
if outcome[:success]
2015-04-26 12:48:37 +05:30
message = { notice: 'We sent a request to the provided URL' }
else
2015-09-11 14:41:01 +05:30
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 }
2015-04-26 12:48:37 +05:30
end
2014-09-02 18:07:02 +05:30
2015-10-24 18:46:33 +05:30
redirect_back_or_default(options: message)
2014-09-02 18:07:02 +05:30
end
private
def service
@service ||= @project.services.find { |service| service.to_param == params[:id] }
end
def service_params
2015-10-24 18:46:33 +05:30
service_params = params.require(:service).permit(ALLOWED_PARAMS)
FILTER_BLANK_PARAMS.each do |param|
service_params.delete(param) if service_params[param].blank?
end
service_params
2014-09-02 18:07:02 +05:30
end
end