Description:
moved root/roles creation from migration to seed.rb
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r276:d30b9a9e9085 - - 3 files changed: 86 inserted, 97 deleted
@@ -1,96 +1,83 | |||
|
1 | - | |
|
2 | - def create_configuration_key(key, | |
|
3 | - value_type, | |
|
4 | - default_value, | |
|
5 | - description='') | |
|
6 | - conf = (Configuration.find_by_key(key) || | |
|
7 | - Configuration.new(:key => key, | |
|
8 | - :value_type => value_type, | |
|
9 | - :value => default_value)) | |
|
10 | - conf.description = description | |
|
11 | - conf.save | |
|
12 | - end | |
|
13 | - | |
|
14 | 1 |
|
|
15 | 2 | [ |
|
16 | 3 | { |
|
17 | 4 | :key => 'system.single_user_mode', |
|
18 | 5 | :value_type => 'boolean', |
|
19 | 6 | :default_value => 'false', |
|
20 | 7 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
21 | 8 | }, |
|
22 | - | |
|
9 | + | |
|
23 | 10 | { |
|
24 | 11 | :key => 'ui.front.title', |
|
25 | 12 | :value_type => 'string', |
|
26 | 13 | :default_value => 'Grader' |
|
27 | 14 | }, |
|
28 | - | |
|
15 | + | |
|
29 | 16 | { |
|
30 | 17 | :key => 'ui.front.welcome_message', |
|
31 | 18 | :value_type => 'string', |
|
32 | 19 | :default_value => 'Welcome!' |
|
33 | 20 | }, |
|
34 | - | |
|
21 | + | |
|
35 | 22 | { |
|
36 | 23 | :key => 'ui.show_score', |
|
37 | 24 | :value_type => 'boolean', |
|
38 | 25 | :default_value => 'true' |
|
39 | 26 | }, |
|
40 | 27 | |
|
41 | 28 | { |
|
42 | 29 | :key => 'contest.time_limit', |
|
43 | 30 | :value_type => 'string', |
|
44 | 31 | :default_value => 'unlimited', |
|
45 | 32 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits.' |
|
46 | 33 | }, |
|
47 | - | |
|
34 | + | |
|
48 | 35 | { |
|
49 | 36 | :key => 'system.mode', |
|
50 | 37 | :value_type => 'string', |
|
51 | 38 | :default_value => 'standard', |
|
52 | 39 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
53 | 40 | }, |
|
54 | - | |
|
41 | + | |
|
55 | 42 | { |
|
56 | 43 | :key => 'contest.name', |
|
57 | 44 | :value_type => 'string', |
|
58 | 45 | :default_value => 'Grader', |
|
59 | 46 | :description => 'This name will be shown on the user header bar.' |
|
60 | 47 | }, |
|
61 | - | |
|
48 | + | |
|
62 | 49 | { |
|
63 | 50 | :key => 'contest.multisites', |
|
64 | 51 | :value_type => 'boolean', |
|
65 | 52 | :default_value => 'false', |
|
66 | 53 | :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.' |
|
67 | 54 | }, |
|
68 | - | |
|
55 | + | |
|
69 | 56 | { |
|
70 | 57 | :key => 'system.online_registration', |
|
71 | 58 | :value_type => 'boolean', |
|
72 | 59 | :default_value => 'false', |
|
73 | 60 | :description => 'This option enables online registration.' |
|
74 | 61 | }, |
|
75 | - | |
|
62 | + | |
|
76 | 63 | # If Configuration['system.online_registration'] is true, the |
|
77 | 64 | # system allows online registration, and will use these |
|
78 | 65 | # information for sending confirmation emails. |
|
79 | 66 | { |
|
80 | 67 | :key => 'system.online_registration.smtp', |
|
81 | 68 | :value_type => 'string', |
|
82 | 69 | :default_value => 'smtp.somehost.com' |
|
83 | 70 | }, |
|
84 | - | |
|
71 | + | |
|
85 | 72 | { |
|
86 | 73 | :key => 'system.online_registration.from', |
|
87 | 74 | :value_type => 'string', |
|
88 | 75 | :default_value => 'your.email@address' |
|
89 | 76 | }, |
|
90 | - | |
|
77 | + | |
|
91 | 78 | { |
|
92 | 79 | :key => 'system.admin_email', |
|
93 | 80 | :value_type => 'string', |
|
94 | 81 | :default_value => 'admin@admin.email' |
|
95 | 82 | }, |
|
96 | 83 | |
@@ -108,17 +95,84 | |||
|
108 | 95 | :key => 'contest.test_request.early_timeout', |
|
109 | 96 | :value_type => 'boolean', |
|
110 | 97 | :default_value => 'false' |
|
111 | 98 | } |
|
112 | 99 | ] |
|
113 | 100 | |
|
114 | - CONFIGURATIONS.each do |conf| | |
|
115 | - if conf.has_key? :description | |
|
116 | - desc = conf[:description] | |
|
117 | - else | |
|
118 | - desc = '' | |
|
101 | + | |
|
102 | + def create_configuration_key(key, | |
|
103 | + value_type, | |
|
104 | + default_value, | |
|
105 | + description='') | |
|
106 | + conf = (Configuration.find_by_key(key) || | |
|
107 | + Configuration.new(:key => key, | |
|
108 | + :value_type => value_type, | |
|
109 | + :value => default_value)) | |
|
110 | + conf.description = description | |
|
111 | + conf.save | |
|
112 | + end | |
|
113 | + | |
|
114 | + def seed_config | |
|
115 | + CONFIGURATIONS.each do |conf| | |
|
116 | + if conf.has_key? :description | |
|
117 | + desc = conf[:description] | |
|
118 | + else | |
|
119 | + desc = '' | |
|
120 | + end | |
|
121 | + create_configuration_key(conf[:key], | |
|
122 | + conf[:value_type], | |
|
123 | + conf[:default_value], | |
|
124 | + desc) | |
|
119 | 125 | end |
|
120 | - create_configuration_key(conf[:key], | |
|
121 | - conf[:value_type], | |
|
122 | - conf[:default_value], | |
|
123 | - desc) | |
|
126 | + end | |
|
127 | + | |
|
128 | + def seed_roles | |
|
129 | + return if Role.find_by_name('admin') | |
|
130 | + | |
|
131 | + role = Role.create(:name => 'admin') | |
|
132 | + user_admin_right = Right.create(:name => 'user_admin', | |
|
133 | + :controller => 'user_admin', | |
|
134 | + :action => 'all') | |
|
135 | + problem_admin_right = Right.create(:name=> 'problem_admin', | |
|
136 | + :controller => 'problems', | |
|
137 | + :action => 'all') | |
|
138 | + | |
|
139 | + graders_right = Right.create(:name => 'graders_admin', | |
|
140 | + :controller => 'graders', | |
|
141 | + :action => 'all') | |
|
142 | + | |
|
143 | + role.rights << user_admin_right; | |
|
144 | + role.rights << problem_admin_right; | |
|
145 | + role.rights << graders_right; | |
|
146 | + role.save | |
|
124 | 147 | end |
|
148 | + | |
|
149 | + def seed_root | |
|
150 | + return if User.find_by_login('root') | |
|
151 | + | |
|
152 | + root = User.new(:login => 'root', | |
|
153 | + :full_name => 'Administrator', | |
|
154 | + :alias => 'root') | |
|
155 | + root.password = 'ioionrails'; | |
|
156 | + | |
|
157 | + class << root | |
|
158 | + public :encrypt_new_password | |
|
159 | + def valid? | |
|
160 | + true | |
|
161 | + end | |
|
162 | + end | |
|
163 | + | |
|
164 | + root.encrypt_new_password | |
|
165 | + | |
|
166 | + root.roles << Role.find_by_name('admin') | |
|
167 | + | |
|
168 | + root.activated = true | |
|
169 | + root.save | |
|
170 | + end | |
|
171 | + | |
|
172 | + def seed_users_and_roles | |
|
173 | + seed_roles | |
|
174 | + seed_root | |
|
175 | + end | |
|
176 | + | |
|
177 | + seed_config | |
|
178 | + seed_users_and_roles |
deleted file |
deleted file |
You need to be logged in to leave comments.
Login now