Browse Source

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

Dominik Klein 2 years ago
parent
commit
ea05aefdf9

+ 9 - 9
.gitlab/ci/integration/otrs.yml

@@ -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
@@ -28,7 +28,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
@@ -45,7 +45,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
@@ -62,7 +62,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
@@ -79,7 +79,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
@@ -96,7 +96,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

+ 0 - 1
app/models/object_manager/attribute.rb

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

+ 5 - 0
lib/import/otrs/dynamic_field.rb

@@ -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)

+ 6 - 0
lib/import/otrs/dynamic_field/dropdown.rb

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

+ 7 - 1
lib/import/otrs/dynamic_field/multiselect.rb

@@ -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

+ 4 - 3
lib/import/otrs/dynamic_field/text_area.rb

@@ -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

+ 20 - 0
spec/fixtures/files/import/otrs/dynamic_field/dropdown/without_possible_values.json

@@ -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"
+}

+ 20 - 0
spec/fixtures/files/import/otrs/dynamic_field/multiselect/without_possible_values.json

@@ -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"
+}

+ 1 - 1
spec/fixtures/files/import/otrs/dynamic_field/text_area/default.json

@@ -14,4 +14,4 @@
   "FieldType": "TextArea",
   "Name": "TextAreaExample",
   "ObjectType": "Ticket"
-}
+}

+ 10 - 0
spec/lib/import/otrs/dynamic_field/dropdown_spec.rb

@@ -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

Some files were not shown because too many files changed in this diff