adjust for multitenant
This commit is contained in:
@@ -3,6 +3,30 @@
|
||||
module Accounts
|
||||
module_function
|
||||
|
||||
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)
|
||||
|
||||
|
||||
@@ -4,7 +4,11 @@ module ActionMailerConfigsInterceptor
|
||||
module_function
|
||||
|
||||
def delivering_email(message)
|
||||
return message unless Rails.env.production?
|
||||
if Rails.env.production? && Rails.application.config.action_mailer.delivery_method
|
||||
message.from = ENV.fetch('SMTP_FROM')
|
||||
|
||||
return message
|
||||
end
|
||||
|
||||
email_configs = EncryptedConfig.find_by(key: EncryptedConfig::EMAIL_SMTP_KEY)
|
||||
|
||||
|
||||
+10
-1
@@ -5,13 +5,22 @@ module Docuseal
|
||||
PRODUCT_NAME = 'DocuSeal'
|
||||
DEFAULT_APP_URL = 'http://localhost:3000'
|
||||
|
||||
CERTS = JSON.parse(ENV.fetch('CERTS', '{}'))
|
||||
|
||||
DEFAULT_URL_OPTIONS = {
|
||||
host: ENV.fetch('HOST', 'localhost'),
|
||||
protocol: ENV['FORCE_SSL'] == 'true' ? 'https' : 'http'
|
||||
}.freeze
|
||||
|
||||
module_function
|
||||
|
||||
def multitenant?
|
||||
ENV['MULTITENANT'] == true
|
||||
ENV['MULTITENANT'] == 'true'
|
||||
end
|
||||
|
||||
def default_url_options
|
||||
return DEFAULT_URL_OPTIONS if multitenant?
|
||||
|
||||
@default_url_options ||= begin
|
||||
value = EncryptedConfig.find_by(key: EncryptedConfig::APP_URL_KEY)&.value
|
||||
value ||= DEFAULT_APP_URL
|
||||
|
||||
@@ -13,12 +13,12 @@ module GenerateCertificate
|
||||
cert, key = generate_certificate(name, sub_cert, sub_key)
|
||||
|
||||
{
|
||||
cert: cert.to_pem,
|
||||
key: key.to_pem,
|
||||
root_ca: root_cert.to_pem,
|
||||
root_key: root_key.to_pem,
|
||||
sub_ca: sub_cert.to_pem,
|
||||
sub_key: sub_key.to_pem
|
||||
cert:,
|
||||
key:,
|
||||
root_ca: root_cert,
|
||||
root_key:,
|
||||
sub_ca: sub_cert,
|
||||
sub_key:
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
module LoadActiveStorageConfigs
|
||||
STORAGE_YML_PATH = Rails.root.join('config/storage.yml')
|
||||
IS_ENV_CONFIGURED =
|
||||
ENV['S3_ATTACHMENTS_BUCKET'].present? || ENV['GCS_BUCKET'].present? || ENV['AZURE_CONTAINER'].present?
|
||||
|
||||
module_function
|
||||
|
||||
@@ -14,6 +16,9 @@ module LoadActiveStorageConfigs
|
||||
end
|
||||
|
||||
def reload
|
||||
return if Docuseal.multitenant?
|
||||
return if IS_ENV_CONFIGURED
|
||||
|
||||
encrypted_config = EncryptedConfig.find_by(key: EncryptedConfig::FILES_STORAGE_KEY)
|
||||
|
||||
return unless encrypted_config
|
||||
|
||||
@@ -23,8 +23,7 @@ module Submissions
|
||||
|
||||
template = submitter.submission.template
|
||||
|
||||
cert = submitter.submission.template.account.encrypted_configs
|
||||
.find_by(key: EncryptedConfig::ESIGN_CERTS_KEY).value
|
||||
certs = Accounts.load_signing_certs(submitter.submission.template.account)
|
||||
|
||||
pdfs_index = build_pdfs_index(submitter)
|
||||
|
||||
@@ -158,7 +157,7 @@ module Submissions
|
||||
template.schema.map do |item|
|
||||
pdf = pdfs_index[item['attachment_uuid']]
|
||||
|
||||
attachment = save_signed_pdf(pdf:, submitter:, cert:, uuid: item['attachment_uuid'], name: item['name'])
|
||||
attachment = save_signed_pdf(pdf:, submitter:, certs:, uuid: item['attachment_uuid'], name: item['name'])
|
||||
|
||||
image_pdfs << pdf if original_documents.find { |a| a.uuid == item['attachment_uuid'] }.image?
|
||||
|
||||
@@ -176,7 +175,7 @@ module Submissions
|
||||
save_signed_pdf(
|
||||
pdf: images_pdf,
|
||||
submitter:,
|
||||
cert:,
|
||||
certs:,
|
||||
uuid: images_pdf_uuid(original_documents.select(&:image?)),
|
||||
name: template.name
|
||||
)
|
||||
@@ -185,16 +184,15 @@ module Submissions
|
||||
end
|
||||
# rubocop:enable Metrics
|
||||
|
||||
def save_signed_pdf(pdf:, submitter:, cert:, uuid:, name:)
|
||||
def save_signed_pdf(pdf:, submitter:, certs:, uuid:, name:)
|
||||
io = StringIO.new
|
||||
|
||||
pdf.trailer.info[:Creator] = INFO_CREATOR
|
||||
|
||||
pdf.sign(io, reason: format(SIGN_REASON, email: submitter.email),
|
||||
certificate: OpenSSL::X509::Certificate.new(cert['cert']),
|
||||
key: OpenSSL::PKey::RSA.new(cert['key']),
|
||||
certificate_chain: [OpenSSL::X509::Certificate.new(cert['sub_ca']),
|
||||
OpenSSL::X509::Certificate.new(cert['root_ca'])])
|
||||
certificate: certs[:cert],
|
||||
key: certs[:key],
|
||||
certificate_chain: [certs[:sub_ca], certs[:root_ca]])
|
||||
|
||||
ActiveStorage::Attachment.create!(
|
||||
uuid:,
|
||||
|
||||
Reference in New Issue
Block a user