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
|
||||
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:
|
||||
|
|
|
@ -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
|
||||
|
||||
# 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 )
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
{
|
||||
"Token": "secret_token",
|
||||
"Users": [
|
||||
{
|
||||
"login": "hans.atila@zammad.org",
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue