chore: Fix emails being sent with the wrong translations (#2236)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
This commit is contained in:
Sojan Jose
2021-06-08 22:45:01 +05:30
committed by GitHub
parent 67ce6f5704
commit 1bf7227843
15 changed files with 75 additions and 38 deletions

View File

@@ -38,6 +38,8 @@ class Api::V1::Accounts::AgentsController < Api::V1::Accounts::BaseController
@user = User.find_by(email: new_agent_params[:email])
end
# TODO: move this to a builder and combine the save account user method into a builder
# ensure the account user association is also created in a single transaction
def create_user
return if @user

View File

@@ -41,7 +41,9 @@ class Api::V1::Accounts::ConversationsController < Api::V1::Accounts::BaseContro
end
def transcript
ConversationReplyMailer.conversation_transcript(@conversation, params[:email])&.deliver_later if params[:email].present?
render json: { error: 'email param missing' }, status: :unprocessable_entity and return if params[:email].blank?
ConversationReplyMailer.with(account: @conversation.account).conversation_transcript(@conversation, params[:email])&.deliver_later
head :ok
end

View File

@@ -23,7 +23,7 @@ class Api::V1::Widget::ConversationsController < Api::V1::Widget::BaseController
def transcript
if permitted_params[:email].present? && conversation.present?
ConversationReplyMailer.conversation_transcript(
ConversationReplyMailer.with(account: conversation.account).conversation_transcript(
conversation,
permitted_params[:email]
)&.deliver_later

View File

@@ -65,6 +65,7 @@ class ApplicationMailer < ActionMailer::Base
end
def ensure_current_account(account)
Current.reset
Current.account = account if account.present?
end

View File

@@ -36,7 +36,9 @@ module Reauthorizable
# could used to manually prompt reauthorization if auth scope changes
def prompt_reauthorization!
::Redis::Alfred.set(reauthorization_required_key, true)
AdministratorNotifications::ChannelNotificationsMailer.slack_disconnect(account)&.deliver_later if (is_a? Integrations::Hook) && slack?
return unless (is_a? Integrations::Hook) && slack?
AdministratorNotifications::ChannelNotificationsMailer.with(account: account).slack_disconnect(account)&.deliver_later
end
# call this after you successfully Reauthorized the object in UI

View File

@@ -91,7 +91,7 @@ class User < ApplicationRecord
scope :order_by_full_name, -> { order('lower(name) ASC') }
def send_devise_notification(notification, *args)
devise_mailer.send(notification, self, *args).deliver_later
devise_mailer.with(account: Current.account).send(notification, self, *args).deliver_later
end
def set_password_and_uid

View File

@@ -43,12 +43,12 @@ class ::EmailTemplates::DbResolverService < ActionView::Resolver
handler = ActionView::Template.registered_template_handler(:liquid)
template_details = {
locals: [],
format: Mime['html'].to_sym,
updated_at: @db_template.updated_at,
virtual_path: virtual_path(path, partial)
}
[ActionView::Template.new(@db_template.body, "DB Template - #{@db_template.id}", handler, template_details)]
[ActionView::Template.new(@db_template.body, "DB Template - #{@db_template.id}", handler, **template_details)]
end
private

View File

@@ -1,7 +1,8 @@
<p>Welcome, <%= @resource.name %>!</p>
<% if @resource&.inviter.present? %>
<p><%= @resource.inviter.name %>, with <%= @resource.inviter.account.name %>, has invited you to try out Chatwoot! </p>
<% account_user = @resource&.account_users&.first %>
<% if account_user&.inviter.present? %>
<p><%= account_user.inviter.name %>, with <%= account_user.account.name %>, has invited you to try out Chatwoot! </p>
<% end %>
<p>You can confirm your account email through the link below:</p>

View File

@@ -8,9 +8,9 @@ class ConversationReplyEmailWorker
# send the email
if @conversation.messages.incoming&.last&.content_type == 'incoming_email' || email_inbox?
ConversationReplyMailer.reply_without_summary(@conversation, queued_time).deliver_later
ConversationReplyMailer.with(account: @conversation.account).reply_without_summary(@conversation, queued_time).deliver_later
else
ConversationReplyMailer.reply_with_summary(@conversation, queued_time).deliver_later
ConversationReplyMailer.with(account: @conversation.account).reply_with_summary(@conversation, queued_time).deliver_later
end
# delete the redis set from the first new message on the conversation