From 3fa9a45b8c2e3699aa1332a4c7f1c0bd8091b760 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sun, 15 Jan 2017 11:47:20 +0100 Subject: [PATCH] Added import check if features used in different approach. --- .../app/controllers/import_otrs.coffee | 44 ++++++++++-- .../javascripts/app/views/import/otrs.jst.eco | 15 ++++- app/controllers/import_otrs_controller.rb | 67 +++++++++++++++++-- config/routes/import_otrs.rb | 1 + test/integration/otrs_import_browser_test.rb | 10 +-- 5 files changed, 118 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/app/controllers/import_otrs.coffee b/app/assets/javascripts/app/controllers/import_otrs.coffee index 0ad417ac1..446ff037a 100644 --- a/app/assets/javascripts/app/controllers/import_otrs.coffee +++ b/app/assets/javascripts/app/controllers/import_otrs.coffee @@ -1,14 +1,17 @@ class Index extends App.ControllerContent className: 'getstarted fit' elements: - '.input-feedback': 'urlStatus' - '[data-target=otrs-start-migration]': 'nextStartMigration' - '.otrs-link-error': 'linkErrorMessage' + '.input-feedback': 'urlStatus' + '.js-migration-check': 'nextStartMigration' + '.otrs-link-error': 'linkErrorMessage' + events: 'click .js-otrs-link': 'showLink' 'click .js-download': 'startDownload' 'click .js-migration-start': 'startMigration' + 'click .js-migration-check': 'checkMigration' 'keyup #otrs-link': 'updateUrl' + updateMigrationDisplayLoop: 0 constructor: -> super @@ -61,6 +64,13 @@ class Index extends App.ControllerContent @$('[data-slide=otrs-plugin]').addClass('hide') @$('[data-slide=otrs-link]').addClass('hide') @$('[data-slide=otrs-import]').removeClass('hide') + @$('[data-slide=otrs-import-notice]').addClass('hide') + + showImportNotice: => + @$('[data-slide=otrs-plugin]').addClass('hide') + @$('[data-slide=otrs-link]').addClass('hide') + @$('[data-slide=otrs-import]').addClass('hide') + @$('[data-slide=otrs-import-notice]').removeClass('hide') updateUrl: (e) => url = $(e.target).val() @@ -86,12 +96,28 @@ class Index extends App.ControllerContent @urlStatus.attr('data-state', 'error') @linkErrorMessage.text(data.message_human || data.message) @nextStartMigration.addClass('hide') - ) @delay(callback, 700, 'import_otrs_url') - startMigration: (e) => + checkMigration: (e) => e.preventDefault() + @ajax( + id: 'import_otrs_check' + type: 'POST' + url: "#{@apiPath}/import/otrs/import_check" + processData: true + success: (data, status, xhr) => + if data.result is 'ok' + @startMigration() + return + for issue in data.issues + @$(".js-#{issue}").removeClass('hide') + @showImportNotice() + ) + + startMigration: (e) => + if e + e.preventDefault() @showImportState() @ajax( id: 'import_start' @@ -100,10 +126,11 @@ class Index extends App.ControllerContent processData: true success: (data, status, xhr) => if data.result is 'ok' - @delay(@updateMigration, 3000) + @delay(@updateMigration, 2000) ) updateMigration: => + @updateMigrationDisplayLoop += 1 @showImportState() @ajax( id: 'import_status' @@ -122,6 +149,11 @@ class Index extends App.ControllerContent else @$('.js-error').addClass('hide') + if data.message is 'not running' && @updateMigrationDisplayLoop > 10 + @$('.js-error').removeClass('hide') + @$('.js-error').html(App.i18n.translateContent('Background process did not start or has not finished! Please contact your support.')) + return + if data.result is 'in_progress' for key, item of data.data if item.done > item.total diff --git a/app/assets/javascripts/app/views/import/otrs.jst.eco b/app/assets/javascripts/app/views/import/otrs.jst.eco index e43911da8..f93f77737 100644 --- a/app/assets/javascripts/app/views/import/otrs.jst.eco +++ b/app/assets/javascripts/app/views/import/otrs.jst.eco @@ -37,14 +37,13 @@
<%- @T('Go Back') %> -
<%- @T('Migrate OTRS Data') %>
+
<%- @T('Migrate OTRS Data') %>

<%- @T('OTRS Migration') %>

-
@@ -90,5 +89,17 @@ +
+

<%- @T('Notice') %>

+
+

<%- @T('We detected OTRS BPM processes which can\'t get imported into Zammad, since we currently don\'t support these kind of workflows.') %>

+

<%- @T('We found many dynamic fields. We use a different approach towards ticket attributes. Zammad uses also tags in addition to custom fields to classify tickets. This difference may conflict with your current use of dynamic fields in OTRS.') %>

+
+ +
+ \ No newline at end of file diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 3b473ae3f..f390ed26c 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -22,8 +22,7 @@ class ImportOtrsController < ApplicationController 'Connection refused' => 'Connection refused!', } - response = UserAgent.request( params[:url] ) - + response = UserAgent.request(params[:url]) if !response.success? && response.code.to_s !~ /^40.$/ message_human = '' translation_map.each { |key, message| @@ -46,12 +45,36 @@ class ImportOtrsController < ApplicationController if migrator_response['Success'] == 1 - url_parts = params[:url].split(';') - key_parts = url_parts[1].split('=') + # set url and key for import endpoint + url = migrator_response['URL'] + key = migrator_response['Key'] + + # get first part url, used for import_otrs_endpoint + if !url || !key + url_parts = params[:url].split(';') + if !url_parts[1] # in case of & instead of ; + url_parts = params[:url].split('&') + end + key_parts = url_parts[1].split('=') + + if !key_parts[1] + render json: { + result: 'invalid', + message_human: 'Unable to get key from URL!' + } + return + end + if !url + url = url_parts[0] + end + if !key + key = key_parts[1] + end + end Setting.set('import_backend', 'otrs') - Setting.set('import_otrs_endpoint', url_parts[0]) - Setting.set('import_otrs_endpoint_key', key_parts[1]) + Setting.set('import_otrs_endpoint', url) + Setting.set('import_otrs_endpoint_key', key) result = { result: 'ok', @@ -98,6 +121,38 @@ class ImportOtrsController < ApplicationController } end + def import_check + statistic = Import::OTRS::Requester.list + issues = [] + + # check count of dynamic fields + dynamic_field_count = 0 + dynamic_fields = Import::OTRS::Requester.load('DynamicField') + dynamic_fields.each { |dynamic_field| + next if dynamic_field['ValidID'].to_i != 1 + dynamic_field_count += 1 + } + if dynamic_field_count > 20 + issues.push 'otrsDynamicFields' + end + + # check if process exsists + sys_configs = Import::OTRS::Requester.load('SysConfig') + sys_configs.each { |sys_config| + next if sys_config['Key'] != 'Process' + issues.push 'otrsProcesses' + } + + result = 'ok' + if !issues.empty? + result = 'failed' + end + render json: { + result: result, + issues: issues, + } + end + def import_status result = Import::OTRS.status_bg if result[:result] == 'import_done' diff --git a/config/routes/import_otrs.rb b/config/routes/import_otrs.rb index 41c8b1c2e..f3e550d34 100644 --- a/config/routes/import_otrs.rb +++ b/config/routes/import_otrs.rb @@ -3,6 +3,7 @@ Zammad::Application.routes.draw do # import otrs match api_path + '/import/otrs/url_check', to: 'import_otrs#url_check', via: :post + match api_path + '/import/otrs/import_check', to: 'import_otrs#import_check', via: :post match api_path + '/import/otrs/import_start', to: 'import_otrs#import_start', via: :post match api_path + '/import/otrs/import_status', to: 'import_otrs#import_status', via: :get diff --git a/test/integration/otrs_import_browser_test.rb b/test/integration/otrs_import_browser_test.rb index 57e52d4f0..52b5ab59a 100644 --- a/test/integration/otrs_import_browser_test.rb +++ b/test/integration/otrs_import_browser_test.rb @@ -15,11 +15,8 @@ class OtrsImportBrowserTest < TestCase location(url: browser_url) click(css: 'a[href="#import"]') - click(css: 'a[href="#import/otrs"]') - click(css: '.js-download') - click(css: '.js-otrs-link') invalid_key_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=31337" @@ -28,7 +25,6 @@ class OtrsImportBrowserTest < TestCase css: '#otrs-link', value: invalid_key_url ) - sleep 5 watch_for( @@ -41,14 +37,18 @@ class OtrsImportBrowserTest < TestCase css: '#otrs-link', value: import_url ) - sleep 5 watch_for_disappear( css: '.otrs-link-error', value: 'Invalid API key.', ) + click(css: '.js-migration-check') + watch_for( + css: '.wizard-slide:not(.hide)', + value: 'Notice', + ) click(css: '.js-migration-start') watch_for(