diff --git a/app/controllers/report_controller.rb b/app/controllers/report_controller.rb --- a/app/controllers/report_controller.rb +++ b/app/controllers/report_controller.rb @@ -17,7 +17,12 @@ def current_score @problems = Problem.available_problems - @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) + if params[:group_id] + @group = Group.find(params[:group_id]) + @users = @group.users.where(enabled: true) + else + @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) + end @scorearray = calculate_max_score(@problems, @users,0,0,true) #rencer accordingly diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -27,20 +27,19 @@ def download problem = Problem.find(params[:id]) unless @current_user.can_view_problem? problem + flash[:notice] = 'You are not authorized to access this file' redirect_to :action => 'index' and return end base_name = params[:file] base_filename = File.basename("#{base_name}.#{params[:ext]}") filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}" - puts "SENDING: #{filename}" if !FileTest.exists?(filename) + flash[:notice] = 'File does not exists' redirect_to :action => 'index' and return end - puts "SENDING: #{filename}" - send_file_to_user(filename, base_filename) end 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 @@ -60,6 +60,8 @@ lines = params[:user_list] note = [] + error_note = [] + ok_user = [] lines.split("\n").each do |line| items = line.chomp.split(',') @@ -101,18 +103,36 @@ :remark => remark}) end user.activated = true - user.save - if added_random_password - note << "'#{login}' (+)" + if user.save + if added_random_password + note << "'#{login}' (+)" + else + note << login + end + ok_user << user else - note << login + error_note << "#{login}" end + end end + + #add to group + if params[:add_to_group] + group = Group.where(id: params[:group_id]).first + if group + group.users << ok_user + end + end + + # show flash flash[:success] = 'User(s) ' + note.join(', ') + ' were successfully created. ' + '( (+) - created with random passwords.)' + if error_note.size > 0 + flash[:error] = "Following user(s) failed to be created: " + error_note.join(', ') + end redirect_to :action => 'index' end diff --git a/app/helpers/main_helper.rb b/app/helpers/main_helper.rb --- a/app/helpers/main_helper.rb +++ b/app/helpers/main_helper.rb @@ -4,6 +4,7 @@ if !problem.url.blank? return link_to name, problem.url, options elsif !problem.description_filename.blank? + #build a link to a problem (via task controller) basename, ext = problem.description_filename.split('.') options[:controller] = 'tasks' options[:action] = 'download' diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -246,13 +246,18 @@ #get a list of available problem def available_problems + # first, we check if this is normal mode if not GraderConfiguration.multicontests? + + #if this is a normal mode + #we show problem based on problem_group, if the config said so if GraderConfiguration.use_problem_group? return available_problems_in_group else return Problem.available_problems end else + #this is multi contest mode contest_problems = [] pin = {} contests.enabled.each do |contest| diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml --- a/app/views/groups/show.html.haml +++ b/app/views/groups/show.html.haml @@ -1,73 +1,80 @@ -%p - %b Name: - = @group.name -%p - %b Description: - = @group.description - -%br -= link_to 'Edit', edit_group_path(@group) -\| -= link_to 'Back', groups_path - -.row - .col-md-12 - %h1 Group details -.row - .col-md-6 - .panel.panel-default - .panel-heading - .panel-title Users in this group - .panel-body - =form_tag add_user_group_path(@group), class: 'form-inline' do - .form-group - =label_tag :user_id, "User" - =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2' - =submit_tag "Add",class: 'btn btn-primary' +.container-fluid + .row + .col-md-6 + %h1 Group #{@group.name} + .row + .col-md-6 + %b Description: + = @group.description + %br + = link_to 'Edit', edit_group_path(@group), class: 'btn btn-primary' + .row + .col-md-12 + %h1 Group details + .row + .col-md-6 + .panel.panel-default + .panel-heading + .panel-title Users in this group + .panel-body + %ul + %li + If you want to add several users to a group, it may be easier to just re-import those users in + = link_to 'New list of users', new_list_user_admin_index_path + page + =form_tag add_user_group_path(@group), class: 'form-inline' do + .form-group + =label_tag :user_id, "User" + =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2' + =submit_tag "Add",class: 'btn btn-primary' - %table.table.table-hover - %thead - %tr - %th Login - %th Full name - %th Remark - %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' - - %tbody - - @group.users.each do |user| + %table.table.table-hover + %thead %tr - %td= user.login - %td= user.full_name - %td= user.remark - %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm' - .col-md-6 - .panel.panel-default - .panel-heading - .panel-title Problems - .panel-body + %th Login + %th Full name + %th Remark + %th= link_to 'Remove All', remove_all_user_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL USERS from group?" }, class: 'btn btn-danger btn-sm' - =form_tag add_problem_group_path(@group), class: 'form-inline' do - .form-group - =label_tag :problem_id, "Problem" - =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2' - =submit_tag "Add",class: 'btn btn-primary' + %tbody + - @group.users.each do |user| + %tr + %td= user.login + %td= user.full_name + %td= user.remark + %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm' + .col-md-6 + .panel.panel-default + .panel-heading + .panel-title Problems + .panel-body + %ul + %li + If you want to add several problem to a group, it may be easier to bulk manage them in the + = link_to 'Bulk Manage', manage_problems_path + page + =form_tag add_problem_group_path(@group), class: 'form-inline' do + .form-group + =label_tag :problem_id, "Problem" + =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2' + =submit_tag "Add",class: 'btn btn-primary' - %table.table.table-hover - %thead - %tr - %th name - %th Full name - %th Full score - %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' + %table.table.table-hover + %thead + %tr + %th name + %th Full name + %th Full score + %th= link_to 'Remove All', remove_all_problem_group_path(@group), method: :delete, :data => { :confirm => "Remove ALL PROBLEMS from group?" }, class: 'btn btn-danger btn-sm' - %tbody - - @group.problems.each do |problem| - %tr - %td= problem.name - %td= problem.full_name - %td= problem.full_score - %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger btn-sm' + %tbody + - @group.problems.each do |problem| + %tr + %td= problem.name + %td= problem.full_name + %td= problem.full_score + %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger btn-sm' diff --git a/app/views/report/current_score.html.haml b/app/views/report/current_score.html.haml --- a/app/views/report/current_score.html.haml +++ b/app/views/report/current_score.html.haml @@ -1,3 +1,11 @@ -%h1 Current Score +.container-fluid + %h1 Current Score + = form_tag current_score_report_path, method: 'get' do + Show only users from this group + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2' + = submit_tag 'Apply',class: 'btn btn-default' -= render "score_table" + %br + + + = render "score_table" diff --git a/app/views/user_admin/new_list.html.erb b/app/views/user_admin/new_list.html.erb deleted file mode 100644 --- a/app/views/user_admin/new_list.html.erb +++ /dev/null @@ -1,9 +0,0 @@ -

Adding list of users

- -<%= form_tag :action => 'create_from_list' do %> - <%= 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/app/views/user_admin/new_list.html.haml b/app/views/user_admin/new_list.html.haml new file mode 100644 --- /dev/null +++ b/app/views/user_admin/new_list.html.haml @@ -0,0 +1,45 @@ +.container-fluid + .row + .col-md-6 + %h1 Adding list of users + .row + .col-md-6 + .panel.panel-default + .panel-heading + .panel-title Info + .panel-body + %ul + %li + List of user information in this format: + %tt user_id,name(,passwd(,alias(,remark))) + %li + Note that + %tt passwd, alias + and + %tt remark + is optional. + %li + When + %tt passwd + or + %tt alias + is empty, the original value will be used instead. + %li + If the users with the same user_id already exists, existing information will be overwritten. + + .row + .col-md-6 + = form_tag :action => 'create_from_list' do + .form-group + = submit_tag 'Create following users',class: 'btn btn-success' + .form-group + .div.checkbox + %label + = check_box_tag :add_to_group + Also add these users to the following group + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2' + .form-group + = text_area_tag 'user_list', nil, :rows => 50, :cols => 80 + .col-md-6 + + diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -135,7 +135,7 @@ get 'login' get 'multiple_login' get 'problem_hof/:id', action: 'problem_hof' - get 'current_score' + get 'current_score(/:group_id)', action: 'current_score', as: 'current_score' get 'max_score' post 'show_max_score' end