From db9076809ebd9d2258db45a1840b119667332136 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 13 Jan 2016 13:07:23 +0100 Subject: [PATCH 1/2] Current state of OTRS import browser test. --- .../app/controllers/import_otrs.coffee | 6 -- .../javascripts/app/views/import/otrs.jst.eco | 19 ++---- app/controllers/import_otrs_controller.rb | 58 +++++++++---------- test/integration/otrs_import_browser_test.rb | 19 ++++++ 4 files changed, 52 insertions(+), 50 deletions(-) diff --git a/app/assets/javascripts/app/controllers/import_otrs.coffee b/app/assets/javascripts/app/controllers/import_otrs.coffee index 4ee161748..4d4aadf34 100644 --- a/app/assets/javascripts/app/controllers/import_otrs.coffee +++ b/app/assets/javascripts/app/controllers/import_otrs.coffee @@ -44,11 +44,6 @@ class Index extends App.ControllerContent if data.import_mode == true @showImportState() @updateMigration() - else - showDownload = => - @$('[data-slide=otrs-prepare]').toggleClass('hide') - @$('[data-slide=otrs-plugin]').toggleClass('hide') - @delay( showDownload, 2500 ) ) render: -> @@ -64,7 +59,6 @@ class Index extends App.ControllerContent @$('[data-slide=otrs-link]').toggleClass('hide') showImportState: => - @$('[data-slide=otrs-prepare]').addClass('hide') @$('[data-slide=otrs-plugin]').addClass('hide') @$('[data-slide=otrs-link]').addClass('hide') @$('[data-slide=otrs-import]').removeClass('hide') diff --git a/app/assets/javascripts/app/views/import/otrs.jst.eco b/app/assets/javascripts/app/views/import/otrs.jst.eco index 0f88fefea..2fe5bd78e 100644 --- a/app/assets/javascripts/app/views/import/otrs.jst.eco +++ b/app/assets/javascripts/app/views/import/otrs.jst.eco @@ -1,24 +1,13 @@
<%- @Icon('full-logo', 'wizard-logo') %>
-
-

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

-
-

- <%- @T('Personalise Migration Plugin ...') %> -

-
- -
-
+

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

- <%- @T('Download and install your personalised OTRS Migration Plugin on your OTRS System') %>: + <%- @T('Download and install the OTRS Migration Plugin on your OTRS System') %>:

- <%- @Icon('download') %> <%- @T('Personal Migration Plugin') %> + <%- @Icon('download') %> <%- @T('Migration Plugin') %>
<%- @T('Go Back') %> @@ -34,7 +23,7 @@
- +
<%- @Icon('diagonal-cross', 'icon-error') %> diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 197073a75..5219e44d0 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -9,7 +9,7 @@ class ImportOtrsController < ApplicationController if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} render json: { result: 'invalid', - message: 'Invalid!', + message: 'Invalid URL!', } return end @@ -22,8 +22,10 @@ class ImportOtrsController < ApplicationController 'Connection refused' => 'Connection refused!', } - # try connecting to otrs - response = UserAgent.request(params[:url]) + url_parts = params[:url].split(';') + + response = UserAgent.request( url_parts[0] ) + if !response.success? && response.code.to_s !~ /^40.$/ message_human = '' translation_map.each {|key, message| @@ -39,34 +41,32 @@ class ImportOtrsController < ApplicationController return end - message_human = 'Host found, but it seems to be no OTRS installation!' - suffixes = ['/public.pl', '/otrs/public.pl'] - suffixes.each {|suffix| - url = params[:url] + suffix + '?Action=ZammadMigrator' - # strip multiple / in url - url.gsub!(%r{([^:])(/+/)}, '\\1/') - response = UserAgent.request( url ) + result = {} + if response.body =~ /zammad migrator/ + + key_parts = url_parts[1].split('=') - #Setting.set('import_mode', true) Setting.set('import_backend', 'otrs') - Setting.set('import_otrs_endpoint', url) - Setting.set('import_otrs_endpoint_key', '01234567899876543210') - if response.body =~ /zammad migrator/ - render json: { - url: url, - result: 'ok', - } - return # rubocop:disable Lint/NonLocalExitFromIterator - elsif response.body =~ /(otrs\sag|otrs.com|otrs.org)/i - message_human = 'Host found, but no OTRS migrator is installed!' - end - } + Setting.set('import_otrs_endpoint', url_parts[0]) + Setting.set('import_otrs_endpoint_key', key_parts[1]) - # return result - render json: { - result: 'invalid', - message_human: message_human, - } + result = { + result: 'ok', + url: params[:url], + } + elsif response.body =~ /(otrs\sag|otrs\.com|otrs\.org)/i + result = { + result: 'invalid', + message_human: 'Host found, but no OTRS migrator is installed!' + } + else + result = { + result: 'invalid', + message_human: 'Host found, but it seems to be no OTRS installation!', + } + end + + render json: result end def import_start @@ -91,7 +91,7 @@ class ImportOtrsController < ApplicationController end def import_status - return if setup_done_response + # return if setup_done_response state = Import::OTRS.current_state diff --git a/test/integration/otrs_import_browser_test.rb b/test/integration/otrs_import_browser_test.rb index 7ca777e46..816f56d47 100644 --- a/test/integration/otrs_import_browser_test.rb +++ b/test/integration/otrs_import_browser_test.rb @@ -3,9 +3,28 @@ require 'browser_test_helper' class OtrsImportBrowserTest < TestCase def test_import + + if !ENV['IMPORT_BT_OTRS_ENDPOINT'] + fail "ERROR: Need IMPORT_BT_OTRS_ENDPOINT - hint IMPORT_BT_OTRS_ENDPOINT='http://vz305.demo.znuny.com/otrs/public.pl?Action=ZammadMigrator'" + end + if !ENV['IMPORT_BT_OTRS_ENDPOINT_KEY'] + 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) + click(css: 'a[href="#import"]') + + click(css: 'a[href="#import/otrs"]') + + set( + css: '#otrs-link', + value: import_url + ) + watch_for( css: 'body', value: 'xxxx', From df306b5e2c1cc3318ea54ae260e3f640b8e8a504 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Wed, 13 Jan 2016 14:12:05 +0100 Subject: [PATCH 2/2] Fixed import wizard. Improved performance initial calendar load (only do it one per ip). --- .../app/controllers/import_otrs.coffee | 14 +- .../app/controllers/import_zendesk.coffee | 145 ++++++++++++++++++ .../app/views/import/index.jst.eco | 10 +- .../javascripts/app/views/import/otrs.jst.eco | 2 +- app/controllers/import_otrs_controller.rb | 8 +- app/models/calendar.rb | 5 + lib/cache.rb | 12 +- lib/import/otrs.rb | 4 +- script/bootstrap.sh | 2 + 9 files changed, 180 insertions(+), 22 deletions(-) create mode 100644 app/assets/javascripts/app/controllers/import_zendesk.coffee diff --git a/app/assets/javascripts/app/controllers/import_otrs.coffee b/app/assets/javascripts/app/controllers/import_otrs.coffee index 4d4aadf34..2d04674a5 100644 --- a/app/assets/javascripts/app/controllers/import_otrs.coffee +++ b/app/assets/javascripts/app/controllers/import_otrs.coffee @@ -74,7 +74,7 @@ class Index extends App.ControllerContent id: 'import_otrs_url', type: 'POST', url: @apiPath + '/import/otrs/url_check', - data: JSON.stringify( { url:url} ) + data: JSON.stringify(url: url) processData: true, success: (data, status, xhr) => @@ -118,8 +118,11 @@ class Index extends App.ControllerContent processData: true, success: (data, status, xhr) => - # validate form - console.log(data) + if data.setup_done + @Config.set('system_init_done', true) + @navigate '#' + return + for key, item of data.data element = @$('.js-' + key.toLowerCase() ) element.find('.js-done').text(item.done) @@ -130,10 +133,6 @@ class Index extends App.ControllerContent element.addClass('is-done') else element.removeClass('is-done') - -#js-finished -#@Config.set('system_init_done', true) - @delay( @updateMigration, 5000 ) ) @@ -142,5 +141,6 @@ App.Config.set( 'otrs', { image: 'otrs-logo.png' title: 'OTRS' name: 'OTRS' + class: 'js-otrs' url: '#import/otrs' }, 'ImportPlugins' ) diff --git a/app/assets/javascripts/app/controllers/import_zendesk.coffee b/app/assets/javascripts/app/controllers/import_zendesk.coffee new file mode 100644 index 000000000..8be4edd9d --- /dev/null +++ b/app/assets/javascripts/app/controllers/import_zendesk.coffee @@ -0,0 +1,145 @@ +class Index extends App.ControllerContent + className: 'getstarted fit' + elements: + '.input-feedback': 'urlStatus' + '[data-target=otrs-start-migration]': 'nextStartMigration' + '.otrs-link-error': 'linkErrorMessage' + events: + 'click .js-otrs-link': 'showLink' + 'click .js-download': 'startDownload' + 'click .js-migration-start': 'startMigration' + 'keyup #otrs-link': 'updateUrl' + + constructor: -> + super + + # set title + @title 'Import' + + @fetch() + + fetch: -> + + # get data + @ajax( + id: 'getting_started', + type: 'GET', + url: @apiPath + '/getting_started', + processData: true, + success: (data, status, xhr) => + + # redirect to login if master user already exists + if @Config.get('system_init_done') + @navigate '#login' + return + + # check if import is active + if data.import_mode == true && data.import_backend != 'otrs' + @navigate '#import/' + data.import_backend + return + + # render page + @render() + + if data.import_mode == true + @showImportState() + @updateMigration() + ) + + render: -> + @html App.view('import/otrs')() + + startDownload: (e) => + e.preventDefault() + @$('.js-otrs-link').removeClass('hide') + + showLink: (e) => + e.preventDefault() + @$('[data-slide=otrs-plugin]').toggleClass('hide') + @$('[data-slide=otrs-link]').toggleClass('hide') + + showImportState: => + @$('[data-slide=otrs-plugin]').addClass('hide') + @$('[data-slide=otrs-link]').addClass('hide') + @$('[data-slide=otrs-import]').removeClass('hide') + + updateUrl: (e) => + url = $(e.target).val() + @urlStatus.attr('data-state', 'loading') + @linkErrorMessage.text('') + + # get data + callback = => + @ajax( + id: 'import_otrs_url', + type: 'POST', + url: @apiPath + '/import/otrs/url_check', + data: JSON.stringify(url: url) + processData: true, + success: (data, status, xhr) => + + # validate form + console.log(data) + if data.result is 'ok' + @urlStatus.attr('data-state', 'success') + @linkErrorMessage.text('') + @nextStartMigration.removeClass('hide') + else + @urlStatus.attr('data-state', 'error') + @linkErrorMessage.text( data.message_human || data.message ) + @nextStartMigration.addClass('hide') + + ) + @delay( callback, 700, 'import_otrs_url' ) + + startMigration: (e) => + e.preventDefault() + @showImportState() + @ajax( + id: 'import_start', + type: 'POST', + url: @apiPath + '/import/otrs/import_start', + processData: true, + success: (data, status, xhr) => + + # validate form + console.log(data) + if data.result is 'ok' + @delay( @updateMigration, 3000 ) + ) + + + updateMigration: => + @showImportState() + @ajax( + id: 'import_status', + type: 'GET', + url: @apiPath + '/import/otrs/import_status', + processData: true, + success: (data, status, xhr) => + + if data.setup_done + @Config.set('system_init_done', true) + @navigate '#' + return + + for key, item of data.data + element = @$('.js-' + key.toLowerCase() ) + element.find('.js-done').text(item.done) + element.find('.js-total').text(item.total) + element.find('progress').attr('max', item.total ) + element.find('progress').attr('value', item.done ) + if item.total <= item.done + element.addClass('is-done') + else + element.removeClass('is-done') + @delay( @updateMigration, 5000 ) + ) + +App.Config.set( 'import/zendesk', Index, 'Routes' ) +App.Config.set( 'zendesk', { + title: 'Zendesk' + name: 'Zendesk' + class: 'js-zendesk' + url: '#import/zendesk' +}, 'ImportPlugins' ) diff --git a/app/assets/javascripts/app/views/import/index.jst.eco b/app/assets/javascripts/app/views/import/index.jst.eco index 8eeeed6de..1be64225a 100644 --- a/app/assets/javascripts/app/views/import/index.jst.eco +++ b/app/assets/javascripts/app/views/import/index.jst.eco @@ -4,11 +4,15 @@

<%- @T('Import from') %>

-
<%- @T('Go Back') %> diff --git a/app/assets/javascripts/app/views/import/otrs.jst.eco b/app/assets/javascripts/app/views/import/otrs.jst.eco index 2fe5bd78e..97def7444 100644 --- a/app/assets/javascripts/app/views/import/otrs.jst.eco +++ b/app/assets/javascripts/app/views/import/otrs.jst.eco @@ -48,7 +48,7 @@ <%- @T('Configuration') %>
-
+
<%- @Icon('checkmark') %>
diff --git a/app/controllers/import_otrs_controller.rb b/app/controllers/import_otrs_controller.rb index 5219e44d0..7b84208a2 100644 --- a/app/controllers/import_otrs_controller.rb +++ b/app/controllers/import_otrs_controller.rb @@ -91,10 +91,14 @@ class ImportOtrsController < ApplicationController end def import_status - # return if setup_done_response + if !Setting.get('import_mode') + render json: { + setup_done: true, + } + return + end state = Import::OTRS.current_state - render json: { data: state, result: 'in_progress', diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 5bbd3ee7b..6c71f3c35 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -27,6 +27,11 @@ returns calendar object ip = nil end + # prevent multible setups for same ip + cache = Cache.get('Calendar.init_setup.done') + return if cache && cache[:ip] == ip + Cache.write('Calendar.init_setup.done', { ip: ip }, { expires_in: 1.hour }) + # call for calendar suggestion calendar_details = Service::GeoCalendar.location(ip) return if !calendar_details diff --git a/lib/cache.rb b/lib/cache.rb index 327443bad..69ef8f905 100644 --- a/lib/cache.rb +++ b/lib/cache.rb @@ -8,8 +8,8 @@ delete a cache =end - def self.delete( key ) - Rails.cache.delete( key.to_s ) + def self.delete(key) + Rails.cache.delete(key.to_s) end =begin @@ -19,14 +19,12 @@ write a cache Cache.write( 'some_key', { some: { data: { 'structure' } } }, - { - expires_in: 24.hours, # optional, default 7 days - } + { expires_in: 24.hours, # optional, default 7 days } ) =end - def self.write( key, data, params = {} ) + def self.write(key, data, params = {}) if !params[:expires_in] params[:expires_in] = 7.days end @@ -45,7 +43,7 @@ get a cache =end - def self.get( key ) + def self.get(key) Rails.cache.read(key.to_s) end diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 7e7b1de34..98c9cd80b 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -409,8 +409,8 @@ module Import::OTRS threads[thread].join } - Setting.set( 'system_init_done', true ) - #Setting.set( 'import_mode', false ) + Setting.set('system_init_done', true) + Setting.set('import_mode', false) true end diff --git a/script/bootstrap.sh b/script/bootstrap.sh index d7d22e15f..ac34cdc3d 100755 --- a/script/bootstrap.sh +++ b/script/bootstrap.sh @@ -4,6 +4,8 @@ bundle install rm -rf tmp/cache* +export Z_LOCALES='en-us:de-de' + rake db:drop rake db:create rake db:migrate