Working on issue #689 - Default states and priorites of OTRS won't get used.

This commit is contained in:
Thorsten Eckel 2017-02-14 18:44:14 +01:00
parent 37e98b1a81
commit ef1da2a22e
7 changed files with 204 additions and 0 deletions

View file

@ -9,6 +9,11 @@ module Import
diff
end
def diff?
return true if @diff
false
end
private
def diff_import_possible?
@ -20,6 +25,8 @@ module Import
def diff
log 'Start diff...'
@diff = true
check_import_mode
updateable_objects

View file

@ -2,6 +2,32 @@ module Import
module OTRS
module PriorityFactory
extend Import::Factory
# rubocop:disable Style/ModuleFunction
extend self
def import_loop(records, *_args, &import_block)
super
update_attribute_settings
end
def update_attribute_settings
return if Import::OTRS.diff?
update_attribute
end
def update_attribute
priority = ::Ticket::Priority.find_by(
name: Import::OTRS::SysConfigFactory.postmaster_default_lookup(:priority_default_create),
active: true
)
return if !priority
priority.default_create = true
priority.callback_loop = true
priority.save
end
end
end
end

View file

@ -20,6 +20,48 @@ module Import
def import_loop(records, *_args, &import_block)
super
update_attribute_settings
end
def update_attribute_settings
return if Import::OTRS.diff?
update_attribute
update_ticket_attributes
end
def update_attribute
update_default_create
update_default_follow_up
end
def update_default_create
state = ::Ticket::State.find_by(
name: Import::OTRS::SysConfigFactory.postmaster_default_lookup(:state_default_create),
active: true
)
return if !state
state.default_create = true
state.callback_loop = true
state.save
end
def update_default_follow_up
state = ::Ticket::State.find_by(
name: Import::OTRS::SysConfigFactory.postmaster_default_lookup(:state_default_follow_up),
active: true
)
return if !state
state.default_follow_up = true
state.callback_loop = true
state.save
end
def update_ticket_attributes
update_ticket_state
update_ticket_pending_time
end

View file

@ -9,9 +9,15 @@ module Import
settings.each do |setting|
next if direct_copy?(setting)
next if number_generator?(setting)
next if postmaster_default?(setting)
end
end
def postmaster_default_lookup(key)
@postmaster_defaults ||= {}
@postmaster_defaults[key]
end
private
def direct_settings
@ -46,6 +52,22 @@ module Import
true
end
def postmaster_default?(setting)
relevant_configs = %w(PostmasterDefaultPriority PostmasterDefaultState PostmasterFollowUpState)
return false if !relevant_configs.include?(setting['Key'])
map = {
'PostmasterDefaultPriority' => :priority_default_create,
'PostmasterDefaultState' => :state_default_create,
'PostmasterFollowUpState' => :state_default_follow_up,
}
@postmaster_defaults ||= {}
@postmaster_defaults[ map[setting['Key']] ] = setting['Value']
true
end
end
end
end

View file

@ -12,4 +12,32 @@ RSpec.describe Import::OTRS::PriorityFactory do
expect(::Import::OTRS::Priority).to receive(:new).with(import_data)
described_class.import([import_data])
end
it 'sets default create Priority' do
priority = ::Ticket::Priority.first
priority.default_create = false
priority.callback_loop = true
priority.save
expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:priority_default_create).and_return(priority.name)
described_class.update_attribute_settings
priority.reload
expect(priority.default_create).to be true
end
it "doesn't set default create Priority in diff import" do
priority = ::Ticket::Priority.first
priority.default_create = false
priority.callback_loop = true
priority.save
expect(Import::OTRS).to receive(:diff?).and_return(true)
described_class.update_attribute_settings
priority.reload
expect(priority.default_create).to be false
end
end

View file

@ -1,6 +1,8 @@
require 'rails_helper'
require 'import/transaction_factory_examples'
RSpec::Matchers.define_negated_matcher :not_change, :change
RSpec.describe Import::OTRS::StateFactory do
it_behaves_like 'Import::TransactionFactory'
@ -45,4 +47,65 @@ RSpec.describe Import::OTRS::StateFactory do
ticket_pending_time.data_option
}
end
it "doesn't update ObjectManager Ticket state_id and pending_time filter in diff import" do
ticket_state_id = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'state_id',
)
ticket_pending_time = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'pending_time',
)
expect(Import::OTRS).to receive(:diff?).and_return(true)
expect {
described_class.update_attribute_settings
# sync changes
ticket_state_id.reload
ticket_pending_time.reload
}.to not_change {
ticket_state_id.data_option
}.and not_change {
ticket_state_id.screens
}.and not_change {
ticket_pending_time.data_option
}
end
it 'sets default create and update State' do
state = ::Ticket::State.first
state.default_create = false
state.default_follow_up = false
state.callback_loop = true
state.save
expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_create).and_return(state.name)
expect(Import::OTRS::SysConfigFactory).to receive(:postmaster_default_lookup).with(:state_default_follow_up).and_return(state.name)
described_class.update_attribute
state.reload
expect(state.default_create).to be true
expect(state.default_follow_up).to be true
end
it "doesn't set default create and update State in diff import" do
state = ::Ticket::State.first
state.default_create = false
state.default_follow_up = false
state.callback_loop = true
state.save
expect(Import::OTRS).to receive(:diff?).and_return(true)
described_class.update_attribute_settings
state.reload
expect(state.default_create).to be false
expect(state.default_follow_up).to be false
end
end

View file

@ -3,4 +3,20 @@ require 'import/import_factory_examples'
RSpec.describe Import::OTRS::SysConfigFactory do
it_behaves_like 'Import factory'
it 'stores default postmaster values' do
value = 'new'
settings = [
{
'Key' => 'PostmasterDefaultState',
'Value' => value
}
]
described_class.import(settings)
expect(described_class.postmaster_default_lookup(:state_default_create)).to eq(value)
end
end