Added first draft of AutoWizzard.
This commit is contained in:
parent
46cdb812f5
commit
37c173ed99
1 changed files with 49 additions and 0 deletions
49
lib/auto_wizzard.rb
Normal file
49
lib/auto_wizzard.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
module AutoWizzard
|
||||
|
||||
def self.setup
|
||||
|
||||
auto_wizzard_file_name = 'auto_wizzard.json'
|
||||
|
||||
return if !File.file?(auto_wizzard_file_name)
|
||||
|
||||
auto_wizzard_file = File.read(auto_wizzard_file_name)
|
||||
|
||||
auto_wizzard_hash = JSON.parse(auto_wizzard_file)
|
||||
|
||||
# create Users
|
||||
if auto_wizzard_hash['Users']
|
||||
|
||||
roles = Role.where( :name => ['Agent', 'Admin'] )
|
||||
groups = Group.all
|
||||
|
||||
auto_wizzard_hash['Users'].each { |user_data|
|
||||
|
||||
user_data_symbolized = user_data.symbolize_keys
|
||||
|
||||
user_data_symbolized = user_data_symbolized.merge(
|
||||
{
|
||||
:active => true,
|
||||
:roles => roles,
|
||||
:groups => groups,
|
||||
:updated_by_id => 1,
|
||||
:created_by_id => 1
|
||||
}
|
||||
)
|
||||
|
||||
User.create_or_update(
|
||||
user_data_symbolized
|
||||
)
|
||||
}
|
||||
end
|
||||
|
||||
# set Settings
|
||||
if auto_wizzard_hash['Settings']
|
||||
|
||||
auto_wizzard_hash['Settings'].each { |setting_data|
|
||||
Setting.set( setting_data['name'], setting_data['value'] )
|
||||
}
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue