Fixes #2941 - Zendesk import error
This commit is contained in:
parent
16b876e3e8
commit
dd5ca52e18
6 changed files with 57 additions and 41 deletions
|
@ -276,7 +276,6 @@ test:integration:zendesk:
|
|||
script:
|
||||
- bundle exec rake zammad:db:unseeded
|
||||
- bundle exec rails test test/integration/zendesk_import_test.rb
|
||||
allow_failure: true
|
||||
|
||||
### OTRS
|
||||
|
||||
|
|
|
@ -253,13 +253,21 @@ returns
|
|||
file.provider
|
||||
end
|
||||
|
||||
RESIZABLE_MIME_REGEXP = %r{image/(jpeg|jpg|png)}i.freeze
|
||||
|
||||
def self.resizable_mime?(input)
|
||||
input.match? RESIZABLE_MIME_REGEXP
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_previews
|
||||
return true if Setting.get('import_mode')
|
||||
|
||||
resizable = preferences.slice('Mime-Type', 'Content-Type', 'mime_type', 'content_type')
|
||||
.values.grep(%r{image/(jpeg|jpg|png)}i).any?
|
||||
resizable = preferences
|
||||
.slice('Mime-Type', 'Content-Type', 'mime_type', 'content_type')
|
||||
.values
|
||||
.any? { |mime| self.class.resizable_mime?(mime) }
|
||||
|
||||
begin
|
||||
if resizable
|
||||
|
|
|
@ -12,7 +12,7 @@ class Sequencer
|
|||
end
|
||||
|
||||
def resource_collection
|
||||
"::ZendeskAPI::#{resource_klass}".constantize.incremental_export(client, 1)
|
||||
client.send resource_klass.pluralize.underscore
|
||||
end
|
||||
|
||||
def resource_iteration
|
||||
|
|
|
@ -11,28 +11,17 @@ class Sequencer
|
|||
|
||||
def statistics_diff
|
||||
%i[Groups Users Organizations Tickets].each_with_object({}) do |object, stats|
|
||||
stats[object] = empty_diff.merge(
|
||||
total: request(object).count!
|
||||
)
|
||||
stats[object] = object_diff(object)
|
||||
end
|
||||
end
|
||||
|
||||
# the special "incremental_export" logic is needed because Zendesk
|
||||
# archives records and doesn't return them via e.g. client.tickets
|
||||
# endpoint as described here:
|
||||
# https://github.com/zammad/zammad/issues/558#issuecomment-267951351
|
||||
# Counting via the incremental_export endpoint has the limitations
|
||||
# that it returns max. 1000. That's why we need to update the total
|
||||
# number while importing in the resource loop
|
||||
def request(object)
|
||||
resource_class = "::ZendeskAPI::#{object.singularize}".safe_constantize
|
||||
if resource_class.respond_to?(:incremental_export)
|
||||
# read as: ::ZendeskAPI::Ticket.incremental_export(client, 1)
|
||||
resource_class.incremental_export(client, 1)
|
||||
else
|
||||
# read as: client.groups
|
||||
client.send(object.to_s.underscore.to_sym)
|
||||
end
|
||||
def object_diff(object)
|
||||
collection_name = object.to_s.underscore
|
||||
collection = client.send collection_name
|
||||
|
||||
empty_diff.merge(
|
||||
total: collection.count!
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -19,14 +19,25 @@ class Sequencer
|
|||
o_id: instance.id,
|
||||
data: response.body,
|
||||
filename: resource.file_name,
|
||||
preferences: {
|
||||
'Content-Type' => resource.content_type
|
||||
},
|
||||
preferences: store_preferences,
|
||||
created_by_id: 1
|
||||
)
|
||||
rescue => e
|
||||
handle_failure(e)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def store_preferences
|
||||
output = { 'Content-Type' => resource.content_type }
|
||||
|
||||
if Store.resizable_mime? resource.content_type
|
||||
output[:resizable] = true
|
||||
output[:content_preview] = true
|
||||
end
|
||||
|
||||
output
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,13 +59,13 @@ class ZendeskImportTest < ActiveSupport::TestCase
|
|||
},
|
||||
Tickets: {
|
||||
skipped: 0,
|
||||
created: 142,
|
||||
created: 141,
|
||||
updated: 1,
|
||||
unchanged: 0,
|
||||
failed: 0,
|
||||
deactivated: 0,
|
||||
sum: 143,
|
||||
total: 143
|
||||
sum: 142,
|
||||
total: 142
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,9 +78,9 @@ class ZendeskImportTest < ActiveSupport::TestCase
|
|||
assert_equal(3, Group.count, 'groups')
|
||||
assert_equal(3, Role.count, 'roles')
|
||||
assert_equal(2, Organization.count, 'organizations')
|
||||
assert_equal(143, Ticket.count, 'tickets')
|
||||
assert_equal(142, Ticket.count, 'tickets')
|
||||
assert_equal(151, Ticket::Article.count, 'ticket articles')
|
||||
assert_equal(2, Store.count, 'ticket article attachments')
|
||||
assert_equal(3, Store.count, 'ticket article attachments')
|
||||
|
||||
# TODO: Macros, Views, Automations...
|
||||
end
|
||||
|
@ -328,15 +328,14 @@ class ZendeskImportTest < ActiveSupport::TestCase
|
|||
id: 2,
|
||||
data: {
|
||||
title: 'test',
|
||||
#note: 'This is the first comment. Feel free to delete this sample ticket.',
|
||||
note: 'test email',
|
||||
note: nil,
|
||||
create_article_type_id: 1,
|
||||
create_article_sender_id: 2,
|
||||
article_count: 2,
|
||||
state_id: 3,
|
||||
group_id: 3,
|
||||
priority_id: 3,
|
||||
owner_id: 1,
|
||||
owner_id: User.find_by(login: 'bob.smith@znuny.com').id,
|
||||
customer_id: 7,
|
||||
organization_id: 2,
|
||||
test_checkbox: true,
|
||||
|
@ -350,16 +349,14 @@ class ZendeskImportTest < ActiveSupport::TestCase
|
|||
id: 3,
|
||||
data: {
|
||||
title: 'Bob Smith, here is the test ticket you requested',
|
||||
note: 'Hello! This is a Zendesk ticket. We are going to go through the basic support ticket operation in Zendesk.
|
||||
|
||||
If you\'re reading this message in your email, click the ticket number link that immediately follows the line \'You have been assigned to this t',
|
||||
note: nil,
|
||||
create_article_type_id: 10,
|
||||
create_article_sender_id: 2,
|
||||
article_count: 4,
|
||||
article_count: 5,
|
||||
state_id: 3,
|
||||
group_id: 3,
|
||||
priority_id: 1,
|
||||
owner_id: 1,
|
||||
owner_id: User.find_by(login: 'bob.smith@znuny.com').id,
|
||||
customer_id: 8,
|
||||
organization_id: nil,
|
||||
test_checkbox: false,
|
||||
|
@ -373,7 +370,7 @@ If you\'re reading this message in your email, click the ticket number link that
|
|||
id: 5,
|
||||
data: {
|
||||
title: 'Twitter',
|
||||
note: "@gabyalanisr Brandon Arely Snuppy Jaz Jerry Liz Irvig & Wera\nY Losa Otrs Yop \npero si quieres Los Que Puedas",
|
||||
note: nil,
|
||||
create_article_type_id: 6,
|
||||
create_article_sender_id: 2,
|
||||
article_count: 1,
|
||||
|
@ -389,7 +386,7 @@ If you\'re reading this message in your email, click the ticket number link that
|
|||
id: 143,
|
||||
data: {
|
||||
title: 'Basti ist cool',
|
||||
note: 'Basti ist cool',
|
||||
note: nil,
|
||||
create_article_type_id: 8,
|
||||
create_article_sender_id: 2,
|
||||
article_count: 1,
|
||||
|
@ -465,6 +462,18 @@ If you\'re reading this message in your email, click the ticket number link that
|
|||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
message_id: 538_901_840_720,
|
||||
data: {
|
||||
count: 1,
|
||||
1 => {
|
||||
preferences: {
|
||||
'Content-Type' => 'text/rtf'
|
||||
},
|
||||
filename: 'test.rtf',
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
checks.each do |check|
|
||||
|
|
Loading…
Reference in a new issue