Description:
add bulk manage for enablind users
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r643:39e4a808eb76 - - 7 files changed: 133 inserted, 8 deleted

@@ -0,0 +1,77
1 + %h1 Bulk Manage User
2 +
3 + = form_tag bulk_manage_user_admin_path
4 + .row
5 + .col-md-6
6 + .panel.panel-primary
7 + .panel-title.panel-heading
8 + Filter User
9 + .panel-body
10 + Filtering users whose login match the following MySQL regex
11 + .form-group
12 + = label_tag "regex", 'Regex Pattern'
13 + = text_field_tag "regex", params[:regex], class: 'form-control'
14 + %p
15 + Example
16 + %ul
17 + %li
18 + %code root
19 + matches every user whose login contains "root"
20 + %li
21 + %code ^56
22 + matches every user whose login starts with "56"
23 + %li
24 + %code 21$
25 + matches every user whose login ends with "21"
26 + .col-md-6
27 + .panel.panel-primary
28 + .panel-title.panel-heading
29 + Action
30 + .panel-body
31 + .row.form-group
32 + .col-md-6
33 + %label.checkbox-inline
34 + = check_box_tag "enabled", true, params[:enabled]
35 + Change "Enabled" to
36 + .col-md-3
37 + %label.radio-inline
38 + = radio_button_tag "enable", 1, params[:enable] == '1', id: 'enable-yes'
39 + Yes
40 + .col-md-3
41 + %label.radio-inline
42 + = radio_button_tag "enable", 0, params[:enable] == '0', id: 'enable-no'
43 + No
44 + .row.form-group
45 + .col-md-6
46 + %label.checkbox-inline
47 + = check_box_tag "gen_password", true, params[:gen_password]
48 + Generate new random password
49 +
50 + .row
51 + .col-md-12
52 + = submit_tag "Preview Result", class: 'btn btn-default'
53 + - if @users
54 + .row
55 + .col-md-4
56 + - if @action
57 + %h2 Confirmation
58 + - if @action[:set_enable]
59 + .alert.alert-info The following users will be set #{(@action[:enabled] ? 'enable' : 'disable')}.
60 + - if @action[:gen_password]
61 + .alert.alert-info The password of the following users will be randomly generated.
62 + .row
63 + .col-md-4
64 + = submit_tag "Perform", class: 'btn btn-primary'
65 + .row
66 + .col-md-12
67 + The pattern matches #{@users.count} following users.
68 + %br
69 + - @users.each do |user|
70 + = user.login
71 + = ' '
72 + = user.full_name
73 + = ' '
74 + = "(#{user.remark})" if user.remark
75 + %br
76 +
77 +
@@ -386,48 +386,81
386 386 redirect_to :action => 'mass_mailing' and return
387 387 end
388 388
389 389 mail_body = params[:email_body]
390 390 if !mail_body or mail_body.blank?
391 391 flash[:notice] = 'You entered an empty mail body.'
392 392 redirect_to :action => 'mass_mailing' and return
393 393 end
394 394
395 395 note = []
396 396 users = []
397 397 lines.split("\n").each do |line|
398 398 user = User.find_by_login(line.chomp)
399 399 if user
400 400 send_mail(user.email, mail_subject, mail_body)
401 401 note << user.login
402 402 end
403 403 end
404 404
405 405 flash[:notice] = 'User(s) ' + note.join(', ') +
406 406 ' were successfully modified. '
407 407 redirect_to :action => 'mass_mailing'
408 408 end
409 409
410 + #bulk manage
411 + def bulk_manage
412 +
413 + begin
414 + @users = User.where('login REGEXP ?',params[:regex]) if params[:regex]
415 + @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised
416 + rescue Exception
417 + flash[:error] = 'Regular Expression is malformed'
418 + @users = nil
419 + end
420 +
421 + if params[:commit]
422 + @action = {}
423 + @action[:set_enable] = params[:enabled]
424 + @action[:enabled] = params[:enable] == "1"
425 + @action[:gen_password] = params[:gen_password]
426 + end
427 +
428 + if params[:commit] == "Perform"
429 + if @action[:set_enable]
430 + @users.update_all(enabled: @action[:enabled])
431 + end
432 + if @action[:gen_password]
433 + @users.each do |u|
434 + password = random_password
435 + u.password = password
436 + u.password_confirmation = password
437 + u.save
438 + end
439 + end
440 + end
441 + end
442 +
410 443 protected
411 444
412 445 def random_password(length=5)
413 446 chars = 'abcdefghijkmnopqrstuvwxyz23456789'
414 447 newpass = ""
415 448 length.times { newpass << chars[rand(chars.size-1)] }
416 449 return newpass
417 450 end
418 451
419 452 def import_from_file(f)
420 453 data_hash = YAML.load(f)
421 454 @import_log = ""
422 455
423 456 country_data = data_hash[:countries]
424 457 site_data = data_hash[:sites]
425 458 user_data = data_hash[:users]
426 459
427 460 # import country
428 461 countries = {}
429 462 country_data.each_pair do |id,country|
430 463 c = Country.find_by_name(country[:name])
431 464 if c!=nil
432 465 countries[id] = c
433 466 @import_log << "Found #{country[:name]}\n"
@@ -40,49 +40,51
40 40
41 41 import_to_db = params.has_key? :import_to_db
42 42
43 43 importer = TestdataImporter.new(problem)
44 44
45 45 if not importer.import_from_file(import_params[:file],
46 46 import_params[:time_limit],
47 47 import_params[:memory_limit],
48 48 import_params[:checker_name],
49 49 import_to_db)
50 50 problem.errors.add(:base,'Import error.')
51 51 end
52 52
53 53 return problem, importer.log_msg
54 54 end
55 55
56 56 def self.download_file_basedir
57 57 return "#{Rails.root}/data/tasks"
58 58 end
59 59
60 60 def get_submission_stat
61 61 result = Hash.new
62 62 #total number of submission
63 63 result[:total_sub] = Submission.where(problem_id: self.id).count
64 - result[:attempted_user] = Submission.where(problem_id: self.id).group_by(:user_id)
64 + result[:attempted_user] = Submission.where(problem_id: self.id).group(:user_id)
65 + result[:pass] = Submission.where(problem_id: self.id).where("points >= ?",self.full_score).count
66 + return result
65 67 end
66 68
67 69 def long_name
68 70 "[#{name}] #{full_name}"
69 71 end
70 72
71 73 protected
72 74
73 75 def self.to_i_or_default(st, default)
74 76 if st!=''
75 77 result = st.to_i
76 78 end
77 79 result ||= default
78 80 end
79 81
80 82 def self.to_f_or_default(st, default)
81 83 if st!=''
82 84 result = st.to_f
83 85 end
84 86 result ||= default
85 87 end
86 88
87 89 def self.extract_params_and_check(params, problem)
88 90 time_limit = Problem.to_f_or_default(params[:time_limit],
@@ -1,18 +1,22
1 1 %tr
2 2 %td
3 - = "#{problem.name}"
3 + - if @current_user and @current_user.admin?
4 + = link_to problem.name, stat_problem_path(problem)
5 + - else
6 + = "#{problem.name}"
4 7 %td
5 8 = "#{problem.full_name}"
9 +
6 10 %br
7 11 = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem
8 12 %td
9 13 = @prob_submissions[problem.id][:count]
10 14 = link_to "[subs]", main_submission_path(problem.id)
11 15 %td
12 16 = render :partial => 'submission_short',
13 17 :locals => {:submission => @prob_submissions[problem.id][:submission], :problem_name => problem.name, :problem_id => problem.id }
14 18 %td
15 19 - if @prob_submissions[problem.id][:submission]
16 20 = link_to 'Edit', edit_submission_path(@prob_submissions[problem.id][:submission]), class: 'btn btn-success'
17 21 - else
18 22 = link_to 'New', direct_edit_problem_submissions_path(problem.id), class: 'btn btn-success'
@@ -21,48 +21,49
21 21 = label_tag 'user_email', 'email'
22 22 = text_field 'user', 'email', :size => 10,class: 'form-control'
23 23 =submit_tag "Create", class: 'btn btn-primary'
24 24
25 25 .panel.panel-primary
26 26 .panel-title.panel-heading
27 27 Import from site management
28 28 .panel-body
29 29 = form_tag({:action => 'import'}, :multipart => true,class: 'form form-inline') do
30 30 .form-group
31 31 = label_tag :file, 'File:'
32 32 .input-group
33 33 %span.input-group-btn
34 34 %span.btn.btn-default.btn-file
35 35 Browse
36 36 = file_field_tag 'file'
37 37 = text_field_tag '' , nil, {readonly: true, class: 'form-control'}
38 38 = submit_tag 'Submit', class: 'btn btn-default'
39 39
40 40
41 41 %p
42 42 = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '}
43 43 = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '}
44 44 = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default '}
45 + = link_to 'Bulk Manage', bulk_manage_user_admin_path , { class: 'btn btn-default '}
45 46 = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '}
46 47 = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '}
47 48 = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '}
48 49
49 50 - if GraderConfiguration.multicontests?
50 51 %br/
51 52 %b Multi-contest:
52 53 = link_to '[Manage bulk users in contests]', :action => 'contest_management'
53 54 View users in:
54 55 - @contests.each do |contest|
55 56 = link_to "[#{contest.name}]", :action => 'contests', :id => contest.id
56 57 = link_to "[no contest]", :action => 'contests', :id => 'none'
57 58
58 59 Total #{@user_count} users |
59 60 - if !@paginated
60 61 Display all users.
61 62 \#{link_to '[show in pages]', :action => 'index', :page => '1'}
62 63 - else
63 64 Display in pages.
64 65 \#{link_to '[display all]', :action => 'index', :page => 'all'} |
65 66 \#{will_paginate @users, :container => false}
66 67
67 68
68 69 %table.table.table-hover.table-condense
@@ -1,8 +1,9
1 1 <h1>Adding list of users</h1>
2 2
3 3 <%= form_tag :action => 'create_from_list' do %>
4 - <%= submit_tag 'create users' %><br/>
5 - List of user information in this format: <tt>user_id,name(,passwd(,alias))</tt><br/>
6 - Note that <tt>passwd</tt> and <tt>alias</tt> is optional.<br/>
4 + <%= submit_tag 'create users',class: 'btn btn-success'%><br/>
5 + List of user information in this format: <tt>user_id,name(,passwd(,alias(,remark)))</tt><br/>
6 + Note that <tt>passwd, alias</tt> and <tt> remark </tt>is optional.<br />
7 + When <tt>passwd</tt> or <tt>alias</tt> is empty, the original value will be used instead.<br/>
7 8 <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %>
8 9 <% end %>
@@ -42,51 +42,58
42 42 end
43 43 end
44 44
45 45 resources :grader_configuration, controller: 'configurations'
46 46
47 47 resources :users do
48 48 member do
49 49 get 'toggle_activate', 'toggle_enable'
50 50 get 'stat'
51 51 end
52 52 end
53 53
54 54 resources :submissions do
55 55 member do
56 56 get 'download'
57 57 get 'compiler_msg'
58 58 end
59 59 collection do
60 60 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
61 61 get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
62 62 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
63 63 end
64 64 end
65 65
66 - get 'tasks/view/:file.:ext' => 'tasks#view'
67 - get 'tasks/download/:id/:file.:ext' => 'tasks#download'
68 - get 'heartbeat/:id/edit' => 'heartbeat#edit'
66 +
69 67
70 68 #main
71 69 get "main/list"
72 70 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
73 71
72 + #user admin
73 + get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
74 +
74 75 #report
75 76 get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
76 77 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
77 78 get "report/login"
78 79 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
79 80 post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
80 81
82 +
83 + #
84 + get 'tasks/view/:file.:ext' => 'tasks#view'
85 + get 'tasks/download/:id/:file.:ext' => 'tasks#download'
86 + get 'heartbeat/:id/edit' => 'heartbeat#edit'
87 +
81 88 #grader
82 89 get 'graders/list', to: 'graders#list', as: 'grader_list'
83 90
84 91
85 92 get 'heartbeat/:id/edit' => 'heartbeat#edit'
86 93
87 94 # See how all your routes lay out with "rake routes"
88 95
89 96 # This is a legacy wild controller route that's not recommended for RESTful applications.
90 97 # Note: This route will make all actions in every controller accessible via GET requests.
91 98 match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
92 99 end
You need to be logged in to leave comments. Login now