From 313081e6776937b4d2a0f898fb805608336fd80d Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Mon, 30 Nov 2020 17:34:04 +0100 Subject: [PATCH] Fixes #3314 - Zendesk import fails if not supported field types are present. --- .../import/zendesk/organization_field.rb | 1 + .../sequence/import/zendesk/ticket_field.rb | 3 +- .../sequence/import/zendesk/user_field.rb | 1 + .../common/object_attribute/sanitized_name.rb | 3 ++ .../import/zendesk/object_attribute/add.rb | 9 +++--- .../object_attribute/sanitized_type.rb | 31 +++++++++++++++++++ .../import/zendesk/ticket/custom_fields.rb | 3 +- .../unit/import/zendesk/ticket_field/add.rb | 17 ---------- .../zendesk/ticket_field/sanitized_name.rb | 5 +-- 9 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 lib/sequencer/unit/import/zendesk/object_attribute/sanitized_type.rb delete mode 100644 lib/sequencer/unit/import/zendesk/ticket_field/add.rb diff --git a/lib/sequencer/sequence/import/zendesk/organization_field.rb b/lib/sequencer/sequence/import/zendesk/organization_field.rb index 718171ece..72e3b06c9 100644 --- a/lib/sequencer/sequence/import/zendesk/organization_field.rb +++ b/lib/sequencer/sequence/import/zendesk/organization_field.rb @@ -7,6 +7,7 @@ class Sequencer def self.sequence [ 'Common::ModelClass::Organization', + 'Import::Zendesk::ObjectAttribute::SanitizedType', 'Import::Zendesk::ObjectAttribute::SanitizedName', 'Import::Zendesk::ObjectAttribute::Add', ] diff --git a/lib/sequencer/sequence/import/zendesk/ticket_field.rb b/lib/sequencer/sequence/import/zendesk/ticket_field.rb index b7ad03cba..4ed980cbf 100644 --- a/lib/sequencer/sequence/import/zendesk/ticket_field.rb +++ b/lib/sequencer/sequence/import/zendesk/ticket_field.rb @@ -8,8 +8,9 @@ class Sequencer [ 'Common::ModelClass::Ticket', 'Import::Zendesk::TicketField::CheckCustom', + 'Import::Zendesk::ObjectAttribute::SanitizedType', 'Import::Zendesk::TicketField::SanitizedName', - 'Import::Zendesk::TicketField::Add', + 'Import::Zendesk::ObjectAttribute::Add', ] end end diff --git a/lib/sequencer/sequence/import/zendesk/user_field.rb b/lib/sequencer/sequence/import/zendesk/user_field.rb index b4549d1eb..54fbaa69c 100644 --- a/lib/sequencer/sequence/import/zendesk/user_field.rb +++ b/lib/sequencer/sequence/import/zendesk/user_field.rb @@ -7,6 +7,7 @@ class Sequencer def self.sequence [ 'Common::ModelClass::User', + 'Import::Zendesk::ObjectAttribute::SanitizedType', 'Import::Zendesk::ObjectAttribute::SanitizedName', 'Import::Zendesk::ObjectAttribute::Add', ] diff --git a/lib/sequencer/unit/import/common/object_attribute/sanitized_name.rb b/lib/sequencer/unit/import/common/object_attribute/sanitized_name.rb index de0c5829f..010746dc5 100644 --- a/lib/sequencer/unit/import/common/object_attribute/sanitized_name.rb +++ b/lib/sequencer/unit/import/common/object_attribute/sanitized_name.rb @@ -4,6 +4,9 @@ class Sequencer module Common module ObjectAttribute class SanitizedName < Sequencer::Unit::Common::Provider::Named + prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action + + skip_action :skipped, :failed private diff --git a/lib/sequencer/unit/import/zendesk/object_attribute/add.rb b/lib/sequencer/unit/import/zendesk/object_attribute/add.rb index 1fd67e150..216075996 100644 --- a/lib/sequencer/unit/import/zendesk/object_attribute/add.rb +++ b/lib/sequencer/unit/import/zendesk/object_attribute/add.rb @@ -4,8 +4,11 @@ class Sequencer module Zendesk module ObjectAttribute class Add < Sequencer::Unit::Base + prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action - uses :model_class, :sanitized_name, :resource + skip_action :skipped, :failed + + uses :model_class, :sanitized_name, :resource, :backend_class provides :instance def process @@ -13,10 +16,6 @@ class Sequencer backend_class.new(model_class, sanitized_name, resource) end end - - def backend_class - "Import::Zendesk::ObjectAttribute::#{resource.type.capitalize}".constantize - end end end end diff --git a/lib/sequencer/unit/import/zendesk/object_attribute/sanitized_type.rb b/lib/sequencer/unit/import/zendesk/object_attribute/sanitized_type.rb new file mode 100644 index 000000000..7de434585 --- /dev/null +++ b/lib/sequencer/unit/import/zendesk/object_attribute/sanitized_type.rb @@ -0,0 +1,31 @@ +class Sequencer + class Unit + module Import + module Zendesk + module ObjectAttribute + class SanitizedType < Sequencer::Unit::Base + include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure + prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action + + skip_action :skipped, :failed + + uses :resource + provides :backend_class + + private + + def process + state.provide(:backend_class, backend_class) + rescue => e + handle_failure(e) + end + + def backend_class + "Import::Zendesk::ObjectAttribute::#{resource.type.capitalize}".constantize + end + end + end + end + end + end +end diff --git a/lib/sequencer/unit/import/zendesk/ticket/custom_fields.rb b/lib/sequencer/unit/import/zendesk/ticket/custom_fields.rb index fb6970c03..c3cab6017 100644 --- a/lib/sequencer/unit/import/zendesk/ticket/custom_fields.rb +++ b/lib/sequencer/unit/import/zendesk/ticket/custom_fields.rb @@ -13,7 +13,8 @@ class Sequencer custom_fields = resource.custom_fields return {} if custom_fields.blank? - custom_fields.map do |custom_field| + custom_fields.select { |custom_field| ticket_field_map[ custom_field['id'] ].present? } + .map do |custom_field| [ ticket_field_map[ custom_field['id'] ].to_sym, # remote_name custom_field['value'] diff --git a/lib/sequencer/unit/import/zendesk/ticket_field/add.rb b/lib/sequencer/unit/import/zendesk/ticket_field/add.rb deleted file mode 100644 index 0522ec456..000000000 --- a/lib/sequencer/unit/import/zendesk/ticket_field/add.rb +++ /dev/null @@ -1,17 +0,0 @@ -class Sequencer - class Unit - module Import - module Zendesk - module TicketField - class Add < Sequencer::Unit::Import::Zendesk::ObjectAttribute::Add - prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action - - skip_action :skipped - - uses :action - end - end - end - end - end -end diff --git a/lib/sequencer/unit/import/zendesk/ticket_field/sanitized_name.rb b/lib/sequencer/unit/import/zendesk/ticket_field/sanitized_name.rb index 10b5595c4..ac89bb182 100644 --- a/lib/sequencer/unit/import/zendesk/ticket_field/sanitized_name.rb +++ b/lib/sequencer/unit/import/zendesk/ticket_field/sanitized_name.rb @@ -4,11 +4,8 @@ class Sequencer module Zendesk module TicketField class SanitizedName < Sequencer::Unit::Import::Common::ObjectAttribute::SanitizedName - prepend ::Sequencer::Unit::Import::Common::Model::Mixin::Skip::Action - skip_action :skipped - - uses :resource, :action + uses :resource private