Working on issue #689 - Ticket state_id and pending_time attributes won't get synced with new OTRS data.

This commit is contained in:
Thorsten Eckel 2017-02-14 09:59:41 +01:00
parent c1d663e4e4
commit 37e98b1a81
11 changed files with 192 additions and 0 deletions

View file

@ -17,6 +17,71 @@ module Import
state.save
}
end
def import_loop(records, *_args, &import_block)
super
update_ticket_state
update_ticket_pending_time
end
def update_ticket_state
agent_new = ::Ticket::State.where(
state_type_id: ::Ticket::StateType.where.not(name: %w(merged removed))
).pluck(:id)
agent_edit = ::Ticket::State.where(
state_type_id: ::Ticket::StateType.where.not(name: %w(new merged removed))
).pluck(:id)
customer_new = ::Ticket::State.where(
state_type_id: ::Ticket::StateType.where.not(name: %w(new closed))
).pluck(:id)
customer_edit = ::Ticket::State.where(
state_type_id: ::Ticket::StateType.where.not(name: %w(open closed))
).pluck(:id)
ticket_state_id = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'state_id',
)
ticket_state_id[:data_option][:filter] = agent_new
ticket_state_id[:screens][:create_middle][:Customer] = customer_new
ticket_state_id[:screens][:edit][:Agent] = agent_edit
ticket_state_id[:screens][:edit][:Customer] = customer_edit
update_ticket_attribute(ticket_state_id)
end
def update_ticket_pending_time
pending_state_ids = ::Ticket::State.where(
state_type_id: ::Ticket::StateType.where(name: ['pending reminder', 'pending action'])
).pluck(:id)
ticket_pending_time = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'pending_time',
)
ticket_pending_time[:data_option][:required_if][:state_id] = pending_state_ids
ticket_pending_time[:data_option][:required_if][:state_id] = pending_state_ids
update_ticket_attribute(ticket_pending_time)
end
def update_ticket_attribute(attribute)
::ObjectManager::Attribute.add(
object_lookup_id: attribute[:object_lookup_id],
name: attribute[:name],
display: attribute[:display],
data_type: attribute[:data_type],
data_option: attribute[:data_option],
active: attribute[:active],
screens: attribute[:screens],
force: true # otherwise _id as a name is not permitted
)
end
end
end
end

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "2",
"ValidID": "1",
"TypeID": "3",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "closed",
"Comment": "Ticket is closed successful.",
"Name": "closed successful"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "3",
"ValidID": "1",
"TypeID": "3",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "closed",
"Comment": "Ticket is closed unsuccessful.",
"Name": "closed unsuccessful"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "9",
"ValidID": "1",
"TypeID": "7",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "merged",
"Comment": "State for merged tickets.",
"Name": "merged"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "1",
"ValidID": "1",
"TypeID": "1",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "new",
"Comment": "New ticket created by customer.",
"Name": "new"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "4",
"ValidID": "1",
"TypeID": "2",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "open",
"Comment": "Open tickets.",
"Name": "open"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "8",
"ValidID": "1",
"TypeID": "5",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "pending auto",
"Comment": "Ticket is pending for automatic close.",
"Name": "pending auto close-"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "7",
"ValidID": "1",
"TypeID": "5",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "pending auto",
"Comment": "Ticket is pending for automatic close.",
"Name": "pending auto close+"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "6",
"ValidID": "1",
"TypeID": "4",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "pending reminder",
"Comment": "Ticket is pending for agent reminder.",
"Name": "pending reminder"
}

View file

@ -0,0 +1,10 @@
{
"ChangeTime": "2014-04-28 10:53:18",
"ID": "5",
"ValidID": "1",
"TypeID": "6",
"CreateTime": "2014-04-28 10:53:18",
"TypeName": "removed",
"Comment": "Customer removed ticket.",
"Name": "removed"
}

View file

@ -8,4 +8,41 @@ RSpec.describe Import::OTRS::StateFactory do
expect(described_class).to receive(:backup)
described_class.pre_import_hook([])
end
def load_state_json(file)
json_fixture("import/otrs/state/#{file}")
end
it 'updates ObjectManager Ticket state_id and pending_time filter' do
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
ticket_state_id = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'state_id',
)
ticket_pending_time = ::ObjectManager::Attribute.get(
object: 'Ticket',
name: 'pending_time',
)
expect {
described_class.import(state_backend_param)
# sync changes
ticket_state_id.reload
ticket_pending_time.reload
}.to change {
ticket_state_id.data_option
}.and change {
ticket_state_id.screens
}.and change {
ticket_pending_time.data_option
}
end
end