Current state of OTRS import browser test.

This commit is contained in:
Thorsten Eckel 2016-01-13 13:07:23 +01:00
parent 6bb8c7b6eb
commit db9076809e
4 changed files with 52 additions and 50 deletions

View file

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

View file

@ -1,24 +1,13 @@
<div class="main flex vertical centered darkBackground">
<%- @Icon('full-logo', 'wizard-logo') %>
<div class="import wizard">
<div class="wizard-slide vertical" data-slide="otrs-prepare">
<h2><%- @T('Create OTRS Migration Plugin') %></h2>
<div class="wizard-body flex vertical justified">
<p class="wizard-loadingText">
<span class="loading icon"></span> <%- @T('Personalise Migration Plugin ...') %>
</p>
</div>
<div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a>
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-plugin">
<div class="wizard-slide vertical" data-slide="otrs-plugin">
<h2><%- @T('Download OTRS Migration Plugin') %></h2>
<div class="wizard-body flex vertical justified">
<p>
<%- @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') %>:
</p>
<a class="btn btn--primary btn--download js-download" download><%- @Icon('download') %> <%- @T('Personal Migration Plugin') %></a>
<a class="btn btn--primary btn--download js-download" download href="https://portal.znuny.com/api/addon_repos/public/268/latest"><%- @Icon('download') %> <%- @T('Migration Plugin') %></a>
</div>
<div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a>
@ -34,7 +23,7 @@
<div class="form-group">
<label for="otrs-link">OTRS Link</label>
<div class="u-positionOrigin">
<input type="url" id="otrs-link" class="form-control" placeholder="http://otrs.example.com" name="url">
<input type="url" id="otrs-link" class="form-control" placeholder="http://example.com/otrs/public.pl?Action=ZammadMigrator;Key=31337" name="url">
<div class="input-feedback centered">
<div class="small loading icon"></div>
<%- @Icon('diagonal-cross', 'icon-error') %>

View file

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

View file

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