diff --git a/app/controllers/user_admin_controller.rb b/app/controllers/user_admin_controller.rb --- a/app/controllers/user_admin_controller.rb +++ b/app/controllers/user_admin_controller.rb @@ -407,6 +407,39 @@ redirect_to :action => 'mass_mailing' end + #bulk manage + def bulk_manage + + begin + @users = User.where('login REGEXP ?',params[:regex]) if params[:regex] + @users.count if @users #i don't know why I have to call count, but if I won't exception is not raised + rescue Exception + flash[:error] = 'Regular Expression is malformed' + @users = nil + end + + if params[:commit] + @action = {} + @action[:set_enable] = params[:enabled] + @action[:enabled] = params[:enable] == "1" + @action[:gen_password] = params[:gen_password] + end + + if params[:commit] == "Perform" + if @action[:set_enable] + @users.update_all(enabled: @action[:enabled]) + end + if @action[:gen_password] + @users.each do |u| + password = random_password + u.password = password + u.password_confirmation = password + u.save + end + end + end + end + protected def random_password(length=5) diff --git a/app/models/problem.rb b/app/models/problem.rb --- a/app/models/problem.rb +++ b/app/models/problem.rb @@ -61,7 +61,9 @@ result = Hash.new #total number of submission result[:total_sub] = Submission.where(problem_id: self.id).count - result[:attempted_user] = Submission.where(problem_id: self.id).group_by(:user_id) + result[:attempted_user] = Submission.where(problem_id: self.id).group(:user_id) + result[:pass] = Submission.where(problem_id: self.id).where("points >= ?",self.full_score).count + return result end def long_name diff --git a/app/views/main/_problem.html.haml b/app/views/main/_problem.html.haml --- a/app/views/main/_problem.html.haml +++ b/app/views/main/_problem.html.haml @@ -1,8 +1,12 @@ %tr %td - = "#{problem.name}" + - if @current_user and @current_user.admin? + = link_to problem.name, stat_problem_path(problem) + - else + = "#{problem.name}" %td = "#{problem.full_name}" + %br = link_to_description_if_any "[#{t 'main.problem_desc'}] ".html_safe, problem %td diff --git a/app/views/user_admin/bulk_manage.html.haml b/app/views/user_admin/bulk_manage.html.haml new file mode 100644 --- /dev/null +++ b/app/views/user_admin/bulk_manage.html.haml @@ -0,0 +1,77 @@ +%h1 Bulk Manage User + += form_tag bulk_manage_user_admin_path +.row + .col-md-6 + .panel.panel-primary + .panel-title.panel-heading + Filter User + .panel-body + Filtering users whose login match the following MySQL regex + .form-group + = label_tag "regex", 'Regex Pattern' + = text_field_tag "regex", params[:regex], class: 'form-control' + %p + Example + %ul + %li + %code root + matches every user whose login contains "root" + %li + %code ^56 + matches every user whose login starts with "56" + %li + %code 21$ + matches every user whose login ends with "21" + .col-md-6 + .panel.panel-primary + .panel-title.panel-heading + Action + .panel-body + .row.form-group + .col-md-6 + %label.checkbox-inline + = check_box_tag "enabled", true, params[:enabled] + Change "Enabled" to + .col-md-3 + %label.radio-inline + = radio_button_tag "enable", 1, params[:enable] == '1', id: 'enable-yes' + Yes + .col-md-3 + %label.radio-inline + = radio_button_tag "enable", 0, params[:enable] == '0', id: 'enable-no' + No + .row.form-group + .col-md-6 + %label.checkbox-inline + = check_box_tag "gen_password", true, params[:gen_password] + Generate new random password + +.row + .col-md-12 + = submit_tag "Preview Result", class: 'btn btn-default' +- if @users + .row + .col-md-4 + - if @action + %h2 Confirmation + - if @action[:set_enable] + .alert.alert-info The following users will be set #{(@action[:enabled] ? 'enable' : 'disable')}. + - if @action[:gen_password] + .alert.alert-info The password of the following users will be randomly generated. + .row + .col-md-4 + = submit_tag "Perform", class: 'btn btn-primary' + .row + .col-md-12 + The pattern matches #{@users.count} following users. + %br + - @users.each do |user| + = user.login + = ' ' + = user.full_name + = ' ' + = "(#{user.remark})" if user.remark + %br + + diff --git a/app/views/user_admin/index.html.haml b/app/views/user_admin/index.html.haml --- a/app/views/user_admin/index.html.haml +++ b/app/views/user_admin/index.html.haml @@ -42,6 +42,7 @@ = link_to '+ New user', { :action => 'new' }, { class: 'btn btn-success '} = link_to '+ New list of users', { :action => 'new_list' }, { class: 'btn btn-success '} = link_to 'View administrators',{ :action => 'admin'}, { class: 'btn btn-default '} + = link_to 'Bulk Manage', bulk_manage_user_admin_path , { class: 'btn btn-default '} = link_to 'Random passwords',{ :action => 'random_all_passwords'}, { class: 'btn btn-default '} = link_to 'View active users',{ :action => 'active'}, { class: 'btn btn-default '} = link_to 'Mass mailing',{ :action => 'mass_mailing'}, { class: 'btn btn-default '} diff --git a/app/views/user_admin/new_list.html.erb b/app/views/user_admin/new_list.html.erb --- a/app/views/user_admin/new_list.html.erb +++ b/app/views/user_admin/new_list.html.erb @@ -1,8 +1,9 @@

Adding list of users

<%= form_tag :action => 'create_from_list' do %> -<%= submit_tag 'create users' %>
-List of user information in this format: user_id,name(,passwd(,alias))
-Note that passwd and alias is optional.
+ <%= submit_tag 'create users',class: 'btn btn-success'%>
+List of user information in this format: user_id,name(,passwd(,alias(,remark)))
+Note that passwd, alias and remark is optional.
+When passwd or alias is empty, the original value will be used instead.
<%= text_area_tag 'user_list', nil, :rows => 50, :cols => 80 %> <% end %> diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -63,14 +63,15 @@ end end - get 'tasks/view/:file.:ext' => 'tasks#view' - get 'tasks/download/:id/:file.:ext' => 'tasks#download' - get 'heartbeat/:id/edit' => 'heartbeat#edit' + #main get "main/list" get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' + #user admin + get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' + #report get 'report/current_score', to: 'report#current_score', as: 'report_current_score' get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' @@ -78,6 +79,12 @@ get 'report/max_score', to: 'report#max_score', as: 'report_max_score' post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' + + # + get 'tasks/view/:file.:ext' => 'tasks#view' + get 'tasks/download/:id/:file.:ext' => 'tasks#download' + get 'heartbeat/:id/edit' => 'heartbeat#edit' + #grader get 'graders/list', to: 'graders#list', as: 'grader_list'