2013-01-20 11:20:50 +00:00
|
|
|
class Admin::HooksController < Admin::ApplicationController
|
2017-04-27 10:08:57 +00:00
|
|
|
include HooksExecution
|
|
|
|
|
|
|
|
before_action :hook_logs, only: :edit
|
2017-04-20 08:31:37 +00:00
|
|
|
|
2012-07-12 19:10:34 +00:00
|
|
|
def index
|
|
|
|
@hooks = SystemHook.all
|
|
|
|
@hook = SystemHook.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2018-06-20 06:25:29 +00:00
|
|
|
@hook = SystemHook.new(hook_params.to_h)
|
2012-07-12 19:10:34 +00:00
|
|
|
|
2012-07-15 12:29:06 +00:00
|
|
|
if @hook.save
|
|
|
|
redirect_to admin_hooks_path, notice: 'Hook was successfully created.'
|
|
|
|
else
|
|
|
|
@hooks = SystemHook.all
|
2012-09-16 11:44:54 +00:00
|
|
|
render :index
|
2012-07-12 19:10:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-20 08:31:37 +00:00
|
|
|
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
|
|
|
|
|
2012-07-12 19:10:34 +00:00
|
|
|
def destroy
|
2017-04-20 08:31:37 +00:00
|
|
|
hook.destroy
|
2012-07-12 19:10:34 +00:00
|
|
|
|
2017-06-06 22:45:16 +00:00
|
|
|
redirect_to admin_hooks_path, status: 302
|
2012-07-12 19:10:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test
|
2017-07-20 15:12:06 +00:00
|
|
|
result = TestHooks::SystemService.new(hook, current_user, params[:trigger]).execute
|
2017-04-27 10:08:57 +00:00
|
|
|
|
2017-07-20 15:12:06 +00:00
|
|
|
set_hook_execution_notice(result)
|
2012-07-12 19:10:34 +00:00
|
|
|
|
2015-10-20 07:28:28 +00:00
|
|
|
redirect_back_or_default
|
2012-07-12 19:10:34 +00:00
|
|
|
end
|
2014-06-26 15:51:11 +00:00
|
|
|
|
2017-04-20 08:31:37 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def hook
|
|
|
|
@hook ||= SystemHook.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-04-27 10:08:57 +00:00
|
|
|
def hook_logs
|
2018-06-28 13:34:31 +00:00
|
|
|
@hook_logs ||= hook.web_hook_logs.recent.page(params[:page])
|
2017-04-27 10:08:57 +00:00
|
|
|
end
|
|
|
|
|
2014-06-26 15:51:11 +00:00
|
|
|
def hook_params
|
2016-04-30 08:34:31 +00:00
|
|
|
params.require(:hook).permit(
|
|
|
|
:enable_ssl_verification,
|
|
|
|
:token,
|
2017-12-18 10:14:51 +00:00
|
|
|
:url,
|
|
|
|
*SystemHook.triggers.values
|
2016-04-30 08:34:31 +00:00
|
|
|
)
|
2014-06-26 15:51:11 +00:00
|
|
|
end
|
2012-07-12 19:10:34 +00:00
|
|
|
end
|