Description:
sort available problem group by date_added, name
bulk manage user filter by remark as well
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r675:4404040ff0ce - - 2 files changed: 12 inserted, 2 deleted
@@ -391,49 +391,49 | |||||
|
391 | if !mail_body or mail_body.blank? |
|
391 | if !mail_body or mail_body.blank? |
|
392 | flash[:notice] = 'You entered an empty mail body.' |
|
392 | flash[:notice] = 'You entered an empty mail body.' |
|
393 | redirect_to :action => 'mass_mailing' and return |
|
393 | redirect_to :action => 'mass_mailing' and return |
|
394 | end |
|
394 | end |
|
395 |
|
395 | ||
|
396 | note = [] |
|
396 | note = [] |
|
397 | users = [] |
|
397 | users = [] |
|
398 | lines.split("\n").each do |line| |
|
398 | lines.split("\n").each do |line| |
|
399 | user = User.find_by_login(line.chomp) |
|
399 | user = User.find_by_login(line.chomp) |
|
400 | if user |
|
400 | if user |
|
401 | send_mail(user.email, mail_subject, mail_body) |
|
401 | send_mail(user.email, mail_subject, mail_body) |
|
402 | note << user.login |
|
402 | note << user.login |
|
403 | end |
|
403 | end |
|
404 | end |
|
404 | end |
|
405 |
|
405 | ||
|
406 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
406 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
407 | ' were successfully modified. ' |
|
407 | ' were successfully modified. ' |
|
408 | redirect_to :action => 'mass_mailing' |
|
408 | redirect_to :action => 'mass_mailing' |
|
409 | end |
|
409 | end |
|
410 |
|
410 | ||
|
411 | #bulk manage |
|
411 | #bulk manage |
|
412 | def bulk_manage |
|
412 | def bulk_manage |
|
413 |
|
413 | ||
|
414 | begin |
|
414 | begin |
|
415 | - @users = User.where('login REGEXP ?',params[:regex]) if params[:regex] |
|
415 | + @users = User.where('(login REGEXP ?) OR (remark REGEXP ?)',params[:regex],params[:regex]) if params[:regex] |
|
416 | @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
416 | @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised |
|
417 | rescue Exception |
|
417 | rescue Exception |
|
418 | flash[:error] = 'Regular Expression is malformed' |
|
418 | flash[:error] = 'Regular Expression is malformed' |
|
419 | @users = nil |
|
419 | @users = nil |
|
420 | end |
|
420 | end |
|
421 |
|
421 | ||
|
422 | if params[:commit] |
|
422 | if params[:commit] |
|
423 | @action = {} |
|
423 | @action = {} |
|
424 | @action[:set_enable] = params[:enabled] |
|
424 | @action[:set_enable] = params[:enabled] |
|
425 | @action[:enabled] = params[:enable] == "1" |
|
425 | @action[:enabled] = params[:enable] == "1" |
|
426 | @action[:gen_password] = params[:gen_password] |
|
426 | @action[:gen_password] = params[:gen_password] |
|
427 | @action[:add_group] = params[:add_group] |
|
427 | @action[:add_group] = params[:add_group] |
|
428 | @action[:group_name] = params[:group_name] |
|
428 | @action[:group_name] = params[:group_name] |
|
429 | end |
|
429 | end |
|
430 |
|
430 | ||
|
431 | if params[:commit] == "Perform" |
|
431 | if params[:commit] == "Perform" |
|
432 | if @action[:set_enable] |
|
432 | if @action[:set_enable] |
|
433 | @users.update_all(enabled: @action[:enabled]) |
|
433 | @users.update_all(enabled: @action[:enabled]) |
|
434 | end |
|
434 | end |
|
435 | if @action[:gen_password] |
|
435 | if @action[:gen_password] |
|
436 | @users.each do |u| |
|
436 | @users.each do |u| |
|
437 | password = random_password |
|
437 | password = random_password |
|
438 | u.password = password |
|
438 | u.password = password |
|
439 | u.password_confirmation = password |
|
439 | u.password_confirmation = password |
@@ -296,49 +296,59 | |||||
|
296 | else |
|
296 | else |
|
297 | return Problem.available_problems |
|
297 | return Problem.available_problems |
|
298 | end |
|
298 | end |
|
299 | else |
|
299 | else |
|
300 | contest_problems = [] |
|
300 | contest_problems = [] |
|
301 | pin = {} |
|
301 | pin = {} |
|
302 | contests.enabled.each do |contest| |
|
302 | contests.enabled.each do |contest| |
|
303 | contest.problems.available.each do |problem| |
|
303 | contest.problems.available.each do |problem| |
|
304 | if not pin.has_key? problem.id |
|
304 | if not pin.has_key? problem.id |
|
305 | contest_problems << problem |
|
305 | contest_problems << problem |
|
306 | end |
|
306 | end |
|
307 | pin[problem.id] = true |
|
307 | pin[problem.id] = true |
|
308 | end |
|
308 | end |
|
309 | end |
|
309 | end |
|
310 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
310 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
311 | return contest_problems + other_avaiable_problems |
|
311 | return contest_problems + other_avaiable_problems |
|
312 | end |
|
312 | end |
|
313 | end |
|
313 | end |
|
314 |
|
314 | ||
|
315 | def available_problems_in_group |
|
315 | def available_problems_in_group |
|
316 | problem = [] |
|
316 | problem = [] |
|
317 | self.groups.each do |group| |
|
317 | self.groups.each do |group| |
|
318 | group.problems.where(available: true).each { |p| problem << p } |
|
318 | group.problems.where(available: true).each { |p| problem << p } |
|
319 | end |
|
319 | end |
|
320 | - return problem.uniq |
|
320 | + problem.uniq!.sort! do |a,b| |
|
|
321 | + case | ||
|
|
322 | + when a.date_added < b.date_added | ||
|
|
323 | + -1 | ||
|
|
324 | + when a.date_added > b.date_added | ||
|
|
325 | + 1 | ||
|
|
326 | + else | ||
|
|
327 | + a.name <=> b.name | ||
|
|
328 | + end | ||
|
|
329 | + end | ||
|
|
330 | + return problem | ||
|
321 | end |
|
331 | end |
|
322 |
|
332 | ||
|
323 | def can_view_problem?(problem) |
|
333 | def can_view_problem?(problem) |
|
324 | if not GraderConfiguration.multicontests? |
|
334 | if not GraderConfiguration.multicontests? |
|
325 | return problem.available |
|
335 | return problem.available |
|
326 | else |
|
336 | else |
|
327 | return problem_in_user_contests? problem |
|
337 | return problem_in_user_contests? problem |
|
328 | end |
|
338 | end |
|
329 | end |
|
339 | end |
|
330 |
|
340 | ||
|
331 | def self.clear_last_login |
|
341 | def self.clear_last_login |
|
332 | User.update_all(:last_ip => nil) |
|
342 | User.update_all(:last_ip => nil) |
|
333 | end |
|
343 | end |
|
334 |
|
344 | ||
|
335 | protected |
|
345 | protected |
|
336 | def encrypt_new_password |
|
346 | def encrypt_new_password |
|
337 | return if password.blank? |
|
347 | return if password.blank? |
|
338 | self.salt = (10+rand(90)).to_s |
|
348 | self.salt = (10+rand(90)).to_s |
|
339 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
349 | self.hashed_password = User.encrypt(self.password,self.salt) |
|
340 | end |
|
350 | end |
|
341 |
|
351 | ||
|
342 | def assign_default_site |
|
352 | def assign_default_site |
|
343 | # have to catch error when migrating (because self.site is not available). |
|
353 | # have to catch error when migrating (because self.site is not available). |
|
344 | begin |
|
354 | begin |
You need to be logged in to leave comments.
Login now