Files
docuseal/app/controllers/webhook_settings_controller.rb
T

36 lines
1.0 KiB
Ruby
Raw Normal View History

2023-08-05 15:25:16 +03:00
# frozen_string_literal: true
class WebhookSettingsController < ApplicationController
before_action :load_webhook_url
authorize_resource :webhook_url, parent: false
2023-08-05 15:25:16 +03:00
2023-09-17 00:45:57 +03:00
def show; end
2023-08-05 15:25:16 +03:00
2023-09-17 00:45:57 +03:00
def create
@webhook_url.assign_attributes(webhook_params)
2023-12-02 22:19:24 +02:00
@webhook_url.url.present? ? @webhook_url.save! : @webhook_url.delete
2023-08-05 15:25:16 +03:00
2024-09-18 19:47:47 +03:00
redirect_back(fallback_location: settings_webhooks_path, notice: I18n.t('webhook_url_has_been_saved'))
2023-08-05 15:25:16 +03:00
end
def update
submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last
2024-07-14 21:38:24 +03:00
SendFormCompletedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id,
'webhook_url_id' => @webhook_url.id })
2023-08-05 15:25:16 +03:00
2024-09-18 19:47:47 +03:00
redirect_back(fallback_location: settings_webhooks_path, notice: I18n.t('webhook_request_has_been_sent'))
2023-08-05 15:25:16 +03:00
end
private
def load_webhook_url
@webhook_url = current_account.webhook_urls.first_or_initialize
2023-09-17 00:45:57 +03:00
end
def webhook_params
params.require(:webhook_url).permit(:url, events: [])
2023-08-05 15:25:16 +03:00
end
end