add webhook urls record

This commit is contained in:
Pete Matsyburka
2024-07-14 21:38:24 +03:00
parent f10e941529
commit de52f2f5e5
8 changed files with 112 additions and 11 deletions
+1
View File
@@ -32,6 +32,7 @@ class Account < ApplicationRecord
has_many :submitters, through: :submissions
has_many :account_linked_accounts, dependent: :destroy
has_many :email_events, dependent: :destroy
has_many :webhook_urls, dependent: :destroy
has_many :account_testing_accounts, -> { testing }, dependent: :destroy,
class_name: 'AccountLinkedAccount',
inverse_of: :account
+38
View File
@@ -0,0 +1,38 @@
# frozen_string_literal: true
# == Schema Information
#
# Table name: webhook_urls
#
# id :bigint not null, primary key
# events :text not null
# sha1 :string not null
# url :text not null
# created_at :datetime not null
# updated_at :datetime not null
# account_id :bigint not null
#
# Indexes
#
# index_webhook_urls_on_account_id (account_id)
# index_webhook_urls_on_sha1 (sha1)
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
#
class WebhookUrl < ApplicationRecord
belongs_to :account
attribute :events, :string, default: -> { [] }
serialize :events, coder: JSON
before_validation :set_sha1
encrypts :url
def set_sha1
self.sha1 = Digest::SHA1.hexdigest(url)
end
end