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,16 +1,3 | |||||
|
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 | CONFIGURATIONS = |
|
15 | [ |
|
2 | [ |
|
16 | { |
|
3 | { |
@@ -19,19 +6,19 | |||||
|
19 | :default_value => 'false', |
|
6 | :default_value => 'false', |
|
20 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
7 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
21 | }, |
|
8 | }, |
|
22 | - |
|
9 | + |
|
23 | { |
|
10 | { |
|
24 | :key => 'ui.front.title', |
|
11 | :key => 'ui.front.title', |
|
25 | :value_type => 'string', |
|
12 | :value_type => 'string', |
|
26 | :default_value => 'Grader' |
|
13 | :default_value => 'Grader' |
|
27 | }, |
|
14 | }, |
|
28 | - |
|
15 | + |
|
29 | { |
|
16 | { |
|
30 | :key => 'ui.front.welcome_message', |
|
17 | :key => 'ui.front.welcome_message', |
|
31 | :value_type => 'string', |
|
18 | :value_type => 'string', |
|
32 | :default_value => 'Welcome!' |
|
19 | :default_value => 'Welcome!' |
|
33 | }, |
|
20 | }, |
|
34 | - |
|
21 | + |
|
35 | { |
|
22 | { |
|
36 | :key => 'ui.show_score', |
|
23 | :key => 'ui.show_score', |
|
37 | :value_type => 'boolean', |
|
24 | :value_type => 'boolean', |
@@ -44,35 +31,35 | |||||
|
44 | :default_value => 'unlimited', |
|
31 | :default_value => 'unlimited', |
|
45 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits.' |
|
32 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits.' |
|
46 | }, |
|
33 | }, |
|
47 | - |
|
34 | + |
|
48 | { |
|
35 | { |
|
49 | :key => 'system.mode', |
|
36 | :key => 'system.mode', |
|
50 | :value_type => 'string', |
|
37 | :value_type => 'string', |
|
51 | :default_value => 'standard', |
|
38 | :default_value => 'standard', |
|
52 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
39 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
53 | }, |
|
40 | }, |
|
54 | - |
|
41 | + |
|
55 | { |
|
42 | { |
|
56 | :key => 'contest.name', |
|
43 | :key => 'contest.name', |
|
57 | :value_type => 'string', |
|
44 | :value_type => 'string', |
|
58 | :default_value => 'Grader', |
|
45 | :default_value => 'Grader', |
|
59 | :description => 'This name will be shown on the user header bar.' |
|
46 | :description => 'This name will be shown on the user header bar.' |
|
60 | }, |
|
47 | }, |
|
61 | - |
|
48 | + |
|
62 | { |
|
49 | { |
|
63 | :key => 'contest.multisites', |
|
50 | :key => 'contest.multisites', |
|
64 | :value_type => 'boolean', |
|
51 | :value_type => 'boolean', |
|
65 | :default_value => 'false', |
|
52 | :default_value => 'false', |
|
66 | :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.' |
|
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 | :key => 'system.online_registration', |
|
57 | :key => 'system.online_registration', |
|
71 | :value_type => 'boolean', |
|
58 | :value_type => 'boolean', |
|
72 | :default_value => 'false', |
|
59 | :default_value => 'false', |
|
73 | :description => 'This option enables online registration.' |
|
60 | :description => 'This option enables online registration.' |
|
74 | }, |
|
61 | }, |
|
75 | - |
|
62 | + |
|
76 | # If Configuration['system.online_registration'] is true, the |
|
63 | # If Configuration['system.online_registration'] is true, the |
|
77 | # system allows online registration, and will use these |
|
64 | # system allows online registration, and will use these |
|
78 | # information for sending confirmation emails. |
|
65 | # information for sending confirmation emails. |
@@ -81,13 +68,13 | |||||
|
81 | :value_type => 'string', |
|
68 | :value_type => 'string', |
|
82 | :default_value => 'smtp.somehost.com' |
|
69 | :default_value => 'smtp.somehost.com' |
|
83 | }, |
|
70 | }, |
|
84 | - |
|
71 | + |
|
85 | { |
|
72 | { |
|
86 | :key => 'system.online_registration.from', |
|
73 | :key => 'system.online_registration.from', |
|
87 | :value_type => 'string', |
|
74 | :value_type => 'string', |
|
88 | :default_value => 'your.email@address' |
|
75 | :default_value => 'your.email@address' |
|
89 | }, |
|
76 | }, |
|
90 | - |
|
77 | + |
|
91 | { |
|
78 | { |
|
92 | :key => 'system.admin_email', |
|
79 | :key => 'system.admin_email', |
|
93 | :value_type => 'string', |
|
80 | :value_type => 'string', |
@@ -111,14 +98,81 | |||||
|
111 | } |
|
98 | } |
|
112 | ] |
|
99 | ] |
|
113 |
|
100 | ||
|
114 | - CONFIGURATIONS.each do |conf| |
|
101 | + |
|
115 | - if conf.has_key? :description |
|
102 | + def create_configuration_key(key, |
|
116 | - desc = conf[:description] |
|
103 | + value_type, |
|
117 | - else |
|
104 | + default_value, |
|
118 | - desc = '' |
|
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 | end |
|
125 | end |
|
120 | - create_configuration_key(conf[:key], |
|
126 | + end |
|
121 | - conf[:value_type], |
|
127 | + |
|
122 | - conf[:default_value], |
|
128 | + def seed_roles |
|
123 | - desc) |
|
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 | end |
|
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