Fixed typo and replaced example email to prevent duplicate index error.

This commit is contained in:
Thorsten Eckel 2015-04-08 16:05:21 +02:00
parent af20b86d84
commit f3511ed502
2 changed files with 49 additions and 17 deletions

View file

@ -0,0 +1,31 @@
{
"Users": [
{
"login": "hans.atila@zammad.org",
"firstname": "Hans",
"lastname": "Atila",
"email": "hans.atila@zammad.org",
"password": "Z4mm4dr0ckZ!"
}
],
"Settings": [
{
"name": "developer_mode",
"value": true
},
{
"name": "product_name",
"value": "Zammad Demo System"
},
{
"name": "system_online_service",
"value": true
}
],
"EmailAddresses": [
{
"realname": "Zammad Demo System",
"email": "zammad_demo@localhost"
}
]
}

View file

@ -1,42 +1,43 @@
module AutoWizzard
module AutoWizard
=begin
creates or updates Users, EmailAddresses and sets Settings based on the 'auto_wizzard.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_wizzard_example.json'
there is an example file 'contrib/auto_wizard_example.json'
AutoWizzard.setup
AutoWizard.setup
returns
the first created User if a 'auto_wizzard.json' file was found and processed, containing at least one entry in Users
the first created User if a 'auto_wizard.json' file was found and processed, containing at least one entry in Users
the User with id 1 (NULL) if a 'auto_wizzard.json' file was found and processed, containing no Users
the User with id 1 (NULL) if a 'auto_wizard.json' file was found and processed, containing no Users
nil if no 'auto_wizzard.json' file was found
nil if no 'auto_wizard.json' file was found
=end
def self.setup
auto_wizzard_file_name = 'auto_wizzard.json'
auto_wizard_file_name = 'auto_wizard.json'
auto_wizard_file_name = "#{Rails.root.to_s}/#{auto_wizard_file_name}"
return if !File.file?(auto_wizzard_file_name)
return if !File.file?(auto_wizard_file_name)
auto_wizzard_file = File.read(auto_wizzard_file_name)
auto_wizard_file = File.read(auto_wizard_file_name)
auto_wizzard_hash = JSON.parse(auto_wizzard_file)
auto_wizard_hash = JSON.parse(auto_wizard_file)
admin_user = User.find( 1 )
# create Users
if auto_wizzard_hash['Users']
if auto_wizard_hash['Users']
roles = Role.where( :name => ['Agent', 'Admin'] )
groups = Group.all
auto_wizzard_hash['Users'].each { |user_data|
auto_wizard_hash['Users'].each { |user_data|
user_data_symbolized = user_data.symbolize_keys
@ -62,17 +63,17 @@ returns
end
# set Settings
if auto_wizzard_hash['Settings']
if auto_wizard_hash['Settings']
auto_wizzard_hash['Settings'].each { |setting_data|
auto_wizard_hash['Settings'].each { |setting_data|
Setting.set( setting_data['name'], setting_data['value'] )
}
end
# add EmailAddresses
if auto_wizzard_hash['EmailAddresses']
if auto_wizard_hash['EmailAddresses']
auto_wizzard_hash['EmailAddresses'].each { |email_address_data|
auto_wizard_hash['EmailAddresses'].each { |email_address_data|
email_address_data_symbolized = email_address_data.symbolize_keys