From 2ab17db3e42b68665ca49b2c6219550fce59819a Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 8 Oct 2019 15:13:27 +0200 Subject: [PATCH] Fixes #2768 - Unable to process email where group has option follow_up_possible: 'new_ticket' and arriving email has no subject header. --- app/models/ticket/subject.rb | 2 + .../filter/follow_up_possible_check_spec.rb | 37 ++++++++++++++ spec/models/ticket/subject_spec.rb | 51 +++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 spec/models/channel/filter/follow_up_possible_check_spec.rb create mode 100644 spec/models/ticket/subject_spec.rb diff --git a/app/models/ticket/subject.rb b/app/models/ticket/subject.rb index 12a307be3..2ab98943c 100644 --- a/app/models/ticket/subject.rb +++ b/app/models/ticket/subject.rb @@ -50,6 +50,8 @@ returns =end def subject_clean(subject) + return '' if subject.blank? + ticket_hook = Setting.get('ticket_hook') ticket_hook_divider = Setting.get('ticket_hook_divider') ticket_subject_size = Setting.get('ticket_subject_size') diff --git a/spec/models/channel/filter/follow_up_possible_check_spec.rb b/spec/models/channel/filter/follow_up_possible_check_spec.rb new file mode 100644 index 000000000..35ef3b945 --- /dev/null +++ b/spec/models/channel/filter/follow_up_possible_check_spec.rb @@ -0,0 +1,37 @@ +require 'rails_helper' + +RSpec.describe Channel::Filter::FollowUpPossibleCheck, type: :channel_filter do + + context 'new_ticket follow_up_possible for group' do + + let(:group) { create(:group, follow_up_possible: 'new_ticket') } + + context 'ticket closed' do + let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'closed')) } + + it 'prevents follow up' do + mail = { + 'x-zammad-ticket-id': ticket.id + } + + filter(mail) + + expect(mail[:'x-zammad-ticket-id']).not_to eq(ticket.id) + end + end + + context 'ticket open' do + let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'new')) } + + it 'allows follow up' do + mail = { + 'x-zammad-ticket-id': ticket.id + } + + filter(mail) + + expect(mail[:'x-zammad-ticket-id']).to eq(ticket.id) + end + end + end +end diff --git a/spec/models/ticket/subject_spec.rb b/spec/models/ticket/subject_spec.rb new file mode 100644 index 000000000..a7e2ecc7c --- /dev/null +++ b/spec/models/ticket/subject_spec.rb @@ -0,0 +1,51 @@ +require 'rails_helper' + +RSpec.describe Ticket::Subject do + let(:ticket) { create(:ticket) } + + describe '.subject_build' do + it 'build subject based on new title' do + expect(ticket.subject_build('other title')).to eq("other title [Ticket##{ticket.number}]") + end + it 'build subject based on new title with ticket_hook_position left' do + Setting.set('ticket_hook_position', 'left') + expect(ticket.subject_build('other title')).to eq("[Ticket##{ticket.number}] other title") + end + + it 'build subject based on new title without ticket_hook_position' do + Setting.set('ticket_hook_position', '') + expect(ticket.subject_build('other title')).to eq('other title') + end + it 'build subject based with forward argument' do + expect(ticket.subject_build('other title', 'forward')).to eq("FWD: other title [Ticket##{ticket.number}]") + end + it 'build subject based with reply argument' do + expect(ticket.subject_build('other title', 'reply')).to eq("RE: other title [Ticket##{ticket.number}]") + end + end + + describe '.subject_clean' do + it 'cleanup subject with undefined string' do + expect(ticket.subject_clean(nil)).to eq('') + end + it 'cleanup subject with empty string' do + expect(ticket.subject_clean('')).to eq('') + end + it 'cleanup subject with long string which need to be truncated by [...]' do + expect(ticket.subject_clean('123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890')).to eq('12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890[...]') + end + it 'cleanup subject with regular ticket#' do + expect(ticket.subject_clean("something [Ticket##{ticket.number}]")).to eq('something') + end + it 'cleanup subject with regular ticket# multiple time' do + expect(ticket.subject_clean("[Ticket##{ticket.number}] [Ticket##{ticket.number}] something [Ticket##{ticket.number}]")).to eq('something') + end + it 'cleanup subject with foreign ticket#' do + expect(ticket.subject_clean('something [Ticket#123456]')).to eq('something [Ticket#123456]') + end + it 'cleanup subject with some reply signs' do + expect(ticket.subject_clean('RE: RE: Re[5]: something [Ticket#123456]')).to eq('something [Ticket#123456]') + end + end + +end