# HG changeset patch # User Nattee Niparnan # Date 2020-09-28 09:06:49 # Node ID b9faf3362123aa2bc289f575cdac1d4c56a7f575 # Parent 36fbb20457ec1493dfdb326b99fc4ba606781de4 # Parent d7e15899622227b8c22d2097ffed71e85b6d1254 merge diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -73,7 +73,7 @@ @submission.submitted_at = Time.new.gmtime @submission.ip_address = request.remote_ip - if GraderConfiguration.time_limit_mode? and user.contest_finished? + if @current_user.admin? == false && GraderConfiguration.time_limit_mode? && @current_user.contest_finished? @submission.errors.add(:base,"The contest is over.") prepare_list_information render :action => 'list' and return 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 @@ -19,7 +19,7 @@ def current_score @problems = Problem.available_problems - if params[:group_id] + if params[:group_id] && params[:users] == 'group' @group = Group.find(params[:group_id]) @users = @group.users.where(enabled: true) else @@ -50,10 +50,12 @@ end #users - @users = if params[:users] == "all" then + @users = if params[:users] == "group" then + Group.find(params[:group_id]).users.all + elsif params[:users] == 'enabled' + User.includes(:contests).includes(:contest_stat).where(enabled: true) + else User.includes(:contests).includes(:contest_stat) - else - User.includes(:contests).includes(:contest_stat).where(enabled: true) end #set up range from param diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -95,7 +95,7 @@ def submission_authorization #admin always has privileged return true if @current_user.admin? - return true if @current_user.has_role?('TA') && (['show','download'].include? action_name) + return true if @current_user.has_role?('ta') && (['show','download'].include? action_name) sub = Submission.find(params[:id]) if @current_user.available_problems.include? sub.problem 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,11 +1,15 @@ .container-fluid %h1 Current Score = form_tag current_score_report_path, method: 'get' do - Show only users from this group + .radio-inline + = radio_button_tag 'users', 'all', (params[:users] == 'all') + = label_tag(:users_all,'Show all users') + %br + .radio-inline + = radio_button_tag 'users', 'group', (params[:users] == 'group') + = label_tag(:users_group, 'Show only users from this group') = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em'; = submit_tag 'Apply',class: 'btn btn-default' %br - - = render "score_table" diff --git a/app/views/report/max_score.html.haml b/app/views/report/max_score.html.haml --- a/app/views/report/max_score.html.haml +++ b/app/views/report/max_score.html.haml @@ -39,6 +39,11 @@ %label = radio_button_tag 'users', 'enabled', (params[:users] == "enabled") Only enabled users + .radio + %label + = radio_button_tag 'users', 'group', (params[:users] == "group") + Only users from this group + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em'; .row .col-md-12 = button_tag 'Show', class: "btn btn-primary btn-large", value: "show" diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -89,7 +89,7 @@ t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id" end - create_table "groups_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "groups_users", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| t.integer "group_id", null: false t.integer "user_id", null: false t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" @@ -116,6 +116,7 @@ t.string "ip_address" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["user_id"], name: "index_logins_on_user_id" end create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| @@ -215,6 +216,7 @@ t.integer "peak_memory" t.integer "effective_code_length" t.string "ip_address" + t.index ["submitted_at"], name: "index_submissions_on_submitted_at" t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id" end diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -225,7 +225,7 @@ end def seed_roles - Role.find_or_create_by(name: 'TA') + Role.find_or_create_by(name: 'ta') return if Role.find_by_name('admin') role = Role.create(:name => 'admin')