Fixes #4057, fixes #2375 - OTRS migration currently do not support custom dropdown multi-select fields.

This commit is contained in:
Dominik Klein 2022-05-10 12:21:53 +02:00
parent e552795183
commit 61f42f950f
13 changed files with 101 additions and 23 deletions

View file

@ -7,11 +7,11 @@
- echo -e "\\e[0Ksection_end:`date +%s`:zammad_db_unseeded\\r\\e[0K"
- bundle exec rails test test/integration/otrs_import_test.rb
variables:
FF_NETWORK_PER_BUILD: 1 # https://docs.gitlab.com/runner/configuration/feature-flags.html
IMPORT_OTRS_ENDPOINT: "http://zammad-ci-otrsimport-app/otrs/public.pl?Action=ZammadMigrator"
TZ: "Europe/Berlin" # Required for the zammad-ci-otrsimport-app containers
FF_NETWORK_PER_BUILD: 1 # https://docs.gitlab.com/runner/configuration/feature-flags.html
IMPORT_OTRS_ENDPOINT: 'http://zammad-ci-otrsimport-app/otrs/public.pl?Action=ZammadMigrator'
TZ: 'Europe/Berlin' # Required for the zammad-ci-otrsimport-app containers
"minitest:integration:otrs:6":
'minitest:integration:otrs:6':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable
@ -23,7 +23,7 @@
- name: $CI_REGISTRY/docker/zammad-ci-otrsimport-app:otrs6
alias: zammad-ci-otrsimport-app
"minitest:integration:otrs:5":
'minitest:integration:otrs:5':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable
@ -35,7 +35,7 @@
- name: $CI_REGISTRY/docker/zammad-ci-otrsimport-app:otrs5
alias: zammad-ci-otrsimport-app
"minitest:integration:otrs:4":
'minitest:integration:otrs:4':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable
@ -47,7 +47,7 @@
- name: $CI_REGISTRY/docker/zammad-ci-otrsimport-app:otrs4
alias: zammad-ci-otrsimport-app
"minitest:integration:otrs:33":
'minitest:integration:otrs:33':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable
@ -59,7 +59,7 @@
- name: $CI_REGISTRY/docker/zammad-ci-otrsimport-app:otrs33
alias: zammad-ci-otrsimport-app
"minitest:integration:otrs:32":
'minitest:integration:otrs:32':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable
@ -71,7 +71,7 @@
- name: $CI_REGISTRY/docker/zammad-ci-otrsimport-app:otrs32
alias: zammad-ci-otrsimport-app
"minitest:integration:otrs:31":
'minitest:integration:otrs:31':
<<: *template_integration_otrs
services:
- name: $CI_REGISTRY/docker/zammad-mysql:stable

View file

@ -306,7 +306,6 @@ possible types
=end
def self.add(data)
force = data[:force]
data.delete(:force)

View file

@ -8,6 +8,7 @@ module Import
@internal_name = self.class.convert_name(dynamic_field['Name'])
return if already_imported?(dynamic_field)
return if skip?(dynamic_field)
initialize_attribute_config(dynamic_field)
@ -54,6 +55,10 @@ module Import
}
end
def skip?(_dynamic_field)
false
end
def add
ObjectManager::Attribute.add(@attribute_config)
ObjectManager::Attribute.migration_execute(false)

View file

@ -17,6 +17,12 @@ module Import
}
)
end
private
def skip?(dynamic_field)
!dynamic_field['Config']['PossibleValues']
end
end
end
end

View file

@ -6,7 +6,7 @@ module Import
class Multiselect < Import::OTRS::DynamicField
def init_callback(dynamic_field)
@attribute_config.merge!(
data_type: 'select',
data_type: 'multiselect',
data_option: {
default: '',
multiple: true,
@ -17,6 +17,12 @@ module Import
}
)
end
private
def skip?(dynamic_field)
!dynamic_field['Config']['PossibleValues']
end
end
end
end

View file

@ -8,9 +8,10 @@ module Import
@attribute_config.merge!(
data_type: 'textarea',
data_option: {
default: dynamic_field['Config']['DefaultValue'],
rows: dynamic_field['Config']['Rows'],
null: true,
default: dynamic_field['Config']['DefaultValue'],
rows: dynamic_field['Config']['Rows'],
null: true,
maxlength: 3000,
}
)
end

View file

@ -0,0 +1,20 @@
{
"ID": "40",
"ChangeTime": "2016-05-25 11:14:06",
"InternalField": "0",
"ValidID": "1",
"CreateTime": "2014-08-21 14:54:15",
"Label": "Dropdown Example Without PossibleValues",
"FieldOrder": "30",
"Config": {
"TranslatableValues": "0",
"PossibleValues": null,
"TreeView": "0",
"DefaultValue": "",
"Link": "",
"PossibleNone": "1"
},
"FieldType": "Dropdown",
"Name": "DropdownExampleWithoutPossibleValues",
"ObjectType": "Ticket"
}

View file

@ -0,0 +1,20 @@
{
"ID": "40",
"ChangeTime": "2016-05-25 11:14:06",
"InternalField": "0",
"ValidID": "1",
"CreateTime": "2014-08-21 14:54:15",
"Label": "Multiselect Example Without PossibleValues",
"FieldOrder": "30",
"Config": {
"TranslatableValues": "0",
"PossibleValues": null,
"TreeView": "0",
"DefaultValue": "",
"Link": "",
"PossibleNone": "1"
},
"FieldType": "Multiselect",
"Name": "MultiselectExampleWithoutPossibleValues",
"ObjectType": "Ticket"
}

View file

@ -42,4 +42,14 @@ RSpec.describe Import::OTRS::DynamicField::Dropdown do
dynamic_field_from_json('dropdown/default', zammad_structure)
end
context 'without possible values' do
it 'imports no field without possible value' do
allow(ObjectManager::Attribute).to receive(:add)
described_class.new(load_dynamic_field_json('dropdown/without_possible_values'))
expect(ObjectManager::Attribute).not_to have_received(:add)
end
end
end

View file

@ -24,7 +24,7 @@ RSpec.describe Import::OTRS::DynamicField::Multiselect do
position: '4',
created_by_id: 1,
updated_by_id: 1,
data_type: 'select',
data_type: 'multiselect',
data_option: {
default: '',
multiple: true,
@ -42,4 +42,14 @@ RSpec.describe Import::OTRS::DynamicField::Multiselect do
dynamic_field_from_json('multiselect/default', zammad_structure)
end
context 'without possible values' do
it 'imports no field without possible value' do
allow(ObjectManager::Attribute).to receive(:add)
described_class.new(load_dynamic_field_json('multiselect/without_possible_values'))
expect(ObjectManager::Attribute).not_to have_received(:add)
end
end
end

View file

@ -26,9 +26,10 @@ RSpec.describe Import::OTRS::DynamicField::TextArea do
updated_by_id: 1,
data_type: 'textarea',
data_option: {
default: '',
rows: '20',
null: true
default: '',
rows: '20',
null: true,
maxlength: 3000,
}
}

View file

@ -36,7 +36,7 @@ class OtrsImportTest < ActiveSupport::TestCase
end.collect do |local_object|
local_object['name']
end
expected_object_attribute_names = %w[vertriebsweg te_test number sugar_crm_remote_no sugar_crm_company_selected_no sugar_crm_company_selection combine title itsm_criticality customer_id itsm_impact itsm_review_required itsm_decision_result organization_id itsm_repair_start_time itsm_recovery_start_time itsm_decision_date itsm_due_date topic_no open_exchange_ticket_number hostname ticket_free_key11 type ticket_free_text11 open_exchange_tn topic zarafa_tn group_id scom_hostname checkbox_example scom_uuid scom_state scom_service location owner_id department customer_location state_id pending_time priority_id tags]
expected_object_attribute_names = %w[vertriebsweg te_test number sugar_crm_remote_no sugar_crm_company_selected_no sugar_crm_company_selection combine title itsm_criticality customer_id itsm_impact itsm_review_required itsm_decision_result organization_id itsm_repair_start_time itsm_recovery_start_time itsm_decision_date itsm_due_date topic_no open_exchange_ticket_number hostname ticket_free_key11 type ticket_free_text11 open_exchange_tn topic zarafa_tn group_id scom_hostname checkbox_example scom_uuid scom_state scom_service location owner_id department customer_location textfeld state_id pending_time priority_id tags]
assert_equal(expected_object_attribute_names, object_attribute_names, 'dynamic field names')
end
@ -109,7 +109,7 @@ class OtrsImportTest < ActiveSupport::TestCase
assert_equal('invalid-temp', user4.firstname)
assert_equal('invalid-temp', user4.lastname)
assert_equal('invalid-temp', user4.login)
assert_equal('invalid-temp@example.com', user4.email)
assert_equal(false, user4.active)
assert(user4.roles.include?(role_agent))
@ -217,10 +217,10 @@ class OtrsImportTest < ActiveSupport::TestCase
ticket = Ticket.find(591)
assert_equal('Some other smart subject!', ticket.title)
assert_equal('488', ticket.vertriebsweg)
assert_equal('["193"]', ticket.te_test) # TODO: multiselect
assert_equal(%w[193 194], ticket.te_test)
assert_equal('358', ticket.sugar_crm_remote_no)
assert_equal('69', ticket.sugar_crm_company_selected_no)
assert_equal('["382"]', ticket.sugar_crm_company_selection) # TODO: multiselect
assert_equal(['382'], ticket.sugar_crm_company_selection)
assert_equal('310', ticket.topic_no)
assert_equal('495', ticket.open_exchange_ticket_number)
assert_equal('208', ticket.hostname)