2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
class Projects::HooksController < Projects::ApplicationController
|
2022-10-11 01:57:18 +05:30
|
|
|
include ::WebHooks::HookActions
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
# Authorize
|
2023-05-27 22:25:52 +05:30
|
|
|
before_action :authorize_admin_project!, except: :destroy
|
|
|
|
before_action :authorize_destroy_project_hook!, only: :destroy
|
2022-01-26 12:08:38 +05:30
|
|
|
before_action -> { check_rate_limit!(:project_testing_hook, scope: [@project, current_user]) }, only: :test
|
2014-09-02 18:07:02 +05:30
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
layout "project_settings"
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :integrations
|
2021-12-11 22:18:48 +05:30
|
|
|
urgency :low, [:test]
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def test
|
2022-08-13 15:12:31 +05:30
|
|
|
trigger = params.fetch(:trigger, ::ProjectHook.triggers.each_value.first.to_s)
|
|
|
|
result = TestHooks::ProjectService.new(hook, current_user, trigger).execute
|
2017-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
set_hook_execution_notice(result)
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
redirect_back_or_default(default: { action: :index })
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
private
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def relation
|
|
|
|
@project.hooks
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= @project.hooks.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
def trigger_values
|
|
|
|
ProjectHook.triggers.values
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
2023-05-27 22:25:52 +05:30
|
|
|
|
|
|
|
def authorize_destroy_project_hook!
|
|
|
|
render_404 unless can?(current_user, :destroy_web_hook, hook)
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|