Description:
disabled unused actions from controllers, protected statuses display, more styling
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r241:ce50017c6bce - - 5 files changed: 12 inserted, 2 deleted

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