Description:
add remove_all in groups consolidate submissions viewing from grader/task
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r680:4ce0b8696d06 - - 9 files changed: 35 inserted, 138 deleted

@@ -1,25 +1,9
1 class GradersController < ApplicationController
1 class GradersController < ApplicationController
2
2
3 - before_filter :admin_authorization, except: [ :submission ]
3 + before_filter :admin_authorization
4 - before_filter(only: [:submission]) {
5 - #check if authenticated
6 - return false unless authenticate
7 -
8 - #admin always has privileged
9 - if @current_user.admin?
10 - return true
11 - end
12 -
13 - if GraderConfiguration["right.user_view_submission"] and Submission.find(params[:id]).problem.available?
14 - return true
15 - else
16 - unauthorized_redirect
17 - return false
18 - end
19 - }
20
4
21 verify :method => :post, :only => ['clear_all',
5 verify :method => :post, :only => ['clear_all',
22 'start_exam',
6 'start_exam',
23 'start_grading',
7 'start_grading',
24 'stop_all',
8 'stop_all',
25 'clear_terminated'],
9 'clear_terminated'],
@@ -74,31 +58,12
74 end
58 end
75
59
76 def task
60 def task
77 @task = Task.find(params[:id])
61 @task = Task.find(params[:id])
78 end
62 end
79
63
80 - def submission
81 - @submission = Submission.find(params[:id])
82 - formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true )
83 - lexer = case @submission.language.name
84 - when "c" then Rouge::Lexers::C.new
85 - when "cpp" then Rouge::Lexers::Cpp.new
86 - when "pas" then Rouge::Lexers::Pas.new
87 - when "ruby" then Rouge::Lexers::Ruby.new
88 - when "python" then Rouge::Lexers::Python.new
89 - when "java" then Rouge::Lexers::Java.new
90 - when "php" then Rouge::Lexers::PHP.new
91 - end
92 - @formatted_code = formatter.format(lexer.lex(@submission.source))
93 - @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight')
94 -
95 - user = User.find(session[:user_id])
96 - SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin?
97 -
98 - end
99
64
100 # various grader controls
65 # various grader controls
101
66
102 def stop
67 def stop
103 grader_proc = GraderProcess.find(params[:id])
68 grader_proc = GraderProcess.find(params[:id])
104 GraderScript.stop_grader(grader_proc.pid)
69 GraderScript.stop_grader(grader_proc.pid)
@@ -1,10 +1,10
1 class GroupsController < ApplicationController
1 class GroupsController < ApplicationController
2 before_action :set_group, only: [:show, :edit, :update, :destroy,
2 before_action :set_group, only: [:show, :edit, :update, :destroy,
3 - :add_user, :remove_user,
3 + :add_user, :remove_user,:remove_all_user,
4 - :add_problem, :remove_problem,
4 + :add_problem, :remove_problem,:remove_all_problem,
5 ]
5 ]
6 before_action :authenticate, :admin_authorization
6 before_action :authenticate, :admin_authorization
7
7
8 # GET /groups
8 # GET /groups
9 def index
9 def index
10 @groups = Group.all
10 @groups = Group.all
@@ -52,12 +52,22
52 def remove_user
52 def remove_user
53 user = User.find(params[:user_id])
53 user = User.find(params[:user_id])
54 @group.users.delete(user)
54 @group.users.delete(user)
55 redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"}
55 redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"}
56 end
56 end
57
57
58 + def remove_all_user
59 + @group.users.clear
60 + redirect_to group_path(@group), alert: 'All users removed'
61 + end
62 +
63 + def remove_all_problem
64 + @group.problems.clear
65 + redirect_to group_path(@group), alert: 'All problems removed'
66 + end
67 +
58 def add_user
68 def add_user
59 user = User.find(params[:user_id])
69 user = User.find(params[:user_id])
60 begin
70 begin
61 @group.users << user
71 @group.users << user
62 redirect_to group_path(@group), flash: { success: "User #{user.login} was add to the group #{@group.name}"}
72 redirect_to group_path(@group), flash: { success: "User #{user.login} was add to the group #{@group.name}"}
63 rescue => e
73 rescue => e
@@ -23,13 +23,13
23 send_file_to_user(filename, base_filename)
23 send_file_to_user(filename, base_filename)
24 end
24 end
25
25
26 # this has problem-level access control
26 # this has problem-level access control
27 def download
27 def download
28 problem = Problem.find(params[:id])
28 problem = Problem.find(params[:id])
29 - if !problem or !problem.available or !@user.can_view_problem? problem
29 + unless @current_user.can_view_problem? problem
30 redirect_to :action => 'index' and return
30 redirect_to :action => 'index' and return
31 end
31 end
32
32
33 base_name = params[:file]
33 base_name = params[:file]
34 base_filename = File.basename("#{base_name}.#{params[:ext]}")
34 base_filename = File.basename("#{base_name}.#{params[:ext]}")
35 filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}"
35 filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}"
@@ -336,17 +336,14
336 else
336 else
337 return []
337 return []
338 end
338 end
339 end
339 end
340
340
341 def can_view_problem?(problem)
341 def can_view_problem?(problem)
342 - if not GraderConfiguration.multicontests?
342 + return true if admin?
343 - return problem.available
343 + return available_problems.include? problem
344 - else
345 - return problem_in_user_contests? problem
346 - end
347 end
344 end
348
345
349 def self.clear_last_login
346 def self.clear_last_login
350 User.update_all(:last_ip => nil)
347 User.update_all(:last_ip => nil)
351 end
348 end
352
349
@@ -6,10 +6,10
6 %br/
6 %br/
7 Status:
7 Status:
8 = "#{@task.status_str} (at #{format_short_time(@task.updated_at)})"
8 = "#{@task.status_str} (at #{format_short_time(@task.updated_at)})"
9 %br/
9 %br/
10 = "Submission: #{@task.submission_id}"
10 = "Submission: #{@task.submission_id}"
11 - if @task.submission !=nil
11 - if @task.submission !=nil
12 - = link_to '[view submission]', :action => 'submission', :id => @task.submission.id
12 + = link_to '[view submission]', submission_path( @task.submission.id )
13 %br/
13 %br/
14 = "Submitted at: #{format_short_time(@task.created_at)}"
14 = "Submitted at: #{format_short_time(@task.created_at)}"
15 %br/
15 %br/
@@ -8,13 +8,14
8 %br
8 %br
9 = link_to 'Edit', edit_group_path(@group)
9 = link_to 'Edit', edit_group_path(@group)
10 \|
10 \|
11 = link_to 'Back', groups_path
11 = link_to 'Back', groups_path
12
12
13 .row
13 .row
14 - %h1 Group details
14 + .col-md-12
15 + %h1 Group details
15 .row
16 .row
16 .col-md-6
17 .col-md-6
17 .panel.panel-default
18 .panel.panel-default
18 .panel-heading
19 .panel-heading
19 .panel-title Users in this group
20 .panel-title Users in this group
20 .panel-body
21 .panel-body
@@ -28,21 +29,21
28 %table.table.table-hover
29 %table.table.table-hover
29 %thead
30 %thead
30 %tr
31 %tr
31 %th Login
32 %th Login
32 %th Full name
33 %th Full name
33 %th Remark
34 %th Remark
34 - %th
35 + %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'
35
36
36 %tbody
37 %tbody
37 - @group.users.each do |user|
38 - @group.users.each do |user|
38 %tr
39 %tr
39 %td= user.login
40 %td= user.login
40 %td= user.full_name
41 %td= user.full_name
41 %td= user.remark
42 %td= user.remark
42 - %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger'
43 + %td= link_to 'Remove', remove_user_group_path(@group,user), :method => :delete, :data => { :confirm => "Remove #{user.full_name}?" }, class: 'btn btn-danger btn-sm'
43 .col-md-6
44 .col-md-6
44 .panel.panel-default
45 .panel.panel-default
45 .panel-heading
46 .panel-heading
46 .panel-title Problems
47 .panel-title Problems
47 .panel-body
48 .panel-body
48
49
@@ -56,17 +57,17
56 %table.table.table-hover
57 %table.table.table-hover
57 %thead
58 %thead
58 %tr
59 %tr
59 %th name
60 %th name
60 %th Full name
61 %th Full name
61 %th Full score
62 %th Full score
62 - %th
63 + %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'
63
64
64 %tbody
65 %tbody
65 - @group.problems.each do |problem|
66 - @group.problems.each do |problem|
66 %tr
67 %tr
67 %td= problem.name
68 %td= problem.name
68 %td= problem.full_name
69 %td= problem.full_name
69 %td= problem.full_score
70 %td= problem.full_score
70 - %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger'
71 + %td= link_to 'Remove', remove_problem_group_path(@group,problem), :method => :delete, :data => { :confirm => "Remove #{problem.full_name}?" }, class: 'btn btn-danger btn-sm'
71
72
72
73
@@ -18,12 +18,15
18 = submit_tag "Create"
18 = submit_tag "Create"
19 %table.table.table-condense.table-hover
19 %table.table.table-condense.table-hover
20 %thead
20 %thead
21 %th Name
21 %th Name
22 %th Full name
22 %th Full name
23 %th.text-right Full score
23 %th.text-right Full score
24 + %th
25 + Submit
26 + %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Admin can always submit to any problem' } [?]
24 %th Date added
27 %th Date added
25 %th.text-center
28 %th.text-center
26 Avail?
29 Avail?
27 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
30 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
28 %th.text-center
31 %th.text-center
29 View Data?
32 View Data?
@@ -34,14 +37,17
34 - if GraderConfiguration.multicontests?
37 - if GraderConfiguration.multicontests?
35 %th Contests
38 %th Contests
36 - for problem in @problems
39 - for problem in @problems
37 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
40 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
38 - @problem=problem
41 - @problem=problem
39 %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1
42 %td= problem.name #in_place_editor_field :problem, :name, {}, :rows=>1
40 - %td= problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1
43 + %td
44 + = problem.full_name #in_place_editor_field :problem, :full_name, {}, :rows=>1
45 + = link_to_description_if_any "[#{t 'main.problem_desc'}] <span class='glyphicon glyphicon-file'></span>".html_safe, problem
41 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
46 %td.text-right= problem.full_score #in_place_editor_field :problem, :full_score, {}, :rows=>1
47 + %td= link_to "Submit", direct_edit_problem_submissions_path(problem), class: 'btn btn-xs btn-primary'
42 %td= problem.date_added
48 %td= problem.date_added
43 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
49 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
44 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
50 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
45 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
51 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
46 - if GraderConfiguration.multicontests?
52 - if GraderConfiguration.multicontests?
47 %td
53 %td
@@ -32,14 +32,19
32 end
32 end
33
33
34 resources :groups do
34 resources :groups do
35 member do
35 member do
36 post 'add_user', to: 'groups#add_user', as: 'add_user'
36 post 'add_user', to: 'groups#add_user', as: 'add_user'
37 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
37 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
38 + delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
38 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
39 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
39 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
40 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
41 + delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
42 + end
43 + collection do
44 +
40 end
45 end
41 end
46 end
42
47
43 resources :testcases, only: [] do
48 resources :testcases, only: [] do
44 member do
49 member do
45 get 'download_input'
50 get 'download_input'
deleted file
You need to be logged in to leave comments. Login now