This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 319
/
Copy pathseeds.rb
76 lines (67 loc) · 4.53 KB
/
seeds.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed.
# Please keep the seeding idempotent, as it may be used as a migration if upgrading a production
# instance is necessary and the target version has introduced any new types requiring seeds.
def should_seed?(model)
empty = model.database.documents['rows'].count == 0
Rails.logger.info(empty ? "Seeding #{model}." : "Not seeding #{model}. Already populated.")
empty
end
def should_seed_env_data?
Rails.env.development? || Rails.env.test?
end
if should_seed? User
registration_worker = Role.create!(:name => 'registration worker', :permissions => [Permission::ENQUIRIES[:view], Permission::CHILDREN[:view_and_search], Permission::CHILDREN[:register], Permission::CHILDREN[:edit], Permission::ENQUIRIES[:create], Permission::ENQUIRIES[:update], Permission::POTENTIAL_MATCHES[:read]])
Role.create!(:name => 'registration officer', :permissions => [Permission::ENQUIRIES[:view], Permission::CHILDREN[:view_and_search], Permission::CHILDREN[:register], Permission::CHILDREN[:edit], Permission::CHILDREN[:export], Permission::REPORTS[:view], Permission::ENQUIRIES[:create], Permission::ENQUIRIES[:update], Permission::POTENTIAL_MATCHES[:read]])
Role.create!(:name => 'child protection specialist', :permissions => [Permission::ENQUIRIES[:view], Permission::CHILDREN[:view_and_search], Permission::CHILDREN[:register], Permission::CHILDREN[:edit], Permission::CHILDREN[:export], Permission::REPORTS[:view], Permission::USERS[:view], Permission::POTENTIAL_MATCHES[:read]])
Role.create!(:name => 'senior official', :permissions => [Permission::REPORTS[:view]])
field_level_admin = Role.create!(:name => 'field level admin', :permissions => [Permission::ENQUIRIES[:view], Permission::USERS[:create_and_edit], Permission::USERS[:view], Permission::USERS[:destroy], Permission::USERS[:disable], Permission::ROLES[:view], Permission::CHILDREN[:view_and_search], Permission::CHILDREN[:export], Permission::REPORTS[:view], Permission::ENQUIRIES[:create], Permission::ENQUIRIES[:update]])
system_admin = Role.create!(:name => 'system admin', :permissions => [Permission::USERS[:create_and_edit], Permission::USERS[:view], Permission::USERS[:destroy], Permission::USERS[:disable], Permission::ROLES[:create_and_edit], Permission::ROLES[:view], Permission::REPORTS[:view], Permission::FORMS[:manage], Permission::SYSTEM[:highlight_fields], Permission::SYSTEM[:system_users], Permission::DEVICES[:blacklist], Permission::DEVICES[:replications]])
User.create!('user_name' => 'rapidftr',
'password' => 'rapidftr',
'password_confirmation' => 'rapidftr',
'full_name' => 'System Administrator',
'email' => '[email protected]',
'disabled' => 'false',
'organisation' => 'N/A',
'role_ids' => [system_admin.id])
User.create!('user_name' => 'field_worker',
'password' => 'field_worker',
'password_confirmation' => 'field_worker',
'full_name' => 'Field Worker',
'email' => '[email protected]',
'disabled' => 'false',
'organisation' => 'N/A',
'role_ids' => [registration_worker.id])
User.create!('user_name' => 'field_admin',
'password' => 'field_admin',
'password_confirmation' => 'field_admin',
'full_name' => 'Field Administrator',
'email' => '[email protected]',
'disabled' => 'false',
'organisation' => 'N/A',
'role_ids' => [field_level_admin.id])
if Rails.env.android?
User.create!('user_name' => 'admin',
'password' => 'admin',
'password_confirmation' => 'admin',
'full_name' => 'admin user',
'email' => '[email protected]',
'disabled' => 'false',
'organisation' => 'Unicef',
'role_ids' => [registration_worker.id, system_admin.id, field_level_admin.id])
end
end
if should_seed? FormSection
if should_seed_env_data?
RapidFTR::ChildrenFormSectionSetup.reset_definitions
RapidFTR::EnquiriesFormSectionSetup.reset_definitions
else
RapidFTR::ChildrenFormSectionSetup.reset_form
RapidFTR::EnquiriesFormSectionSetup.reset_form
end
RapidFTR::I18nSetup.reset_definitions
end
if should_seed? SystemVariable
SystemVariable.create(:name => SystemVariable::SCORE_THRESHOLD, :value => '0.00')
end