Description:
Merge branch 'master' into codejom (bug fix)
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r230:1925d77bb0c3 - - 1 file changed: 1 inserted, 1 deleted
@@ -1,216 +1,216 | |||
|
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 | - flash[:notice] = saved_notice | |
|
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 | 103 | @user = User.find(session[:user_id]) |
|
104 | 104 | @problems = Problem.find_available_problems |
|
105 | 105 | if params[:id]==nil |
|
106 | 106 | @problem = nil |
|
107 | 107 | @submissions = nil |
|
108 | 108 | else |
|
109 | 109 | @problem = Problem.find_by_name(params[:id]) |
|
110 | 110 | if not @problem.available |
|
111 | 111 | redirect_to :action => 'list' |
|
112 | 112 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
113 | 113 | return |
|
114 | 114 | end |
|
115 | 115 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
116 | 116 | end |
|
117 | 117 | end |
|
118 | 118 | |
|
119 | 119 | def result |
|
120 | 120 | if !Configuration.show_grading_result |
|
121 | 121 | redirect_to :action => 'list' and return |
|
122 | 122 | end |
|
123 | 123 | @user = User.find(session[:user_id]) |
|
124 | 124 | @submission = Submission.find(params[:id]) |
|
125 | 125 | if @submission.user!=@user |
|
126 | 126 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
127 | 127 | redirect_to :action => 'list' and return |
|
128 | 128 | end |
|
129 | 129 | prepare_grading_result(@submission) |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def load_output |
|
133 | 133 | if !Configuration.show_grading_result or params[:num]==nil |
|
134 | 134 | redirect_to :action => 'list' and return |
|
135 | 135 | end |
|
136 | 136 | @user = User.find(session[:user_id]) |
|
137 | 137 | @submission = Submission.find(params[:id]) |
|
138 | 138 | if @submission.user!=@user |
|
139 | 139 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
140 | 140 | redirect_to :action => 'list' and return |
|
141 | 141 | end |
|
142 | 142 | case_num = params[:num].to_i |
|
143 | 143 | out_filename = output_filename(@user.login, |
|
144 | 144 | @submission.problem.name, |
|
145 | 145 | @submission.id, |
|
146 | 146 | case_num) |
|
147 | 147 | if !FileTest.exists?(out_filename) |
|
148 | 148 | flash[:notice] = 'Output not found.' |
|
149 | 149 | redirect_to :action => 'list' and return |
|
150 | 150 | end |
|
151 | 151 | |
|
152 | 152 | response.headers['Content-Type'] = "application/force-download" |
|
153 | 153 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
154 | 154 | response.headers["X-Sendfile"] = out_filename |
|
155 | 155 | response.headers['Content-length'] = File.size(out_filename) |
|
156 | 156 | render :nothing => true |
|
157 | 157 | end |
|
158 | 158 | |
|
159 | 159 | def error |
|
160 | 160 | @user = User.find(session[:user_id]) |
|
161 | 161 | end |
|
162 | 162 | |
|
163 | 163 | # announcement refreshing and hiding methods |
|
164 | 164 | |
|
165 | 165 | def announcements |
|
166 | 166 | if params.has_key? 'recent' |
|
167 | 167 | prepare_announcements(params[:recent]) |
|
168 | 168 | else |
|
169 | 169 | prepare_announcements |
|
170 | 170 | end |
|
171 | 171 | render(:partial => 'announcement', |
|
172 | 172 | :collection => @announcements, |
|
173 | 173 | :locals => {:announcement_effect => true}) |
|
174 | 174 | end |
|
175 | 175 | |
|
176 | 176 | # |
|
177 | 177 | # actions for Code Jom |
|
178 | 178 | # |
|
179 | 179 | def download_input |
|
180 | 180 | problem = Problem.find(params[:id]) |
|
181 | 181 | user = User.find(session[:user_id]) |
|
182 | 182 | if user.can_request_new_test_pair_for? problem |
|
183 | 183 | assignment = user.get_new_test_pair_assignment_for problem |
|
184 | 184 | assignment.save |
|
185 | 185 | |
|
186 | 186 | send_data(assignment.test_pair.input, |
|
187 | 187 | { :filename => "#{problem.name}-#{assignment.request_number}.in", |
|
188 | 188 | :type => 'text/plain' }) |
|
189 | 189 | else |
|
190 | 190 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
191 | 191 | send_data(recent_assignment.test_pair.input, |
|
192 | 192 | { :filename => "#{problem.name}-#{recent_assignment.request_number}.in", |
|
193 | 193 | :type => 'text/plain' }) |
|
194 | 194 | end |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def submit_solution |
|
198 | 198 | problem = Problem.find(params[:id]) |
|
199 | 199 | user = User.find(session[:user_id]) |
|
200 | 200 | recent_assignment = user.get_recent_test_pair_assignment_for problem |
|
201 | 201 | |
|
202 | 202 | if recent_assignment == nil |
|
203 | 203 | flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.' |
|
204 | 204 | session[:current_problem_id] = problem.id |
|
205 | 205 | redirect_to :action => 'list' and return |
|
206 | 206 | end |
|
207 | 207 | |
|
208 | 208 | if recent_assignment.expired? |
|
209 | 209 | flash[:notice] = 'The current input is expired. Please download a new input data.' |
|
210 | 210 | session[:current_problem_id] = problem.id |
|
211 | 211 | redirect_to :action => 'list' and return |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | if recent_assignment.submitted |
|
215 | 215 | flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.' |
|
216 | 216 | session[:current_problem_id] = problem.id |
You need to be logged in to leave comments.
Login now