2022-06-09 15:57:36 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class WebhooksController < BaseController
|
|
|
|
before_action :set_webhook, except: [:index, :new, :create]
|
|
|
|
|
|
|
|
def index
|
|
|
|
authorize :webhook, :index?
|
|
|
|
|
|
|
|
@webhooks = Webhook.page(params[:page])
|
|
|
|
end
|
|
|
|
|
2023-04-30 00:46:39 -04:00
|
|
|
def show
|
|
|
|
authorize @webhook, :show?
|
|
|
|
end
|
|
|
|
|
2022-06-09 15:57:36 -04:00
|
|
|
def new
|
|
|
|
authorize :webhook, :create?
|
|
|
|
|
|
|
|
@webhook = Webhook.new
|
|
|
|
end
|
|
|
|
|
2023-04-30 00:46:39 -04:00
|
|
|
def edit
|
|
|
|
authorize @webhook, :update?
|
|
|
|
end
|
|
|
|
|
2022-06-09 15:57:36 -04:00
|
|
|
def create
|
|
|
|
authorize :webhook, :create?
|
|
|
|
|
|
|
|
@webhook = Webhook.new(resource_params)
|
|
|
|
|
|
|
|
if @webhook.save
|
|
|
|
redirect_to admin_webhook_path(@webhook)
|
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
authorize @webhook, :update?
|
|
|
|
|
|
|
|
if @webhook.update(resource_params)
|
|
|
|
redirect_to admin_webhook_path(@webhook)
|
|
|
|
else
|
2023-06-20 12:15:35 -04:00
|
|
|
render :edit
|
2022-06-09 15:57:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def enable
|
|
|
|
authorize @webhook, :enable?
|
|
|
|
@webhook.enable!
|
|
|
|
redirect_to admin_webhook_path(@webhook)
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable
|
|
|
|
authorize @webhook, :disable?
|
|
|
|
@webhook.disable!
|
|
|
|
redirect_to admin_webhook_path(@webhook)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
authorize @webhook, :destroy?
|
|
|
|
@webhook.destroy!
|
|
|
|
redirect_to admin_webhooks_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_webhook
|
|
|
|
@webhook = Webhook.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def resource_params
|
2023-06-06 04:42:47 -04:00
|
|
|
params.require(:webhook).permit(:url, :template, events: [])
|
2022-06-09 15:57:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|