mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
809 B
31 lines
809 B
# frozen_string_literal: true
|
|
|
|
class WebhookSecretController < ApplicationController
|
|
load_and_authorize_resource :webhook_url, parent: false
|
|
|
|
HEADER_NAME_REGEXP = /\A[\w-]+\z/
|
|
|
|
def show; end
|
|
|
|
def update
|
|
key = webhook_secret_params[:key]
|
|
|
|
if key.present? && !HEADER_NAME_REGEXP.match?(key)
|
|
return redirect_back(fallback_location: settings_webhook_path(@webhook_url), alert: I18n.t('unable_to_save'))
|
|
end
|
|
|
|
@webhook_url.update!(secret: {
|
|
key => webhook_secret_params[:value]
|
|
}.compact_blank)
|
|
|
|
redirect_back(fallback_location: settings_webhook_path(@webhook_url),
|
|
notice: I18n.t('webhook_secret_has_been_saved'))
|
|
end
|
|
|
|
private
|
|
|
|
def webhook_secret_params
|
|
params.require(:webhook_url).permit(secret: %i[key value]).fetch(:secret, {})
|
|
end
|
|
end
|