Merge branch 'develop' of github.com:martini/zammad into develop

This commit is contained in:
Felix Niklas 2016-01-13 15:45:25 +01:00
commit 4addd7b063
10 changed files with 231 additions and 71 deletions

View file

@ -44,11 +44,6 @@ class Index extends App.ControllerContent
if data.import_mode == true if data.import_mode == true
@showImportState() @showImportState()
@updateMigration() @updateMigration()
else
showDownload = =>
@$('[data-slide=otrs-prepare]').toggleClass('hide')
@$('[data-slide=otrs-plugin]').toggleClass('hide')
@delay( showDownload, 2500 )
) )
render: -> render: ->
@ -64,7 +59,6 @@ class Index extends App.ControllerContent
@$('[data-slide=otrs-link]').toggleClass('hide') @$('[data-slide=otrs-link]').toggleClass('hide')
showImportState: => showImportState: =>
@$('[data-slide=otrs-prepare]').addClass('hide')
@$('[data-slide=otrs-plugin]').addClass('hide') @$('[data-slide=otrs-plugin]').addClass('hide')
@$('[data-slide=otrs-link]').addClass('hide') @$('[data-slide=otrs-link]').addClass('hide')
@$('[data-slide=otrs-import]').removeClass('hide') @$('[data-slide=otrs-import]').removeClass('hide')
@ -80,7 +74,7 @@ class Index extends App.ControllerContent
id: 'import_otrs_url', id: 'import_otrs_url',
type: 'POST', type: 'POST',
url: @apiPath + '/import/otrs/url_check', url: @apiPath + '/import/otrs/url_check',
data: JSON.stringify( { url:url} ) data: JSON.stringify(url: url)
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
@ -124,8 +118,11 @@ class Index extends App.ControllerContent
processData: true, processData: true,
success: (data, status, xhr) => success: (data, status, xhr) =>
# validate form if data.setup_done
console.log(data) @Config.set('system_init_done', true)
@navigate '#'
return
for key, item of data.data for key, item of data.data
element = @$('.js-' + key.toLowerCase() ) element = @$('.js-' + key.toLowerCase() )
element.find('.js-done').text(item.done) element.find('.js-done').text(item.done)
@ -136,10 +133,6 @@ class Index extends App.ControllerContent
element.addClass('is-done') element.addClass('is-done')
else else
element.removeClass('is-done') element.removeClass('is-done')
#js-finished
#@Config.set('system_init_done', true)
@delay( @updateMigration, 5000 ) @delay( @updateMigration, 5000 )
) )
@ -148,5 +141,6 @@ App.Config.set( 'otrs', {
image: 'otrs-logo.png' image: 'otrs-logo.png'
title: 'OTRS' title: 'OTRS'
name: 'OTRS' name: 'OTRS'
class: 'js-otrs'
url: '#import/otrs' url: '#import/otrs'
}, 'ImportPlugins' ) }, 'ImportPlugins' )

View file

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

View file

@ -4,11 +4,15 @@
<div class="wizard-slide vertical"> <div class="wizard-slide vertical">
<h2><%- @T('Import from') %></h2> <h2><%- @T('Import from') %></h2>
<div class="wizard-body flex vertical justified"> <div class="wizard-body flex vertical justified">
<div class="import-source centered">
<% for key, item of @items: %> <% for key, item of @items: %>
<a href="<%= item.url %>"><img class="logo" src="<%= @C('image_path') + '/' + item.image %>" alt="<%= item.name %>" height="37"></a> <a href="<%= item.url %>" class="import-source centered <%= item.class %>">
<% if item.image: %>
<img class="logo" src="<%= @C('image_path') + '/' + item.image %>" alt="<%= item.name %>" height="37">
<% else: %>
<%= item.name %>
<% end %>
</a>
<% end %> <% end %>
</div>
</div> </div>
<div class="wizard-controls horizontal center"> <div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#getting_started"><%- @T('Go Back') %></a> <a class="btn btn--text btn--secondary" href="#getting_started"><%- @T('Go Back') %></a>

View file

@ -1,24 +1,13 @@
<div class="main flex vertical centered darkBackground"> <div class="main flex vertical centered darkBackground">
<%- @Icon('full-logo', 'wizard-logo') %> <%- @Icon('full-logo', 'wizard-logo') %>
<div class="import wizard"> <div class="import wizard">
<div class="wizard-slide vertical" data-slide="otrs-prepare"> <div class="wizard-slide vertical" data-slide="otrs-plugin">
<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">
<h2><%- @T('Download OTRS Migration Plugin') %></h2> <h2><%- @T('Download OTRS Migration Plugin') %></h2>
<div class="wizard-body flex vertical justified"> <div class="wizard-body flex vertical justified">
<p> <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> </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>
<div class="wizard-controls horizontal center"> <div class="wizard-controls horizontal center">
<a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a> <a class="btn btn--text btn--secondary" href="#import"><%- @T('Go Back') %></a>
@ -34,7 +23,7 @@
<div class="form-group"> <div class="form-group">
<label for="otrs-link">OTRS Link</label> <label for="otrs-link">OTRS Link</label>
<div class="u-positionOrigin"> <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="input-feedback centered">
<div class="small loading icon"></div> <div class="small loading icon"></div>
<%- @Icon('diagonal-cross', 'icon-error') %> <%- @Icon('diagonal-cross', 'icon-error') %>
@ -59,7 +48,7 @@
<td><span><%- @T('Configuration') %></span> <td><span><%- @T('Configuration') %></span>
<td class="progressTable-progressCell"> <td class="progressTable-progressCell">
<div class="horizontal center"> <div class="horizontal center">
<div class="flex"><progress value="0.3"></progress></div><!-- if there is no max, the value is between 0..1 --> <div class="flex"><progress value="1"></progress></div>
<%- @Icon('checkmark') %> <%- @Icon('checkmark') %>
</div> </div>
</tr> </tr>

View file

@ -9,7 +9,7 @@ class ImportOtrsController < ApplicationController
if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$} if !params[:url] || params[:url] !~ %r{^(http|https)://.+?$}
render json: { render json: {
result: 'invalid', result: 'invalid',
message: 'Invalid!', message: 'Invalid URL!',
} }
return return
end end
@ -22,8 +22,10 @@ class ImportOtrsController < ApplicationController
'Connection refused' => 'Connection refused!', 'Connection refused' => 'Connection refused!',
} }
# try connecting to otrs url_parts = params[:url].split(';')
response = UserAgent.request(params[:url])
response = UserAgent.request( url_parts[0] )
if !response.success? && response.code.to_s !~ /^40.$/ if !response.success? && response.code.to_s !~ /^40.$/
message_human = '' message_human = ''
translation_map.each {|key, message| translation_map.each {|key, message|
@ -39,34 +41,32 @@ class ImportOtrsController < ApplicationController
return return
end end
message_human = 'Host found, but it seems to be no OTRS installation!' result = {}
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 )
#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/ 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
}
# return result key_parts = url_parts[1].split('=')
render json: {
result: 'invalid', Setting.set('import_backend', 'otrs')
message_human: message_human, Setting.set('import_otrs_endpoint', url_parts[0])
Setting.set('import_otrs_endpoint_key', key_parts[1])
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 end
def import_start def import_start
@ -91,10 +91,14 @@ class ImportOtrsController < ApplicationController
end end
def import_status 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 state = Import::OTRS.current_state
render json: { render json: {
data: state, data: state,
result: 'in_progress', result: 'in_progress',

View file

@ -27,6 +27,11 @@ returns calendar object
ip = nil ip = nil
end 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 # call for calendar suggestion
calendar_details = Service::GeoCalendar.location(ip) calendar_details = Service::GeoCalendar.location(ip)
return if !calendar_details return if !calendar_details

View file

@ -19,9 +19,7 @@ write a cache
Cache.write( Cache.write(
'some_key', 'some_key',
{ some: { data: { 'structure' } } }, { some: { data: { 'structure' } } },
{ { expires_in: 24.hours, # optional, default 7 days }
expires_in: 24.hours, # optional, default 7 days
}
) )
=end =end

View file

@ -410,7 +410,7 @@ module Import::OTRS
} }
Setting.set('system_init_done', true) Setting.set('system_init_done', true)
#Setting.set( 'import_mode', false ) Setting.set('import_mode', false)
true true
end end

View file

@ -4,6 +4,8 @@ bundle install
rm -rf tmp/cache* rm -rf tmp/cache*
export Z_LOCALES='en-us:de-de'
rake db:drop rake db:drop
rake db:create rake db:create
rake db:migrate rake db:migrate

View file

@ -3,9 +3,28 @@ require 'browser_test_helper'
class OtrsImportBrowserTest < TestCase class OtrsImportBrowserTest < TestCase
def test_import 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 @browser = browser_instance
location(url: browser_url) location(url: browser_url)
click(css: 'a[href="#import"]')
click(css: 'a[href="#import/otrs"]')
set(
css: '#otrs-link',
value: import_url
)
watch_for( watch_for(
css: 'body', css: 'body',
value: 'xxxx', value: 'xxxx',