diff --git a/app/controllers/graders_controller.rb b/app/controllers/graders_controller.rb --- a/app/controllers/graders_controller.rb +++ b/app/controllers/graders_controller.rb @@ -1,22 +1,6 @@ class GradersController < ApplicationController - before_filter :admin_authorization, except: [ :submission ] - before_filter(only: [:submission]) { - #check if authenticated - return false unless authenticate - - #admin always has privileged - if @current_user.admin? - return true - end - - if GraderConfiguration["right.user_view_submission"] and Submission.find(params[:id]).problem.available? - return true - else - unauthorized_redirect - return false - end - } + before_filter :admin_authorization verify :method => :post, :only => ['clear_all', 'start_exam', @@ -77,25 +61,6 @@ @task = Task.find(params[:id]) end - def submission - @submission = Submission.find(params[:id]) - formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true ) - lexer = case @submission.language.name - when "c" then Rouge::Lexers::C.new - when "cpp" then Rouge::Lexers::Cpp.new - when "pas" then Rouge::Lexers::Pas.new - when "ruby" then Rouge::Lexers::Ruby.new - when "python" then Rouge::Lexers::Python.new - when "java" then Rouge::Lexers::Java.new - when "php" then Rouge::Lexers::PHP.new - end - @formatted_code = formatter.format(lexer.lex(@submission.source)) - @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight') - - user = User.find(session[:user_id]) - SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? - - end # various grader controls diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -1,7 +1,7 @@ class GroupsController < ApplicationController before_action :set_group, only: [:show, :edit, :update, :destroy, - :add_user, :remove_user, - :add_problem, :remove_problem, + :add_user, :remove_user,:remove_all_user, + :add_problem, :remove_problem,:remove_all_problem, ] before_action :authenticate, :admin_authorization @@ -55,6 +55,16 @@ redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"} end + def remove_all_user + @group.users.clear + redirect_to group_path(@group), alert: 'All users removed' + end + + def remove_all_problem + @group.problems.clear + redirect_to group_path(@group), alert: 'All problems removed' + end + def add_user user = User.find(params[:user_id]) begin 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 @@ -26,7 +26,7 @@ # this has problem-level access control def download problem = Problem.find(params[:id]) - if !problem or !problem.available or !@user.can_view_problem? problem + unless @current_user.can_view_problem? problem redirect_to :action => 'index' and return end diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -339,11 +339,8 @@ end def can_view_problem?(problem) - if not GraderConfiguration.multicontests? - return problem.available - else - return problem_in_user_contests? problem - end + return true if admin? + return available_problems.include? problem end def self.clear_last_login diff --git a/app/views/graders/submission.html.haml b/app/views/graders/submission.html.haml deleted file mode 100644 --- a/app/views/graders/submission.html.haml +++ /dev/null @@ -1,87 +0,0 @@ -%h1= "Submission: #{@submission.id}" - -%textarea#data{style: "display:none;"} - :preserve - #{@submission.source} - -//%div.highlight{:style => "border: 1px solid black;"} -//=@formatted_code.html_safe -.containter - .row - .col-md-7 - %h2 Source Code - .col-md-5 - %h2 Stat - .row - .col-md-7 - %div#editor{ style: "font-size: 14px; height: 400px; border-radius:5px;" } - :javascript - e = ace.edit("editor") - e.setOptions({ maxLines: Infinity }) - e.setValue($("#data").text()) - e.gotoLine(1) - e.getSession().setMode("#{get_ace_mode(@submission.language)}") - e.setReadOnly(true) - .col-md-5 - %table.table.table-striped - %tr - %td.text-right - %strong User - %td - - if @submission.user - = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user - = @submission.user.full_name - - else - = "(n/a)" - %tr - %td.text-right - %strong Task - %td - - if @submission.problem!=nil - = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem - = @submission.problem.full_name - - else - = "(n/a)" - %tr - %td.text-right - %strong Tries - %td= @submission.number - %tr - %td.text-right - %strong Language - %td= @submission.language.pretty_name - %tr - %td.text-right - %strong Submitted - %td #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)}) - %tr - %td.text-right - %strong Graded - - if @submission.graded_at - %td #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)}) - - else - %td - - %tr - %td.text-right - %strong Points - %td #{@submission.points}/#{@submission.problem.full_score} - %tr - %td.text-right - %strong Comment - %td #{@submission.grader_comment} - %tr - %td.text-right - %strong Runtime (s) - %td #{@submission.max_runtime} - %tr - %td.text-right - %strong Memory (kb) - %td #{@submission.peak_memory} - - if session[:admin] - %tr - %td.text-right - %strong IP - %td #{@submission.ip_address} - - - diff --git a/app/views/graders/task.html.haml b/app/views/graders/task.html.haml --- a/app/views/graders/task.html.haml +++ b/app/views/graders/task.html.haml @@ -9,7 +9,7 @@ %br/ = "Submission: #{@task.submission_id}" - if @task.submission !=nil - = link_to '[view submission]', :action => 'submission', :id => @task.submission.id + = link_to '[view submission]', submission_path( @task.submission.id ) %br/ = "Submitted at: #{format_short_time(@task.created_at)}" %br/ 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 @@ -11,7 +11,8 @@ = link_to 'Back', groups_path .row - %h1 Group details + .col-md-12 + %h1 Group details .row .col-md-6 .panel.panel-default @@ -31,7 +32,7 @@ %th Login %th Full name %th Remark - %th + %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| @@ -39,7 +40,7 @@ %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' + %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 @@ -59,7 +60,7 @@ %th name %th Full name %th Full score - %th + %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| @@ -67,6 +68,6 @@ %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' + %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/problems/index.html.haml b/app/views/problems/index.html.haml --- a/app/views/problems/index.html.haml +++ b/app/views/problems/index.html.haml @@ -21,6 +21,9 @@ %th Name %th Full name %th.text-right Full score + %th + Submit + %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Admin can always submit to any problem' } [?] %th Date added %th.text-center Avail? @@ -37,8 +40,11 @@ %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"} - @problem=problem %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1 - %td= problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 + %td + = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1 + = link_to_description_if_any "[#{t 'main.problem_desc'}] ".html_safe, problem %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1 + %td= link_to "Submit", direct_edit_problem_submissions_path(problem), class: 'btn btn-xs btn-primary' %td= problem.date_added %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}") %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}") diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -35,8 +35,13 @@ member do post 'add_user', to: 'groups#add_user', as: 'add_user' delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user' + delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user' post 'add_problem', to: 'groups#add_problem', as: 'add_problem' delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' + delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' + end + collection do + end end