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,31 +1,15
1 1 class GradersController < ApplicationController
2 2
3 - before_filter :admin_authorization, except: [ :submission ]
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 - }
3 + before_filter :admin_authorization
20 4
21 5 verify :method => :post, :only => ['clear_all',
22 6 'start_exam',
23 7 'start_grading',
24 8 'stop_all',
25 9 'clear_terminated'],
26 10 :redirect_to => {:action => 'index'}
27 11
28 12 def index
29 13 redirect_to :action => 'list'
30 14 end
31 15
@@ -68,43 +52,24
68 52 redirect_to :action => 'test_request', :id => params[:id]
69 53 end
70 54 end
71 55
72 56 def test_request
73 57 @test_request = TestRequest.find(params[:id])
74 58 end
75 59
76 60 def task
77 61 @task = Task.find(params[:id])
78 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 65 # various grader controls
101 66
102 67 def stop
103 68 grader_proc = GraderProcess.find(params[:id])
104 69 GraderScript.stop_grader(grader_proc.pid)
105 70 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
106 71 redirect_to :action => 'list'
107 72 end
108 73
109 74 def stop_all
110 75 GraderScript.stop_graders(GraderProcess.find_running_graders +
@@ -1,16 +1,16
1 1 class GroupsController < ApplicationController
2 2 before_action :set_group, only: [:show, :edit, :update, :destroy,
3 - :add_user, :remove_user,
4 - :add_problem, :remove_problem,
3 + :add_user, :remove_user,:remove_all_user,
4 + :add_problem, :remove_problem,:remove_all_problem,
5 5 ]
6 6 before_action :authenticate, :admin_authorization
7 7
8 8 # GET /groups
9 9 def index
10 10 @groups = Group.all
11 11 end
12 12
13 13 # GET /groups/1
14 14 def show
15 15 end
16 16
@@ -46,24 +46,34
46 46 # DELETE /groups/1
47 47 def destroy
48 48 @group.destroy
49 49 redirect_to groups_url, notice: 'Group was successfully destroyed.'
50 50 end
51 51
52 52 def remove_user
53 53 user = User.find(params[:user_id])
54 54 @group.users.delete(user)
55 55 redirect_to group_path(@group), flash: {success: "User #{user.login} was removed from the group #{@group.name}"}
56 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 68 def add_user
59 69 user = User.find(params[:user_id])
60 70 begin
61 71 @group.users << user
62 72 redirect_to group_path(@group), flash: { success: "User #{user.login} was add to the group #{@group.name}"}
63 73 rescue => e
64 74 redirect_to group_path(@group), alert: e.message
65 75 end
66 76 end
67 77
68 78 def remove_problem
69 79 problem = Problem.find(params[:problem_id])
@@ -17,25 +17,25
17 17 filename = "#{Problem.download_file_basedir}/#{base_filename}"
18 18
19 19 if !FileTest.exists?(filename)
20 20 redirect_to :action => 'index' and return
21 21 end
22 22
23 23 send_file_to_user(filename, base_filename)
24 24 end
25 25
26 26 # this has problem-level access control
27 27 def download
28 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 30 redirect_to :action => 'index' and return
31 31 end
32 32
33 33 base_name = params[:file]
34 34 base_filename = File.basename("#{base_name}.#{params[:ext]}")
35 35 filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}"
36 36 puts "SENDING: #{filename}"
37 37
38 38 if !FileTest.exists?(filename)
39 39 redirect_to :action => 'index' and return
40 40 end
41 41
@@ -330,29 +330,26
330 330 -1
331 331 else
332 332 a.name <=> b.name
333 333 end
334 334 end
335 335 return problem
336 336 else
337 337 return []
338 338 end
339 339 end
340 340
341 341 def can_view_problem?(problem)
342 - if not GraderConfiguration.multicontests?
343 - return problem.available
344 - else
345 - return problem_in_user_contests? problem
346 - end
342 + return true if admin?
343 + return available_problems.include? problem
347 344 end
348 345
349 346 def self.clear_last_login
350 347 User.update_all(:last_ip => nil)
351 348 end
352 349
353 350 protected
354 351 def encrypt_new_password
355 352 return if password.blank?
356 353 self.salt = (10+rand(90)).to_s
357 354 self.hashed_password = User.encrypt(self.password,self.salt)
358 355 end
@@ -1,15 +1,15
1 1 %h1= "Task: #{@task.id}"
2 2
3 3 %p
4 4 User:
5 5 = "#{@task.submission.user.login}"
6 6 %br/
7 7 Status:
8 8 = "#{@task.status_str} (at #{format_short_time(@task.updated_at)})"
9 9 %br/
10 10 = "Submission: #{@task.submission_id}"
11 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 13 %br/
14 14 = "Submitted at: #{format_short_time(@task.created_at)}"
15 15 %br/
@@ -2,71 +2,72
2 2 %b Name:
3 3 = @group.name
4 4 %p
5 5 %b Description:
6 6 = @group.description
7 7
8 8 %br
9 9 = link_to 'Edit', edit_group_path(@group)
10 10 \|
11 11 = link_to 'Back', groups_path
12 12
13 13 .row
14 - %h1 Group details
14 + .col-md-12
15 + %h1 Group details
15 16 .row
16 17 .col-md-6
17 18 .panel.panel-default
18 19 .panel-heading
19 20 .panel-title Users in this group
20 21 .panel-body
21 22 =form_tag add_user_group_path(@group), class: 'form-inline' do
22 23 .form-group
23 24 =label_tag :user_id, "User"
24 25 =select_tag :user_id, options_from_collection_for_select(User.all,'id','full_name'), class: 'select2'
25 26 =submit_tag "Add",class: 'btn btn-primary'
26 27
27 28
28 29 %table.table.table-hover
29 30 %thead
30 31 %tr
31 32 %th Login
32 33 %th Full name
33 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 37 %tbody
37 38 - @group.users.each do |user|
38 39 %tr
39 40 %td= user.login
40 41 %td= user.full_name
41 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 44 .col-md-6
44 45 .panel.panel-default
45 46 .panel-heading
46 47 .panel-title Problems
47 48 .panel-body
48 49
49 50 =form_tag add_problem_group_path(@group), class: 'form-inline' do
50 51 .form-group
51 52 =label_tag :problem_id, "Problem"
52 53 =select_tag :problem_id, options_from_collection_for_select(Problem.all,'id','full_name'), class: 'select2'
53 54 =submit_tag "Add",class: 'btn btn-primary'
54 55
55 56
56 57 %table.table.table-hover
57 58 %thead
58 59 %tr
59 60 %th name
60 61 %th Full name
61 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 65 %tbody
65 66 - @group.problems.each do |problem|
66 67 %tr
67 68 %td= problem.name
68 69 %td= problem.full_name
69 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
@@ -12,42 +12,48
12 12 %b Quick New:
13 13 %label{:for => "problem_name"} Name
14 14 = text_field 'problem', 'name'
15 15 |
16 16 %label{:for => "problem_full_name"} Full name
17 17 = text_field 'problem', 'full_name'
18 18 = submit_tag "Create"
19 19 %table.table.table-condense.table-hover
20 20 %thead
21 21 %th Name
22 22 %th Full name
23 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 27 %th Date added
25 28 %th.text-center
26 29 Avail?
27 30 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user submits to this problem?' } [?]
28 31 %th.text-center
29 32 View Data?
30 33 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user view the testcase of this problem?' } [?]
31 34 %th.text-center
32 35 Test?
33 36 %sup{class: 'text-primary',data: {toggle: 'tooltip'}, title: 'Let user uses test interface on this problem?' } [?]
34 37 - if GraderConfiguration.multicontests?
35 38 %th Contests
36 39 - for problem in @problems
37 40 %tr{:class => "#{(problem.available) ? "success" : "danger"}", :id => "prob-#{problem.id}", :name => "prob-#{problem.id}"}
38 41 - @problem=problem
39 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 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 48 %td= problem.date_added
43 49 %td= toggle_button(@problem.available?, toggle_problem_path(@problem), "problem-avail-#{@problem.id}")
44 50 %td= toggle_button(@problem.view_testcase?, toggle_view_testcase_problem_path(@problem), "problem-view-testcase-#{@problem.id}")
45 51 %td= toggle_button(@problem.test_allowed?, toggle_test_problem_path(@problem), "problem-test-#{@problem.id}")
46 52 - if GraderConfiguration.multicontests?
47 53 %td
48 54 = problem.contests.collect { |c| c.name }.join(', ')
49 55 %td= link_to 'Stat', {:action => 'stat', :id => problem.id}, class: 'btn btn-info btn-xs btn-block'
50 56 %td= link_to 'Show', {:action => 'show', :id => problem}, class: 'btn btn-info btn-xs btn-block'
51 57 %td= link_to 'Edit', {:action => 'edit', :id => problem}, class: 'btn btn-info btn-xs btn-block'
52 58 %td= link_to 'Destroy', { :action => 'destroy', :id => problem }, :confirm => 'Are you sure?', :method => :delete, class: 'btn btn-danger btn-xs btn-block'
53 59 %br/
@@ -26,26 +26,31
26 26 collection do
27 27 get 'turn_all_off'
28 28 get 'turn_all_on'
29 29 get 'import'
30 30 get 'manage'
31 31 end
32 32 end
33 33
34 34 resources :groups do
35 35 member do
36 36 post 'add_user', to: 'groups#add_user', as: 'add_user'
37 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 39 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
39 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 45 end
41 46 end
42 47
43 48 resources :testcases, only: [] do
44 49 member do
45 50 get 'download_input'
46 51 get 'download_sol'
47 52 end
48 53 collection do
49 54 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
50 55 end
51 56 end
deleted file
You need to be logged in to leave comments. Login now