Description:
fix user update
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r639:2826fdf23cce - - 2 files changed: 4 inserted, 4 deleted
@@ -361,195 +361,195 | |||||
|
361 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
361 | flash[:notice] = 'You cannot revoke admisnistrator permission from root.' |
|
362 | redirect_to :action => 'admin' and return |
|
362 | redirect_to :action => 'admin' and return |
|
363 | end |
|
363 | end |
|
364 |
|
364 | ||
|
365 | admin_role = Role.find_by_name('admin') |
|
365 | admin_role = Role.find_by_name('admin') |
|
366 | user.roles.delete(admin_role) |
|
366 | user.roles.delete(admin_role) |
|
367 | flash[:notice] = 'User permission revoked' |
|
367 | flash[:notice] = 'User permission revoked' |
|
368 | redirect_to :action => 'admin' |
|
368 | redirect_to :action => 'admin' |
|
369 | end |
|
369 | end |
|
370 |
|
370 | ||
|
371 | # mass mailing |
|
371 | # mass mailing |
|
372 |
|
372 | ||
|
373 | def mass_mailing |
|
373 | def mass_mailing |
|
374 | end |
|
374 | end |
|
375 |
|
375 | ||
|
376 | def bulk_mail |
|
376 | def bulk_mail |
|
377 | lines = params[:login_list] |
|
377 | lines = params[:login_list] |
|
378 | if !lines or lines.blank? |
|
378 | if !lines or lines.blank? |
|
379 | flash[:notice] = 'You entered an empty list.' |
|
379 | flash[:notice] = 'You entered an empty list.' |
|
380 | redirect_to :action => 'mass_mailing' and return |
|
380 | redirect_to :action => 'mass_mailing' and return |
|
381 | end |
|
381 | end |
|
382 |
|
382 | ||
|
383 | mail_subject = params[:subject] |
|
383 | mail_subject = params[:subject] |
|
384 | if !mail_subject or mail_subject.blank? |
|
384 | if !mail_subject or mail_subject.blank? |
|
385 | flash[:notice] = 'You entered an empty mail subject.' |
|
385 | flash[:notice] = 'You entered an empty mail subject.' |
|
386 | redirect_to :action => 'mass_mailing' and return |
|
386 | redirect_to :action => 'mass_mailing' and return |
|
387 | end |
|
387 | end |
|
388 |
|
388 | ||
|
389 | mail_body = params[:email_body] |
|
389 | mail_body = params[:email_body] |
|
390 | if !mail_body or mail_body.blank? |
|
390 | if !mail_body or mail_body.blank? |
|
391 | flash[:notice] = 'You entered an empty mail body.' |
|
391 | flash[:notice] = 'You entered an empty mail body.' |
|
392 | redirect_to :action => 'mass_mailing' and return |
|
392 | redirect_to :action => 'mass_mailing' and return |
|
393 | end |
|
393 | end |
|
394 |
|
394 | ||
|
395 | note = [] |
|
395 | note = [] |
|
396 | users = [] |
|
396 | users = [] |
|
397 | lines.split("\n").each do |line| |
|
397 | lines.split("\n").each do |line| |
|
398 | user = User.find_by_login(line.chomp) |
|
398 | user = User.find_by_login(line.chomp) |
|
399 | if user |
|
399 | if user |
|
400 | send_mail(user.email, mail_subject, mail_body) |
|
400 | send_mail(user.email, mail_subject, mail_body) |
|
401 | note << user.login |
|
401 | note << user.login |
|
402 | end |
|
402 | end |
|
403 | end |
|
403 | end |
|
404 |
|
404 | ||
|
405 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
405 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
406 | ' were successfully modified. ' |
|
406 | ' were successfully modified. ' |
|
407 | redirect_to :action => 'mass_mailing' |
|
407 | redirect_to :action => 'mass_mailing' |
|
408 | end |
|
408 | end |
|
409 |
|
409 | ||
|
410 | protected |
|
410 | protected |
|
411 |
|
411 | ||
|
412 | def random_password(length=5) |
|
412 | def random_password(length=5) |
|
413 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
413 | chars = 'abcdefghijkmnopqrstuvwxyz23456789' |
|
414 | newpass = "" |
|
414 | newpass = "" |
|
415 | length.times { newpass << chars[rand(chars.size-1)] } |
|
415 | length.times { newpass << chars[rand(chars.size-1)] } |
|
416 | return newpass |
|
416 | return newpass |
|
417 | end |
|
417 | end |
|
418 |
|
418 | ||
|
419 | def import_from_file(f) |
|
419 | def import_from_file(f) |
|
420 | data_hash = YAML.load(f) |
|
420 | data_hash = YAML.load(f) |
|
421 | @import_log = "" |
|
421 | @import_log = "" |
|
422 |
|
422 | ||
|
423 | country_data = data_hash[:countries] |
|
423 | country_data = data_hash[:countries] |
|
424 | site_data = data_hash[:sites] |
|
424 | site_data = data_hash[:sites] |
|
425 | user_data = data_hash[:users] |
|
425 | user_data = data_hash[:users] |
|
426 |
|
426 | ||
|
427 | # import country |
|
427 | # import country |
|
428 | countries = {} |
|
428 | countries = {} |
|
429 | country_data.each_pair do |id,country| |
|
429 | country_data.each_pair do |id,country| |
|
430 | c = Country.find_by_name(country[:name]) |
|
430 | c = Country.find_by_name(country[:name]) |
|
431 | if c!=nil |
|
431 | if c!=nil |
|
432 | countries[id] = c |
|
432 | countries[id] = c |
|
433 | @import_log << "Found #{country[:name]}\n" |
|
433 | @import_log << "Found #{country[:name]}\n" |
|
434 | else |
|
434 | else |
|
435 | countries[id] = Country.new(:name => country[:name]) |
|
435 | countries[id] = Country.new(:name => country[:name]) |
|
436 | countries[id].save |
|
436 | countries[id].save |
|
437 | @import_log << "Created #{country[:name]}\n" |
|
437 | @import_log << "Created #{country[:name]}\n" |
|
438 | end |
|
438 | end |
|
439 | end |
|
439 | end |
|
440 |
|
440 | ||
|
441 | # import sites |
|
441 | # import sites |
|
442 | sites = {} |
|
442 | sites = {} |
|
443 | site_data.each_pair do |id,site| |
|
443 | site_data.each_pair do |id,site| |
|
444 | s = Site.find_by_name(site[:name]) |
|
444 | s = Site.find_by_name(site[:name]) |
|
445 | if s!=nil |
|
445 | if s!=nil |
|
446 | @import_log << "Found #{site[:name]}\n" |
|
446 | @import_log << "Found #{site[:name]}\n" |
|
447 | else |
|
447 | else |
|
448 | s = Site.new(:name => site[:name]) |
|
448 | s = Site.new(:name => site[:name]) |
|
449 | @import_log << "Created #{site[:name]}\n" |
|
449 | @import_log << "Created #{site[:name]}\n" |
|
450 | end |
|
450 | end |
|
451 | s.password = site[:password] |
|
451 | s.password = site[:password] |
|
452 | s.country = countries[site[:country_id]] |
|
452 | s.country = countries[site[:country_id]] |
|
453 | s.save |
|
453 | s.save |
|
454 | sites[id] = s |
|
454 | sites[id] = s |
|
455 | end |
|
455 | end |
|
456 |
|
456 | ||
|
457 | # import users |
|
457 | # import users |
|
458 | user_data.each_pair do |id,user| |
|
458 | user_data.each_pair do |id,user| |
|
459 | u = User.find_by_login(user[:login]) |
|
459 | u = User.find_by_login(user[:login]) |
|
460 | if u!=nil |
|
460 | if u!=nil |
|
461 | @import_log << "Found #{user[:login]}\n" |
|
461 | @import_log << "Found #{user[:login]}\n" |
|
462 | else |
|
462 | else |
|
463 | u = User.new(:login => user[:login]) |
|
463 | u = User.new(:login => user[:login]) |
|
464 | @import_log << "Created #{user[:login]}\n" |
|
464 | @import_log << "Created #{user[:login]}\n" |
|
465 | end |
|
465 | end |
|
466 | u.full_name = user[:name] |
|
466 | u.full_name = user[:name] |
|
467 | u.password = user[:password] |
|
467 | u.password = user[:password] |
|
468 | u.country = countries[user[:country_id]] |
|
468 | u.country = countries[user[:country_id]] |
|
469 | u.site = sites[user[:site_id]] |
|
469 | u.site = sites[user[:site_id]] |
|
470 | u.activated = true |
|
470 | u.activated = true |
|
471 | u.email = "empty-#{u.login}@none.com" |
|
471 | u.email = "empty-#{u.login}@none.com" |
|
472 | if not u.save |
|
472 | if not u.save |
|
473 | @import_log << "Errors\n" |
|
473 | @import_log << "Errors\n" |
|
474 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
474 | u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" } |
|
475 | end |
|
475 | end |
|
476 | end |
|
476 | end |
|
477 |
|
477 | ||
|
478 | end |
|
478 | end |
|
479 |
|
479 | ||
|
480 | def logout_users(users) |
|
480 | def logout_users(users) |
|
481 | users.each do |user| |
|
481 | users.each do |user| |
|
482 | contest_stat = user.contest_stat(true) |
|
482 | contest_stat = user.contest_stat(true) |
|
483 | if contest_stat and !contest_stat.forced_logout |
|
483 | if contest_stat and !contest_stat.forced_logout |
|
484 | contest_stat.forced_logout = true |
|
484 | contest_stat.forced_logout = true |
|
485 | contest_stat.save |
|
485 | contest_stat.save |
|
486 | end |
|
486 | end |
|
487 | end |
|
487 | end |
|
488 | end |
|
488 | end |
|
489 |
|
489 | ||
|
490 | def send_contest_update_notification_email(user, contest) |
|
490 | def send_contest_update_notification_email(user, contest) |
|
491 | contest_title_name = GraderConfiguration['contest.name'] |
|
491 | contest_title_name = GraderConfiguration['contest.name'] |
|
492 | contest_name = contest.name |
|
492 | contest_name = contest.name |
|
493 | mail_subject = t('contest.notification.email_subject', { |
|
493 | mail_subject = t('contest.notification.email_subject', { |
|
494 | :contest_title_name => contest_title_name, |
|
494 | :contest_title_name => contest_title_name, |
|
495 | :contest_name => contest_name }) |
|
495 | :contest_name => contest_name }) |
|
496 | mail_body = t('contest.notification.email_body', { |
|
496 | mail_body = t('contest.notification.email_body', { |
|
497 | :full_name => user.full_name, |
|
497 | :full_name => user.full_name, |
|
498 | :contest_title_name => contest_title_name, |
|
498 | :contest_title_name => contest_title_name, |
|
499 | :contest_name => contest.name, |
|
499 | :contest_name => contest.name, |
|
500 | }) |
|
500 | }) |
|
501 |
|
501 | ||
|
502 | logger.info mail_body |
|
502 | logger.info mail_body |
|
503 | send_mail(user.email, mail_subject, mail_body) |
|
503 | send_mail(user.email, mail_subject, mail_body) |
|
504 | end |
|
504 | end |
|
505 |
|
505 | ||
|
506 | def find_contest_and_user_from_contest_id(id) |
|
506 | def find_contest_and_user_from_contest_id(id) |
|
507 | if id!='none' |
|
507 | if id!='none' |
|
508 | @contest = Contest.find(id) |
|
508 | @contest = Contest.find(id) |
|
509 | else |
|
509 | else |
|
510 | @contest = nil |
|
510 | @contest = nil |
|
511 | end |
|
511 | end |
|
512 | if @contest |
|
512 | if @contest |
|
513 | @users = @contest.users |
|
513 | @users = @contest.users |
|
514 | else |
|
514 | else |
|
515 | @users = User.find_users_with_no_contest |
|
515 | @users = User.find_users_with_no_contest |
|
516 | end |
|
516 | end |
|
517 | return [@contest, @users] |
|
517 | return [@contest, @users] |
|
518 | end |
|
518 | end |
|
519 |
|
519 | ||
|
520 | def gen_csv_from_scorearray(scorearray,problem) |
|
520 | def gen_csv_from_scorearray(scorearray,problem) |
|
521 | CSV.generate do |csv| |
|
521 | CSV.generate do |csv| |
|
522 | #add header |
|
522 | #add header |
|
523 | header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] |
|
523 | header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] |
|
524 | problem.each { |p| header << p.name } |
|
524 | problem.each { |p| header << p.name } |
|
525 | header += ['Total','Passed'] |
|
525 | header += ['Total','Passed'] |
|
526 | csv << header |
|
526 | csv << header |
|
527 | #add data |
|
527 | #add data |
|
528 | scorearray.each do |sc| |
|
528 | scorearray.each do |sc| |
|
529 | total = num_passed = 0 |
|
529 | total = num_passed = 0 |
|
530 | row = Array.new |
|
530 | row = Array.new |
|
531 | sc.each_index do |i| |
|
531 | sc.each_index do |i| |
|
532 | if i == 0 |
|
532 | if i == 0 |
|
533 | row << sc[i].login |
|
533 | row << sc[i].login |
|
534 | row << sc[i].full_name |
|
534 | row << sc[i].full_name |
|
535 | row << sc[i].activated |
|
535 | row << sc[i].activated |
|
536 | row << (sc[i].try(:contest_stat).try(:started_at).nil? ? 'no' : 'yes') |
|
536 | row << (sc[i].try(:contest_stat).try(:started_at).nil? ? 'no' : 'yes') |
|
537 | row << sc[i].contests.collect {|c| c.name}.join(', ') |
|
537 | row << sc[i].contests.collect {|c| c.name}.join(', ') |
|
538 | else |
|
538 | else |
|
539 | row << sc[i][0] |
|
539 | row << sc[i][0] |
|
540 | total += sc[i][0] |
|
540 | total += sc[i][0] |
|
541 | num_passed += 1 if sc[i][1] |
|
541 | num_passed += 1 if sc[i][1] |
|
542 | end |
|
542 | end |
|
543 | end |
|
543 | end |
|
544 | row << total |
|
544 | row << total |
|
545 | row << num_passed |
|
545 | row << num_passed |
|
546 | csv << row |
|
546 | csv << row |
|
547 | end |
|
547 | end |
|
548 | end |
|
548 | end |
|
549 | end |
|
549 | end |
|
550 |
|
550 | ||
|
551 | private |
|
551 | private |
|
552 | def user_params |
|
552 | def user_params |
|
553 | - params.require(:user).permit(:login,:full_name,:hashed_password,:salt,:alias,:email,:site_id,:country_id,:activated,:enabled,:remark,:last_ip,:section) |
|
553 | + params.require(:user).permit(:login,:password,:password_confirmation,:email, :alias, :full_name,:remark) |
|
554 | end |
|
554 | end |
|
555 | end |
|
555 | end |
@@ -1,50 +1,50 | |||||
|
1 | require 'test_helper' |
|
1 | require 'test_helper' |
|
2 |
|
2 | ||
|
3 | class AnnouncementsControllerTest < ActionController::TestCase |
|
3 | class AnnouncementsControllerTest < ActionController::TestCase |
|
4 | setup do |
|
4 | setup do |
|
5 | @announcement = announcements(:one) |
|
5 | @announcement = announcements(:one) |
|
6 |
- @request.session[:user_id] = user |
|
6 | + @request.session[:user_id] = user(:admin).id |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | test "should get index" do |
|
9 | test "should get index" do |
|
10 | get :index |
|
10 | get :index |
|
11 | assert_response :success |
|
11 | assert_response :success |
|
12 | assert_not_nil assigns(:announcements) |
|
12 | assert_not_nil assigns(:announcements) |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | test "should get new" do |
|
15 | test "should get new" do |
|
16 | get :new |
|
16 | get :new |
|
17 | assert_response :success |
|
17 | assert_response :success |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
20 | test "should create announcement" do |
|
20 | test "should create announcement" do |
|
21 | assert_difference('Announcement.count') do |
|
21 | assert_difference('Announcement.count') do |
|
22 |
- post :create, announcement: { |
|
22 | + post :create, announcement: { } |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
25 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
26 | end |
|
26 | end |
|
27 |
|
27 | ||
|
28 | test "should show announcement" do |
|
28 | test "should show announcement" do |
|
29 | get :show, id: @announcement |
|
29 | get :show, id: @announcement |
|
30 | assert_response :success |
|
30 | assert_response :success |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | test "should get edit" do |
|
33 | test "should get edit" do |
|
34 | get :edit, id: @announcement |
|
34 | get :edit, id: @announcement |
|
35 | assert_response :success |
|
35 | assert_response :success |
|
36 | end |
|
36 | end |
|
37 |
|
37 | ||
|
38 | test "should update announcement" do |
|
38 | test "should update announcement" do |
|
39 |
- patch :update, id: @announcement, announcement: { |
|
39 | + patch :update, id: @announcement, announcement: { } |
|
40 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
40 | assert_redirected_to announcement_path(assigns(:announcement)) |
|
41 | end |
|
41 | end |
|
42 |
|
42 | ||
|
43 | test "should destroy announcement" do |
|
43 | test "should destroy announcement" do |
|
44 | assert_difference('Announcement.count', -1) do |
|
44 | assert_difference('Announcement.count', -1) do |
|
45 | delete :destroy, id: @announcement |
|
45 | delete :destroy, id: @announcement |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | assert_redirected_to announcements_path |
|
48 | assert_redirected_to announcements_path |
|
49 | end |
|
49 | end |
|
50 | end |
|
50 | end |
You need to be logged in to leave comments.
Login now