use webhook urls instead of encrypted configs

This commit is contained in:
Alex Turchyn
2024-10-28 20:39:09 +02:00
committed by Pete Matsyburka
parent f669045362
commit 84edb6dbda
50 changed files with 1350 additions and 269 deletions
+9 -10
View File
@@ -1,15 +1,15 @@
# frozen_string_literal: true
class WebhookSettingsController < ApplicationController
before_action :load_encrypted_config
authorize_resource :encrypted_config, parent: false
before_action :load_webhook_url
authorize_resource :webhook_url, parent: false
def show; end
def create
@encrypted_config.assign_attributes(encrypted_config_params)
@webhook_url.assign_attributes(webhook_params)
@encrypted_config.value.present? ? @encrypted_config.save! : @encrypted_config.delete
@webhook_url.url.present? ? @webhook_url.save! : @webhook_url.delete
redirect_back(fallback_location: settings_webhooks_path, notice: I18n.t('webhook_url_has_been_saved'))
end
@@ -18,19 +18,18 @@ class WebhookSettingsController < ApplicationController
submitter = current_account.submitters.where.not(completed_at: nil).order(:id).last
SendFormCompletedWebhookRequestJob.perform_async({ 'submitter_id' => submitter.id,
'encrypted_config_id' => @encrypted_config.id })
'webhook_url_id' => @webhook_url.id })
redirect_back(fallback_location: settings_webhooks_path, notice: I18n.t('webhook_request_has_been_sent'))
end
private
def load_encrypted_config
@encrypted_config =
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_URL_KEY)
def load_webhook_url
@webhook_url = current_account.webhook_urls.first_or_initialize
end
def encrypted_config_params
params.require(:encrypted_config).permit(:value)
def webhook_params
params.require(:webhook_url).permit(:url, events: [])
end
end