Description:
controllers get available problems from current user
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r288:74436ad04ad0 - - 3 files changed: 42 inserted, 45 deleted
@@ -98,25 +98,25 | |||||
|
98 | def compiler_msg |
|
98 | def compiler_msg |
|
99 | @submission = Submission.find(params[:id]) |
|
99 | @submission = Submission.find(params[:id]) |
|
100 | if @submission.user_id == session[:user_id] |
|
100 | if @submission.user_id == session[:user_id] |
|
101 | render :action => 'compiler_msg', :layout => 'empty' |
|
101 | render :action => 'compiler_msg', :layout => 'empty' |
|
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 submission |
|
108 | def submission |
|
109 | @user = User.find(session[:user_id]) |
|
109 | @user = User.find(session[:user_id]) |
|
110 |
- @problems = |
|
110 | + @problems = @user.available_problems |
|
111 | if params[:id]==nil |
|
111 | if params[:id]==nil |
|
112 | @problem = nil |
|
112 | @problem = nil |
|
113 | @submissions = nil |
|
113 | @submissions = nil |
|
114 | else |
|
114 | else |
|
115 | @problem = Problem.find_by_name(params[:id]) |
|
115 | @problem = Problem.find_by_name(params[:id]) |
|
116 | if not @problem.available |
|
116 | if not @problem.available |
|
117 | redirect_to :action => 'list' |
|
117 | redirect_to :action => 'list' |
|
118 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
118 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
119 | return |
|
119 | return |
|
120 | end |
|
120 | end |
|
121 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
121 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id) |
|
122 | end |
|
122 | end |
@@ -184,72 +184,31 | |||||
|
184 | def prepare_announcements(recent=nil) |
|
184 | def prepare_announcements(recent=nil) |
|
185 | if Configuration.show_tasks_to?(@user) |
|
185 | if Configuration.show_tasks_to?(@user) |
|
186 | @announcements = Announcement.find_published(true) |
|
186 | @announcements = Announcement.find_published(true) |
|
187 | else |
|
187 | else |
|
188 | @announcements = Announcement.find_published |
|
188 | @announcements = Announcement.find_published |
|
189 | end |
|
189 | end |
|
190 | if recent!=nil |
|
190 | if recent!=nil |
|
191 | recent_id = recent.to_i |
|
191 | recent_id = recent.to_i |
|
192 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
192 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
193 | end |
|
193 | end |
|
194 | end |
|
194 | end |
|
195 |
|
195 | ||
|
196 | - def problem_list_by_user_contests(user) |
|
||
|
197 | - contest_problems = [] |
|
||
|
198 | - pin = {} |
|
||
|
199 | - user.contests.enabled.each do |contest| |
|
||
|
200 | - available_problems = contest.problems.available |
|
||
|
201 | - contest_problems << { |
|
||
|
202 | - :contest => contest, |
|
||
|
203 | - :problems => available_problems |
|
||
|
204 | - } |
|
||
|
205 | - available_problems.each {|p| pin[p.id] = true} |
|
||
|
206 | - end |
|
||
|
207 | - other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
||
|
208 | - contest_problems << { |
|
||
|
209 | - :contest => nil, |
|
||
|
210 | - :problems => other_avaiable_problems |
|
||
|
211 | - } |
|
||
|
212 | - return contest_problems |
|
||
|
213 | - end |
|
||
|
214 | - |
|
||
|
215 | - def problem_list_for_user(user, contest_problems=nil) |
|
||
|
216 | - if not Configuration.multicontests? |
|
||
|
217 | - return Problem.find_available_problems |
|
||
|
218 | - else |
|
||
|
219 | - if contest_problems==nil |
|
||
|
220 | - contest_problems = problem_list_by_user_contests(user) |
|
||
|
221 | - end |
|
||
|
222 | - |
|
||
|
223 | - problems = [] |
|
||
|
224 | - collected = {} |
|
||
|
225 | - contest_problems.each do |cp| |
|
||
|
226 | - cp[:problems].each do |problem| |
|
||
|
227 | - if not collected[problem.id] |
|
||
|
228 | - problems << problem |
|
||
|
229 | - collected[problem.id] = true |
|
||
|
230 | - end |
|
||
|
231 | - end |
|
||
|
232 | - end |
|
||
|
233 | - return problems |
|
||
|
234 | - end |
|
||
|
235 | - end |
|
||
|
236 | - |
|
||
|
237 | def prepare_list_information |
|
196 | def prepare_list_information |
|
238 | @user = User.find(session[:user_id]) |
|
197 | @user = User.find(session[:user_id]) |
|
239 | if not Configuration.multicontests? |
|
198 | if not Configuration.multicontests? |
|
240 | @problems = problem_list_for_user(@user) |
|
199 | @problems = problem_list_for_user(@user) |
|
241 | else |
|
200 | else |
|
242 |
- @contest_problems = |
|
201 | + @contest_problems = @user.available_problems_group_by_contests |
|
243 |
- @problems = |
|
202 | + @problems = @user.available_problems |
|
244 | end |
|
203 | end |
|
245 | @prob_submissions = {} |
|
204 | @prob_submissions = {} |
|
246 | @problems.each do |p| |
|
205 | @problems.each do |p| |
|
247 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
206 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
248 | if sub!=nil |
|
207 | if sub!=nil |
|
249 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
208 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
250 | else |
|
209 | else |
|
251 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
210 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
252 | end |
|
211 | end |
|
253 | end |
|
212 | end |
|
254 | prepare_announcements |
|
213 | prepare_announcements |
|
255 | end |
|
214 | end |
@@ -1,22 +1,22 | |||||
|
1 | class TasksController < ApplicationController |
|
1 | class TasksController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :authenticate, :check_viewability |
|
3 | before_filter :authenticate, :check_viewability |
|
4 |
|
4 | ||
|
5 | def index |
|
5 | def index |
|
6 | redirect_to :action => 'list' |
|
6 | redirect_to :action => 'list' |
|
7 | end |
|
7 | end |
|
8 |
|
8 | ||
|
9 | def list |
|
9 | def list |
|
10 |
- @problems = |
|
10 | + @problems = @user.available_problems |
|
11 | end |
|
11 | end |
|
12 |
|
12 | ||
|
13 | # this has contest-wide access control |
|
13 | # this has contest-wide access control |
|
14 | def view |
|
14 | def view |
|
15 | base_name = params[:file] |
|
15 | base_name = params[:file] |
|
16 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
16 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
17 | filename = "#{Problem.download_file_basedir}/#{base_filename}" |
|
17 | filename = "#{Problem.download_file_basedir}/#{base_filename}" |
|
18 |
|
18 | ||
|
19 | if !FileTest.exists?(filename) |
|
19 | if !FileTest.exists?(filename) |
|
20 | redirect_to :action => 'index' and return |
|
20 | redirect_to :action => 'index' and return |
|
21 | end |
|
21 | end |
|
22 |
|
22 |
@@ -188,24 +188,62 | |||||
|
188 | if problem_contests.length == 0 # this is public contest |
|
188 | if problem_contests.length == 0 # this is public contest |
|
189 | return true |
|
189 | return true |
|
190 | end |
|
190 | end |
|
191 |
|
191 | ||
|
192 | contests.each do |contest| |
|
192 | contests.each do |contest| |
|
193 | if problem_contests.find {|c| c.id == contest.id } |
|
193 | if problem_contests.find {|c| c.id == contest.id } |
|
194 | return true |
|
194 | return true |
|
195 | end |
|
195 | end |
|
196 | end |
|
196 | end |
|
197 | return false |
|
197 | return false |
|
198 | end |
|
198 | end |
|
199 |
|
199 | ||
|
|
200 | + def available_problems_group_by_contests | ||
|
|
201 | + contest_problems = [] | ||
|
|
202 | + pin = {} | ||
|
|
203 | + contests.enabled.each do |contest| | ||
|
|
204 | + available_problems = contest.problems.available | ||
|
|
205 | + contest_problems << { | ||
|
|
206 | + :contest => contest, | ||
|
|
207 | + :problems => available_problems | ||
|
|
208 | + } | ||
|
|
209 | + available_problems.each {|p| pin[p.id] = true} | ||
|
|
210 | + end | ||
|
|
211 | + other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} | ||
|
|
212 | + contest_problems << { | ||
|
|
213 | + :contest => nil, | ||
|
|
214 | + :problems => other_avaiable_problems | ||
|
|
215 | + } | ||
|
|
216 | + return contest_problems | ||
|
|
217 | + end | ||
|
|
218 | + | ||
|
|
219 | + def available_problems | ||
|
|
220 | + if not Configuration.multicontests? | ||
|
|
221 | + return Problem.find_available_problems | ||
|
|
222 | + else | ||
|
|
223 | + contest_problems = [] | ||
|
|
224 | + pin = {} | ||
|
|
225 | + contests.enabled.each do |contest| | ||
|
|
226 | + contest.problems.available.each do |problem| | ||
|
|
227 | + if not pin.has_key? problem.id | ||
|
|
228 | + contest_problems << problem | ||
|
|
229 | + end | ||
|
|
230 | + pin[problem.id] = true | ||
|
|
231 | + end | ||
|
|
232 | + end | ||
|
|
233 | + other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} | ||
|
|
234 | + return contest_problems + other_avaiable_problems | ||
|
|
235 | + end | ||
|
|
236 | + end | ||
|
|
237 | + | ||
|
200 | def can_view_problem?(problem) |
|
238 | def can_view_problem?(problem) |
|
201 | if not Configuration.multicontests? |
|
239 | if not Configuration.multicontests? |
|
202 | return problem.available |
|
240 | return problem.available |
|
203 | else |
|
241 | else |
|
204 | return problem_in_user_contests? problem |
|
242 | return problem_in_user_contests? problem |
|
205 | end |
|
243 | end |
|
206 | end |
|
244 | end |
|
207 |
|
245 | ||
|
208 | protected |
|
246 | protected |
|
209 | def encrypt_new_password |
|
247 | def encrypt_new_password |
|
210 | return if password.blank? |
|
248 | return if password.blank? |
|
211 | self.salt = (10+rand(90)).to_s |
|
249 | self.salt = (10+rand(90)).to_s |
You need to be logged in to leave comments.
Login now