mirror of https://github.com/docusealco/docuseal
parent
514987138a
commit
01333e5b2e
@ -0,0 +1,39 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: email_messages
|
||||||
|
#
|
||||||
|
# id :bigint not null, primary key
|
||||||
|
# body :text not null
|
||||||
|
# sha1 :string not null
|
||||||
|
# subject :text not null
|
||||||
|
# uuid :string not null
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# account_id :bigint not null
|
||||||
|
# author_id :bigint not null
|
||||||
|
#
|
||||||
|
# Indexes
|
||||||
|
#
|
||||||
|
# index_email_messages_on_account_id (account_id)
|
||||||
|
# index_email_messages_on_sha1 (sha1)
|
||||||
|
# index_email_messages_on_uuid (uuid)
|
||||||
|
#
|
||||||
|
# Foreign Keys
|
||||||
|
#
|
||||||
|
# fk_rails_... (account_id => accounts.id)
|
||||||
|
# fk_rails_... (author_id => users.id)
|
||||||
|
#
|
||||||
|
class EmailMessage < ApplicationRecord
|
||||||
|
belongs_to :author, class_name: 'User'
|
||||||
|
belongs_to :account
|
||||||
|
|
||||||
|
attribute :uuid, :string, default: -> { SecureRandom.uuid }
|
||||||
|
|
||||||
|
before_validation :set_sha1, on: :create
|
||||||
|
|
||||||
|
def set_sha1
|
||||||
|
self.sha1 = Digest::SHA1.hexdigest({ subject:, body: }.to_json)
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddPreferencesToSubmitters < ActiveRecord::Migration[7.0]
|
||||||
|
class MigrationSubmitter < ApplicationRecord
|
||||||
|
self.table_name = 'submitters'
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_column :submitters, :preferences, :text
|
||||||
|
|
||||||
|
MigrationSubmitter.where(preferences: nil).update_all(preferences: '{}')
|
||||||
|
|
||||||
|
change_column_null :submitters, :preferences, false
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddPreferencesToSubmissions < ActiveRecord::Migration[7.0]
|
||||||
|
class MigrationSubmission < ApplicationRecord
|
||||||
|
self.table_name = 'submissions'
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_column :submissions, :preferences, :text
|
||||||
|
|
||||||
|
MigrationSubmission.where(preferences: nil).update_all(preferences: '{}')
|
||||||
|
|
||||||
|
change_column_null :submissions, :preferences, false
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class CreateEmailMessages < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
create_table :email_messages do |t|
|
||||||
|
t.string :uuid, null: false, index: true
|
||||||
|
t.references :author, null: false, foreign_key: { to_table: :users }, index: false
|
||||||
|
t.references :account, null: false, foreign_key: true, index: true
|
||||||
|
t.text :subject, null: false
|
||||||
|
t.text :body, null: false
|
||||||
|
t.string :sha1, null: false, index: true
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module EmailMessages
|
||||||
|
module_function
|
||||||
|
|
||||||
|
def find_or_create_for_account_user(account, user, subject, body)
|
||||||
|
subject = SubmitterMailer::DEFAULT_INVITATION_SUBJECT if subject.blank?
|
||||||
|
|
||||||
|
sha1 = Digest::SHA1.hexdigest({ subject:, body: }.to_json)
|
||||||
|
|
||||||
|
message = account.email_messages.find_by(sha1:)
|
||||||
|
|
||||||
|
message ||= account.email_messages.create!(author: user, subject:, body:)
|
||||||
|
|
||||||
|
message
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in new issue