From 4f10d35bad5a7b018b78144cec044b5f7f593fd7 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Mon, 7 Jan 2013 10:30:07 +0100 Subject: [PATCH] Added import setting options. --- .../app/controllers/settings.js.coffee | 14 ++++++ db/seeds.rb | 44 ++++++++++++++++++- lib/import/otrs.rb | 23 +++++----- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/app/assets/javascripts/app/controllers/settings.js.coffee b/app/assets/javascripts/app/controllers/settings.js.coffee index b82c67739..e6f1c5ebb 100644 --- a/app/assets/javascripts/app/controllers/settings.js.coffee +++ b/app/assets/javascripts/app/controllers/settings.js.coffee @@ -38,6 +38,19 @@ class Index extends App.ControllerLevel2 nav: '#settings/security', } + # import + if @type is 'import' + @menu = [ + { name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Import::Base' } }, + { name: 'OTRS', 'target': 'otrs', controller: App.SettingsArea, params: { area: 'Import::OTRS' } }, + ] + @page = { + title: 'Import', + head: 'Import', + sub_title: 'System' + nav: '#settings/import', + } + # ticket if @type is 'ticket' @menu = [ @@ -60,5 +73,6 @@ App.Config.set( 'settings/:type', Index, 'Routes' ) App.Config.set( 'System', { prio: 1400, parent: '#settings', name: 'System', target: '#settings/system', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Security', { prio: 1500, parent: '#settings', name: 'Security', target: '#settings/security', role: ['Admin'] }, 'NavBar' ) +App.Config.set( 'Import', { prio: 1550, parent: '#settings', name: 'Import', target: '#settings/import', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Ticket', { prio: 1600, parent: '#settings', name: 'Ticket', target: '#settings/ticket', role: ['Admin'] }, 'NavBar' ) App.Config.set( 'Object', { prio: 1700, parent: '#settings', name: 'Objects', target: '#settings/objects', role: ['Admin'] }, 'NavBar' ) diff --git a/db/seeds.rb b/db/seeds.rb index 26a7c5a91..4d9fec238 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1021,7 +1021,7 @@ Setting.create_if_not_exists( Setting.create_if_not_exists( :title => 'Import Mode', :name => 'import_mode', - :area => 'System::Import', + :area => 'Import::Base', :description => 'Set system in import mode (disable some triggers).', :options => { :form => [ @@ -1043,6 +1043,48 @@ Setting.create_if_not_exists( :frontend => true ) +Setting.create_if_not_exists( + :title => 'Import Endpoint', + :name => 'import_otrs_endpoint', + :area => 'Import::OTRS', + :description => 'Defines OTRS endpoint to import users, ticket, ticket_states and articles.', + :options => { + :form => [ + { + :display => '', + :null => false, + :name => 'import_otrs_endpoint', + :tag => 'input', + }, + ], + }, + :state => { + :value => 'http://otrs_host/otrs', + }, + :frontend => true +) +Setting.create_if_not_exists( + :title => 'Import Key', + :name => 'import_otrs_endpoint_key', + :area => 'Import::OTRS', + :description => 'Defines OTRS endpoint auth key.', + :options => { + :form => [ + { + :display => '', + :null => false, + :name => 'import_otrs_endpoint_key', + :tag => 'input', + }, + ], + }, + :state => { + :value => '', + }, + :frontend => true +) + + email_address = EmailAddress.create_if_not_exists( :id => 1, :realname => 'Zammad', diff --git a/lib/import/otrs.rb b/lib/import/otrs.rb index 9997d6e34..8b74d2a58 100644 --- a/lib/import/otrs.rb +++ b/lib/import/otrs.rb @@ -1,9 +1,6 @@ module Import::OTRS - @@url = 'http://vz109.demo.znuny.com/' - @@key = 'KFWUKfasdjuiU3424k212mALGJU3591KFE' - def self.request(part) - url = @@url + part + url = Setting.get('import_otrs_endpoint') + '/' + part + ';Key=' + Setting.get('import_otrs_endpoint_key') puts 'GET:' + url # response = Net::HTTP.get_response( URI.parse(url), { :use_ssl => true, :verify_mode => OpenSSL::SSL::VERIFY_NONE } ) uri = URI.parse(url) @@ -26,15 +23,15 @@ module Import::OTRS def self.start puts 'Start import...' - # set system in import mode - Setting.set('import_mode', true) +# # set system in import mode +# Setting.set('import_mode', true) # check if system is in import mode if !Setting.get('import_mode') raise "System is not in import mode!" end - response = request("/otrs/public.pl?Key=#{@@key};Action=Export") + response = request("public.pl?Action=Export") return if response.code.to_s != '200' #self.ticket('156115') @@ -69,7 +66,7 @@ module Import::OTRS end def self.ticket(ticket_ids) - url = "/otrs/public.pl?Key=#{@@key};Action=Export;Type=Ticket;" + url = "public.pl?Action=Export;Type=Ticket;" ticket_ids.each {|ticket_id| url = url + "TicketID=#{CGI::escape ticket_id};" } @@ -396,7 +393,7 @@ module Import::OTRS end def self.ticket_state - response = request( "/otrs/public.pl?Key=#{@@key};Action=Export;Type=State" ) + response = request( "public.pl?Action=Export;Type=State" ) return if response.code.to_s != '200' result = json(response) @@ -451,7 +448,7 @@ module Import::OTRS } end def self.ticket_priority - response = request( "/otrs/public.pl?Key=#{@@key};Action=Export;Type=Priority" ) + response = request( "public.pl?Action=Export;Type=Priority" ) return if response.code.to_s != '200' result = json(response) @@ -494,7 +491,7 @@ module Import::OTRS } end def self.ticket_group - response = request( "/otrs/public.pl?Key=#{@@key};Action=Export;Type=Queue" ) + response = request( "public.pl?Action=Export;Type=Queue" ) return if response.code.to_s != '200' result = json(response) @@ -537,7 +534,7 @@ module Import::OTRS } end def self.user - response = request( "/otrs/public.pl?Key=#{@@key};Action=Export;Type=User" ) + response = request( "public.pl?Action=Export;Type=User" ) return if response.code.to_s != '200' result = json(response) map = { @@ -601,7 +598,7 @@ module Import::OTRS while done == false sleep 2 puts "Count=#{count};Offset=#{count}" - response = request( "/otrs/public.pl?Key=#{@@key};Action=Export;Type=Customer;Count=100;Offset=#{count}" ) + response = request( "public.pl?Action=Export;Type=Customer;Count=100;Offset=#{count}" ) count = count + 3000 return if response.code.to_s != '200' result = json(response)