-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
54 changed files
with
1,294 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
class WebhookPreferencesController < ApplicationController | ||
EVENTS = %w[ | ||
form.viewed | ||
form.started | ||
form.completed | ||
form.declined | ||
template.created | ||
template.updated | ||
submission.created | ||
submission.archived | ||
].freeze | ||
load_and_authorize_resource :webhook_url, parent: false | ||
|
||
before_action :load_account_config | ||
authorize_resource :account_config, parent: false | ||
def update | ||
webhook_preferences_params[:events].each do |event, val| | ||
@webhook_url.events.delete(event) if val == '0' | ||
@webhook_url.events.push(event) if val == '1' && @webhook_url.events.exclude?(event) | ||
end | ||
|
||
def create | ||
@account_config.value[account_config_params[:event]] = account_config_params[:value] == '1' | ||
|
||
@account_config.save! | ||
@webhook_url.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) | ||
def webhook_preferences_params | ||
params.require(:webhook_url).permit(events: {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class WebhookSecretController < ApplicationController | ||
before_action :load_encrypted_config | ||
authorize_resource :encrypted_config, parent: false | ||
load_and_authorize_resource :webhook_url, parent: false | ||
|
||
def index; end | ||
def show; end | ||
|
||
def create | ||
@encrypted_config.assign_attributes(value: { | ||
encrypted_config_params[:key] => encrypted_config_params[:value] | ||
def update | ||
@webhook_url.update!(secret: { | ||
webhook_secret_params[:key] => webhook_secret_params[:value] | ||
}.compact_blank) | ||
|
||
@encrypted_config.value.present? ? @encrypted_config.save! : @encrypted_config.delete | ||
|
||
redirect_back(fallback_location: settings_webhooks_path, notice: I18n.t('webhook_secret_has_been_saved')) | ||
end | ||
|
||
private | ||
|
||
def load_encrypted_config | ||
@encrypted_config = | ||
current_account.encrypted_configs.find_or_initialize_by(key: EncryptedConfig::WEBHOOK_SECRET_KEY) | ||
end | ||
|
||
def encrypted_config_params | ||
params.require(:encrypted_config).permit(value: %i[key value]).fetch(:value, {}) | ||
def webhook_secret_params | ||
params.require(:webhook_url).permit(secret: %i[key value]).fetch(:secret, {}) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
# 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 | ||
|
||
def update | ||
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 }) | ||
SendFormCompletedWebhookRequestJob.perform_async('submitter_id' => submitter.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) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.