2024-04-09 18:11:58 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class WebhookPreferencesController < ApplicationController
|
|
|
|
|
EVENTS = %w[
|
|
|
|
|
form.viewed
|
|
|
|
|
form.started
|
|
|
|
|
form.completed
|
2024-08-21 09:22:59 +03:00
|
|
|
form.declined
|
2024-05-12 11:37:33 +03:00
|
|
|
template.created
|
|
|
|
|
template.updated
|
2024-05-17 13:28:10 +03:00
|
|
|
submission.created
|
2024-04-09 18:11:58 +03:00
|
|
|
submission.archived
|
|
|
|
|
].freeze
|
|
|
|
|
|
|
|
|
|
before_action :load_account_config
|
|
|
|
|
authorize_resource :account_config, parent: false
|
|
|
|
|
|
|
|
|
|
def create
|
|
|
|
|
@account_config.value[account_config_params[:event]] = account_config_params[:value] == '1'
|
|
|
|
|
|
|
|
|
|
@account_config.save!
|
|
|
|
|
|
|
|
|
|
head :ok
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def load_account_config
|
|
|
|
|
@account_config =
|
|
|
|
|
current_account.account_configs.find_or_initialize_by(key: AccountConfig::WEBHOOK_PREFERENCES_KEY)
|
|
|
|
|
@account_config.value ||= {}
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def account_config_params
|
|
|
|
|
params.permit(:event, :value)
|
|
|
|
|
end
|
|
|
|
|
end
|