diff --git a/app/assets/javascripts/app/controllers/getting_started.js.coffee b/app/assets/javascripts/app/controllers/getting_started.js.coffee
index 88f464700..7c82b8821 100644
--- a/app/assets/javascripts/app/controllers/getting_started.js.coffee
+++ b/app/assets/javascripts/app/controllers/getting_started.js.coffee
@@ -39,13 +39,9 @@ class Index extends App.ControllerContent
# check if auto wizard is executed
if data.auto_wizard == true
- # login check / get session user
- App.Auth.loginCheck()
-
- if App.Config.get('system_online_service')
- @navigate 'getting_started/agents'
- else
- @navigate 'getting_started/channel'
+ # show message, auto wizard is enabled
+ @renderAutoWizard()
+ return
# check if import is active
if data.import_mode == true
@@ -57,11 +53,83 @@ class Index extends App.ControllerContent
)
render: ->
-
@html App.view('getting_started/intro')()
+ renderAutoWizard: ->
+ @html App.view('getting_started/auto_wizard_enabled')()
+
App.Config.set( 'getting_started', Index, 'Routes' )
+
+class AutoWizard extends App.ControllerContent
+ className: 'getstarted fit'
+
+ constructor: ->
+ super
+
+ # if already logged in, got to #
+ if @authenticate(true)
+ @navigate '#'
+ return
+
+ # set title
+ @title 'Auto Wizard'
+ @renderSplash()
+ @fetch()
+
+ release: =>
+ @el.removeClass('fit getstarted')
+
+ fetch: ->
+
+ url = "#{@apiPath}/getting_started/auto_wizard"
+ if @token
+ url += "/#{@token}"
+
+ # get data
+ @ajax(
+ id: 'auto_wizard'
+ type: 'GET'
+ url: url
+ processData: true
+ success: (data, status, xhr) =>
+ console.log('DDD', data)
+ # redirect to login if master user already exists
+ if @Config.get('system_init_done')
+ @navigate '#login'
+ return
+
+ # check if auto wizard enabled
+ if data.auto_wizard is false
+ @navigate '#'
+ return
+
+ if data.auto_wizard_success is false
+ if data.message
+ @renderFailed(data)
+ else
+ @renderToken()
+ return
+
+ # login check / get session user
+ App.Auth.loginCheck()
+ @navigate '#'
+ return
+ )
+
+ renderFailed: (data) ->
+ @html App.view('getting_started/auto_wizard_failed')(data)
+
+ renderSplash: ->
+ @html App.view('getting_started/auto_wizard_splash')()
+
+ renderToken: ->
+ @html App.view('getting_started/auto_wizard_enabled')()
+
+App.Config.set( 'getting_started/auto_wizard', AutoWizard, 'Routes' )
+App.Config.set( 'getting_started/auto_wizard/:token', AutoWizard, 'Routes' )
+
+
class Admin extends App.ControllerContent
className: 'getstarted fit'
events:
diff --git a/app/assets/javascripts/app/views/getting_started/auto_wizard_enabled.jst.eco b/app/assets/javascripts/app/views/getting_started/auto_wizard_enabled.jst.eco
new file mode 100644
index 000000000..f37c50427
--- /dev/null
+++ b/app/assets/javascripts/app/views/getting_started/auto_wizard_enabled.jst.eco
@@ -0,0 +1,10 @@
+
+
![Zammad](<%= @C('image_path') + '/' + 'full logo on dark.svg' %>)
+
+
+
+ <%- @T('The auto wizard is enabled, please use the prodvided auto wizard url.') %>
+
+
+
+
\ No newline at end of file
diff --git a/app/assets/javascripts/app/views/getting_started/auto_wizard_failed.jst.eco b/app/assets/javascripts/app/views/getting_started/auto_wizard_failed.jst.eco
new file mode 100644
index 000000000..0036b1e40
--- /dev/null
+++ b/app/assets/javascripts/app/views/getting_started/auto_wizard_failed.jst.eco
@@ -0,0 +1,10 @@
+
+
![Zammad](<%= @C('image_path') + '/' + 'full logo on dark.svg' %>)
+
+
+
+ <%- @T(@message) %>
+
+
+
+
\ No newline at end of file
diff --git a/app/assets/javascripts/app/views/getting_started/auto_wizard_splash.jst.eco b/app/assets/javascripts/app/views/getting_started/auto_wizard_splash.jst.eco
new file mode 100644
index 000000000..8cb182521
--- /dev/null
+++ b/app/assets/javascripts/app/views/getting_started/auto_wizard_splash.jst.eco
@@ -0,0 +1,3 @@
+
+
![Zammad](<%= @C('image_path') + '/' + 'full logo on dark.svg' %>)
+
\ No newline at end of file
diff --git a/app/controllers/getting_started_controller.rb b/app/controllers/getting_started_controller.rb
index f8e799ab2..a38be1db8 100644
--- a/app/controllers/getting_started_controller.rb
+++ b/app/controllers/getting_started_controller.rb
@@ -35,24 +35,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
return if setup_done_response
# check it auto wizard is already done
- auto_wizard_admin = AutoWizard.setup
- if auto_wizard_admin
-
- # set current session user
- current_user_set(auto_wizard_admin)
-
- # set system init to done
- Setting.set( 'system_init_done', true )
-
- render json: {
- auto_wizard: true,
- setup_done: setup_done,
- import_mode: Setting.get('import_mode'),
- import_backend: Setting.get('import_backend'),
- system_online_service: Setting.get('system_online_service'),
- }
- return
- end
+ return if auto_wizard_enabled_response
# if master user already exists, we need to be authenticated
if setup_done
@@ -68,6 +51,62 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
}
end
+ def auto_wizard_admin
+
+ # check if system setup is already done
+ return if setup_done_response
+
+ # check it auto wizard is enabled
+ if !AutoWizard.enabled?
+ render json: {
+ auto_wizard: false,
+ }
+ return
+ end
+
+ # verify auto wizard file
+ auto_wizard_data = AutoWizard.data
+ if !auto_wizard_data || auto_wizard_data.empty?
+ render json: {
+ auto_wizard: true,
+ auto_wizard_success: false,
+ message: 'Invalid auto wizard file.',
+ }
+ return
+ end
+
+ # verify auto wizard token
+ if auto_wizard_data['Token'] && auto_wizard_data['Token'] != params[:token]
+ render json: {
+ auto_wizard: true,
+ auto_wizard_success: false,
+ }
+ return
+ end
+
+ # execute auto wizard
+ auto_wizard_admin = AutoWizard.setup
+ if !auto_wizard_admin
+ render json: {
+ auto_wizard: true,
+ auto_wizard_success: false,
+ message: 'Error during execution of auto wizard.',
+ }
+ return
+ end
+
+ # set current session user
+ current_user_set(auto_wizard_admin)
+
+ # set system init to done
+ Setting.set('system_init_done', true)
+
+ render json: {
+ auto_wizard: true,
+ auto_wizard_success: true,
+ }
+ end
+
def base
# check admin permissions
@@ -903,6 +942,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
mxs
end
+ def auto_wizard_enabled_response
+ return false if !AutoWizard.enabled?
+
+ render json: {
+ auto_wizard: true
+ }
+ true
+ end
+
def setup_done
#return false
count = User.all.count()
@@ -914,9 +962,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
end
def setup_done_response
- if !setup_done
- return false
- end
+ return false if !setup_done
# get all groups
groups = Group.where( active: true )
diff --git a/config/routes/getting_started.rb b/config/routes/getting_started.rb
index 72d1e2fe5..7597256d5 100644
--- a/config/routes/getting_started.rb
+++ b/config/routes/getting_started.rb
@@ -2,11 +2,13 @@ Zammad::Application.routes.draw do
api_path = Rails.configuration.api_path
# getting_started
- match api_path + '/getting_started', to: 'getting_started#index', via: :get
- match api_path + '/getting_started/base', to: 'getting_started#base', via: :post
- match api_path + '/getting_started/email_probe', to: 'getting_started#email_probe', via: :post
- match api_path + '/getting_started/email_outbound', to: 'getting_started#email_outbound', via: :post
- match api_path + '/getting_started/email_inbound', to: 'getting_started#email_inbound', via: :post
- match api_path + '/getting_started/email_verify', to: 'getting_started#email_verify', via: :post
+ match api_path + '/getting_started', to: 'getting_started#index', via: :get
+ match api_path + '/getting_started/auto_wizard/:token', to: 'getting_started#auto_wizard_admin', via: :get
+ match api_path + '/getting_started/auto_wizard', to: 'getting_started#auto_wizard_admin', via: :get
+ match api_path + '/getting_started/base', to: 'getting_started#base', via: :post
+ match api_path + '/getting_started/email_probe', to: 'getting_started#email_probe', via: :post
+ match api_path + '/getting_started/email_outbound', to: 'getting_started#email_outbound', via: :post
+ match api_path + '/getting_started/email_inbound', to: 'getting_started#email_inbound', via: :post
+ match api_path + '/getting_started/email_verify', to: 'getting_started#email_verify', via: :post
end
diff --git a/contrib/auto_wizard_example.json b/contrib/auto_wizard_example.json
index 384078c57..3dbd73e59 100644
--- a/contrib/auto_wizard_example.json
+++ b/contrib/auto_wizard_example.json
@@ -1,4 +1,5 @@
{
+ "Token": "secret_token",
"Users": [
{
"login": "hans.atila@zammad.org",
diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb
index 3686625ed..18c2f3346 100644
--- a/lib/auto_wizard.rb
+++ b/lib/auto_wizard.rb
@@ -2,6 +2,42 @@ module AutoWizard
=begin
+check if auto wizard is enabled
+
+ AutoWizard.enabled?
+
+returns
+
+ true | false
+
+=end
+
+ def self.enabled?
+ auto_wizard_file_location = file_location
+ return false if !File.file?(auto_wizard_file_location)
+ true
+ end
+
+=begin
+
+get auto wizard data
+
+ AutoWizard.data
+
+returns
+
+ content of auto wizard file as object
+
+=end
+
+ def self.data
+ auto_wizard_file_location = file_location
+ fail "So such file #{auto_wizard_file_location}" if !File.file?(auto_wizard_file_location)
+ JSON.parse( File.read(auto_wizard_file_location) )
+ end
+
+=begin
+
creates or updates Users, EmailAddresses and sets Settings based on the 'auto_wizard.json' file placed in the root directory.
there is an example file 'contrib/auto_wizard_example.json'
@@ -19,16 +55,11 @@ returns
=end
def self.setup
+ auto_wizard_file_location = file_location
- auto_wizard_file_name = 'auto_wizard.json'
- auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}"
+ auto_wizard_hash = data
- return if !File.file?(auto_wizard_file_location)
-
- auto_wizard_file = File.read(auto_wizard_file_location)
- auto_wizard_hash = JSON.parse(auto_wizard_file)
-
- admin_user = User.find( 1 )
+ admin_user = User.find(1)
# set Settings
if auto_wizard_hash['Settings']
@@ -125,4 +156,12 @@ returns
admin_user
end
+
+ private
+
+ def self.file_location
+ auto_wizard_file_name = 'auto_wizard.json'
+ auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}"
+ auto_wizard_file_location
+ end
end