Skip to content

Commit

Permalink
adjust email configs loading
Browse files Browse the repository at this point in the history
  • Loading branch information
omohokcoj committed Nov 17, 2023
1 parent 3575a25 commit 0698aad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/mailers/submitter_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def invitation_email(submitter, body: nil, subject: nil)
@submitter = submitter
@body = body.presence

@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY)
@email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY)

subject =
if @email_config || subject.present?
Expand All @@ -31,7 +31,7 @@ def completed_email(submitter, user, bcc: nil)

Submissions::EnsureResultGenerated.call(submitter)

@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY)
@email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY)

add_completed_email_attachments!(submitter)

Expand All @@ -58,7 +58,7 @@ def documents_copy_email(submitter, to: nil)

@documents = add_completed_email_attachments!(submitter)

@email_config = @current_account.account_configs.find_by(key: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY)
@email_config = AccountConfigs.find_for_account(@current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY)

subject =
if @email_config
Expand Down
10 changes: 9 additions & 1 deletion lib/account_configs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ module AccountConfigs
module_function

def find_or_initialize_for_key(account, key)
account.account_configs.find_by(key:) ||
find_for_account(account, key) ||
account.account_configs.new(key:, value: AccountConfig::DEFAULT_VALUES[key])
end

def find_for_account(account, key)
configs = account.account_configs.find_by(key:)

configs ||= Account.order(:id).first.account_configs.find_by(key:) unless Docuseal.multitenant?

configs
end
end

0 comments on commit 0698aad

Please sign in to comment.