Description:
resets contest start time when changing users' contest
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r289:bafc73878f35 - - 2 files changed: 9 inserted, 3 deleted
@@ -115,192 +115,195 | |||
|
115 | 115 | @scorearray = Array.new |
|
116 | 116 | @users.each do |u| |
|
117 | 117 | ustat = Array.new |
|
118 | 118 | ustat[0] = u |
|
119 | 119 | @problems.each do |p| |
|
120 | 120 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
121 | 121 | if (sub!=nil) and (sub.points!=nil) |
|
122 | 122 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
123 | 123 | else |
|
124 | 124 | ustat << [0,false] |
|
125 | 125 | end |
|
126 | 126 | end |
|
127 | 127 | @scorearray << ustat |
|
128 | 128 | end |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | def import |
|
132 | 132 | if params[:file]=='' |
|
133 | 133 | flash[:notice] = 'Error importing no file' |
|
134 | 134 | redirect_to :action => 'list' and return |
|
135 | 135 | end |
|
136 | 136 | import_from_file(params[:file]) |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | def random_all_passwords |
|
140 | 140 | users = User.find(:all) |
|
141 | 141 | @prefix = params[:prefix] || '' |
|
142 | 142 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
143 | 143 | @changed = false |
|
144 | 144 | if request.request_method == :post |
|
145 | 145 | @non_admin_users.each do |user| |
|
146 | 146 | password = random_password |
|
147 | 147 | user.password = password |
|
148 | 148 | user.password_confirmation = password |
|
149 | 149 | user.save |
|
150 | 150 | end |
|
151 | 151 | @changed = true |
|
152 | 152 | end |
|
153 | 153 | end |
|
154 | 154 | |
|
155 | 155 | # contest management |
|
156 | 156 | |
|
157 | 157 | def add_to_contest |
|
158 | 158 | user = User.find(params[:id]) |
|
159 | 159 | contest = Contest.find(params[:contest_id]) |
|
160 | 160 | if user and contest |
|
161 | 161 | user.contests << contest |
|
162 | 162 | end |
|
163 | 163 | redirect_to :action => 'list' |
|
164 | 164 | end |
|
165 | 165 | |
|
166 | 166 | def remove_from_contest |
|
167 | 167 | user = User.find(params[:id]) |
|
168 | 168 | contest = Contest.find(params[:contest_id]) |
|
169 | 169 | if user and contest |
|
170 | 170 | user.contests.delete(contest) |
|
171 | 171 | end |
|
172 | 172 | redirect_to :action => 'list' |
|
173 | 173 | end |
|
174 | 174 | |
|
175 | 175 | def contest_management |
|
176 | 176 | end |
|
177 | 177 | |
|
178 | 178 | def manage_contest |
|
179 | 179 | contest = Contest.find(params[:contest][:id]) |
|
180 | 180 | if !contest |
|
181 | 181 | flash[:notice] = 'You did not choose the contest.' |
|
182 | 182 | redirect_to :action => 'contest_management' and return |
|
183 | 183 | end |
|
184 | 184 | |
|
185 | 185 | operation = params[:operation] |
|
186 | 186 | |
|
187 | 187 | if not ['add','remove','assign'].include? operation |
|
188 | 188 | flash[:notice] = 'You did not choose the operation to perform.' |
|
189 | 189 | redirect_to :action => 'contest_management' and return |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | 192 | lines = params[:login_list] |
|
193 | 193 | if !lines or lines.blank? |
|
194 | 194 | flash[:notice] = 'You entered an empty list.' |
|
195 | 195 | redirect_to :action => 'contest_management' and return |
|
196 | 196 | end |
|
197 | 197 | |
|
198 | 198 | note = [] |
|
199 | 199 | lines.split("\n").each do |line| |
|
200 | 200 | puts line |
|
201 | 201 | user = User.find_by_login(line.chomp) |
|
202 | 202 | puts user |
|
203 | 203 | if user |
|
204 | 204 | if operation=='add' |
|
205 | 205 | user.contests << contest |
|
206 | 206 | elsif operation=='remove' |
|
207 | 207 | user.contests.delete(contest) |
|
208 | 208 | else |
|
209 | 209 | user.contests = [contest] |
|
210 | 210 | end |
|
211 | + | |
|
212 | + user.contest_stat.destroy if params[:reset_timer] | |
|
213 | + | |
|
211 | 214 | note << user.login |
|
212 | 215 | end |
|
213 | 216 | end |
|
214 | 217 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
215 | 218 | ' were successfully modified. ' |
|
216 | 219 | redirect_to :action => 'contest_management' |
|
217 | 220 | end |
|
218 | 221 | |
|
219 | 222 | # admin management |
|
220 | 223 | |
|
221 | 224 | def admin |
|
222 | 225 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
223 | 226 | end |
|
224 | 227 | |
|
225 | 228 | def grant_admin |
|
226 | 229 | login = params[:login] |
|
227 | 230 | user = User.find_by_login(login) |
|
228 | 231 | if user!=nil |
|
229 | 232 | admin_role = Role.find_by_name('admin') |
|
230 | 233 | user.roles << admin_role |
|
231 | 234 | else |
|
232 | 235 | flash[:notice] = 'Unknown user' |
|
233 | 236 | end |
|
234 | 237 | flash[:notice] = 'User added as admins' |
|
235 | 238 | redirect_to :action => 'admin' |
|
236 | 239 | end |
|
237 | 240 | |
|
238 | 241 | def revoke_admin |
|
239 | 242 | user = User.find(params[:id]) |
|
240 | 243 | if user==nil |
|
241 | 244 | flash[:notice] = 'Unknown user' |
|
242 | 245 | redirect_to :action => 'admin' and return |
|
243 | 246 | elsif user.login == 'root' |
|
244 | 247 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
245 | 248 | redirect_to :action => 'admin' and return |
|
246 | 249 | end |
|
247 | 250 | |
|
248 | 251 | admin_role = Role.find_by_name('admin') |
|
249 | 252 | user.roles.delete(admin_role) |
|
250 | 253 | flash[:notice] = 'User permission revoked' |
|
251 | 254 | redirect_to :action => 'admin' |
|
252 | 255 | end |
|
253 | 256 | |
|
254 | 257 | protected |
|
255 | 258 | |
|
256 | 259 | def random_password(length=5) |
|
257 | 260 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
258 | 261 | newpass = "" |
|
259 | 262 | length.times { newpass << chars[rand(chars.size-1)] } |
|
260 | 263 | return newpass |
|
261 | 264 | end |
|
262 | 265 | |
|
263 | 266 | def import_from_file(f) |
|
264 | 267 | data_hash = YAML.load(f) |
|
265 | 268 | @import_log = "" |
|
266 | 269 | |
|
267 | 270 | country_data = data_hash[:countries] |
|
268 | 271 | site_data = data_hash[:sites] |
|
269 | 272 | user_data = data_hash[:users] |
|
270 | 273 | |
|
271 | 274 | # import country |
|
272 | 275 | countries = {} |
|
273 | 276 | country_data.each_pair do |id,country| |
|
274 | 277 | c = Country.find_by_name(country[:name]) |
|
275 | 278 | if c!=nil |
|
276 | 279 | countries[id] = c |
|
277 | 280 | @import_log << "Found #{country[:name]}\n" |
|
278 | 281 | else |
|
279 | 282 | countries[id] = Country.new(:name => country[:name]) |
|
280 | 283 | countries[id].save |
|
281 | 284 | @import_log << "Created #{country[:name]}\n" |
|
282 | 285 | end |
|
283 | 286 | end |
|
284 | 287 | |
|
285 | 288 | # import sites |
|
286 | 289 | sites = {} |
|
287 | 290 | site_data.each_pair do |id,site| |
|
288 | 291 | s = Site.find_by_name(site[:name]) |
|
289 | 292 | if s!=nil |
|
290 | 293 | @import_log << "Found #{site[:name]}\n" |
|
291 | 294 | else |
|
292 | 295 | s = Site.new(:name => site[:name]) |
|
293 | 296 | @import_log << "Created #{site[:name]}\n" |
|
294 | 297 | end |
|
295 | 298 | s.password = site[:password] |
|
296 | 299 | s.country = countries[site[:country_id]] |
|
297 | 300 | s.save |
|
298 | 301 | sites[id] = s |
|
299 | 302 | end |
|
300 | 303 | |
|
301 | 304 | # import users |
|
302 | 305 | user_data.each_pair do |id,user| |
|
303 | 306 | u = User.find_by_login(user[:login]) |
|
304 | 307 | if u!=nil |
|
305 | 308 | @import_log << "Found #{user[:login]}\n" |
|
306 | 309 | else |
@@ -1,16 +1,19 | |||
|
1 | 1 | %h1 Bulk edit users in contests |
|
2 | 2 | |
|
3 | 3 | - form_tag :action => 'manage_contest' do |
|
4 | 4 | List users' login below; one per line. |
|
5 | 5 | %br/ |
|
6 |
- = text_area_tag 'login_list', nil, :rows => 2 |
|
|
6 | + = text_area_tag 'login_list', nil, :rows => 23, :cols => 80 | |
|
7 | 7 | %br/ |
|
8 | 8 | You want to |
|
9 | 9 | = select(nil,"operation",[['assign users to','assign'],['add users to','add'],['remove users from','remove']]) |
|
10 | 10 | contest |
|
11 | 11 | = select("contest","id",Contest.all.collect {|c| [c.title, c.id]}) |
|
12 | - | |
|
13 | - = submit_tag "Perform action", :confirm => 'Are you sure?' | |
|
12 | + = check_box_tag 'reset_timer' | |
|
13 | + Auto-reset current contest timer. | |
|
14 | + %br/ | |
|
15 | + | |
|
16 | + = submit_tag "Perform action!", :confirm => 'Are you sure?' | |
|
14 | 17 | |
|
15 | 18 | %hr/ |
|
16 | 19 | = link_to '[go back to index]', :action => 'index' |
You need to be logged in to leave comments.
Login now