diff --git a/app/assets/javascripts/app/controllers/import_otrs.coffee b/app/assets/javascripts/app/controllers/import_otrs.coffee index 2d04674a5..887737c97 100644 --- a/app/assets/javascripts/app/controllers/import_otrs.coffee +++ b/app/assets/javascripts/app/controllers/import_otrs.coffee @@ -18,6 +18,12 @@ class Index extends App.ControllerContent @fetch() + @bind('import:finished', => + console.log('import:finished') + @Config.set('system_init_done', true) + @navigate '#' + ) + fetch: -> # get data @@ -79,7 +85,6 @@ class Index extends App.ControllerContent success: (data, status, xhr) => # validate form - console.log(data) if data.result is 'ok' @urlStatus.attr('data-state', 'success') @linkErrorMessage.text('') @@ -103,7 +108,6 @@ class Index extends App.ControllerContent success: (data, status, xhr) => # validate form - console.log(data) if data.result is 'ok' @delay( @updateMigration, 3000 ) ) diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 7b84208a2..24a174659 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -22,9 +22,7 @@ class ImportOtrsController < ApplicationController 'Connection refused' => 'Connection refused!', } - url_parts = params[:url].split(';') - - response = UserAgent.request( url_parts[0] ) + response = UserAgent.request( params[:url] ) if !response.success? && response.code.to_s !~ /^40.$/ message_human = '' @@ -44,16 +42,27 @@ class ImportOtrsController < ApplicationController result = {} if response.body =~ /zammad migrator/ - key_parts = url_parts[1].split('=') + migrator_response = JSON.parse(response.body) - Setting.set('import_backend', 'otrs') - Setting.set('import_otrs_endpoint', url_parts[0]) - Setting.set('import_otrs_endpoint_key', key_parts[1]) + if migrator_response['Success'] == 1 - result = { - result: 'ok', - url: params[:url], - } + url_parts = params[:url].split(';') + key_parts = url_parts[1].split('=') + + Setting.set('import_backend', 'otrs') + Setting.set('import_otrs_endpoint', url_parts[0]) + Setting.set('import_otrs_endpoint_key', key_parts[1]) + + result = { + result: 'ok', + url: params[:url], + } + else + result = { + result: 'invalid', + message_human: migrator_response['Error'] + } + end elsif response.body =~ /(otrs\sag|otrs\.com|otrs\.org)/i result = { result: 'invalid', diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 98c9cd80b..0ec12c2ba 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -412,6 +412,11 @@ module Import::OTRS Setting.set('system_init_done', true) Setting.set('import_mode', false) + # broadcast import finish + Sessions.broadcast( + event: 'import:finished', + ) + true end diff --git a/test/integration/otrs_import_browser_test.rb b/test/integration/otrs_import_browser_test.rb index 816f56d47..4f59578aa 100644 --- a/test/integration/otrs_import_browser_test.rb +++ b/test/integration/otrs_import_browser_test.rb @@ -11,8 +11,6 @@ class OtrsImportBrowserTest < TestCase fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT_KEY - hint IMPORT_BT_OTRS_ENDPOINT_KEY='01234567899876543210'" end - import_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=#{ENV['IMPORT_BT_OTRS_ENDPOINT_KEY']}" - @browser = browser_instance location(url: browser_url) @@ -20,26 +18,44 @@ class OtrsImportBrowserTest < TestCase 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" + + set( + css: '#otrs-link', + value: invalid_key_url + ) + + sleep 5 + + watch_for( + css: '.otrs-link-error', + value: 'Invalid API key.', + ) + + import_url = "#{ENV['IMPORT_BT_OTRS_ENDPOINT']};Key=#{ENV['IMPORT_BT_OTRS_ENDPOINT_KEY']}" set( css: '#otrs-link', value: import_url ) - watch_for( - css: 'body', - value: 'xxxx', - timeout: 10, + sleep 5 + + watch_for_disappear( + css: '.otrs-link-error', + value: 'Invalid API key.', ) - # click import + click(css: '.js-migration-start') - # click otrs - - # enter otrs url + key - - # watch for import start - - # watch for import end + watch_for( + css: 'body', + value: 'login', + timeout: 300, + ) end