Added init version of importer.

This commit is contained in:
Martin Edenhofer 2014-10-26 13:13:44 +01:00
parent a16717f509
commit 0225ba1cdf
13 changed files with 465 additions and 198 deletions

View file

@ -7,6 +7,11 @@ class Index extends App.Controller
if window.location.pathname.substr(0,5) is '/test'
return
# check if import is active
if @Config.get('import_mode')
@navigate '#import'
return
# route to getting started screen
if !@Config.get('system_init_done')
@navigate '#getting_started'

View file

@ -6,10 +6,16 @@ class Index extends App.ControllerContent
if @authenticate(true)
@navigate '#'
return
# set title
@title 'Get Started'
# if not import backend exists, go ahead
if !App.Config.get('ImportPlugins')
@navigate 'getting_started/base'
return
@fetch()
release: =>
@ -30,6 +36,11 @@ class Index extends App.ControllerContent
@navigate '#login'
return
# check if import is active
if data.import_mode == true
@navigate '#import/' + data.import_backend
return
# render page
@render()
)
@ -55,6 +66,7 @@ class Base extends App.ControllerContent
if @authenticate(true)
@navigate '#'
return
# set title
@title 'Configure Base'
@ -79,6 +91,11 @@ class Base extends App.ControllerContent
@navigate '#login'
return
# check if import is active
if data.import_mode == true
@navigate '#import/' + data.import_backend
return
# render page
@render()
)
@ -263,6 +280,7 @@ class Admin extends App.ControllerContent
if @authenticate(true)
@navigate '#'
return
# set title
@title 'Create Admin'
@ -290,6 +308,11 @@ class Admin extends App.ControllerContent
@navigate '#login'
return
# check if import is active
if data.import_mode == true
@navigate '#import/' + data.import_backend
return
# load group collection
App.Collection.load( type: 'Group', data: data.groups )
@ -393,9 +416,6 @@ class Agent extends App.ControllerContent
id: 'getting_started',
type: 'GET',
url: @apiPath + '/getting_started',
data: {
# view: @view,
}
processData: true,
success: (data, status, xhr) =>
@ -404,6 +424,11 @@ class Agent extends App.ControllerContent
@navigate '#getting_started/admin'
return
# check if import is active
if data.import_mode == true
@navigate '#import/' + data.import_backend
return
# load group collection
App.Collection.load( type: 'Group', data: data.groups )
@ -469,44 +494,4 @@ class Agent extends App.ControllerContent
}
)
App.Config.set( 'getting_started/agents', Agent, 'Routes' )
class Import extends App.ControllerContent
className: 'getstarted fit'
constructor: ->
super
# set title
@title 'Import'
@fetch()
fetch: ->
# get data
@ajax(
id: 'getting_started',
type: 'GET',
url: @apiPath + '/getting_started',
data: {
# view: @view,
}
processData: true,
success: (data, status, xhr) =>
# redirect to login if master user already exists
if data.setup_done
@navigate '#login'
return
# render page
@render()
)
render: ->
@html App.view('getting_started/import')()
App.Config.set( 'getting_started/import', Import, 'Routes' )
App.Config.set( 'getting_started/agents', Agent, 'Routes' )

View file

@ -1,18 +1,12 @@
class Index extends App.ControllerContent
class Import extends App.ControllerContent
className: 'getstarted fit'
events:
'submit form': 'submit',
'click .submit': 'submit',
constructor: ->
super
# set title
@title 'Get Started'
@navupdate '#get_started'
@title 'Import'
@master_user = 0
@fetch()
fetch: ->
@ -22,17 +16,17 @@ class Index extends App.ControllerContent
id: 'getting_started',
type: 'GET',
url: @apiPath + '/getting_started',
data: {
# view: @view,
}
processData: true,
success: (data, status, xhr) =>
# get meta data
@master_user = data.master_user
# redirect to login if master user already exists
if data.setup_done
@navigate '#login'
return
# load group collection
App.Collection.load( type: 'Group', data: data.groups )
if data.import_mode == true
@navigate '#import/' + data.import_backend
return
# render page
@render()
@ -40,113 +34,10 @@ class Index extends App.ControllerContent
render: ->
# check authentication, redirect to login if master user already exists
#if !@master_user && !@authenticate()
# @navigate '#login'
items = App.Config.get('ImportPlugins')
@html App.view('getting_started')(
master_user: @master_user
@html App.view('import/index')(
items: items
)
new App.ControllerForm(
el: @el.find('#form-master')
model: App.User
screen: 'signup'
autofocus: true
)
new App.ControllerForm(
el: @el.find('#form-agent')
model: App.User
screen: 'invite_agent'
autofocus: true
)
if !@master_user
@el.find('.agent_user').removeClass('hide')
submit: (e) ->
e.preventDefault()
@params = @formParam(e.target)
# if no login is given, use emails as fallback
if !@params.login && @params.email
@params.login = @params.email
# set invite flag
@params.invite = true
# find agent role
role = App.Role.findByAttribute( 'name', 'Agent' )
if role
@params.role_ids = role.id
else
@params.role_ids = [0]
@log 'notice', 'updateAttributes', @params
user = new App.User
user.load(@params)
errors = user.validate()
if errors
@log 'error', errors
@formValidate( form: e.target, errors: errors )
return false
# save user
user.save(
done: =>
if @master_user
@master_user = false
App.Auth.login(
data: {
username: @params.login
password: @params.password
},
success: @relogin
# error: @error,
)
@Config.set('system_init_done', true)
App.Event.trigger 'notify', {
type: 'success'
msg: App.i18n.translateContent( 'Welcome to %s!', @Config.get('product_name') )
timeout: 2500
}
else
App.Event.trigger 'notify', {
type: 'success'
msg: App.i18n.translateContent( 'Invitation sent!' )
timeout: 3500
}
# rerender page
@render()
fail: (data) ->
App.Event.trigger 'notify', {
type: 'error'
msg: App.i18n.translateContent( 'Can\'t create user!' )
timeout: 2500
}
# @modalHide()
)
relogin: (data, status, xhr) =>
@log 'notice', 'relogin:success', data
# add notify
App.Event.trigger 'notify:removeall'
# @notify
# type: 'success',
# msg: 'Thanks for joining. Email sent to "' + @params.email + '". Please verify your email address.'
@el.find('.master_user').addClass('hide')
@el.find('.agent_user').removeClass('hide')
@el.find('.tabs .tab.active').removeClass('active')
@el.find('.tabs .invite_agents').addClass('active')
# @el.find('.master_user').fadeOut('slow', =>
# @el.find('.agent_user').fadeIn()
# )
App.Config.set( 'import', Index, 'Routes' )
App.Config.set( 'import', Import, 'Routes' )

View file

@ -0,0 +1,149 @@
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 data.setup_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()
else
showDownload = =>
@$('[data-slide=otrs-prepare]').toggleClass('hide')
@$('[data-slide=otrs-plugin]').toggleClass('hide')
@delay( showDownload, 2500 )
)
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-prepare]').addClass('hide')
@$('[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) =>
# validate form
console.log(data)
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 is item.done
element.addClass('is-done')
else
element.removeClass('is-done')
@delay( @updateMigration, 3000 )
)
App.Config.set( 'import/otrs', Index, 'Routes' )
App.Config.set( 'otrs', {
image: 'otrs-logo.png'
title: 'OTRS'
name: 'OTRS'
url: '#import/otrs'
}, 'ImportPlugins' )

View file

@ -1,23 +0,0 @@
<div class="main flex centered darkBackground">
<div class="import wizard hero-unit">
<div class="wizard-slide vertical" data-slide="home">
<h2><%- @T('Import from') %></h2>
<div class="wizard-body flex vertical justified">
<div class="import-source centered" data-source="otrs" data-target="otrs-prepare-plugin">
<img class="logo" src="<%= @C('otrs-logo.png') %>" alt="OTRS" height="37">
</div>
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-prepare-plugin" data-hide="2330">
<h2>Create OTRS Migration Plugin</h2>
<div class="wizard-body flex vertical justified">
<p class="wizard-loadingText">
<span class="loading icon"></span> Personalise Migration Plugin ..
</p>
</div>
<div class="wizard-controls horizontal center">
<a class="subtle-link" data-target="home">Go Back</a>
</div>
</div>
</div>
</div>

View file

@ -4,7 +4,7 @@
<h2><%- @T('Welcome to %s', @C('product_name') ) %></h2>
<div class="wizard-body flex vertical justified">
<div class="centered">
<a href="#getting_started/import"><%- @T('Import from other System') %></a>
<a href="#import"><%- @T('Import from other System') %></a>
|
<a href="#getting_started/base"><%- @T('Setup new System') %></a>
</div>

View file

@ -0,0 +1,17 @@
<div class="main flex centered darkBackground">
<div class="import wizard hero-unit">
<div class="wizard-slide vertical">
<h2><%- @T('Import from') %></h2>
<div class="wizard-body flex vertical justified">
<div class="import-source centered">
<% for key, item of @items: %>
<a href="<%= item.url %>"><img class="logo" src="<%= @C('image_path') + '/' + item.image %>" alt="<%= item.name %>" height="37"></a>
<% end %>
</div>
</div>
<div class="wizard-controls horizontal center">
<a class="subtle-link" href="#getting_started"><%- @T('Go Back') %></a>
</div>
</div>
</div>
</div>

View file

@ -0,0 +1,91 @@
<div class="main flex centered darkBackground">
<div class="import wizard hero-unit">
<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="subtle-link" 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>
<div class="wizard-body flex vertical justified">
<p>
<%- @T('Download and install your personalised OTRS Migration Plugin on your OTRS System') %>:
</p>
<a class="btn btn--primary btn--download js-download" download><span class="download icon"></span> <%- @T('Personal Migration Plugin') %></a>
</div>
<div class="wizard-controls horizontal center">
<a class="subtle-link" href="#import"><%- @T('Go Back') %></a>
<div class="btn btn--primary align-right hide js-otrs-link"><%- @T('Next') %></div>
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-link">
<h2><%- @T('Link OTRS') %></h2>
<div class="wizard-body flex vertical justified">
<p>
<%- @T('Enter the link provided by the plugin at the end of the installation to link the two systems') %>:
</p>
<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">
<div class="input-feedback centered">
<div class="small loading icon"></div>
<div class="error icon"></div>
<div class="checkmark icon"></div>
</div>
</div>
<div class="error otrs-link-error"></div>
</div>
</div>
<div class="wizard-controls horizontal center">
<a class="subtle-link" href="#import"><%- @T('Go Back') %></a>
<div class="btn btn--primary align-right hide js-migration-start" data-target="otrs-start-migration"><%- @T('Migrate OTRS Data') %></div>
</div>
</div>
<div class="wizard-slide vertical hide" data-slide="otrs-import">
<h2><%- @T('OTRS Migration') %></h2>
<div class="wizard-body flex vertical justified">
<table class="progressTable">
<tr class="js-config">
<td>
<td><span><%- @T('Configuration') %></span>
<td class="progressTable-progressCell">
<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="checkmark icon"></div>
</div>
</tr>
<tr class="js-user">
<td><span class="js-done">-</span>/<span class="js-total">-</span>
<td><span><%- @T('Users') %></span>
<td class="progressTable-progressCell">
<div class="horizontal center">
<div class="flex"><progress max="42" value="42"></progress></div>
<div class="checkmark icon"></div>
</div>
</tr>
<tr class="js-ticket">
<td><span class="js-done">-</span>/<span class="js-total">-</span>
<td><span><%- @T('Tickets') %></span>
<td class="progressTable-progressCell">
<div class="horizontal center">
<div class="flex"><progress max="134318" value="134318"></progress></div>
<div class="checkmark icon"></div>
</div>
</tr>
</table>
</div>
<div class="wizard-controls horizontal center">
<a href="#" class="btn btn--primary align-right js-finished"><%- @T('Done') %></a>
</div>
</div>
</div>
</div>

View file

@ -42,8 +42,10 @@ curl http://localhost/api/v1/getting_started.json -v -u #{login}:#{password}
# return result
render :json => {
:setup_done => setup_done,
:groups => groups,
:setup_done => setup_done,
:import_mode => Setting.get('import_mode'),
:import_backend => Setting.get('import_backend'),
:groups => groups,
}
end
@ -201,10 +203,10 @@ curl http://localhost/api/v1/getting_started.json -v -u #{login}:#{password}
# connection test
translationMap = {
'authentication failed' => 'Authentication failed!',
'authentication failed' => 'Authentication failed!',
'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
'No route to host' => 'No route to host!',
'Connection refused' => 'Connection refused!',
'No route to host' => 'No route to host!',
'Connection refused' => 'Connection refused!',
}
if params[:adapter] == 'IMAP'
begin
@ -253,7 +255,7 @@ curl http://localhost/api/v1/getting_started.json -v -u #{login}:#{password}
'x-zammad-ignore' => 'true',
}
)
(1..10).each {|loop|
(1..5).each {|loop|
sleep 10
# fetch mailbox
@ -315,7 +317,7 @@ curl http://localhost/api/v1/getting_started.json -v -u #{login}:#{password}
private
def setup_done
#return false
return false
count = User.all.count()
done = true
if count <= 2

View file

@ -0,0 +1,132 @@
# Copyright (C) 2012-2014 Zammad Foundation, http://zammad-foundation.org/
class ImportOtrsController < ApplicationController
def url_check
return if setup_done_response
# validate
if !params[:url] ||params[:url] !~ /^(http|https):\/\/.+?$/
render :json => {
:result => 'invalid',
:message => 'Invalid!',
}
return
end
# connection test
translationMap = {
'authentication failed' => 'Authentication failed!',
'getaddrinfo: nodename nor servname provided, or not known' => 'Hostname not found!',
'No route to host' => 'No route to host!',
'Connection refused' => 'Connection refused!',
}
# try connecting to otrs
response = UserAgent.request(params[:url])
if !response.success? && response.code.to_s !~ /^40.$/
message_human = ''
translationMap.each {|key, message|
if response.error.to_s =~ /#{Regexp.escape(key)}/i
message_human = message
end
}
render :json => {
:result => 'invalid',
:message_human => message_human,
:message => response.error.to_s,
}
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 multible / in url
url.gsub!(/([^:])(\/+\/)/, "\\1/")
response = UserAgent.request( url )
Setting.set('import_otrs_endpoint', url)
Setting.set('import_mode', true)
Setting.set('import_backend', 'otrs')
if response.body =~ /zammad migrator/
render :json => {
:url => url,
:result => 'ok',
}
return
elsif response.body =~ /(otrs\sag|otrs.com|otrs.org)/i
message_human = 'Host found, but no OTRS migrator is installed!'
end
}
# return result
render :json => {
:result => 'invalid',
:message_human => message_human,
}
end
def import_start
return if setup_done_response
# start migration
render :json => {
:result => 'ok',
}
end
def import_status
return if setup_done_response
# start migration
render :json => {
:data => {
:User => {
:total => 1300,
:done => rand(1300).to_i,
},
:Ticket => {
:total => 13000,
:done => rand(13000).to_i,
},
:Config => {
:total => 1,
:done => rand(2).to_i
},
},
:result => 'in_progress',
}
end
private
def setup_done
return false
count = User.all.count()
done = true
if count <= 2
done = false
end
done
end
def setup_done_response
if !setup_done
return false
end
render :json => {
:setup_done => true,
}
true
end
end

View file

@ -3,7 +3,7 @@ Zammad::Application.routes.draw do
# getting_started
match api_path + '/getting_started', :to => 'getting_started#index', :via => :get
match api_path + '/getting_started/base_fqdn', :to => 'getting_started#base_fqdn', :via => :post
match api_path + '/getting_started/base_url', :to => 'getting_started#base_url', :via => :post
match api_path + '/getting_started/base_outbound', :to => 'getting_started#base_outbound', :via => :post
match api_path + '/getting_started/base_inbound', :to => 'getting_started#base_inbound', :via => :post

View file

@ -0,0 +1,9 @@
Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path
# import otrs
match api_path + '/import/otrs/url_check', :to => 'import_otrs#url_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
end

View file

@ -1115,6 +1115,15 @@ Setting.create_if_not_exists(
:state => false,
:frontend => true
)
Setting.create_if_not_exists(
:title => 'Import Backend',
:name => 'import_backend',
:area => 'Import::Base::Internal',
:description => 'Set backend which is used for import.',
:options => {},
:state => '',
:frontend => true
)
Setting.create_if_not_exists(
:title => 'Ignore Escalation/SLA Information',
:name => 'import_ignore_sla',