use webhook urls instead of encrypted configs
This commit is contained in:
committed by
Pete Matsyburka
parent
f669045362
commit
84edb6dbda
@@ -35,7 +35,6 @@ class AccountConfig < ApplicationRecord
|
||||
FORM_WITH_CONFETTI_KEY = 'form_with_confetti'
|
||||
FORM_PREFILL_SIGNATURE_KEY = 'form_prefill_signature'
|
||||
ESIGNING_PREFERENCE_KEY = 'esigning_preference'
|
||||
WEBHOOK_PREFERENCES_KEY = 'webhook_preferences'
|
||||
DOWNLOAD_LINKS_AUTH_KEY = 'download_links_auth'
|
||||
FORCE_SSO_AUTH_KEY = 'force_sso_auth'
|
||||
FLATTEN_RESULT_PDF_KEY = 'flatten_result_pdf'
|
||||
|
||||
@@ -26,9 +26,7 @@ class EncryptedConfig < ApplicationRecord
|
||||
EMAIL_SMTP_KEY = 'action_mailer_smtp',
|
||||
ESIGN_CERTS_KEY = 'esign_certs',
|
||||
TIMESTAMP_SERVER_URL_KEY = 'timestamp_server_url',
|
||||
APP_URL_KEY = 'app_url',
|
||||
WEBHOOK_URL_KEY = 'webhook_url',
|
||||
WEBHOOK_SECRET_KEY = 'webhook_secret'
|
||||
APP_URL_KEY = 'app_url'
|
||||
].freeze
|
||||
|
||||
belongs_to :account
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#
|
||||
# id :bigint not null, primary key
|
||||
# events :text not null
|
||||
# secret :text
|
||||
# sha1 :string not null
|
||||
# url :text not null
|
||||
# created_at :datetime not null
|
||||
@@ -22,15 +23,34 @@
|
||||
# fk_rails_... (account_id => accounts.id)
|
||||
#
|
||||
class WebhookUrl < ApplicationRecord
|
||||
EVENTS = %w[
|
||||
form.viewed
|
||||
form.started
|
||||
form.completed
|
||||
form.declined
|
||||
template.created
|
||||
template.updated
|
||||
submission.created
|
||||
submission.archived
|
||||
].freeze
|
||||
|
||||
belongs_to :account
|
||||
|
||||
attribute :events, :string, default: -> { [] }
|
||||
attribute :events, :string, default: -> { %w[form.viewed form.started form.completed form.declined] }
|
||||
|
||||
serialize :events, coder: JSON
|
||||
serialize :secret, coder: JSON
|
||||
|
||||
scope :with_event, ->(event) { with_events([event]) }
|
||||
scope :with_events, lambda { |events|
|
||||
where(events.map do |event|
|
||||
Arel::Table.new(:webhook_urls)[:events].matches("%\"#{event}\"%")
|
||||
end.reduce(:or))
|
||||
}
|
||||
|
||||
before_validation :set_sha1
|
||||
|
||||
encrypts :url
|
||||
encrypts :url, :secret
|
||||
|
||||
def set_sha1
|
||||
self.sha1 = Digest::SHA1.hexdigest(url)
|
||||
|
||||
Reference in New Issue
Block a user