debian-mirror-gitlab/app/controllers/admin/hooks_controller.rb

69 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
class Admin::HooksController < Admin::ApplicationController
2017-09-10 17:25:29 +05:30
include HooksExecution
before_action :hook_logs, only: :edit
2017-08-17 22:00:37 +05:30
2014-09-02 18:07:02 +05:30
def index
@hooks = SystemHook.all
@hook = SystemHook.new
end
def create
2018-11-08 19:23:39 +05:30
@hook = SystemHook.new(hook_params.to_h)
2014-09-02 18:07:02 +05:30
if @hook.save
2019-07-07 11:18:12 +05:30
redirect_to admin_hooks_path, notice: _('Hook was successfully created.')
2014-09-02 18:07:02 +05:30
else
@hooks = SystemHook.all
render :index
end
end
2017-08-17 22:00:37 +05:30
def edit
end
def update
2018-11-18 11:00:15 +05:30
if hook.update(hook_params)
2019-07-07 11:18:12 +05:30
flash[:notice] = _('System hook was successfully updated.')
2017-08-17 22:00:37 +05:30
redirect_to admin_hooks_path
else
render 'edit'
end
end
2014-09-02 18:07:02 +05:30
def destroy
2017-08-17 22:00:37 +05:30
hook.destroy
2014-09-02 18:07:02 +05:30
2018-11-18 11:00:15 +05:30
redirect_to admin_hooks_path, status: :found
2014-09-02 18:07:02 +05:30
end
def test
2017-09-10 17:25:29 +05:30
result = TestHooks::SystemService.new(hook, current_user, params[:trigger]).execute
set_hook_execution_notice(result)
2014-09-02 18:07:02 +05:30
2015-10-24 18:46:33 +05:30
redirect_back_or_default
2014-09-02 18:07:02 +05:30
end
2017-08-17 22:00:37 +05:30
private
def hook
@hook ||= SystemHook.find(params[:id])
end
2017-09-10 17:25:29 +05:30
def hook_logs
2018-11-08 19:23:39 +05:30
@hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
2017-09-10 17:25:29 +05:30
end
2014-09-02 18:07:02 +05:30
def hook_params
2016-06-02 11:05:42 +05:30
params.require(:hook).permit(
:enable_ssl_verification,
:token,
2018-03-17 18:26:18 +05:30
:url,
*SystemHook.triggers.values
2016-06-02 11:05:42 +05:30
)
2014-09-02 18:07:02 +05:30
end
end