From 1ab179f22f7d8a6891f22e2e0a43716f0dcfa4c1 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Tue, 24 Mar 2020 17:15:34 +0100 Subject: [PATCH] Fixed issue #2923 - Zammad should not inform himself. --- app/models/ticket.rb | 3 +++ spec/models/trigger_spec.rb | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/app/models/ticket.rb b/app/models/ticket.rb index ea9f48881..9f76e2231 100644 --- a/app/models/ticket.rb +++ b/app/models/ticket.rb @@ -1411,6 +1411,9 @@ result email_address_validation = EmailAddressValidation.new(recipient_email) next if !email_address_validation.valid_format? + # do not send notification if system address + next if EmailAddress.exists?(email: recipient_email.downcase) + # do not sent notifications to this recipients send_no_auto_response_reg_exp = Setting.get('send_no_auto_response_reg_exp') begin diff --git a/spec/models/trigger_spec.rb b/spec/models/trigger_spec.rb index 54516a81c..f31b5e210 100644 --- a/spec/models/trigger_spec.rb +++ b/spec/models/trigger_spec.rb @@ -293,6 +293,54 @@ RSpec.describe Trigger, type: :model do end end end + + context 'with article last sender equals system address' do + let!(:ticket) { create(:ticket) } + let(:perform) do + { + 'notification.email' => { + 'recipient' => 'article_last_sender', + 'subject' => 'foo last sender', + 'body' => 'some body with >snip<#{article.body_as_html}>/snip<', # rubocop:disable Lint/InterpolationCheck + } + } + end + let(:condition) do + { 'ticket.state_id' => { 'operator' => 'is', 'value' => Ticket::State.all.pluck(:id) } } + end + let!(:system_address) do + create(:email_address) + end + + context 'article with from equal to the a system address' do + let!(:article) do + create(:ticket_article, + ticket: ticket, + from: system_address.email,) + end + + it 'does not trigger because of the last article is created my system address' do + expect { Observer::Transaction.commit }.to change { ticket.reload.articles.count }.by(0) + expect(Ticket::Article.where(ticket: ticket).last.subject).not_to eq('foo last sender') + expect(Ticket::Article.where(ticket: ticket).last.to).not_to eq(system_address.email) + end + end + + context 'article with reply_to equal to the a system address' do + let!(:article) do + create(:ticket_article, + ticket: ticket, + from: system_address.email, + reply_to: system_address.email,) + end + + it 'does not trigger because of the last article is created my system address' do + expect { Observer::Transaction.commit }.to change { ticket.reload.articles.count }.by(0) + expect(Ticket::Article.where(ticket: ticket).last.subject).not_to eq('foo last sender') + expect(Ticket::Article.where(ticket: ticket).last.to).not_to eq(system_address.email) + end + end + end end context 'with pre condition current_user.id' do