From f3511ed502886874242d22695d8cc151f8dd2ce8 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Wed, 8 Apr 2015 16:05:21 +0200 Subject: [PATCH] Fixed typo and replaced example email to prevent duplicate index error. --- contrib/auto_wizard_example.json | 31 ++++++++++++++++++++++++++++ lib/auto_wizzard.rb | 35 ++++++++++++++++---------------- 2 files changed, 49 insertions(+), 17 deletions(-) create mode 100644 contrib/auto_wizard_example.json diff --git a/contrib/auto_wizard_example.json b/contrib/auto_wizard_example.json new file mode 100644 index 000000000..2f554c40e --- /dev/null +++ b/contrib/auto_wizard_example.json @@ -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" + } + ] +} diff --git a/lib/auto_wizzard.rb b/lib/auto_wizzard.rb index a0e7ab971..8e8cb583c 100644 --- a/lib/auto_wizzard.rb +++ b/lib/auto_wizzard.rb @@ -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