Fixes #2455 - Assign Follow ups has no affect.
This commit is contained in:
parent
25178b27b8
commit
f862f7ac5d
6 changed files with 152 additions and 0 deletions
18
app/models/channel/filter/follow_up_assignment.rb
Normal file
18
app/models/channel/filter/follow_up_assignment.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
module Channel::Filter::FollowUpAssignment
|
||||
|
||||
def self.run(_channel, mail, _transaction_params)
|
||||
return if !mail[:'x-zammad-ticket-id']
|
||||
|
||||
ticket = Ticket.lookup(id: mail[:'x-zammad-ticket-id'])
|
||||
|
||||
return if ticket.blank?
|
||||
return if ticket.state.state_type.name != 'closed'
|
||||
return if ticket.group.follow_up_assignment
|
||||
|
||||
mail[:'x-zammad-ticket-followup-owner'] = User.lookup(id: 1).login
|
||||
|
||||
true
|
||||
end
|
||||
end
|
22
db/migrate/20210823112140_issue_2455_follow_up_assignment.rb
Normal file
22
db/migrate/20210823112140_issue_2455_follow_up_assignment.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
class Issue2455FollowUpAssignment < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
# return if it's a new setup
|
||||
return if !Setting.exists?(name: 'system_init_done')
|
||||
|
||||
Group.where(follow_up_assignment: false).find_each do |group|
|
||||
group.update(follow_up_assignment: true)
|
||||
end
|
||||
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Defines postmaster filter.',
|
||||
name: '0009_postmaster_filter_follow_up_assignment',
|
||||
area: 'Postmaster::PreFilter',
|
||||
description: 'Defines postmaster filter to set the owner (based on group follow up assignment).',
|
||||
options: {},
|
||||
state: 'Channel::Filter::FollowUpAssignment',
|
||||
frontend: false
|
||||
)
|
||||
end
|
||||
end
|
|
@ -3418,6 +3418,15 @@ Setting.create_if_not_exists(
|
|||
state: 'Channel::Filter::FollowUpMerged',
|
||||
frontend: false
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Defines postmaster filter.',
|
||||
name: '0009_postmaster_filter_follow_up_assignment',
|
||||
area: 'Postmaster::PreFilter',
|
||||
description: 'Defines postmaster filter to set the owner (based on group follow up assignment).',
|
||||
options: {},
|
||||
state: 'Channel::Filter::FollowUpAssignment',
|
||||
frontend: false
|
||||
)
|
||||
Setting.create_if_not_exists(
|
||||
title: 'Defines postmaster filter.',
|
||||
name: '0011_postmaster_sender_based_on_reply_to',
|
||||
|
|
11
spec/db/migrate/issue_2455_follow_up_assignment_spec.rb
Normal file
11
spec/db/migrate/issue_2455_follow_up_assignment_spec.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Issue2455FollowUpAssignment, type: :db_migration do
|
||||
let!(:group) { create(:group, follow_up_assignment: false) }
|
||||
|
||||
it 'sets groups to follow_up_assignment true' do
|
||||
expect { migrate }.to change { group.reload.follow_up_assignment }.to(true)
|
||||
end
|
||||
end
|
|
@ -902,6 +902,28 @@ RSpec.describe Channel::EmailParser, type: :model do
|
|||
expect { described_class.new.process({}, raw_mail) }
|
||||
.to change { ticket.reload.state.name }.to('open')
|
||||
end
|
||||
|
||||
context 'when group has follow_up_assignment true' do
|
||||
let(:group) { create(:group, follow_up_assignment: true) }
|
||||
let(:agent) { create(:agent, groups: [group]) }
|
||||
let(:ticket) { create(:ticket, state_name: 'closed', owner: agent, group: group) }
|
||||
|
||||
it 'does not change the owner' do
|
||||
expect { described_class.new.process({}, raw_mail) }
|
||||
.not_to change { ticket.reload.owner.login }
|
||||
end
|
||||
end
|
||||
|
||||
context 'when group has follow_up_assignment false' do
|
||||
let(:group) { create(:group, follow_up_assignment: false) }
|
||||
let(:agent) { create(:agent, groups: [group]) }
|
||||
let(:ticket) { create(:ticket, state_name: 'closed', owner: agent, group: group) }
|
||||
|
||||
it 'does change the owner' do
|
||||
expect { described_class.new.process({}, raw_mail) }
|
||||
.to change { ticket.reload.owner.login }.to eq(User.find(1).login)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
70
spec/models/channel/filter/follow_up_assignment_spec.rb
Normal file
70
spec/models/channel/filter/follow_up_assignment_spec.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Channel::Filter::FollowUpAssignment, type: :channel_filter do
|
||||
|
||||
context 'with group follow_up_assignment true' do
|
||||
let(:group) { create(:group, follow_up_assignment: true) }
|
||||
|
||||
context 'when ticket closed' do
|
||||
let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'closed')) }
|
||||
|
||||
it 'does not change the owner' do
|
||||
mail = {
|
||||
'x-zammad-ticket-id': ticket.id
|
||||
}
|
||||
|
||||
filter(mail)
|
||||
|
||||
expect(mail[:'x-zammad-ticket-followup-owner']).to be nil
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ticket open' do
|
||||
let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'open')) }
|
||||
|
||||
it 'does not change the owner' do
|
||||
mail = {
|
||||
'x-zammad-ticket-id': ticket.id
|
||||
}
|
||||
|
||||
filter(mail)
|
||||
|
||||
expect(mail[:'x-zammad-ticket-followup-owner']).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with group follow_up_assignment false' do
|
||||
let(:group) { create(:group, follow_up_assignment: false) }
|
||||
|
||||
context 'when ticket closed' do
|
||||
let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'closed')) }
|
||||
|
||||
it 'does change the owner' do
|
||||
mail = {
|
||||
'x-zammad-ticket-id': ticket.id
|
||||
}
|
||||
|
||||
filter(mail)
|
||||
|
||||
expect(mail[:'x-zammad-ticket-followup-owner']).to eq(User.lookup(id: 1).login)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when ticket open' do
|
||||
let(:ticket) { create(:ticket, group: group, state: Ticket::State.find_by(name: 'open')) }
|
||||
|
||||
it 'does not change the owner' do
|
||||
mail = {
|
||||
'x-zammad-ticket-id': ticket.id
|
||||
}
|
||||
|
||||
filter(mail)
|
||||
|
||||
expect(mail[:'x-zammad-ticket-followup-owner']).to be nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue