Description:
disabled unused actions from controllers, protected statuses display, more styling
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r241:ce50017c6bce - - 5 files changed: 12 inserted, 2 deleted
@@ -1,294 +1,297 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
3 | before_filter :authenticate, :except => [:index, :login] |
|
4 | before_filter :check_viewability, :except => [:index, :login] |
|
4 | before_filter :check_viewability, :except => [:index, :login] |
|
5 |
|
5 | ||
|
6 | # COMMENTED OUT: filter in each action instead |
|
6 | # COMMENTED OUT: filter in each action instead |
|
7 | # before_filter :verify_time_limit, :only => [:submit] |
|
7 | # before_filter :verify_time_limit, :only => [:submit] |
|
8 |
|
8 | ||
|
9 | verify :method => :post, :only => [:submit, :download_input, :submit_solution], |
|
9 | verify :method => :post, :only => [:submit, :download_input, :submit_solution], |
|
10 | :redirect_to => { :action => :index } |
|
10 | :redirect_to => { :action => :index } |
|
11 |
|
11 | ||
|
12 | # COMMENT OUT: only need when having high load |
|
12 | # COMMENT OUT: only need when having high load |
|
13 | # caches_action :index, :login |
|
13 | # caches_action :index, :login |
|
14 |
|
14 | ||
|
15 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
15 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
16 | # assigned action login as a default action. |
|
16 | # assigned action login as a default action. |
|
17 | def index |
|
17 | def index |
|
18 | redirect_to :action => 'login' |
|
18 | redirect_to :action => 'login' |
|
19 | end |
|
19 | end |
|
20 |
|
20 | ||
|
21 | def login |
|
21 | def login |
|
22 | saved_notice = flash[:notice] |
|
22 | saved_notice = flash[:notice] |
|
23 | reset_session |
|
23 | reset_session |
|
24 | flash.now[:notice] = saved_notice |
|
24 | flash.now[:notice] = saved_notice |
|
25 |
|
25 | ||
|
26 | # EXPERIMENT: |
|
26 | # EXPERIMENT: |
|
27 | # Hide login if in single user mode and the url does not |
|
27 | # Hide login if in single user mode and the url does not |
|
28 | # explicitly specify /login |
|
28 | # explicitly specify /login |
|
29 | # |
|
29 | # |
|
30 | # logger.info "PATH: #{request.path}" |
|
30 | # logger.info "PATH: #{request.path}" |
|
31 | # if Configuration['system.single_user_mode'] and |
|
31 | # if Configuration['system.single_user_mode'] and |
|
32 | # request.path!='/main/login' |
|
32 | # request.path!='/main/login' |
|
33 | # @hidelogin = true |
|
33 | # @hidelogin = true |
|
34 | # end |
|
34 | # end |
|
35 |
|
35 | ||
|
36 | @announcements = Announcement.find_for_frontpage |
|
36 | @announcements = Announcement.find_for_frontpage |
|
37 | render :action => 'login', :layout => 'empty' |
|
37 | render :action => 'login', :layout => 'empty' |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | def list |
|
40 | def list |
|
41 | prepare_list_information |
|
41 | prepare_list_information |
|
42 | end |
|
42 | end |
|
43 |
|
43 | ||
|
44 | def help |
|
44 | def help |
|
45 | @user = User.find(session[:user_id]) |
|
45 | @user = User.find(session[:user_id]) |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | def submit |
|
48 | def submit |
|
49 | user = User.find(session[:user_id]) |
|
49 | user = User.find(session[:user_id]) |
|
50 |
|
50 | ||
|
51 | @submission = Submission.new(params[:submission]) |
|
51 | @submission = Submission.new(params[:submission]) |
|
52 | @submission.user = user |
|
52 | @submission.user = user |
|
53 | @submission.language_id = 0 |
|
53 | @submission.language_id = 0 |
|
54 | if (params['file']) and (params['file']!='') |
|
54 | if (params['file']) and (params['file']!='') |
|
55 | @submission.source = params['file'].read |
|
55 | @submission.source = params['file'].read |
|
56 | @submission.source_filename = params['file'].original_filename |
|
56 | @submission.source_filename = params['file'].original_filename |
|
57 | end |
|
57 | end |
|
58 | @submission.submitted_at = Time.new.gmtime |
|
58 | @submission.submitted_at = Time.new.gmtime |
|
59 |
|
59 | ||
|
60 | if Configuration.time_limit_mode? and user.contest_finished? |
|
60 | if Configuration.time_limit_mode? and user.contest_finished? |
|
61 | @submission.errors.add_to_base "The contest is over." |
|
61 | @submission.errors.add_to_base "The contest is over." |
|
62 | prepare_list_information |
|
62 | prepare_list_information |
|
63 | render :action => 'list' and return |
|
63 | render :action => 'list' and return |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | if @submission.valid? |
|
66 | if @submission.valid? |
|
67 | if @submission.save == false |
|
67 | if @submission.save == false |
|
68 | flash[:notice] = 'Error saving your submission' |
|
68 | flash[:notice] = 'Error saving your submission' |
|
69 | elsif Task.create(:submission_id => @submission.id, |
|
69 | elsif Task.create(:submission_id => @submission.id, |
|
70 | :status => Task::STATUS_INQUEUE) == false |
|
70 | :status => Task::STATUS_INQUEUE) == false |
|
71 | flash[:notice] = 'Error adding your submission to task queue' |
|
71 | flash[:notice] = 'Error adding your submission to task queue' |
|
72 | end |
|
72 | end |
|
73 | else |
|
73 | else |
|
74 | prepare_list_information |
|
74 | prepare_list_information |
|
75 | render :action => 'list' and return |
|
75 | render :action => 'list' and return |
|
76 | end |
|
76 | end |
|
77 | redirect_to :action => 'list' |
|
77 | redirect_to :action => 'list' |
|
78 | end |
|
78 | end |
|
79 |
|
79 | ||
|
80 | def source |
|
80 | def source |
|
81 | submission = Submission.find(params[:id]) |
|
81 | submission = Submission.find(params[:id]) |
|
82 | if submission.user_id == session[:user_id] |
|
82 | if submission.user_id == session[:user_id] |
|
83 | send_data(submission.source, |
|
83 | send_data(submission.source, |
|
84 | {:filename => submission.download_filename, |
|
84 | {:filename => submission.download_filename, |
|
85 | :type => 'text/plain'}) |
|
85 | :type => 'text/plain'}) |
|
86 | else |
|
86 | else |
|
87 | flash[:notice] = 'Error viewing source' |
|
87 | flash[:notice] = 'Error viewing source' |
|
88 | redirect_to :action => 'list' |
|
88 | redirect_to :action => 'list' |
|
89 | end |
|
89 | end |
|
90 | end |
|
90 | end |
|
91 |
|
91 | ||
|
92 | def compiler_msg |
|
92 | def compiler_msg |
|
93 | @submission = Submission.find(params[:id]) |
|
93 | @submission = Submission.find(params[:id]) |
|
94 | if @submission.user_id == session[:user_id] |
|
94 | if @submission.user_id == session[:user_id] |
|
95 | render :action => 'compiler_msg', :layout => 'empty' |
|
95 | render :action => 'compiler_msg', :layout => 'empty' |
|
96 | else |
|
96 | else |
|
97 | flash[:notice] = 'Error viewing source' |
|
97 | flash[:notice] = 'Error viewing source' |
|
98 | redirect_to :action => 'list' |
|
98 | redirect_to :action => 'list' |
|
99 | end |
|
99 | end |
|
100 | end |
|
100 | end |
|
101 |
|
101 | ||
|
102 | def submission |
|
102 | def submission |
|
|
103 | + # protect the action for Code Jom | ||
|
|
104 | + redirect_to :action => 'list' | ||
|
|
105 | + | ||
|
103 | @user = User.find(session[:user_id]) |
|
106 | @user = User.find(session[:user_id]) |
|
104 | @problems = Problem.find_available_problems |
|
107 | @problems = Problem.find_available_problems |
|
105 | if params[:id]==nil |
|
108 | if params[:id]==nil |
|
106 | @problem = nil |
|
109 | @problem = nil |
|
107 | @submissions = nil |
|
110 | @submissions = nil |
|
108 | else |
|
111 | else |
|
109 | @problem = Problem.find_by_name(params[:id]) |
|
112 | @problem = Problem.find_by_name(params[:id]) |
|
110 | if not @problem.available |
|
113 | if not @problem.available |
|
111 | redirect_to :action => 'list' |
|
114 | redirect_to :action => 'list' |
|
112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
115 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
113 | return |
|
116 | return |
|
114 | end |
|
117 | end |
|
115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
118 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
116 | end |
|
119 | end |
|
117 | end |
|
120 | end |
|
118 |
|
121 | ||
|
119 | def result |
|
122 | def result |
|
120 | if !Configuration.show_grading_result |
|
123 | if !Configuration.show_grading_result |
|
121 | redirect_to :action => 'list' and return |
|
124 | redirect_to :action => 'list' and return |
|
122 | end |
|
125 | end |
|
123 | @user = User.find(session[:user_id]) |
|
126 | @user = User.find(session[:user_id]) |
|
124 | @submission = Submission.find(params[:id]) |
|
127 | @submission = Submission.find(params[:id]) |
|
125 | if @submission.user!=@user |
|
128 | if @submission.user!=@user |
|
126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
129 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
127 | redirect_to :action => 'list' and return |
|
130 | redirect_to :action => 'list' and return |
|
128 | end |
|
131 | end |
|
129 | prepare_grading_result(@submission) |
|
132 | prepare_grading_result(@submission) |
|
130 | end |
|
133 | end |
|
131 |
|
134 | ||
|
132 | def load_output |
|
135 | def load_output |
|
133 | if !Configuration.show_grading_result or params[:num]==nil |
|
136 | if !Configuration.show_grading_result or params[:num]==nil |
|
134 | redirect_to :action => 'list' and return |
|
137 | redirect_to :action => 'list' and return |
|
135 | end |
|
138 | end |
|
136 | @user = User.find(session[:user_id]) |
|
139 | @user = User.find(session[:user_id]) |
|
137 | @submission = Submission.find(params[:id]) |
|
140 | @submission = Submission.find(params[:id]) |
|
138 | if @submission.user!=@user |
|
141 | if @submission.user!=@user |
|
139 | 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.' |
|
140 | redirect_to :action => 'list' and return |
|
143 | redirect_to :action => 'list' and return |
|
141 | end |
|
144 | end |
|
142 | case_num = params[:num].to_i |
|
145 | case_num = params[:num].to_i |
|
143 | out_filename = output_filename(@user.login, |
|
146 | out_filename = output_filename(@user.login, |
|
144 | @submission.problem.name, |
|
147 | @submission.problem.name, |
|
145 | @submission.id, |
|
148 | @submission.id, |
|
146 | case_num) |
|
149 | case_num) |
|
147 | if !FileTest.exists?(out_filename) |
|
150 | if !FileTest.exists?(out_filename) |
|
148 | flash[:notice] = 'Output not found.' |
|
151 | flash[:notice] = 'Output not found.' |
|
149 | redirect_to :action => 'list' and return |
|
152 | redirect_to :action => 'list' and return |
|
150 | end |
|
153 | end |
|
151 |
|
154 | ||
|
152 | response.headers['Content-Type'] = "application/force-download" |
|
155 | response.headers['Content-Type'] = "application/force-download" |
|
153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
156 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
154 | response.headers["X-Sendfile"] = out_filename |
|
157 | response.headers["X-Sendfile"] = out_filename |
|
155 | response.headers['Content-length'] = File.size(out_filename) |
|
158 | response.headers['Content-length'] = File.size(out_filename) |
|
156 | render :nothing => true |
|
159 | render :nothing => true |
|
157 | end |
|
160 | end |
|
158 |
|
161 | ||
|
159 | def error |
|
162 | def error |
|
160 | @user = User.find(session[:user_id]) |
|
163 | @user = User.find(session[:user_id]) |
|
161 | end |
|
164 | end |
|
162 |
|
165 | ||
|
163 | # announcement refreshing and hiding methods |
|
166 | # announcement refreshing and hiding methods |
|
164 |
|
167 | ||
|
165 | def announcements |
|
168 | def announcements |
|
166 | if params.has_key? 'recent' |
|
169 | if params.has_key? 'recent' |
|
167 | prepare_announcements(params[:recent]) |
|
170 | prepare_announcements(params[:recent]) |
|
168 | else |
|
171 | else |
|
169 | prepare_announcements |
|
172 | prepare_announcements |
|
170 | end |
|
173 | end |
|
171 | render(:partial => 'announcement', |
|
174 | render(:partial => 'announcement', |
|
172 | :collection => @announcements, |
|
175 | :collection => @announcements, |
|
173 | :locals => {:announcement_effect => true}) |
|
176 | :locals => {:announcement_effect => true}) |
|
174 | end |
|
177 | end |
|
175 |
|
178 | ||
|
176 | # |
|
179 | # |
|
177 | # actions for Code Jom |
|
180 | # actions for Code Jom |
|
178 | # |
|
181 | # |
|
179 | def download_input |
|
182 | def download_input |
|
180 | problem = Problem.find(params[:id]) |
|
183 | problem = Problem.find(params[:id]) |
|
181 | user = User.find(session[:user_id]) |
|
184 | user = User.find(session[:user_id]) |
|
182 | if user.can_request_new_test_pair_for? problem |
|
185 | if user.can_request_new_test_pair_for? problem |
|
183 | assignment = user.get_new_test_pair_assignment_for problem |
|
186 | assignment = user.get_new_test_pair_assignment_for problem |
|
184 | assignment.save |
|
187 | assignment.save |
|
185 |
|
188 | ||
|
186 | send_data(assignment.test_pair.input, |
|
189 | send_data(assignment.test_pair.input, |
|
187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
190 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
188 | :type => 'text/plain' }) |
|
191 | :type => 'text/plain' }) |
|
189 | else |
|
192 | else |
|
190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
193 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
191 | send_data(recent_assignment.test_pair.input, |
|
194 | send_data(recent_assignment.test_pair.input, |
|
192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
195 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
193 | :type => 'text/plain' }) |
|
196 | :type => 'text/plain' }) |
|
194 | end |
|
197 | end |
|
195 | end |
|
198 | end |
|
196 |
|
199 | ||
|
197 | def submit_solution |
|
200 | def submit_solution |
|
198 | problem = Problem.find(params[:id]) |
|
201 | problem = Problem.find(params[:id]) |
|
199 | user = User.find(session[:user_id]) |
|
202 | user = User.find(session[:user_id]) |
|
200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
203 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
201 |
|
204 | ||
|
202 | if recent_assignment == nil |
|
205 | if recent_assignment == nil |
|
203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
206 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
204 | session[:current_problem_id] = problem.id |
|
207 | session[:current_problem_id] = problem.id |
|
205 | redirect_to :action => 'list' and return |
|
208 | redirect_to :action => 'list' and return |
|
206 | end |
|
209 | end |
|
207 |
|
210 | ||
|
208 | if recent_assignment.expired? |
|
211 | if recent_assignment.expired? |
|
209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
212 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
210 | session[:current_problem_id] = problem.id |
|
213 | session[:current_problem_id] = problem.id |
|
211 | redirect_to :action => 'list' and return |
|
214 | redirect_to :action => 'list' and return |
|
212 | end |
|
215 | end |
|
213 |
|
216 | ||
|
214 | if recent_assignment.submitted |
|
217 | if recent_assignment.submitted |
|
215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
218 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
216 | session[:current_problem_id] = problem.id |
|
219 | session[:current_problem_id] = problem.id |
|
217 | redirect_to :action => 'list' and return |
|
220 | redirect_to :action => 'list' and return |
|
218 | end |
|
221 | end |
|
219 |
|
222 | ||
|
220 | if params[:file] == nil |
|
223 | if params[:file] == nil |
|
221 | flash[:notice] = 'You have not submitted any output.' |
|
224 | flash[:notice] = 'You have not submitted any output.' |
|
222 | session[:current_problem_id] = problem.id |
|
225 | session[:current_problem_id] = problem.id |
|
223 | redirect_to :action => 'list' and return |
|
226 | redirect_to :action => 'list' and return |
|
224 | end |
|
227 | end |
|
225 |
|
228 | ||
|
226 | submitted_solution = params[:file].read |
|
229 | submitted_solution = params[:file].read |
|
227 | test_pair = recent_assignment.test_pair |
|
230 | test_pair = recent_assignment.test_pair |
|
228 | passed = test_pair.grade(submitted_solution) |
|
231 | passed = test_pair.grade(submitted_solution) |
|
229 | points = passed ? 100 : 0 |
|
232 | points = passed ? 100 : 0 |
|
230 | submission = Submission.new(:user => user, |
|
233 | submission = Submission.new(:user => user, |
|
231 | :problem => problem, |
|
234 | :problem => problem, |
|
232 | :source => submitted_solution, |
|
235 | :source => submitted_solution, |
|
233 | :source_filename => params['file'].original_filename, |
|
236 | :source_filename => params['file'].original_filename, |
|
234 | :language_id => 0, |
|
237 | :language_id => 0, |
|
235 | :submitted_at => Time.new.gmtime, |
|
238 | :submitted_at => Time.new.gmtime, |
|
236 | :graded_at => Time.new.gmtime, |
|
239 | :graded_at => Time.new.gmtime, |
|
237 | :points => points) |
|
240 | :points => points) |
|
238 | submission.save |
|
241 | submission.save |
|
239 | recent_assignment.submitted = true |
|
242 | recent_assignment.submitted = true |
|
240 | recent_assignment.save |
|
243 | recent_assignment.save |
|
241 |
|
244 | ||
|
242 | status = user.get_submission_status_for(problem) |
|
245 | status = user.get_submission_status_for(problem) |
|
243 | if status == nil |
|
246 | if status == nil |
|
244 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
247 | status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0 |
|
245 | end |
|
248 | end |
|
246 |
|
249 | ||
|
247 | status.submission_count += 1 |
|
250 | status.submission_count += 1 |
|
248 | status.passed = passed |
|
251 | status.passed = passed |
|
249 | status.save |
|
252 | status.save |
|
250 |
|
253 | ||
|
251 | if passed |
|
254 | if passed |
|
252 | flash[:notice] = 'Correct solution.' |
|
255 | flash[:notice] = 'Correct solution.' |
|
253 | user.update_codejom_status |
|
256 | user.update_codejom_status |
|
254 | else |
|
257 | else |
|
255 | session[:current_problem_id] = problem.id |
|
258 | session[:current_problem_id] = problem.id |
|
256 | flash[:notice] = 'Incorrect solution.' |
|
259 | flash[:notice] = 'Incorrect solution.' |
|
257 | end |
|
260 | end |
|
258 | redirect_to :action => 'list' |
|
261 | redirect_to :action => 'list' |
|
259 | end |
|
262 | end |
|
260 |
|
263 | ||
|
261 | protected |
|
264 | protected |
|
262 |
|
265 | ||
|
263 | def prepare_announcements(recent=nil) |
|
266 | def prepare_announcements(recent=nil) |
|
264 | if Configuration.show_tasks_to?(@user) |
|
267 | if Configuration.show_tasks_to?(@user) |
|
265 | @announcements = Announcement.find_published(true) |
|
268 | @announcements = Announcement.find_published(true) |
|
266 | else |
|
269 | else |
|
267 | @announcements = Announcement.find_published |
|
270 | @announcements = Announcement.find_published |
|
268 | end |
|
271 | end |
|
269 | if recent!=nil |
|
272 | if recent!=nil |
|
270 | recent_id = recent.to_i |
|
273 | recent_id = recent.to_i |
|
271 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
274 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
272 | end |
|
275 | end |
|
273 | end |
|
276 | end |
|
274 |
|
277 | ||
|
275 | def prepare_timeout_information(problems) |
|
278 | def prepare_timeout_information(problems) |
|
276 | @submission_timeouts = {} |
|
279 | @submission_timeouts = {} |
|
277 | problems.each do |problem| |
|
280 | problems.each do |problem| |
|
278 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
281 | assignment = @user.get_recent_test_pair_assignment_for(problem) |
|
279 | if assignment == nil |
|
282 | if assignment == nil |
|
280 | timeout = nil |
|
283 | timeout = nil |
|
281 | else |
|
284 | else |
|
282 | if (assignment.expired?) or (assignment.submitted) |
|
285 | if (assignment.expired?) or (assignment.submitted) |
|
283 | timeout = 0 |
|
286 | timeout = 0 |
|
284 | else |
|
287 | else |
|
285 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
288 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
286 | end |
|
289 | end |
|
287 | end |
|
290 | end |
|
288 | @submission_timeouts[problem.id] = timeout |
|
291 | @submission_timeouts[problem.id] = timeout |
|
289 | end |
|
292 | end |
|
290 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
293 | @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"} |
|
291 | end |
|
294 | end |
|
292 |
|
295 | ||
|
293 | def prepare_list_information |
|
296 | def prepare_list_information |
|
294 | @user = User.find(session[:user_id]) |
|
297 | @user = User.find(session[:user_id]) |
@@ -1,24 +1,27 | |||||
|
1 | class StatusesController < ApplicationController |
|
1 | class StatusesController < ApplicationController |
|
2 |
|
2 | ||
|
|
3 | + # protect the statuses, for now | ||
|
|
4 | + before_filter :admin_authorization | ||
|
|
5 | + | ||
|
3 | def index |
|
6 | def index |
|
4 | problem_count = Problem.available_problem_count |
|
7 | problem_count = Problem.available_problem_count |
|
5 |
|
8 | ||
|
6 | @dead_users = [] |
|
9 | @dead_users = [] |
|
7 | @level_users = {} |
|
10 | @level_users = {} |
|
8 | @levels = (0..CODEJOM_MAX_ALIVE_LEVEL) |
|
11 | @levels = (0..CODEJOM_MAX_ALIVE_LEVEL) |
|
9 | @levels.each { |l| @level_users[l] = [] } |
|
12 | @levels.each { |l| @level_users[l] = [] } |
|
10 | User.find(:all).each do |user| |
|
13 | User.find(:all).each do |user| |
|
11 | if user.codejom_status==nil |
|
14 | if user.codejom_status==nil |
|
12 | user.update_codejom_status |
|
15 | user.update_codejom_status |
|
13 | user.codejom_status(true) # reload |
|
16 | user.codejom_status(true) # reload |
|
14 | end |
|
17 | end |
|
15 |
|
18 | ||
|
16 | if not user.codejom_status.alive |
|
19 | if not user.codejom_status.alive |
|
17 | @dead_users << user |
|
20 | @dead_users << user |
|
18 | else |
|
21 | else |
|
19 | @level_users[user.codejom_level] << user |
|
22 | @level_users[user.codejom_level] << user |
|
20 | end |
|
23 | end |
|
21 | end |
|
24 | end |
|
22 | end |
|
25 | end |
|
23 |
|
26 | ||
|
24 | end |
|
27 | end |
@@ -1,118 +1,121 | |||||
|
1 | class TestController < ApplicationController |
|
1 | class TestController < ApplicationController |
|
2 |
|
2 | ||
|
|
3 | + # this page is unavailable in Code Jom | ||
|
|
4 | + before_filter :admin_authorization | ||
|
|
5 | + | ||
|
3 | before_filter :authenticate, :check_viewability |
|
6 | before_filter :authenticate, :check_viewability |
|
4 |
|
7 | ||
|
5 | # |
|
8 | # |
|
6 | # COMMENT OUT: filter in each action instead |
|
9 | # COMMENT OUT: filter in each action instead |
|
7 | # |
|
10 | # |
|
8 | # before_filter :verify_time_limit, :only => [:submit] |
|
11 | # before_filter :verify_time_limit, :only => [:submit] |
|
9 |
|
12 | ||
|
10 | verify :method => :post, :only => [:submit], |
|
13 | verify :method => :post, :only => [:submit], |
|
11 | :redirect_to => { :action => :index } |
|
14 | :redirect_to => { :action => :index } |
|
12 |
|
15 | ||
|
13 | def index |
|
16 | def index |
|
14 | prepare_index_information |
|
17 | prepare_index_information |
|
15 | end |
|
18 | end |
|
16 |
|
19 | ||
|
17 | def submit |
|
20 | def submit |
|
18 | @user = User.find(session[:user_id]) |
|
21 | @user = User.find(session[:user_id]) |
|
19 |
|
22 | ||
|
20 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
23 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
21 |
|
24 | ||
|
22 | if @submitted_test_request.errors.length != 0 |
|
25 | if @submitted_test_request.errors.length != 0 |
|
23 | prepare_index_information |
|
26 | prepare_index_information |
|
24 | render :action => 'index' and return |
|
27 | render :action => 'index' and return |
|
25 | end |
|
28 | end |
|
26 |
|
29 | ||
|
27 | if Configuration.time_limit_mode? |
|
30 | if Configuration.time_limit_mode? |
|
28 | if @user.contest_finished? |
|
31 | if @user.contest_finished? |
|
29 | @submitted_test_request.errors.add_to_base('Contest is over.') |
|
32 | @submitted_test_request.errors.add_to_base('Contest is over.') |
|
30 | prepare_index_information |
|
33 | prepare_index_information |
|
31 | render :action => 'index' and return |
|
34 | render :action => 'index' and return |
|
32 | end |
|
35 | end |
|
33 |
|
36 | ||
|
34 | if !Configuration.allow_test_request(@user) |
|
37 | if !Configuration.allow_test_request(@user) |
|
35 | prepare_index_information |
|
38 | prepare_index_information |
|
36 | flash[:notice] = 'Test request is not allowed during the last 30 minutes' |
|
39 | flash[:notice] = 'Test request is not allowed during the last 30 minutes' |
|
37 | redirect_to :action => 'index' and return |
|
40 | redirect_to :action => 'index' and return |
|
38 | end |
|
41 | end |
|
39 | end |
|
42 | end |
|
40 |
|
43 | ||
|
41 | if @submitted_test_request.save |
|
44 | if @submitted_test_request.save |
|
42 | redirect_to :action => 'index' |
|
45 | redirect_to :action => 'index' |
|
43 | else |
|
46 | else |
|
44 | prepare_index_information |
|
47 | prepare_index_information |
|
45 | render :action => 'index' |
|
48 | render :action => 'index' |
|
46 | end |
|
49 | end |
|
47 | end |
|
50 | end |
|
48 |
|
51 | ||
|
49 | def read |
|
52 | def read |
|
50 | user = User.find(session[:user_id]) |
|
53 | user = User.find(session[:user_id]) |
|
51 | begin |
|
54 | begin |
|
52 | test_request = TestRequest.find(params[:id]) |
|
55 | test_request = TestRequest.find(params[:id]) |
|
53 | rescue |
|
56 | rescue |
|
54 | test_request = nil |
|
57 | test_request = nil |
|
55 | end |
|
58 | end |
|
56 | if test_request==nil or test_request.user_id != user.id |
|
59 | if test_request==nil or test_request.user_id != user.id |
|
57 | flash[:notice] = 'Invalid output' |
|
60 | flash[:notice] = 'Invalid output' |
|
58 | redirect_to :action => 'index' |
|
61 | redirect_to :action => 'index' |
|
59 | return |
|
62 | return |
|
60 | end |
|
63 | end |
|
61 | if test_request.output_file_name!=nil |
|
64 | if test_request.output_file_name!=nil |
|
62 | data = File.open(test_request.output_file_name).read(2048) |
|
65 | data = File.open(test_request.output_file_name).read(2048) |
|
63 | if data==nil |
|
66 | if data==nil |
|
64 | data="" |
|
67 | data="" |
|
65 | end |
|
68 | end |
|
66 | send_data(data, |
|
69 | send_data(data, |
|
67 | {:filename => 'output.txt', |
|
70 | {:filename => 'output.txt', |
|
68 | :type => 'text/plain'}) |
|
71 | :type => 'text/plain'}) |
|
69 | return |
|
72 | return |
|
70 | end |
|
73 | end |
|
71 | redirect_to :action => 'index' |
|
74 | redirect_to :action => 'index' |
|
72 | end |
|
75 | end |
|
73 |
|
76 | ||
|
74 | def result |
|
77 | def result |
|
75 | @user = User.find(session[:user_id]) |
|
78 | @user = User.find(session[:user_id]) |
|
76 | begin |
|
79 | begin |
|
77 | @test_request = TestRequest.find(params[:id]) |
|
80 | @test_request = TestRequest.find(params[:id]) |
|
78 | rescue |
|
81 | rescue |
|
79 | @test_request = nil |
|
82 | @test_request = nil |
|
80 | end |
|
83 | end |
|
81 | if @test_request==nil or @test_request.user_id != @user.id |
|
84 | if @test_request==nil or @test_request.user_id != @user.id |
|
82 | flash[:notice] = 'Invalid request' |
|
85 | flash[:notice] = 'Invalid request' |
|
83 | redirect_to :action => 'index' |
|
86 | redirect_to :action => 'index' |
|
84 | return |
|
87 | return |
|
85 | end |
|
88 | end |
|
86 | end |
|
89 | end |
|
87 |
|
90 | ||
|
88 | protected |
|
91 | protected |
|
89 |
|
92 | ||
|
90 | def prepare_index_information |
|
93 | def prepare_index_information |
|
91 | @user = User.find(session[:user_id]) |
|
94 | @user = User.find(session[:user_id]) |
|
92 | @submissions = Submission.find_last_for_all_available_problems(@user.id) |
|
95 | @submissions = Submission.find_last_for_all_available_problems(@user.id) |
|
93 | all_problems = @submissions.collect { |submission| submission.problem } |
|
96 | all_problems = @submissions.collect { |submission| submission.problem } |
|
94 | @problems = [] |
|
97 | @problems = [] |
|
95 | all_problems.each do |problem| |
|
98 | all_problems.each do |problem| |
|
96 | if problem.test_allowed |
|
99 | if problem.test_allowed |
|
97 | @problems << problem |
|
100 | @problems << problem |
|
98 | end |
|
101 | end |
|
99 | end |
|
102 | end |
|
100 | @test_requests = [] |
|
103 | @test_requests = [] |
|
101 | @user.test_requests.each do |ts| |
|
104 | @user.test_requests.each do |ts| |
|
102 | if ts.problem and ts.problem.available |
|
105 | if ts.problem and ts.problem.available |
|
103 | @test_requests << ts |
|
106 | @test_requests << ts |
|
104 | end |
|
107 | end |
|
105 | end |
|
108 | end |
|
106 | end |
|
109 | end |
|
107 |
|
110 | ||
|
108 | def check_viewability |
|
111 | def check_viewability |
|
109 | user = User.find(session[:user_id]) |
|
112 | user = User.find(session[:user_id]) |
|
110 | if !Configuration.show_tasks_to?(user) |
|
113 | if !Configuration.show_tasks_to?(user) |
|
111 | redirect_to :controller => 'main', :action => 'list' |
|
114 | redirect_to :controller => 'main', :action => 'list' |
|
112 | end |
|
115 | end |
|
113 | if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit') |
|
116 | if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit') |
|
114 | redirect_to :controller => 'test', :action => 'index' |
|
117 | redirect_to :controller => 'test', :action => 'index' |
|
115 | end |
|
118 | end |
|
116 | end |
|
119 | end |
|
117 |
|
120 | ||
|
118 | end |
|
121 | end |
@@ -1,8 +1,8 | |||||
|
1 | .problem-bar{:id => "problem-bar-#{problem.id}"} |
|
1 | .problem-bar{:id => "problem-bar-#{problem.id}"} |
|
2 | %a{:href => "#", :onclick => "$$('.problem-panel').each(function(elt) {elt.hide();}); $('problem-panel-#{problem.id}').show(); $('problem-panel-filler').hide(); return false;"} |
|
2 | %a{:href => "#", :onclick => "$$('.problem-panel').each(function(elt) {elt.hide();}); $('problem-panel-#{problem.id}').show(); $('problem-panel-filler').hide(); return false;"} |
|
3 | %span{:class => 'problem-title'} |
|
3 | %span{:class => 'problem-title'} |
|
4 |
- = "#{problem.full_name} |
|
4 | + = "#{problem.full_name}" |
|
5 | - if @prob_submissions[problem_title_counter][:count] > 0 |
|
5 | - if @prob_submissions[problem_title_counter][:count] > 0 |
|
6 | = "[#{@prob_submissions[problem_title_counter][:count]} trials(s)]" |
|
6 | = "[#{@prob_submissions[problem_title_counter][:count]} trials(s)]" |
|
7 | - else |
|
7 | - else |
|
8 | [No trials] |
|
8 | [No trials] |
@@ -1,37 +1,38 | |||||
|
1 | - content_for :head do |
|
1 | - content_for :head do |
|
2 | = javascript_include_tag :defaults |
|
2 | = javascript_include_tag :defaults |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
3 | = javascript_include_tag 'announcement_refresh.js' |
|
4 | = javascript_include_tag 'codejom_timeout.js' |
|
4 | = javascript_include_tag 'codejom_timeout.js' |
|
5 |
|
5 | ||
|
6 | = user_title_bar(@user) |
|
6 | = user_title_bar(@user) |
|
7 |
|
7 | ||
|
8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
8 | .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")} |
|
9 | %span{:class => 'title'} |
|
9 | %span{:class => 'title'} |
|
10 | Announcements |
|
10 | Announcements |
|
11 | #announcementbox-body |
|
11 | #announcementbox-body |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
12 | = render :partial => 'announcement', :collection => @announcements |
|
13 |
|
13 | ||
|
14 | %hr/ |
|
14 | %hr/ |
|
15 |
|
15 | ||
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
16 | - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true) |
|
17 | %p=t 'main.start_soon' |
|
17 | %p=t 'main.start_soon' |
|
18 |
|
18 | ||
|
19 | - if Configuration.show_tasks_to?(@user) |
|
19 | - if Configuration.show_tasks_to?(@user) |
|
20 | .problem-list |
|
20 | .problem-list |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
21 | = render :partial => 'problem_title', :collection => @problems, :as => :problem |
|
22 | .problem-content |
|
22 | .problem-content |
|
23 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
23 | %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""} |
|
24 | - %b Welcome to Code Jom |
|
24 | + %h2 |
|
|
25 | + Welcome to Code Jom | ||
|
25 | %br/ |
|
26 | %br/ |
|
26 | Choose problems from the list on the right. |
|
27 | Choose problems from the list on the right. |
|
27 | = render :partial => 'problem', :collection => @problems |
|
28 | = render :partial => 'problem', :collection => @problems |
|
28 |
|
29 | ||
|
29 | %br{:clear=>'both'}/ |
|
30 | %br{:clear=>'both'}/ |
|
30 | %hr/ |
|
31 | %hr/ |
|
31 |
|
32 | ||
|
32 | %script{:type => "text/javascript"} |
|
33 | %script{:type => "text/javascript"} |
|
33 | Announcement.registerRefreshEventTimer(); |
|
34 | Announcement.registerRefreshEventTimer(); |
|
34 | = render :partial => 'submission_timeouts' |
|
35 | = render :partial => 'submission_timeouts' |
|
35 | CodejomTimeout.updateProblemMessages(); |
|
36 | CodejomTimeout.updateProblemMessages(); |
|
36 | CodejomTimeout.registerRefreshEvent(); |
|
37 | CodejomTimeout.registerRefreshEvent(); |
|
37 |
|
38 |
You need to be logged in to leave comments.
Login now