From a75f49ddcc57239ca0da88d97fe852ccf8a477dc Mon Sep 17 00:00:00 2001 From: sony-mathew Date: Sun, 10 May 2020 13:14:57 +0530 Subject: [PATCH 1/3] Bug: Fixed private note being sent to customer (#837) --- app/mailers/conversation_reply_mailer.rb | 4 ++-- app/models/message.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/mailers/conversation_reply_mailer.rb b/app/mailers/conversation_reply_mailer.rb index 4b41d81db..0b0b75669 100644 --- a/app/mailers/conversation_reply_mailer.rb +++ b/app/mailers/conversation_reply_mailer.rb @@ -9,8 +9,8 @@ class ConversationReplyMailer < ApplicationMailer @contact = @conversation.contact @agent = @conversation.assignee - recap_messages = @conversation.messages.where('created_at < ?', message_queued_time).order(created_at: :asc).last(10) - new_messages = @conversation.messages.where('created_at >= ?', message_queued_time) + recap_messages = @conversation.messages.chat.where('created_at < ?', message_queued_time).last(10) + new_messages = @conversation.messages.chat.where('created_at >= ?', message_queued_time) @messages = recap_messages + new_messages @messages = @messages.select(&:reportable?) diff --git a/app/models/message.rb b/app/models/message.rb index 99572a751..47ea8c425 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -59,7 +59,7 @@ class Message < ApplicationRecord # .succ is a hack to avoid https://makandracards.com/makandra/1057-why-two-ruby-time-objects-are-not-equal-although-they-appear-to-be scope :unread_since, ->(datetime) { where('EXTRACT(EPOCH FROM created_at) > (?)', datetime.to_i.succ) } - scope :chat, -> { where.not(message_type: :activity).where.not(private: true) } + scope :chat, -> { where.not(message_type: :activity).where(private: false) } default_scope { order(created_at: :asc) } belongs_to :account From 1a123a4f566e3b39563fee5c0f66a80f47a27693 Mon Sep 17 00:00:00 2001 From: sony-mathew Date: Sun, 10 May 2020 14:03:11 +0530 Subject: [PATCH 2/3] Spec for private messages not to be included in mails (#837) --- spec/mailers/conversation_reply_mailer_spec.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index f6d61a577..21ec9addb 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -12,15 +12,31 @@ RSpec.describe ConversationReplyMailer, type: :mailer do allow(class_instance).to receive(:smtp_config_set_or_development?).and_return(true) end - context 'when custom domain and email is not enabled' do + context 'with all mails' do let(:conversation) { create(:conversation, assignee: agent) } let(:message) { create(:message, conversation: conversation) } + let(:private_message) { create(:message, content: 'This is a private message', private: true, conversation: conversation) } let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } it 'renders the subject' do expect(mail.subject).to eq("[##{message.conversation.display_id}] #{message.content.truncate(30)}") end + it 'not have private notes' do + # make the message private + private_message.private = true + private_message.save + + expect(mail.body.decoded).not_to include(private_message.content) + expect(mail.body.decoded).to include(message.content) + end + end + + context 'when custom domain and email is not enabled' do + let(:conversation) { create(:conversation, assignee: agent) } + let(:message) { create(:message, conversation: conversation) } + let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } + it 'renders the receiver email' do expect(mail.to).to eq([message&.conversation&.contact&.email]) end From 35b2bdd074fc3d1960a816db280f2b82ab53b919 Mon Sep 17 00:00:00 2001 From: sony-mathew Date: Sun, 10 May 2020 14:08:17 +0530 Subject: [PATCH 3/3] Removed the un-neccessary attribute from msg create factory --- spec/mailers/conversation_reply_mailer_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/mailers/conversation_reply_mailer_spec.rb b/spec/mailers/conversation_reply_mailer_spec.rb index 21ec9addb..cb49dbe22 100644 --- a/spec/mailers/conversation_reply_mailer_spec.rb +++ b/spec/mailers/conversation_reply_mailer_spec.rb @@ -15,7 +15,7 @@ RSpec.describe ConversationReplyMailer, type: :mailer do context 'with all mails' do let(:conversation) { create(:conversation, assignee: agent) } let(:message) { create(:message, conversation: conversation) } - let(:private_message) { create(:message, content: 'This is a private message', private: true, conversation: conversation) } + let(:private_message) { create(:message, content: 'This is a private message', conversation: conversation) } let(:mail) { described_class.reply_with_summary(message.conversation, Time.zone.now).deliver_now } it 'renders the subject' do