Description:
fixed submission view bug, reported by chalet
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@292 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r153:15e1ee6d602b - - 1 file changed: 5 inserted, 0 deleted
@@ -78,96 +78,101 | |||||
|
78 | if @submission.save == false |
|
78 | if @submission.save == false |
|
79 | flash[:notice] = 'Error saving your submission' |
|
79 | flash[:notice] = 'Error saving your submission' |
|
80 | elsif Task.create(:submission_id => @submission.id, |
|
80 | elsif Task.create(:submission_id => @submission.id, |
|
81 | :status => Task::STATUS_INQUEUE) == false |
|
81 | :status => Task::STATUS_INQUEUE) == false |
|
82 | flash[:notice] = 'Error adding your submission to task queue' |
|
82 | flash[:notice] = 'Error adding your submission to task queue' |
|
83 | end |
|
83 | end |
|
84 | else |
|
84 | else |
|
85 | prepare_list_information |
|
85 | prepare_list_information |
|
86 | render :action => 'list' and return |
|
86 | render :action => 'list' and return |
|
87 | end |
|
87 | end |
|
88 | redirect_to :action => 'list' |
|
88 | redirect_to :action => 'list' |
|
89 | end |
|
89 | end |
|
90 |
|
90 | ||
|
91 | def source |
|
91 | def source |
|
92 | submission = Submission.find(params[:id]) |
|
92 | submission = Submission.find(params[:id]) |
|
93 | if submission.user_id == session[:user_id] |
|
93 | if submission.user_id == session[:user_id] |
|
94 | if submission.problem.output_only |
|
94 | if submission.problem.output_only |
|
95 | fname = submission.source_filename |
|
95 | fname = submission.source_filename |
|
96 | else |
|
96 | else |
|
97 | fname = submission.problem.name + '.' + submission.language.ext |
|
97 | fname = submission.problem.name + '.' + submission.language.ext |
|
98 | end |
|
98 | end |
|
99 | send_data(submission.source, |
|
99 | send_data(submission.source, |
|
100 | {:filename => fname, |
|
100 | {:filename => fname, |
|
101 | :type => 'text/plain'}) |
|
101 | :type => 'text/plain'}) |
|
102 | else |
|
102 | else |
|
103 | flash[:notice] = 'Error viewing source' |
|
103 | flash[:notice] = 'Error viewing source' |
|
104 | redirect_to :action => 'list' |
|
104 | redirect_to :action => 'list' |
|
105 | end |
|
105 | end |
|
106 | end |
|
106 | end |
|
107 |
|
107 | ||
|
108 | def compiler_msg |
|
108 | def compiler_msg |
|
109 | @submission = Submission.find(params[:id]) |
|
109 | @submission = Submission.find(params[:id]) |
|
110 | if @submission.user_id == session[:user_id] |
|
110 | if @submission.user_id == session[:user_id] |
|
111 | render :action => 'compiler_msg', :layout => 'empty' |
|
111 | render :action => 'compiler_msg', :layout => 'empty' |
|
112 | else |
|
112 | else |
|
113 | flash[:notice] = 'Error viewing source' |
|
113 | flash[:notice] = 'Error viewing source' |
|
114 | redirect_to :action => 'list' |
|
114 | redirect_to :action => 'list' |
|
115 | end |
|
115 | end |
|
116 | end |
|
116 | end |
|
117 |
|
117 | ||
|
118 | def submission |
|
118 | def submission |
|
119 | @user = User.find(session[:user_id]) |
|
119 | @user = User.find(session[:user_id]) |
|
120 | @problems = Problem.find_available_problems |
|
120 | @problems = Problem.find_available_problems |
|
121 | if params[:id]==nil |
|
121 | if params[:id]==nil |
|
122 | @problem = nil |
|
122 | @problem = nil |
|
123 | @submissions = nil |
|
123 | @submissions = nil |
|
124 | else |
|
124 | else |
|
125 | @problem = Problem.find_by_name(params[:id]) |
|
125 | @problem = Problem.find_by_name(params[:id]) |
|
|
126 | + if not @problem.available | ||
|
|
127 | + redirect_to :action => 'list' | ||
|
|
128 | + flash[:notice] = 'Error: submissions for that problem is not available' | ||
|
|
129 | + return | ||
|
|
130 | + end | ||
|
126 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
131 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
127 | end |
|
132 | end |
|
128 | end |
|
133 | end |
|
129 |
|
134 | ||
|
130 | def result |
|
135 | def result |
|
131 | if !Configuration.show_grading_result |
|
136 | if !Configuration.show_grading_result |
|
132 | redirect_to :action => 'list' and return |
|
137 | redirect_to :action => 'list' and return |
|
133 | end |
|
138 | end |
|
134 | @user = User.find(session[:user_id]) |
|
139 | @user = User.find(session[:user_id]) |
|
135 | @submission = Submission.find(params[:id]) |
|
140 | @submission = Submission.find(params[:id]) |
|
136 | if @submission.user!=@user |
|
141 | if @submission.user!=@user |
|
137 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
142 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
138 | redirect_to :action => 'list' and return |
|
143 | redirect_to :action => 'list' and return |
|
139 | end |
|
144 | end |
|
140 | prepare_grading_result(@submission) |
|
145 | prepare_grading_result(@submission) |
|
141 | end |
|
146 | end |
|
142 |
|
147 | ||
|
143 | def load_output |
|
148 | def load_output |
|
144 | if !Configuration.show_grading_result or params[:num]==nil |
|
149 | if !Configuration.show_grading_result or params[:num]==nil |
|
145 | redirect_to :action => 'list' and return |
|
150 | redirect_to :action => 'list' and return |
|
146 | end |
|
151 | end |
|
147 | @user = User.find(session[:user_id]) |
|
152 | @user = User.find(session[:user_id]) |
|
148 | @submission = Submission.find(params[:id]) |
|
153 | @submission = Submission.find(params[:id]) |
|
149 | if @submission.user!=@user |
|
154 | if @submission.user!=@user |
|
150 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
155 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
151 | redirect_to :action => 'list' and return |
|
156 | redirect_to :action => 'list' and return |
|
152 | end |
|
157 | end |
|
153 | case_num = params[:num].to_i |
|
158 | case_num = params[:num].to_i |
|
154 | out_filename = output_filename(@user.login, |
|
159 | out_filename = output_filename(@user.login, |
|
155 | @submission.problem.name, |
|
160 | @submission.problem.name, |
|
156 | @submission.id, |
|
161 | @submission.id, |
|
157 | case_num) |
|
162 | case_num) |
|
158 | if !FileTest.exists?(out_filename) |
|
163 | if !FileTest.exists?(out_filename) |
|
159 | flash[:notice] = 'Output not found.' |
|
164 | flash[:notice] = 'Output not found.' |
|
160 | redirect_to :action => 'list' and return |
|
165 | redirect_to :action => 'list' and return |
|
161 | end |
|
166 | end |
|
162 |
|
167 | ||
|
163 | response.headers['Content-Type'] = "application/force-download" |
|
168 | response.headers['Content-Type'] = "application/force-download" |
|
164 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
169 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
165 | response.headers["X-Sendfile"] = out_filename |
|
170 | response.headers["X-Sendfile"] = out_filename |
|
166 | response.headers['Content-length'] = File.size(out_filename) |
|
171 | response.headers['Content-length'] = File.size(out_filename) |
|
167 | render :nothing => true |
|
172 | render :nothing => true |
|
168 | end |
|
173 | end |
|
169 |
|
174 | ||
|
170 | def error |
|
175 | def error |
|
171 | @user = User.find(session[:user_id]) |
|
176 | @user = User.find(session[:user_id]) |
|
172 | end |
|
177 | end |
|
173 |
|
178 |
You need to be logged in to leave comments.
Login now