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

70 lines
1.3 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
@hook = SystemHook.new(hook_params)
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
@hook_logs ||=
Kaminari.paginate_array(hook.web_hook_logs.order(created_at: :desc)).page(params[:page])
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,
:push_events,
:tag_push_events,
2017-09-10 17:25:29 +05:30
:repository_update_events,
2016-06-02 11:05:42 +05:30
:token,
:url
)
2014-09-02 18:07:02 +05:30
end
end