From 54d4a87eadfd3deb17df2849be5179d8e87d0bc3 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Tue, 16 May 2017 18:11:36 +0200 Subject: [PATCH] Fixed bug #890 - Imported states from OTRS are not correctly mapped to Zammad states. --- lib/import/otrs/state_factory.rb | 12 ++++ spec/lib/import/otrs/state_factory_spec.rb | 70 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/lib/import/otrs/state_factory.rb b/lib/import/otrs/state_factory.rb index b9dcb9eec..b86501824 100644 --- a/lib/import/otrs/state_factory.rb +++ b/lib/import/otrs/state_factory.rb @@ -64,6 +64,7 @@ module Import def update_ticket_attributes update_ticket_state update_ticket_pending_time + reseed_dependent_objects end def update_ticket_state @@ -124,6 +125,17 @@ module Import force: true # otherwise _id as a name is not permitted ) end + + def reseed_dependent_objects + Overview.reseed + Trigger.reseed + Macro.reseed + + # we don't have to re-seed the ObjectManager + # Attributes since they contain the already + # imported DynamicFields which will be lost + ObjectManager::Attribute.seed + end end end end diff --git a/spec/lib/import/otrs/state_factory_spec.rb b/spec/lib/import/otrs/state_factory_spec.rb index 5f425d5c8..205cfb892 100644 --- a/spec/lib/import/otrs/state_factory_spec.rb +++ b/spec/lib/import/otrs/state_factory_spec.rb @@ -108,4 +108,74 @@ RSpec.describe Import::OTRS::StateFactory do expect(state.default_create).to be false expect(state.default_follow_up).to be false end + + context 'changing Ticket::State IDs' do + + let(:state_backend_param) { + states = %w(new open merged pending_reminder pending_auto_close_p pending_auto_close_n pending_auto_close_p closed_successful closed_unsuccessful closed_successful removed) + + state_backend_param = [] + states.each do |state| + state_backend_param.push(load_state_json(state)) + end + state_backend_param + } + + it 'updates Overviews' do + name = 'My pending reached Tickets' + overview = Overview.find_by(name: name) + expect do + described_class.import(state_backend_param) + overview = Overview.find_by(name: name) + end.to change { + overview.id + }.and change { + overview.condition['ticket.state_id'][:value] + } + end + + it 'updates Macros' do + name = 'Close & Tag as Spam' + macro = Macro.find_by(name: name) + expect do + described_class.import(state_backend_param) + macro = Macro.find_by(name: name) + end.to change { + macro.id + }.and change { + macro.perform['ticket.state_id'][:value] + } + end + + it 'updates Triggers' do + name = 'auto reply (on new tickets)' + trigger = Trigger.find_by(name: name) + expect do + described_class.import(state_backend_param) + trigger = Trigger.find_by(name: name) + end.to change { + trigger.id + }.and change { + trigger.condition['ticket.state_id'][:value] + } + end + + it 'updates ObjectManager::Attributes' do + + attribute = ObjectManager::Attribute.get( + object: 'Ticket', + name: 'pending_time', + ) + expect do + described_class.import(state_backend_param) + + attribute = ObjectManager::Attribute.get( + object: 'Ticket', + name: 'pending_time', + ) + end.to change { + attribute.data_option[:required_if][:state_id] + } + end + end end