mirror of https://github.com/docusealco/docuseal
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.6 KiB
61 lines
1.6 KiB
# frozen_string_literal: true
|
|
|
|
module Accounts
|
|
module_function
|
|
|
|
def create_duplicate(account)
|
|
new_account = account.dup
|
|
|
|
new_user = account.users.first.dup
|
|
|
|
new_user.account = new_account
|
|
new_user.encrypted_password = SecureRandom.hex
|
|
new_user.email = "#{SecureRandom.hex}@docuseal.co"
|
|
|
|
account.templates.each do |template|
|
|
new_template = template.dup
|
|
|
|
new_template.account = new_account
|
|
new_template.slug = SecureRandom.base58(10)
|
|
|
|
new_template.save!
|
|
|
|
Templates::CloneAttachments.call(template: new_template, original_template: template)
|
|
end
|
|
|
|
new_user.save!(validate: false)
|
|
|
|
new_account
|
|
end
|
|
|
|
def load_signing_certs(account)
|
|
certs =
|
|
if Docuseal.multitenant?
|
|
Docuseal::CERTS
|
|
else
|
|
EncryptedConfig.find_by(account:, key: EncryptedConfig::ESIGN_CERTS_KEY).value
|
|
end
|
|
|
|
{
|
|
cert: OpenSSL::X509::Certificate.new(certs['cert']),
|
|
key: OpenSSL::PKey::RSA.new(certs['key']),
|
|
sub_ca: OpenSSL::X509::Certificate.new(certs['sub_ca']),
|
|
sub_key: OpenSSL::PKey::RSA.new(certs['sub_key']),
|
|
root_ca: OpenSSL::X509::Certificate.new(certs['root_ca']),
|
|
root_key: OpenSSL::PKey::RSA.new(certs['root_key'])
|
|
}
|
|
end
|
|
|
|
def can_send_emails?(account)
|
|
return true if Docuseal.multitenant?
|
|
|
|
EncryptedConfig.exists?(account_id: account.id, key: EncryptedConfig::EMAIL_SMTP_KEY)
|
|
end
|
|
|
|
def normalize_timezone(timezone)
|
|
tzinfo = TZInfo::Timezone.get(ActiveSupport::TimeZone::MAPPING[timezone] || timezone)
|
|
|
|
::ActiveSupport::TimeZone.all.find { |e| e.tzinfo == tzinfo }&.name || timezone
|
|
end
|
|
end
|