Description:
fix various bug
(grafted from cb6577a84dff16a5d7ba91166873cc8a2e2a2628)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r660:241769f05803 - - 3 files changed: 5 inserted, 5 deleted
@@ -140,399 +140,399 | |||||
|
140 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
140 | @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true) |
|
141 | @scorearray = Array.new |
|
141 | @scorearray = Array.new |
|
142 | @users.each do |u| |
|
142 | @users.each do |u| |
|
143 | ustat = Array.new |
|
143 | ustat = Array.new |
|
144 | ustat[0] = u |
|
144 | ustat[0] = u |
|
145 | @problems.each do |p| |
|
145 | @problems.each do |p| |
|
146 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
146 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
147 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
147 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
148 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
148 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
149 | else |
|
149 | else |
|
150 | ustat << [0,false] |
|
150 | ustat << [0,false] |
|
151 | end |
|
151 | end |
|
152 | end |
|
152 | end |
|
153 | @scorearray << ustat |
|
153 | @scorearray << ustat |
|
154 | end |
|
154 | end |
|
155 | if params[:commit] == 'download csv' then |
|
155 | if params[:commit] == 'download csv' then |
|
156 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
156 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
157 | send_data csv, filename: 'last_score.csv' |
|
157 | send_data csv, filename: 'last_score.csv' |
|
158 | else |
|
158 | else |
|
159 | render template: 'user_admin/user_stat' |
|
159 | render template: 'user_admin/user_stat' |
|
160 | end |
|
160 | end |
|
161 | end |
|
161 | end |
|
162 |
|
162 | ||
|
163 | def user_stat_max |
|
163 | def user_stat_max |
|
164 | if params[:commit] == 'download csv' |
|
164 | if params[:commit] == 'download csv' |
|
165 | @problems = Problem.all |
|
165 | @problems = Problem.all |
|
166 | else |
|
166 | else |
|
167 | @problems = Problem.find_available_problems |
|
167 | @problems = Problem.find_available_problems |
|
168 | end |
|
168 | end |
|
169 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
169 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
170 | @scorearray = Array.new |
|
170 | @scorearray = Array.new |
|
171 | #set up range from param |
|
171 | #set up range from param |
|
172 | since_id = params.fetch(:since_id, 0).to_i |
|
172 | since_id = params.fetch(:since_id, 0).to_i |
|
173 | until_id = params.fetch(:until_id, 0).to_i |
|
173 | until_id = params.fetch(:until_id, 0).to_i |
|
174 | @users.each do |u| |
|
174 | @users.each do |u| |
|
175 | ustat = Array.new |
|
175 | ustat = Array.new |
|
176 | ustat[0] = u |
|
176 | ustat[0] = u |
|
177 | @problems.each do |p| |
|
177 | @problems.each do |p| |
|
178 | max_points = 0 |
|
178 | max_points = 0 |
|
179 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
179 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
180 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
180 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
181 | end |
|
181 | end |
|
182 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
182 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
183 | end |
|
183 | end |
|
184 | @scorearray << ustat |
|
184 | @scorearray << ustat |
|
185 | end |
|
185 | end |
|
186 |
|
186 | ||
|
187 | if params[:commit] == 'download csv' then |
|
187 | if params[:commit] == 'download csv' then |
|
188 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
188 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
189 | send_data csv, filename: 'max_score.csv' |
|
189 | send_data csv, filename: 'max_score.csv' |
|
190 | else |
|
190 | else |
|
191 | render template: 'user_admin/user_stat' |
|
191 | render template: 'user_admin/user_stat' |
|
192 | end |
|
192 | end |
|
193 | end |
|
193 | end |
|
194 |
|
194 | ||
|
195 | def import |
|
195 | def import |
|
196 | if params[:file]=='' |
|
196 | if params[:file]=='' |
|
197 | flash[:notice] = 'Error importing no file' |
|
197 | flash[:notice] = 'Error importing no file' |
|
198 | redirect_to :action => 'index' and return |
|
198 | redirect_to :action => 'index' and return |
|
199 | end |
|
199 | end |
|
200 | import_from_file(params[:file]) |
|
200 | import_from_file(params[:file]) |
|
201 | end |
|
201 | end |
|
202 |
|
202 | ||
|
203 | def random_all_passwords |
|
203 | def random_all_passwords |
|
204 | users = User.find(:all) |
|
204 | users = User.find(:all) |
|
205 | @prefix = params[:prefix] || '' |
|
205 | @prefix = params[:prefix] || '' |
|
206 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
206 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
207 | @changed = false |
|
207 | @changed = false |
|
208 | if request.request_method == 'POST' |
|
208 | if request.request_method == 'POST' |
|
209 | @non_admin_users.each do |user| |
|
209 | @non_admin_users.each do |user| |
|
210 | password = random_password |
|
210 | password = random_password |
|
211 | user.password = password |
|
211 | user.password = password |
|
212 | user.password_confirmation = password |
|
212 | user.password_confirmation = password |
|
213 | user.save |
|
213 | user.save |
|
214 | end |
|
214 | end |
|
215 | @changed = true |
|
215 | @changed = true |
|
216 | end |
|
216 | end |
|
217 | end |
|
217 | end |
|
218 |
|
218 | ||
|
219 | # contest management |
|
219 | # contest management |
|
220 |
|
220 | ||
|
221 | def contests |
|
221 | def contests |
|
222 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
222 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
223 | @contests = Contest.enabled |
|
223 | @contests = Contest.enabled |
|
224 | end |
|
224 | end |
|
225 |
|
225 | ||
|
226 | def assign_from_list |
|
226 | def assign_from_list |
|
227 | contest_id = params[:users_contest_id] |
|
227 | contest_id = params[:users_contest_id] |
|
228 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
228 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
229 | contest = Contest.find(params[:new_contest][:id]) |
|
229 | contest = Contest.find(params[:new_contest][:id]) |
|
230 | if !contest |
|
230 | if !contest |
|
231 | flash[:notice] = 'Error: no contest' |
|
231 | flash[:notice] = 'Error: no contest' |
|
232 | redirect_to :action => 'contests', :id =>contest_id |
|
232 | redirect_to :action => 'contests', :id =>contest_id |
|
233 | end |
|
233 | end |
|
234 |
|
234 | ||
|
235 | note = [] |
|
235 | note = [] |
|
236 | users.each do |u| |
|
236 | users.each do |u| |
|
237 | u.contests = [contest] |
|
237 | u.contests = [contest] |
|
238 | note << u.login |
|
238 | note << u.login |
|
239 | end |
|
239 | end |
|
240 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
240 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
241 | " were successfully reassigned to #{contest.title}." |
|
241 | " were successfully reassigned to #{contest.title}." |
|
242 | redirect_to :action => 'contests', :id =>contest.id |
|
242 | redirect_to :action => 'contests', :id =>contest.id |
|
243 | end |
|
243 | end |
|
244 |
|
244 | ||
|
245 | def add_to_contest |
|
245 | def add_to_contest |
|
246 | user = User.find(params[:id]) |
|
246 | user = User.find(params[:id]) |
|
247 | contest = Contest.find(params[:contest_id]) |
|
247 | contest = Contest.find(params[:contest_id]) |
|
248 | if user and contest |
|
248 | if user and contest |
|
249 | user.contests << contest |
|
249 | user.contests << contest |
|
250 | end |
|
250 | end |
|
251 | redirect_to :action => 'index' |
|
251 | redirect_to :action => 'index' |
|
252 | end |
|
252 | end |
|
253 |
|
253 | ||
|
254 | def remove_from_contest |
|
254 | def remove_from_contest |
|
255 | user = User.find(params[:id]) |
|
255 | user = User.find(params[:id]) |
|
256 | contest = Contest.find(params[:contest_id]) |
|
256 | contest = Contest.find(params[:contest_id]) |
|
257 | if user and contest |
|
257 | if user and contest |
|
258 | user.contests.delete(contest) |
|
258 | user.contests.delete(contest) |
|
259 | end |
|
259 | end |
|
260 | redirect_to :action => 'index' |
|
260 | redirect_to :action => 'index' |
|
261 | end |
|
261 | end |
|
262 |
|
262 | ||
|
263 | def contest_management |
|
263 | def contest_management |
|
264 | end |
|
264 | end |
|
265 |
|
265 | ||
|
266 | def manage_contest |
|
266 | def manage_contest |
|
267 | contest = Contest.find(params[:contest][:id]) |
|
267 | contest = Contest.find(params[:contest][:id]) |
|
268 | if !contest |
|
268 | if !contest |
|
269 | flash[:notice] = 'You did not choose the contest.' |
|
269 | flash[:notice] = 'You did not choose the contest.' |
|
270 | redirect_to :action => 'contest_management' and return |
|
270 | redirect_to :action => 'contest_management' and return |
|
271 | end |
|
271 | end |
|
272 |
|
272 | ||
|
273 | operation = params[:operation] |
|
273 | operation = params[:operation] |
|
274 |
|
274 | ||
|
275 | if not ['add','remove','assign'].include? operation |
|
275 | if not ['add','remove','assign'].include? operation |
|
276 | flash[:notice] = 'You did not choose the operation to perform.' |
|
276 | flash[:notice] = 'You did not choose the operation to perform.' |
|
277 | redirect_to :action => 'contest_management' and return |
|
277 | redirect_to :action => 'contest_management' and return |
|
278 | end |
|
278 | end |
|
279 |
|
279 | ||
|
280 | lines = params[:login_list] |
|
280 | lines = params[:login_list] |
|
281 | if !lines or lines.blank? |
|
281 | if !lines or lines.blank? |
|
282 | flash[:notice] = 'You entered an empty list.' |
|
282 | flash[:notice] = 'You entered an empty list.' |
|
283 | redirect_to :action => 'contest_management' and return |
|
283 | redirect_to :action => 'contest_management' and return |
|
284 | end |
|
284 | end |
|
285 |
|
285 | ||
|
286 | note = [] |
|
286 | note = [] |
|
287 | users = [] |
|
287 | users = [] |
|
288 | lines.split("\n").each do |line| |
|
288 | lines.split("\n").each do |line| |
|
289 | user = User.find_by_login(line.chomp) |
|
289 | user = User.find_by_login(line.chomp) |
|
290 | if user |
|
290 | if user |
|
291 | if operation=='add' |
|
291 | if operation=='add' |
|
292 | if ! user.contests.include? contest |
|
292 | if ! user.contests.include? contest |
|
293 | user.contests << contest |
|
293 | user.contests << contest |
|
294 | end |
|
294 | end |
|
295 | elsif operation=='remove' |
|
295 | elsif operation=='remove' |
|
296 | user.contests.delete(contest) |
|
296 | user.contests.delete(contest) |
|
297 | else |
|
297 | else |
|
298 | user.contests = [contest] |
|
298 | user.contests = [contest] |
|
299 | end |
|
299 | end |
|
300 |
|
300 | ||
|
301 | if params[:reset_timer] |
|
301 | if params[:reset_timer] |
|
302 | user.contest_stat.forced_logout = true |
|
302 | user.contest_stat.forced_logout = true |
|
303 | user.contest_stat.reset_timer_and_save |
|
303 | user.contest_stat.reset_timer_and_save |
|
304 | end |
|
304 | end |
|
305 |
|
305 | ||
|
306 | if params[:notification_emails] |
|
306 | if params[:notification_emails] |
|
307 | send_contest_update_notification_email(user, contest) |
|
307 | send_contest_update_notification_email(user, contest) |
|
308 | end |
|
308 | end |
|
309 |
|
309 | ||
|
310 | note << user.login |
|
310 | note << user.login |
|
311 | users << user |
|
311 | users << user |
|
312 | end |
|
312 | end |
|
313 | end |
|
313 | end |
|
314 |
|
314 | ||
|
315 | if params[:reset_timer] |
|
315 | if params[:reset_timer] |
|
316 | logout_users(users) |
|
316 | logout_users(users) |
|
317 | end |
|
317 | end |
|
318 |
|
318 | ||
|
319 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
319 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
320 | ' were successfully modified. ' |
|
320 | ' were successfully modified. ' |
|
321 | redirect_to :action => 'contest_management' |
|
321 | redirect_to :action => 'contest_management' |
|
322 | end |
|
322 | end |
|
323 |
|
323 | ||
|
324 | # admin management |
|
324 | # admin management |
|
325 |
|
325 | ||
|
326 | def admin |
|
326 | def admin |
|
327 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
327 | @admins = User.find(:all).find_all {|user| user.admin? } |
|
328 | end |
|
328 | end |
|
329 |
|
329 | ||
|
330 | def grant_admin |
|
330 | def grant_admin |
|
331 | login = params[:login] |
|
331 | login = params[:login] |
|
332 | user = User.find_by_login(login) |
|
332 | user = User.find_by_login(login) |
|
333 | if user!=nil |
|
333 | if user!=nil |
|
334 | admin_role = Role.find_by_name('admin') |
|
334 | admin_role = Role.find_by_name('admin') |
|
335 | user.roles << admin_role |
|
335 | user.roles << admin_role |
|
336 | else |
|
336 | else |
|
337 | flash[:notice] = 'Unknown user' |
|
337 | flash[:notice] = 'Unknown user' |
|
338 | end |
|
338 | end |
|
339 | flash[:notice] = 'User added as admins' |
|
339 | flash[:notice] = 'User added as admins' |
|
340 | redirect_to :action => 'admin' |
|
340 | redirect_to :action => 'admin' |
|
341 | end |
|
341 | end |
|
342 |
|
342 | ||
|
343 | def revoke_admin |
|
343 | def revoke_admin |
|
344 | user = User.find(params[:id]) |
|
344 | user = User.find(params[:id]) |
|
345 | if user==nil |
|
345 | if user==nil |
|
346 | flash[:notice] = 'Unknown user' |
|
346 | flash[:notice] = 'Unknown user' |
|
347 | redirect_to :action => 'admin' and return |
|
347 | redirect_to :action => 'admin' and return |
|
348 | elsif user.login == 'root' |
|
348 | elsif user.login == 'root' |
|
349 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
349 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
350 | redirect_to :action => 'admin' and return |
|
350 | redirect_to :action => 'admin' and return |
|
351 | end |
|
351 | end |
|
352 |
|
352 | ||
|
353 | admin_role = Role.find_by_name('admin') |
|
353 | admin_role = Role.find_by_name('admin') |
|
354 | user.roles.delete(admin_role) |
|
354 | user.roles.delete(admin_role) |
|
355 | flash[:notice] = 'User permission revoked' |
|
355 | flash[:notice] = 'User permission revoked' |
|
356 | redirect_to :action => 'admin' |
|
356 | redirect_to :action => 'admin' |
|
357 | end |
|
357 | end |
|
358 |
|
358 | ||
|
359 | # mass mailing |
|
359 | # mass mailing |
|
360 |
|
360 | ||
|
361 | def mass_mailing |
|
361 | def mass_mailing |
|
362 | end |
|
362 | end |
|
363 |
|
363 | ||
|
364 | def bulk_mail |
|
364 | def bulk_mail |
|
365 | lines = params[:login_list] |
|
365 | lines = params[:login_list] |
|
366 | if !lines or lines.blank? |
|
366 | if !lines or lines.blank? |
|
367 | flash[:notice] = 'You entered an empty list.' |
|
367 | flash[:notice] = 'You entered an empty list.' |
|
368 | redirect_to :action => 'mass_mailing' and return |
|
368 | redirect_to :action => 'mass_mailing' and return |
|
369 | end |
|
369 | end |
|
370 |
|
370 | ||
|
371 | mail_subject = params[:subject] |
|
371 | mail_subject = params[:subject] |
|
372 | if !mail_subject or mail_subject.blank? |
|
372 | if !mail_subject or mail_subject.blank? |
|
373 | flash[:notice] = 'You entered an empty mail subject.' |
|
373 | flash[:notice] = 'You entered an empty mail subject.' |
|
374 | redirect_to :action => 'mass_mailing' and return |
|
374 | redirect_to :action => 'mass_mailing' and return |
|
375 | end |
|
375 | end |
|
376 |
|
376 | ||
|
377 | mail_body = params[:email_body] |
|
377 | mail_body = params[:email_body] |
|
378 | if !mail_body or mail_body.blank? |
|
378 | if !mail_body or mail_body.blank? |
|
379 | flash[:notice] = 'You entered an empty mail body.' |
|
379 | flash[:notice] = 'You entered an empty mail body.' |
|
380 | redirect_to :action => 'mass_mailing' and return |
|
380 | redirect_to :action => 'mass_mailing' and return |
|
381 | end |
|
381 | end |
|
382 |
|
382 | ||
|
383 | note = [] |
|
383 | note = [] |
|
384 | users = [] |
|
384 | users = [] |
|
385 | lines.split("\n").each do |line| |
|
385 | lines.split("\n").each do |line| |
|
386 | user = User.find_by_login(line.chomp) |
|
386 | user = User.find_by_login(line.chomp) |
|
387 | if user |
|
387 | if user |
|
388 | send_mail(user.email, mail_subject, mail_body) |
|
388 | send_mail(user.email, mail_subject, mail_body) |
|
389 | note << user.login |
|
389 | note << user.login |
|
390 | end |
|
390 | end |
|
391 | end |
|
391 | end |
|
392 |
|
392 | ||
|
393 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
393 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
394 | ' were successfully modified. ' |
|
394 | ' were successfully modified. ' |
|
395 | redirect_to :action => 'mass_mailing' |
|
395 | redirect_to :action => 'mass_mailing' |
|
396 | end |
|
396 | end |
|
397 |
|
397 | ||
|
398 | protected |
|
398 | protected |
|
399 |
|
399 | ||
|
400 | def random_password(length=5) |
|
400 | def random_password(length=5) |
|
401 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
401 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
402 | newpass = "" |
|
402 | newpass = "" |
|
403 | length.times { newpass << chars[rand(chars.size-1)] } |
|
403 | length.times { newpass << chars[rand(chars.size-1)] } |
|
404 | return newpass |
|
404 | return newpass |
|
405 | end |
|
405 | end |
|
406 |
|
406 | ||
|
407 | def import_from_file(f) |
|
407 | def import_from_file(f) |
|
408 | data_hash = YAML.load(f) |
|
408 | data_hash = YAML.load(f) |
|
409 | @import_log = "" |
|
409 | @import_log = "" |
|
410 |
|
410 | ||
|
411 | country_data = data_hash[:countries] |
|
411 | country_data = data_hash[:countries] |
|
412 | site_data = data_hash[:sites] |
|
412 | site_data = data_hash[:sites] |
|
413 | user_data = data_hash[:users] |
|
413 | user_data = data_hash[:users] |
|
414 |
|
414 | ||
|
415 | # import country |
|
415 | # import country |
|
416 | countries = {} |
|
416 | countries = {} |
|
417 | country_data.each_pair do |id,country| |
|
417 | country_data.each_pair do |id,country| |
|
418 | c = Country.find_by_name(country[:name]) |
|
418 | c = Country.find_by_name(country[:name]) |
|
419 | if c!=nil |
|
419 | if c!=nil |
|
420 | countries[id] = c |
|
420 | countries[id] = c |
|
421 | @import_log << "Found #{country[:name]}\n" |
|
421 | @import_log << "Found #{country[:name]}\n" |
|
422 | else |
|
422 | else |
|
423 | countries[id] = Country.new(:name => country[:name]) |
|
423 | countries[id] = Country.new(:name => country[:name]) |
|
424 | countries[id].save |
|
424 | countries[id].save |
|
425 | @import_log << "Created #{country[:name]}\n" |
|
425 | @import_log << "Created #{country[:name]}\n" |
|
426 | end |
|
426 | end |
|
427 | end |
|
427 | end |
|
428 |
|
428 | ||
|
429 | # import sites |
|
429 | # import sites |
|
430 | sites = {} |
|
430 | sites = {} |
|
431 | site_data.each_pair do |id,site| |
|
431 | site_data.each_pair do |id,site| |
|
432 | s = Site.find_by_name(site[:name]) |
|
432 | s = Site.find_by_name(site[:name]) |
|
433 | if s!=nil |
|
433 | if s!=nil |
|
434 | @import_log << "Found #{site[:name]}\n" |
|
434 | @import_log << "Found #{site[:name]}\n" |
|
435 | else |
|
435 | else |
|
436 | s = Site.new(:name => site[:name]) |
|
436 | s = Site.new(:name => site[:name]) |
|
437 | @import_log << "Created #{site[:name]}\n" |
|
437 | @import_log << "Created #{site[:name]}\n" |
|
438 | end |
|
438 | end |
|
439 | s.password = site[:password] |
|
439 | s.password = site[:password] |
|
440 | s.country = countries[site[:country_id]] |
|
440 | s.country = countries[site[:country_id]] |
|
441 | s.save |
|
441 | s.save |
|
442 | sites[id] = s |
|
442 | sites[id] = s |
|
443 | end |
|
443 | end |
|
444 |
|
444 | ||
|
445 | # import users |
|
445 | # import users |
|
446 | user_data.each_pair do |id,user| |
|
446 | user_data.each_pair do |id,user| |
|
447 | u = User.find_by_login(user[:login]) |
|
447 | u = User.find_by_login(user[:login]) |
|
448 | if u!=nil |
|
448 | if u!=nil |
|
449 | @import_log << "Found #{user[:login]}\n" |
|
449 | @import_log << "Found #{user[:login]}\n" |
|
450 | else |
|
450 | else |
|
451 | u = User.new(:login => user[:login]) |
|
451 | u = User.new(:login => user[:login]) |
|
452 | @import_log << "Created #{user[:login]}\n" |
|
452 | @import_log << "Created #{user[:login]}\n" |
|
453 | end |
|
453 | end |
|
454 | u.full_name = user[:name] |
|
454 | u.full_name = user[:name] |
|
455 | u.password = user[:password] |
|
455 | u.password = user[:password] |
|
456 | u.country = countries[user[:country_id]] |
|
456 | u.country = countries[user[:country_id]] |
|
457 | u.site = sites[user[:site_id]] |
|
457 | u.site = sites[user[:site_id]] |
|
458 | u.activated = true |
|
458 | u.activated = true |
|
459 | u.email = "empty-#{u.login}@none.com" |
|
459 | u.email = "empty-#{u.login}@none.com" |
|
460 | if not u.save |
|
460 | if not u.save |
|
461 | @import_log << "Errors\n" |
|
461 | @import_log << "Errors\n" |
|
462 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
462 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
463 | end |
|
463 | end |
|
464 | end |
|
464 | end |
|
465 |
|
465 | ||
|
466 | end |
|
466 | end |
|
467 |
|
467 | ||
|
468 | def logout_users(users) |
|
468 | def logout_users(users) |
|
469 | users.each do |user| |
|
469 | users.each do |user| |
|
470 | contest_stat = user.contest_stat(true) |
|
470 | contest_stat = user.contest_stat(true) |
|
471 | if contest_stat and !contest_stat.forced_logout |
|
471 | if contest_stat and !contest_stat.forced_logout |
|
472 | contest_stat.forced_logout = true |
|
472 | contest_stat.forced_logout = true |
|
473 | contest_stat.save |
|
473 | contest_stat.save |
|
474 | end |
|
474 | end |
|
475 | end |
|
475 | end |
|
476 | end |
|
476 | end |
|
477 |
|
477 | ||
|
478 | def send_contest_update_notification_email(user, contest) |
|
478 | def send_contest_update_notification_email(user, contest) |
|
479 | contest_title_name = GraderConfiguration['contest.name'] |
|
479 | contest_title_name = GraderConfiguration['contest.name'] |
|
480 | contest_name = contest.name |
|
480 | contest_name = contest.name |
|
481 | mail_subject = t('contest.notification.email_subject', { |
|
481 | mail_subject = t('contest.notification.email_subject', { |
|
482 | :contest_title_name => contest_title_name, |
|
482 | :contest_title_name => contest_title_name, |
|
483 | :contest_name => contest_name }) |
|
483 | :contest_name => contest_name }) |
|
484 | mail_body = t('contest.notification.email_body', { |
|
484 | mail_body = t('contest.notification.email_body', { |
|
485 | :full_name => user.full_name, |
|
485 | :full_name => user.full_name, |
|
486 | :contest_title_name => contest_title_name, |
|
486 | :contest_title_name => contest_title_name, |
|
487 | :contest_name => contest.name, |
|
487 | :contest_name => contest.name, |
|
488 | }) |
|
488 | }) |
|
489 |
|
489 | ||
|
490 | logger.info mail_body |
|
490 | logger.info mail_body |
|
491 | send_mail(user.email, mail_subject, mail_body) |
|
491 | send_mail(user.email, mail_subject, mail_body) |
|
492 | end |
|
492 | end |
|
493 |
|
493 | ||
|
494 | def find_contest_and_user_from_contest_id(id) |
|
494 | def find_contest_and_user_from_contest_id(id) |
|
495 | if id!='none' |
|
495 | if id!='none' |
|
496 | @contest = Contest.find(id) |
|
496 | @contest = Contest.find(id) |
|
497 | else |
|
497 | else |
|
498 | @contest = nil |
|
498 | @contest = nil |
|
499 | end |
|
499 | end |
|
500 | if @contest |
|
500 | if @contest |
|
501 | @users = @contest.users |
|
501 | @users = @contest.users |
|
502 | else |
|
502 | else |
|
503 | @users = User.find_users_with_no_contest |
|
503 | @users = User.find_users_with_no_contest |
|
504 | end |
|
504 | end |
|
505 | return [@contest, @users] |
|
505 | return [@contest, @users] |
|
506 | end |
|
506 | end |
|
507 |
|
507 | ||
|
508 | def gen_csv_from_scorearray(scorearray,problem) |
|
508 | def gen_csv_from_scorearray(scorearray,problem) |
|
509 | CSV.generate do |csv| |
|
509 | CSV.generate do |csv| |
|
510 | #add header |
|
510 | #add header |
|
511 | header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] |
|
511 | header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] |
|
512 | problem.each { |p| header << p.name } |
|
512 | problem.each { |p| header << p.name } |
|
513 | header += ['Total','Passed'] |
|
513 | header += ['Total','Passed'] |
|
514 | csv << header |
|
514 | csv << header |
|
515 | #add data |
|
515 | #add data |
|
516 | scorearray.each do |sc| |
|
516 | scorearray.each do |sc| |
|
517 | total = num_passed = 0 |
|
517 | total = num_passed = 0 |
|
518 | row = Array.new |
|
518 | row = Array.new |
|
519 | sc.each_index do |i| |
|
519 | sc.each_index do |i| |
|
520 | if i == 0 |
|
520 | if i == 0 |
|
521 | row << sc[i].login |
|
521 | row << sc[i].login |
|
522 | row << sc[i].full_name |
|
522 | row << sc[i].full_name |
|
523 | row << sc[i].activated |
|
523 | row << sc[i].activated |
|
524 |
- row << (sc[i].try(:contest_stat).try(:started_at) |
|
524 | + row << (sc[i].try(:contest_stat).try(:started_at).nil? 'no' : 'yes') |
|
525 | row << sc[i].contests.collect {|c| c.name}.join(', ') |
|
525 | row << sc[i].contests.collect {|c| c.name}.join(', ') |
|
526 | else |
|
526 | else |
|
527 | row << sc[i][0] |
|
527 | row << sc[i][0] |
|
528 | total += sc[i][0] |
|
528 | total += sc[i][0] |
|
529 | num_passed += 1 if sc[i][1] |
|
529 | num_passed += 1 if sc[i][1] |
|
530 | end |
|
530 | end |
|
531 | end |
|
531 | end |
|
532 | row << total |
|
532 | row << total |
|
533 | row << num_passed |
|
533 | row << num_passed |
|
534 | csv << row |
|
534 | csv << row |
|
535 | end |
|
535 | end |
|
536 | end |
|
536 | end |
|
537 | end |
|
537 | end |
|
538 | end |
|
538 | end |
@@ -1,15 +1,15 | |||||
|
1 | %li.list-group-item |
|
1 | %li.list-group-item |
|
2 | %strong |
|
2 | %strong |
|
3 | = announcement.title |
|
3 | = announcement.title |
|
4 | - - if @current_user.admin? |
|
4 | + - if @current_user and @current_user.admin? |
|
5 | = link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-xs btn-default' |
|
5 | = link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-xs btn-default' |
|
6 | %small= "(updated #{time_ago_in_words(announcement.updated_at)} ago on #{announcement.updated_at})" |
|
6 | %small= "(updated #{time_ago_in_words(announcement.updated_at)} ago on #{announcement.updated_at})" |
|
7 |
|
7 | ||
|
8 | %br |
|
8 | %br |
|
9 | = markdown(announcement.body) |
|
9 | = markdown(announcement.body) |
|
10 | :javascript |
|
10 | :javascript |
|
11 | Announcement.updateRecentId(#{announcement.id}); |
|
11 | Announcement.updateRecentId(#{announcement.id}); |
|
12 | - if (defined? announcement_effect) and announcement_effect |
|
12 | - if (defined? announcement_effect) and announcement_effect |
|
13 | :javascript |
|
13 | :javascript |
|
14 | $("announcement-#{announcement.id}").blindDown({duration: 0.2}); |
|
14 | $("announcement-#{announcement.id}").blindDown({duration: 0.2}); |
|
15 | $("announcement-#{announcement.id}").appear({duration: 0.5, queue: 'end'}); |
|
15 | $("announcement-#{announcement.id}").appear({duration: 0.5, queue: 'end'}); |
@@ -1,26 +1,26 | |||||
|
1 |
|
1 | ||
|
2 | - if submission.nil? |
|
2 | - if submission.nil? |
|
3 | = "-" |
|
3 | = "-" |
|
4 | - else |
|
4 | - else |
|
5 |
- - |
|
5 | + - unless submission.graded_at |
|
6 |
- = |
|
6 | + =t 'main.submitted_at' |
|
7 | = format_short_time(submission.submitted_at.localtime) |
|
7 | = format_short_time(submission.submitted_at.localtime) |
|
8 | - else |
|
8 | - else |
|
9 | %strong= t 'main.graded_at' |
|
9 | %strong= t 'main.graded_at' |
|
10 | = "#{format_short_time(submission.graded_at.localtime)} " |
|
10 | = "#{format_short_time(submission.graded_at.localtime)} " |
|
11 | %br |
|
11 | %br |
|
12 | - if GraderConfiguration['ui.show_score'] |
|
12 | - if GraderConfiguration['ui.show_score'] |
|
13 |
- |
|
13 | + =t 'main.score' |
|
14 | = "#{(submission.points*100/submission.problem.full_score).to_i} " |
|
14 | = "#{(submission.points*100/submission.problem.full_score).to_i} " |
|
15 | = " [" |
|
15 | = " [" |
|
16 | %tt |
|
16 | %tt |
|
17 | = submission.grader_comment |
|
17 | = submission.grader_comment |
|
18 | = "]" |
|
18 | = "]" |
|
19 | %br |
|
19 | %br |
|
20 | %strong View: |
|
20 | %strong View: |
|
21 | - if GraderConfiguration.show_grading_result |
|
21 | - if GraderConfiguration.show_grading_result |
|
22 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
22 | = link_to '[detailed result]', :action => 'result', :id => submission.id |
|
23 | = link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} |
|
23 | = link_to "#{t 'main.cmp_msg'}", {:action => 'compiler_msg', :id => submission.id}, {popup: true,class: 'btn btn-xs btn-info'} |
|
24 | = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info' |
|
24 | = link_to "#{t 'main.src_link'}",{:action => 'source', :id => submission.id}, class: 'btn btn-xs btn-info' |
|
25 | = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' |
|
25 | = link_to "#{t 'main.submissions_link'}", problem_submissions_path(problem_id), class: 'btn btn-xs btn-info' |
|
26 |
|
26 |
You need to be logged in to leave comments.
Login now