Description:
add bulk manage for enablind users
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r643:39e4a808eb76 - - 7 files changed: 132 inserted, 7 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 | + |
@@ -407,6 +407,39 | |||||
|
407 | redirect_to :action => 'mass_mailing' |
|
407 | redirect_to :action => 'mass_mailing' |
|
408 | end |
|
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 | protected |
|
443 | protected |
|
411 |
|
444 | ||
|
412 | def random_password(length=5) |
|
445 | def random_password(length=5) |
@@ -61,7 +61,9 | |||||
|
61 | result = Hash.new |
|
61 | result = Hash.new |
|
62 | #total number of submission |
|
62 | #total number of submission |
|
63 | result[:total_sub] = Submission.where(problem_id: self.id).count |
|
63 | result[:total_sub] = Submission.where(problem_id: self.id).count |
|
64 |
- result[:attempted_user] = Submission.where(problem_id: self.id).group |
|
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 | end |
|
67 | end |
|
66 |
|
68 | ||
|
67 | def long_name |
|
69 | def long_name |
@@ -1,8 +1,12 | |||||
|
1 | %tr |
|
1 | %tr |
|
2 | %td |
|
2 | %td |
|
|
3 | + - if @current_user and @current_user.admin? | ||
|
|
4 | + = link_to problem.name, stat_problem_path(problem) | ||
|
|
5 | + - else | ||
|
3 | = "#{problem.name}" |
|
6 | = "#{problem.name}" |
|
4 | %td |
|
7 | %td |
|
5 | = "#{problem.full_name}" |
|
8 | = "#{problem.full_name}" |
|
|
9 | + | ||
|
6 | %br |
|
10 | %br |
|
7 | = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem |
|
11 | = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem |
|
8 | %td |
|
12 | %td |
@@ -42,6 +42,7 | |||||
|
42 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
42 | = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} |
|
43 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
43 | = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} |
|
44 | = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default '} |
|
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 | = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '} |
|
46 | = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '} |
|
46 | = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '} |
|
47 | = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '} |
|
47 | = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '} |
|
48 | = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '} |
@@ -1,8 +1,9 | |||||
|
1 | <h1>Adding list of users</h1> |
|
1 | <h1>Adding list of users</h1> |
|
2 |
|
2 | ||
|
3 | <%= form_tag :action => 'create_from_list' do %> |
|
3 | <%= form_tag :action => 'create_from_list' do %> |
|
4 | - <%= submit_tag 'create users' %><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))</tt><br/> |
|
5 | + List of user information in this format: <tt>user_id,name(,passwd(,alias(,remark)))</tt><br/> |
|
6 |
- Note that <tt>passwd</tt> and <tt> |
|
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 | <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %> |
|
8 | <%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %> |
|
8 | <% end %> |
|
9 | <% end %> |
@@ -63,14 +63,15 | |||||
|
63 | end |
|
63 | end |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | - get 'tasks/view/:file.:ext' => 'tasks#view' |
|
66 | + |
|
67 | - get 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
||
|
68 | - get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
||
|
69 |
|
67 | ||
|
70 | #main |
|
68 | #main |
|
71 | get "main/list" |
|
69 | get "main/list" |
|
72 | get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' |
|
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 | #report |
|
75 | #report |
|
75 | get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
76 | get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
76 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
77 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
@@ -78,6 +79,12 | |||||
|
78 | get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
79 | get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
79 | post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
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 | #grader |
|
88 | #grader |
|
82 | get 'graders/list', to: 'graders#list', as: 'grader_list' |
|
89 | get 'graders/list', to: 'graders#list', as: 'grader_list' |
|
83 |
|
90 |
You need to be logged in to leave comments.
Login now