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: 67 inserted, 78 deleted
@@ -1,25 +1,12 | |||
|
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', |
@@ -102,23 +89,90 | |||
|
102 | 89 | }, |
|
103 | 90 | |
|
104 | 91 | # If Configuration['contest.test_request.early_timeout'] is true |
|
105 | 92 | # the user will not be able to use test request at 30 minutes |
|
106 | 93 | # before the contest ends. |
|
107 | 94 | { |
|
108 | 95 | :key => 'contest.test_request.early_timeout', |
|
109 | 96 | :value_type => 'boolean', |
|
110 | 97 | :default_value => 'false' |
|
111 | 98 | } |
|
112 | 99 | ] |
|
113 | 100 | |
|
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 | |
|
114 | 115 | CONFIGURATIONS.each do |conf| |
|
115 | 116 | if conf.has_key? :description |
|
116 | 117 | desc = conf[:description] |
|
117 | 118 | else |
|
118 | 119 | desc = '' |
|
119 | 120 | end |
|
120 | 121 | create_configuration_key(conf[:key], |
|
121 | 122 | conf[:value_type], |
|
122 | 123 | conf[:default_value], |
|
123 | 124 | desc) |
|
124 | 125 | end |
|
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 | |
|
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