Files
docuseal/app/controllers/webhook_settings_controller.rb
T

37 lines
1.1 KiB
Ruby
Raw Normal View History

2023-08-05 15:25:16 +03:00
# frozen_string_literal: true
class WebhookSettingsController < ApplicationController
2023-09-17 00:45:57 +03:00
before_action :load_encrypted_config
authorize_resource :encrypted_config, 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
2023-12-02 22:19:24 +02:00
@encrypted_config.assign_attributes(encrypted_config_params)
@encrypted_config.value.present? ? @encrypted_config.save! : @encrypted_config.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,
'encrypted_config_id' => @encrypted_config.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
2023-09-17 00:45:57 +03:00
def load_encrypted_config
@encrypted_config =
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
end
2023-08-05 15:25:16 +03:00
def encrypted_config_params
params.require(:encrypted_config).permit(:value)
end
end