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

67 lines
1.2 KiB
Ruby
Raw Normal View History

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
redirect_to admin_hooks_path, notice: 'Hook was successfully created.'
else
@hooks = SystemHook.all
render :index
end
end
2017-08-17 22:00:37 +05:30
def edit
end
def update
if hook.update_attributes(hook_params)
flash[:notice] = 'System hook was successfully updated.'
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
2017-09-10 17:25:29 +05:30
redirect_to admin_hooks_path, status: 302
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