Browse Source

Fixes #3489 - mention in email body breaks email parsing.

Rolf Schmidt 4 years ago
parent
commit
ae4c601d1c
2 changed files with 19 additions and 0 deletions
  1. 1 0
      app/models/ticket/article.rb
  2. 18 0
      spec/models/channel/email_parser_spec.rb

+ 1 - 0
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)

+ 18 - 0
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 <a data-mention-user-id=\"#{agent.id}\">agent</a>
+        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