From 47d2aa5a349f904cb8b3b84a90c11505003bf5a1 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Sat, 23 May 2015 01:54:33 +0200 Subject: [PATCH] Added support to add initial org to initial user. --- contrib/auto_wizard_example.json | 3 ++- lib/auto_wizard.rb | 30 ++++++++++++++-------------- test/integration/auto_wizard_test.rb | 12 +++++++++++ 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/contrib/auto_wizard_example.json b/contrib/auto_wizard_example.json index d781cd3db..5c488c104 100644 --- a/contrib/auto_wizard_example.json +++ b/contrib/auto_wizard_example.json @@ -5,6 +5,7 @@ "firstname": "Hans", "lastname": "Atila", "email": "hans.atila@zammad.org", + "organization": "Demo Organization", "password": "Z4mm4dr0ckZ!" } ], @@ -28,7 +29,7 @@ "email": "zammad_demo@localhost" } ], - "Organization": [ + "Organizations": [ { "name": "Demo Organization" } diff --git a/lib/auto_wizard.rb b/lib/auto_wizard.rb index 31d3e6a3f..0677bcd40 100644 --- a/lib/auto_wizard.rb +++ b/lib/auto_wizard.rb @@ -20,13 +20,12 @@ returns def self.setup - auto_wizard_file_name = 'auto_wizard.json' - auto_wizard_file_name = "#{Rails.root}/#{auto_wizard_file_name}" + auto_wizard_file_name = 'auto_wizard.json' + auto_wizard_file_location = "#{Rails.root}/#{auto_wizard_file_name}" - return if !File.file?(auto_wizard_file_name) - - auto_wizard_file = File.read(auto_wizard_file_name) + 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 ) @@ -40,12 +39,9 @@ returns # create Organizations if auto_wizard_hash['Organizations'] - auto_wizard_hash['Organizations'].each { |organization_data| - organization_data_symbolized = organization_data.symbolize_keys - - organization_data_symbolized = organization_data_symbolized.merge( + organization_data_symbolized = organization_data.symbolize_keys.merge( { updated_by_id: admin_user.id, created_by_id: admin_user.id @@ -66,9 +62,16 @@ returns auto_wizard_hash['Users'].each { |user_data| - user_data_symbolized = user_data.symbolize_keys + # lookup organization + if user_data['organization'] + organization = Organization.find_by(name: user_data['organization']) + user_data.delete('organization') + if organization + user_data['organization_id'] = organization.id + end + end - user_data_symbolized = user_data_symbolized.merge( + user_data_symbolized = user_data.symbolize_keys.merge( { active: true, roles: roles, @@ -91,12 +94,9 @@ returns # create EmailAddresses if auto_wizard_hash['EmailAddresses'] - auto_wizard_hash['EmailAddresses'].each { |email_address_data| - email_address_data_symbolized = email_address_data.symbolize_keys - - email_address_data_symbolized = email_address_data_symbolized.merge( + email_address_data_symbolized = email_address_data.symbolize_keys.merge( { updated_by_id: admin_user.id, created_by_id: admin_user.id diff --git a/test/integration/auto_wizard_test.rb b/test/integration/auto_wizard_test.rb index a6c7ce4bf..8971c52e2 100644 --- a/test/integration/auto_wizard_test.rb +++ b/test/integration/auto_wizard_test.rb @@ -21,6 +21,18 @@ class AutoWizardTest < TestCase timeout: 20, ) + organization_open_by_search( + value: 'Demo Organization', + ) + watch_for( + css: '.active .profile-window', + value: 'Demo Organization', + ) + watch_for( + css: '.active .profile-window', + value: 'Atila', + ) + end end