Skip to content

Commit

Permalink
Merge branch 'develop' into rtl-refactor-9
Browse files Browse the repository at this point in the history
  • Loading branch information
iamsivin committed Feb 24, 2023
2 parents dfb336f + 76650c8 commit 1b43515
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
npx --no-install lint-staged

# lint only staged ruby files
git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop -a
git diff --name-only --cached | xargs ls -1 2>/dev/null | grep '\.rb$' | xargs bundle exec rubocop --force-exclusion -a

# stage rubocop changes to files
git diff --name-only --cached | xargs git add
2 changes: 1 addition & 1 deletion app/controllers/api/v1/widget/messages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def update
@message.update!(submitted_email: contact_email)
ContactIdentifyAction.new(
contact: @contact,
params: { email: contact_email }
params: { email: contact_email, name: contact_name }
).perform
else
@message.update!(message_update_params[:message])
Expand Down
9 changes: 8 additions & 1 deletion app/mailers/conversation_reply_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def email_reply(message)
init_conversation_attributes(message.conversation)
@message = message
reply_mail_object = prepare_mail(true)

message.update(source_id: reply_mail_object.message_id)
end

Expand Down Expand Up @@ -115,6 +114,14 @@ def from_email_with_name
end
end

def channel_email_with_name
if @conversation.assignee.present?
I18n.t('conversations.reply.channel_email.header.reply_with_name', assignee_name: assignee_name, from_email: @channel.email)
else
I18n.t('conversations.reply.channel_email.header.reply_with_inbox_name', inbox_name: @inbox.name, from_email: @channel.email)
end
end

def parse_email(email_string)
Mail::Address.new(email_string).address
end
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/conversation_reply_mailer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def email_microsoft_auth_enabled
end

def email_from
email_microsoft_auth_enabled || email_smtp_enabled ? @channel.email : from_email_with_name
email_microsoft_auth_enabled || email_smtp_enabled ? channel_email_with_name : from_email_with_name
end

def email_reply_to
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ en:
header:
from_with_name: '%{assignee_name} from %{inbox_name} <%{from_email}>'
reply_with_name: '%{assignee_name} from %{inbox_name} <reply+%{reply_email}>'
channel_email:
header:
reply_with_name: '%{assignee_name} from <%{from_email}>'
reply_with_inbox_name: '%{inbox_name} <%{from_email}>'
email_subject: "New messages on this conversation"
transcript_subject: "Conversation Transcript"
survey:
Expand Down
1 change: 1 addition & 0 deletions spec/controllers/api/v1/widget/messages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
message.reload
expect(message.submitted_email).to eq(email)
expect(message.conversation.contact.email).to eq(email)
expect(message.conversation.contact.name).to eq(email.split('@')[0])
end
end

Expand Down
11 changes: 11 additions & 0 deletions spec/mailers/conversation_reply_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,17 @@
expect(mail.delivery_method.settings[:address]).to eq 'smtp.gmail.com'
expect(mail.delivery_method.settings[:port]).to eq 587
end

it 'renders assignee name in the from address' do
mail = described_class.email_reply(message)
expect(mail['from'].value).to eq "#{conversation.assignee.available_name} from <#{smtp_email_channel.email}>"
end

it 'renders inbox name in the from address' do
conversation.update(assignee: nil)
mail = described_class.email_reply(message)
expect(mail['from'].value).to eq "#{smtp_email_channel.inbox.name} <#{smtp_email_channel.email}>"
end
end

context 'when smtp enabled for microsoft email channel' do
Expand Down

0 comments on commit 1b43515

Please sign in to comment.