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