Improved auto wizard.
This commit is contained in:
parent
695d7a9ecc
commit
b239021546
8 changed files with 222 additions and 43 deletions
|
@ -39,13 +39,9 @@ class Index extends App.ControllerContent
|
||||||
# check if auto wizard is executed
|
# check if auto wizard is executed
|
||||||
if data.auto_wizard == true
|
if data.auto_wizard == true
|
||||||
|
|
||||||
# login check / get session user
|
# show message, auto wizard is enabled
|
||||||
App.Auth.loginCheck()
|
@renderAutoWizard()
|
||||||
|
return
|
||||||
if App.Config.get('system_online_service')
|
|
||||||
@navigate 'getting_started/agents'
|
|
||||||
else
|
|
||||||
@navigate 'getting_started/channel'
|
|
||||||
|
|
||||||
# check if import is active
|
# check if import is active
|
||||||
if data.import_mode == true
|
if data.import_mode == true
|
||||||
|
@ -57,11 +53,83 @@ class Index extends App.ControllerContent
|
||||||
)
|
)
|
||||||
|
|
||||||
render: ->
|
render: ->
|
||||||
|
|
||||||
@html App.view('getting_started/intro')()
|
@html App.view('getting_started/intro')()
|
||||||
|
|
||||||
|
renderAutoWizard: ->
|
||||||
|
@html App.view('getting_started/auto_wizard_enabled')()
|
||||||
|
|
||||||
App.Config.set( 'getting_started', Index, 'Routes' )
|
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
|
class Admin extends App.ControllerContent
|
||||||
className: 'getstarted fit'
|
className: 'getstarted fit'
|
||||||
events:
|
events:
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<div class="main flex vertical centered darkBackground">
|
||||||
|
<img class="zammad full logo" src="<%= @C('image_path') + '/' + 'full logo on dark.svg' %>" alt="Zammad">
|
||||||
|
<div class="setup wizard">
|
||||||
|
<div class="wizard-slide">
|
||||||
|
<div class="wizard-body vertical centered">
|
||||||
|
<%- @T('The auto wizard is enabled, please use the prodvided auto wizard url.') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,10 @@
|
||||||
|
<div class="main flex vertical centered darkBackground">
|
||||||
|
<img class="zammad full logo" src="<%= @C('image_path') + '/' + 'full logo on dark.svg' %>" alt="Zammad">
|
||||||
|
<div class="setup wizard">
|
||||||
|
<div class="wizard-slide">
|
||||||
|
<div class="wizard-body vertical centered">
|
||||||
|
<%- @T(@message) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="main flex vertical centered darkBackground">
|
||||||
|
<img class="zammad full logo" src="<%= @C('image_path') + '/' + 'full logo on dark.svg' %>" alt="Zammad">
|
||||||
|
</div>
|
|
@ -35,24 +35,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
|
||||||
return if setup_done_response
|
return if setup_done_response
|
||||||
|
|
||||||
# check it auto wizard is already done
|
# check it auto wizard is already done
|
||||||
auto_wizard_admin = AutoWizard.setup
|
return if auto_wizard_enabled_response
|
||||||
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
|
|
||||||
|
|
||||||
# if master user already exists, we need to be authenticated
|
# if master user already exists, we need to be authenticated
|
||||||
if setup_done
|
if setup_done
|
||||||
|
@ -68,6 +51,62 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
|
||||||
}
|
}
|
||||||
end
|
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
|
def base
|
||||||
|
|
||||||
# check admin permissions
|
# check admin permissions
|
||||||
|
@ -903,6 +942,15 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
|
||||||
mxs
|
mxs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def auto_wizard_enabled_response
|
||||||
|
return false if !AutoWizard.enabled?
|
||||||
|
|
||||||
|
render json: {
|
||||||
|
auto_wizard: true
|
||||||
|
}
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
def setup_done
|
def setup_done
|
||||||
#return false
|
#return false
|
||||||
count = User.all.count()
|
count = User.all.count()
|
||||||
|
@ -914,9 +962,7 @@ curl http://localhost/api/v1/getting_started -v -u #{login}:#{password}
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_done_response
|
def setup_done_response
|
||||||
if !setup_done
|
return false if !setup_done
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
# get all groups
|
# get all groups
|
||||||
groups = Group.where( active: true )
|
groups = Group.where( active: true )
|
||||||
|
|
|
@ -2,11 +2,13 @@ Zammad::Application.routes.draw do
|
||||||
api_path = Rails.configuration.api_path
|
api_path = Rails.configuration.api_path
|
||||||
|
|
||||||
# getting_started
|
# getting_started
|
||||||
match api_path + '/getting_started', to: 'getting_started#index', via: :get
|
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/auto_wizard/:token', to: 'getting_started#auto_wizard_admin', via: :get
|
||||||
match api_path + '/getting_started/email_probe', to: 'getting_started#email_probe', via: :post
|
match api_path + '/getting_started/auto_wizard', to: 'getting_started#auto_wizard_admin', via: :get
|
||||||
match api_path + '/getting_started/email_outbound', to: 'getting_started#email_outbound', via: :post
|
match api_path + '/getting_started/base', to: 'getting_started#base', via: :post
|
||||||
match api_path + '/getting_started/email_inbound', to: 'getting_started#email_inbound', via: :post
|
match api_path + '/getting_started/email_probe', to: 'getting_started#email_probe', via: :post
|
||||||
match api_path + '/getting_started/email_verify', to: 'getting_started#email_verify', 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
|
end
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"Token": "secret_token",
|
||||||
"Users": [
|
"Users": [
|
||||||
{
|
{
|
||||||
"login": "hans.atila@zammad.org",
|
"login": "hans.atila@zammad.org",
|
||||||
|
|
|
@ -2,6 +2,42 @@ module AutoWizard
|
||||||
|
|
||||||
=begin
|
=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.
|
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'
|
there is an example file 'contrib/auto_wizard_example.json'
|
||||||
|
@ -19,16 +55,11 @@ returns
|
||||||
=end
|
=end
|
||||||
|
|
||||||
def self.setup
|
def self.setup
|
||||||
|
auto_wizard_file_location = file_location
|
||||||
|
|
||||||
auto_wizard_file_name = 'auto_wizard.json'
|
auto_wizard_hash = data
|
||||||
auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}"
|
|
||||||
|
|
||||||
return if !File.file?(auto_wizard_file_location)
|
admin_user = User.find(1)
|
||||||
|
|
||||||
auto_wizard_file = File.read(auto_wizard_file_location)
|
|
||||||
auto_wizard_hash = JSON.parse(auto_wizard_file)
|
|
||||||
|
|
||||||
admin_user = User.find( 1 )
|
|
||||||
|
|
||||||
# set Settings
|
# set Settings
|
||||||
if auto_wizard_hash['Settings']
|
if auto_wizard_hash['Settings']
|
||||||
|
@ -125,4 +156,12 @@ returns
|
||||||
|
|
||||||
admin_user
|
admin_user
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue