Description:
fix direct edit link
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r641:2a2038aee8bd - - 1 file changed: 1 inserted, 1 deleted
@@ -1,96 +1,96 | |||||
|
1 | class SubmissionsController < ApplicationController |
|
1 | class SubmissionsController < ApplicationController |
|
2 | before_filter :authenticate |
|
2 | before_filter :authenticate |
|
3 | - before_filter :submission_authorization, only: [:show, :direct_edit_submission, :download] |
|
3 | + before_filter :submission_authorization, only: [:show, :direct_edit_submission, :download, :edit] |
|
4 |
|
4 | ||
|
5 | # GET /submissions |
|
5 | # GET /submissions |
|
6 | # GET /submissions.json |
|
6 | # GET /submissions.json |
|
7 | # Show problem selection and user's submission of that problem |
|
7 | # Show problem selection and user's submission of that problem |
|
8 | def index |
|
8 | def index |
|
9 | @user = @current_user |
|
9 | @user = @current_user |
|
10 | @problems = @user.available_problems |
|
10 | @problems = @user.available_problems |
|
11 |
|
11 | ||
|
12 | if params[:problem_id]==nil |
|
12 | if params[:problem_id]==nil |
|
13 | @problem = nil |
|
13 | @problem = nil |
|
14 | @submissions = nil |
|
14 | @submissions = nil |
|
15 | else |
|
15 | else |
|
16 | @problem = Problem.find_by_id(params[:problem_id]) |
|
16 | @problem = Problem.find_by_id(params[:problem_id]) |
|
17 | if (@problem == nil) or (not @problem.available) |
|
17 | if (@problem == nil) or (not @problem.available) |
|
18 | redirect_to main_list_path |
|
18 | redirect_to main_list_path |
|
19 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
19 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
20 | return |
|
20 | return |
|
21 | end |
|
21 | end |
|
22 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
22 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
23 | end |
|
23 | end |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | # GET /submissions/1 |
|
26 | # GET /submissions/1 |
|
27 | # GET /submissions/1.json |
|
27 | # GET /submissions/1.json |
|
28 | def show |
|
28 | def show |
|
29 | @submission = Submission.find(params[:id]) |
|
29 | @submission = Submission.find(params[:id]) |
|
30 |
|
30 | ||
|
31 | #log the viewing |
|
31 | #log the viewing |
|
32 | user = User.find(session[:user_id]) |
|
32 | user = User.find(session[:user_id]) |
|
33 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
33 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | def download |
|
36 | def download |
|
37 | @submission = Submission.find(params[:id]) |
|
37 | @submission = Submission.find(params[:id]) |
|
38 | send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'}) |
|
38 | send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'}) |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | def compiler_msg |
|
41 | def compiler_msg |
|
42 | @submission = Submission.find(params[:id]) |
|
42 | @submission = Submission.find(params[:id]) |
|
43 | respond_to do |format| |
|
43 | respond_to do |format| |
|
44 | format.js |
|
44 | format.js |
|
45 | end |
|
45 | end |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | #on-site new submission on specific problem |
|
48 | #on-site new submission on specific problem |
|
49 | def direct_edit_problem |
|
49 | def direct_edit_problem |
|
50 | @problem = Problem.find(params[:problem_id]) |
|
50 | @problem = Problem.find(params[:problem_id]) |
|
51 | @source = '' |
|
51 | @source = '' |
|
52 | render 'edit' |
|
52 | render 'edit' |
|
53 | end |
|
53 | end |
|
54 |
|
54 | ||
|
55 | # GET /submissions/1/edit |
|
55 | # GET /submissions/1/edit |
|
56 | def edit |
|
56 | def edit |
|
57 | @submission = Submission.find(params[:id]) |
|
57 | @submission = Submission.find(params[:id]) |
|
58 | @source = @submission.source.to_s |
|
58 | @source = @submission.source.to_s |
|
59 | @problem = @submission.problem |
|
59 | @problem = @submission.problem |
|
60 | @lang_id = @submission.language.id |
|
60 | @lang_id = @submission.language.id |
|
61 | end |
|
61 | end |
|
62 |
|
62 | ||
|
63 |
|
63 | ||
|
64 | def get_latest_submission_status |
|
64 | def get_latest_submission_status |
|
65 | @problem = Problem.find(params[:pid]) |
|
65 | @problem = Problem.find(params[:pid]) |
|
66 | @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) |
|
66 | @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) |
|
67 | puts User.find(params[:uid]).login |
|
67 | puts User.find(params[:uid]).login |
|
68 | puts Problem.find(params[:pid]).name |
|
68 | puts Problem.find(params[:pid]).name |
|
69 | puts 'nil' unless @submission |
|
69 | puts 'nil' unless @submission |
|
70 | respond_to do |format| |
|
70 | respond_to do |format| |
|
71 | format.js |
|
71 | format.js |
|
72 | end |
|
72 | end |
|
73 | end |
|
73 | end |
|
74 |
|
74 | ||
|
75 |
|
75 | ||
|
76 | protected |
|
76 | protected |
|
77 |
|
77 | ||
|
78 | def submission_authorization |
|
78 | def submission_authorization |
|
79 | #admin always has privileged |
|
79 | #admin always has privileged |
|
80 | if @current_user.admin? |
|
80 | if @current_user.admin? |
|
81 | return true |
|
81 | return true |
|
82 | end |
|
82 | end |
|
83 |
|
83 | ||
|
84 | sub = Submission.find(params[:id]) |
|
84 | sub = Submission.find(params[:id]) |
|
85 | if sub.problem.available? |
|
85 | if sub.problem.available? |
|
86 | puts "sub = #{sub.user.id}, current = #{@current_user.id}" |
|
86 | puts "sub = #{sub.user.id}, current = #{@current_user.id}" |
|
87 | return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
87 | return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
88 | end |
|
88 | end |
|
89 |
|
89 | ||
|
90 | #default to NO |
|
90 | #default to NO |
|
91 | unauthorized_redirect |
|
91 | unauthorized_redirect |
|
92 | return false |
|
92 | return false |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 |
|
95 | ||
|
96 | end |
|
96 | end |
You need to be logged in to leave comments.
Login now