Files
leadchat/app/mailers/application_mailer.rb
Vishnu Narayanan b1ec67d110 chore: upgrade ruby to 3.1.3 (#5555)
* chore: update to ruby 3.1.3

* chore: ping docker version to alpine3.16 for nodev16.x

Starting with Node 17, nodejs switched to OpenSSL3. The docker builds
are installing node18.xx with alpine-3.1.3.

From Node.js 17's announcement post:

    If you hit an ERR_OSSL_EVP_UNSUPPORTED error in your application
with Node.js 17, it’s likely that your application or a module you’re
using is attempting to use an algorithm or key size which is no longer
allowed by default with OpenSSL 3.0. A new command-line option,
--openssl-legacy-provider, has been added to revert to the legacy
provider as a temporary workaround for these tightened restrictions.

Looks like a webpack issue. This is fixed in webpacl 5+ and we are on
webpack4 at the moment.
Solutions

    Upgrade webpack.
    Pin nodejs version to be 16.x.x
    Use  --openssl-legacy-provider as a workaround.

Pin docker version to alpine3.16 branch to have node16.x by default

ref:
https://github.com/chatwoot/chatwoot/pull/5555#issuecomment-1379778532

* chore: update webmock

* chore: fix ruby gem path in dockerfile

* chore: switch to node16 in circleci

* chore: update ruby version in linux installer script

* chore: update ruby version in linux installer script

* chore: fix circleci

* chore: fix circleci

* feat: upgrade node version to 16.x in linux installer

* chore: update systemd files

Co-authored-by: Sojan Jose <sojan@chatwoot.com>
2023-01-24 23:55:07 +05:30

80 lines
2.4 KiB
Ruby

class ApplicationMailer < ActionMailer::Base
include ActionView::Helpers::SanitizeHelper
default from: ENV.fetch('MAILER_SENDER_EMAIL', 'Chatwoot <accounts@chatwoot.com>')
before_action { ensure_current_account(params.try(:[], :account)) }
around_action :switch_locale
layout 'mailer/base'
# Fetch template from Database if available
# Order: Account Specific > Installation Specific > Fallback to file
prepend_view_path ::EmailTemplate.resolver
append_view_path Rails.root.join('app/views/mailers')
helper :frontend_urls
helper do
def global_config
@global_config ||= GlobalConfig.get('BRAND_NAME', 'BRAND_URL')
end
end
rescue_from(*ExceptionList::SMTP_EXCEPTIONS, with: :handle_smtp_exceptions)
def smtp_config_set_or_development?
ENV.fetch('SMTP_ADDRESS', nil).present? || Rails.env.development?
end
private
def handle_smtp_exceptions(message)
Rails.logger.warn 'Failed to send Email'
Rails.logger.error "Exception: #{message}"
end
def send_mail_with_liquid(*args)
mail(*args) do |format|
# explored sending a multipart email containing both text type and html
# parsing the html with nokogiri will remove the links as well
# might also remove tags like b,li etc. so lets rethink about this later
# format.text { Nokogiri::HTML(render(layout: false)).text }
format.html { render }
end
end
def liquid_droppables
# Merge additional objects into this in your mailer
# liquid template handler converts these objects into drop objects
{
account: Current.account,
user: @agent,
conversation: @conversation,
inbox: @conversation&.inbox
}
end
def liquid_locals
# expose variables you want to be exposed in liquid
{
global_config: GlobalConfig.get('BRAND_NAME', 'BRAND_URL'),
action_url: @action_url
}
end
def locale_from_account(account)
return unless account
I18n.available_locales.map(&:to_s).include?(account.locale) ? account.locale : nil
end
def ensure_current_account(account)
Current.reset
Current.account = account if account.present?
end
def switch_locale(&)
locale ||= locale_from_account(Current.account)
locale ||= I18n.default_locale
# ensure locale won't bleed into other requests
# https://guides.rubyonrails.org/i18n.html#managing-the-locale-across-requests
I18n.with_locale(locale, &)
end
end