From ae4c601d1c85893c9e0d179bc322b42bbb5cd1e0 Mon Sep 17 00:00:00 2001 From: Rolf Schmidt Date: Thu, 1 Apr 2021 08:20:00 +0100 Subject: [PATCH] Fixes #3489 - mention in email body breaks email parsing. --- app/models/ticket/article.rb | 1 + spec/models/channel/email_parser_spec.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/models/ticket/article.rb b/app/models/ticket/article.rb index 2d75686fb..80429d63b 100644 --- a/app/models/ticket/article.rb +++ b/app/models/ticket/article.rb @@ -336,6 +336,7 @@ returns end return if mention_user_ids.blank? + return if ApplicationHandleInfo.postmaster? && !MentionPolicy.new(updated_by, Mention.new).create? raise "User #{updated_by_id} has no permission to mention other Users!" if !MentionPolicy.new(updated_by, Mention.new).create? user_ids = User.where(id: mention_user_ids).pluck(:id) diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb index fdda001a6..080431fe3 100644 --- a/spec/models/channel/email_parser_spec.rb +++ b/spec/models/channel/email_parser_spec.rb @@ -234,6 +234,24 @@ RSpec.describe Channel::EmailParser, type: :model do end end end + + context 'Mentions:' do + let(:agent) { create(:agent) } + let(:raw_mail) { <<~RAW.chomp } + From: foo@bar.com + To: baz@qux.net + Subject: Foo + + Lorem ipsum dolor agent + RAW + + it 'creates a ticket and article without mentions and no exception raised' do + expect { described_class.new.process({}, raw_mail) } + .to change(Ticket, :count).by(1) + .and change(Ticket::Article, :count).by_at_least(1) + .and not_change(Mention, :count) + end + end end describe 'associating emails to existing tickets' do