adjust webhooks

This commit is contained in:
Pete Matsyburka
2024-11-01 15:35:02 +02:00
parent 84edb6dbda
commit 2542f26d96
40 changed files with 156 additions and 235 deletions
+2 -8
View File
@@ -6,7 +6,7 @@
#
# id :bigint not null, primary key
# events :text not null
# secret :text
# secret :text not null
# sha1 :string not null
# url :text not null
# created_at :datetime not null
@@ -37,17 +37,11 @@ class WebhookUrl < ApplicationRecord
belongs_to :account
attribute :events, :string, default: -> { %w[form.viewed form.started form.completed form.declined] }
attribute :secret, :string, default: -> { {} }
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, :secret