Description:
change find(:xxx) to correct syntax for rails 4
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r619:35d86016ce86 - - 26 files changed: 108 inserted, 147 deleted

@@ -1,9 +1,9
1 source 'https://rubygems.org'
1 source 'https://rubygems.org'
2
2
3 - gem 'rails', '~>4.0.0'
3 + gem 'rails', '~>4.1.0'
4 gem 'activerecord-session_store'
4 gem 'activerecord-session_store'
5
5
6 gem 'select2-rails'
6 gem 'select2-rails'
7
7
8 # Bundle edge Rails instead:
8 # Bundle edge Rails instead:
9 # gem 'rails', :git => 'git://github.com/rails/rails.git'
9 # gem 'rails', :git => 'git://github.com/rails/rails.git'
@@ -7,60 +7,62
7 activesupport (>= 3.0.0, < 5.0)
7 activesupport (>= 3.0.0, < 5.0)
8
8
9 GEM
9 GEM
10 remote: https://rubygems.org/
10 remote: https://rubygems.org/
11 specs:
11 specs:
12 ace-rails-ap (4.1.1)
12 ace-rails-ap (4.1.1)
13 - actionmailer (4.0.13)
13 + actionmailer (4.1.16)
14 - actionpack (= 4.0.13)
14 + actionpack (= 4.1.16)
15 + actionview (= 4.1.16)
15 mail (~> 2.5, >= 2.5.4)
16 mail (~> 2.5, >= 2.5.4)
16 - actionpack (4.0.13)
17 + actionpack (4.1.16)
17 - activesupport (= 4.0.13)
18 + actionview (= 4.1.16)
18 - builder (~> 3.1.0)
19 + activesupport (= 4.1.16)
19 - erubis (~> 2.7.0)
20 rack (~> 1.5.2)
20 rack (~> 1.5.2)
21 rack-test (~> 0.6.2)
21 rack-test (~> 0.6.2)
22 - activemodel (4.0.13)
22 + actionview (4.1.16)
23 - activesupport (= 4.0.13)
23 + activesupport (= 4.1.16)
24 - builder (~> 3.1.0)
24 + builder (~> 3.1)
25 - activerecord (4.0.13)
25 + erubis (~> 2.7.0)
26 - activemodel (= 4.0.13)
26 + activemodel (4.1.16)
27 - activerecord-deprecated_finders (~> 1.0.2)
27 + activesupport (= 4.1.16)
28 - activesupport (= 4.0.13)
28 + builder (~> 3.1)
29 - arel (~> 4.0.0)
29 + activerecord (4.1.16)
30 - activerecord-deprecated_finders (1.0.4)
30 + activemodel (= 4.1.16)
31 + activesupport (= 4.1.16)
32 + arel (~> 5.0.0)
31 activerecord-session_store (1.0.0)
33 activerecord-session_store (1.0.0)
32 actionpack (>= 4.0, < 5.1)
34 actionpack (>= 4.0, < 5.1)
33 activerecord (>= 4.0, < 5.1)
35 activerecord (>= 4.0, < 5.1)
34 multi_json (~> 1.11, >= 1.11.2)
36 multi_json (~> 1.11, >= 1.11.2)
35 rack (>= 1.5.2, < 3)
37 rack (>= 1.5.2, < 3)
36 railties (>= 4.0, < 5.1)
38 railties (>= 4.0, < 5.1)
37 - activesupport (4.0.13)
39 + activesupport (4.1.16)
38 i18n (~> 0.6, >= 0.6.9)
40 i18n (~> 0.6, >= 0.6.9)
39 - minitest (~> 4.2)
41 + json (~> 1.7, >= 1.7.7)
40 - multi_json (~> 1.3)
42 + minitest (~> 5.1)
41 thread_safe (~> 0.1)
43 thread_safe (~> 0.1)
42 - tzinfo (~> 0.3.37)
44 + tzinfo (~> 1.1)
43 - arel (4.0.2)
45 + arel (5.0.1.20140414130214)
44 - autoprefixer-rails (6.5.2)
46 + autoprefixer-rails (6.5.3.1)
45 execjs
47 execjs
46 best_in_place (3.0.3)
48 best_in_place (3.0.3)
47 actionpack (>= 3.2)
49 actionpack (>= 3.2)
48 railties (>= 3.2)
50 railties (>= 3.2)
49 bootstrap-sass (3.2.0.2)
51 bootstrap-sass (3.2.0.2)
50 sass (~> 3.2)
52 sass (~> 3.2)
51 bootstrap-switch-rails (3.3.3)
53 bootstrap-switch-rails (3.3.3)
52 bootstrap-toggle-rails (2.2.1.0)
54 bootstrap-toggle-rails (2.2.1.0)
53 - builder (3.1.4)
55 + builder (3.2.2)
54 coffee-rails (4.2.1)
56 coffee-rails (4.2.1)
55 coffee-script (>= 2.2.0)
57 coffee-script (>= 2.2.0)
56 railties (>= 4.0.0, < 5.2.x)
58 railties (>= 4.0.0, < 5.2.x)
57 coffee-script (2.4.1)
59 coffee-script (2.4.1)
58 coffee-script-source
60 coffee-script-source
59 execjs
61 execjs
60 - coffee-script-source (1.10.0)
62 + coffee-script-source (1.11.1)
61 concurrent-ruby (1.0.2)
63 concurrent-ruby (1.0.2)
62 diff-lcs (1.2.5)
64 diff-lcs (1.2.5)
63 dynamic_form (1.1.4)
65 dynamic_form (1.1.4)
64 erubis (2.7.0)
66 erubis (2.7.0)
65 execjs (2.7.0)
67 execjs (2.7.0)
66 haml (4.0.7)
68 haml (4.0.7)
@@ -79,58 +81,61
79 i18n (0.7.0)
81 i18n (0.7.0)
80 in_place_editing (1.2.0)
82 in_place_editing (1.2.0)
81 jquery-countdown-rails (2.0.2)
83 jquery-countdown-rails (2.0.2)
82 jquery-rails (3.1.4)
84 jquery-rails (3.1.4)
83 railties (>= 3.0, < 5.0)
85 railties (>= 3.0, < 5.0)
84 thor (>= 0.14, < 2.0)
86 thor (>= 0.14, < 2.0)
85 - jquery-tablesorter (1.22.7)
87 + jquery-tablesorter (1.23.1)
86 railties (>= 3.2, < 6)
88 railties (>= 3.2, < 6)
87 jquery-timepicker-addon-rails (1.4.1)
89 jquery-timepicker-addon-rails (1.4.1)
88 railties (>= 3.1)
90 railties (>= 3.1)
89 jquery-ui-rails (4.0.3)
91 jquery-ui-rails (4.0.3)
90 jquery-rails
92 jquery-rails
91 railties (>= 3.1.0)
93 railties (>= 3.1.0)
92 jquery-ui-sass-rails (4.0.3.0)
94 jquery-ui-sass-rails (4.0.3.0)
93 jquery-rails
95 jquery-rails
94 jquery-ui-rails (= 4.0.3)
96 jquery-ui-rails (= 4.0.3)
95 railties (>= 3.1.0)
97 railties (>= 3.1.0)
98 + json (1.8.3)
96 mail (2.6.4)
99 mail (2.6.4)
97 mime-types (>= 1.16, < 4)
100 mime-types (>= 1.16, < 4)
98 mime-types (3.1)
101 mime-types (3.1)
99 mime-types-data (~> 3.2015)
102 mime-types-data (~> 3.2015)
100 mime-types-data (3.2016.0521)
103 mime-types-data (3.2016.0521)
101 mini_portile2 (2.1.0)
104 mini_portile2 (2.1.0)
102 - minitest (4.7.5)
105 + minitest (5.10.1)
103 momentjs-rails (2.15.1)
106 momentjs-rails (2.15.1)
104 railties (>= 3.1)
107 railties (>= 3.1)
105 multi_json (1.12.1)
108 multi_json (1.12.1)
106 mysql2 (0.3.21)
109 mysql2 (0.3.21)
107 nokogiri (1.6.8.1)
110 nokogiri (1.6.8.1)
108 mini_portile2 (~> 2.1.0)
111 mini_portile2 (~> 2.1.0)
109 - power_assert (0.3.1)
112 + power_assert (0.4.1)
110 rack (1.5.5)
113 rack (1.5.5)
111 rack-test (0.6.3)
114 rack-test (0.6.3)
112 rack (>= 1.0)
115 rack (>= 1.0)
113 - rails (4.0.13)
116 + rails (4.1.16)
114 - actionmailer (= 4.0.13)
117 + actionmailer (= 4.1.16)
115 - actionpack (= 4.0.13)
118 + actionpack (= 4.1.16)
116 - activerecord (= 4.0.13)
119 + actionview (= 4.1.16)
117 - activesupport (= 4.0.13)
120 + activemodel (= 4.1.16)
121 + activerecord (= 4.1.16)
122 + activesupport (= 4.1.16)
118 bundler (>= 1.3.0, < 2.0)
123 bundler (>= 1.3.0, < 2.0)
119 - railties (= 4.0.13)
124 + railties (= 4.1.16)
120 sprockets-rails (~> 2.0)
125 sprockets-rails (~> 2.0)
121 rails_bootstrap_sortable (2.0.1)
126 rails_bootstrap_sortable (2.0.1)
122 momentjs-rails (>= 2.8.3)
127 momentjs-rails (>= 2.8.3)
123 - railties (4.0.13)
128 + railties (4.1.16)
124 - actionpack (= 4.0.13)
129 + actionpack (= 4.1.16)
125 - activesupport (= 4.0.13)
130 + activesupport (= 4.1.16)
126 rake (>= 0.8.7)
131 rake (>= 0.8.7)
127 thor (>= 0.18.1, < 2.0)
132 thor (>= 0.18.1, < 2.0)
128 - rake (11.3.0)
133 + rake (12.0.0)
129 rdiscount (2.2.0.1)
134 rdiscount (2.2.0.1)
130 - rouge (2.0.6)
135 + rouge (2.0.7)
131 rspec-collection_matchers (1.1.2)
136 rspec-collection_matchers (1.1.2)
132 rspec-expectations (>= 2.99.0.beta1)
137 rspec-expectations (>= 2.99.0.beta1)
133 rspec-core (2.99.2)
138 rspec-core (2.99.2)
134 rspec-expectations (2.99.2)
139 rspec-expectations (2.99.2)
135 diff-lcs (>= 1.1.3, < 2.0)
140 diff-lcs (>= 1.1.3, < 2.0)
136 rspec-mocks (2.99.4)
141 rspec-mocks (2.99.4)
@@ -159,19 +164,20
159 concurrent-ruby (~> 1.0)
164 concurrent-ruby (~> 1.0)
160 rack (> 1, < 3)
165 rack (> 1, < 3)
161 sprockets-rails (2.3.3)
166 sprockets-rails (2.3.3)
162 actionpack (>= 3.0)
167 actionpack (>= 3.0)
163 activesupport (>= 3.0)
168 activesupport (>= 3.0)
164 sprockets (>= 2.8, < 4.0)
169 sprockets (>= 2.8, < 4.0)
165 - test-unit (3.2.2)
170 + test-unit (3.2.3)
166 power_assert
171 power_assert
167 - thor (0.19.1)
172 + thor (0.19.4)
168 thread_safe (0.3.5)
173 thread_safe (0.3.5)
169 tilt (2.0.5)
174 tilt (2.0.5)
170 - tzinfo (0.3.52)
175 + tzinfo (1.2.2)
171 - uglifier (3.0.3)
176 + thread_safe (~> 0.1)
177 + uglifier (3.0.4)
172 execjs (>= 0.3.0, < 3)
178 execjs (>= 0.3.0, < 3)
173 will_paginate (3.0.12)
179 will_paginate (3.0.12)
174
180
175 PLATFORMS
181 PLATFORMS
176 ruby
182 ruby
177
183
@@ -193,13 +199,13
193 jquery-tablesorter
199 jquery-tablesorter
194 jquery-timepicker-addon-rails
200 jquery-timepicker-addon-rails
195 jquery-ui-sass-rails
201 jquery-ui-sass-rails
196 mail
202 mail
197 momentjs-rails
203 momentjs-rails
198 mysql2 (~> 0.3.0)
204 mysql2 (~> 0.3.0)
199 - rails (~> 4.0.0)
205 + rails (~> 4.1.0)
200 rails_bootstrap_sortable
206 rails_bootstrap_sortable
201 rdiscount
207 rdiscount
202 rouge
208 rouge
203 rspec-rails (~> 2.99.0)
209 rspec-rails (~> 2.99.0)
204 sass-rails
210 sass-rails
205 select2-rails
211 select2-rails
@@ -4,14 +4,13
4
4
5 in_place_edit_for :announcement, :published
5 in_place_edit_for :announcement, :published
6
6
7 # GET /announcements
7 # GET /announcements
8 # GET /announcements.xml
8 # GET /announcements.xml
9 def index
9 def index
10 - @announcements = Announcement.find(:all,
10 + @announcements = Announcement.order(created_at: :desc)
11 - :order => "created_at DESC")
12
11
13 respond_to do |format|
12 respond_to do |format|
14 format.html # index.html.erb
13 format.html # index.html.erb
15 format.xml { render :xml => @announcements }
14 format.xml { render :xml => @announcements }
16 end
15 end
17 end
16 end
@@ -17,13 +17,13
17 return nil unless session[:user_id]
17 return nil unless session[:user_id]
18 @current_user ||= User.find(session[:user_id])
18 @current_user ||= User.find(session[:user_id])
19 end
19 end
20
20
21 def admin_authorization
21 def admin_authorization
22 return false unless authenticate
22 return false unless authenticate
23 - user = User.find(session[:user_id], :include => ['roles'])
23 + user = User.includes(:roles).find(session[:user_id])
24 unless user.admin?
24 unless user.admin?
25 unauthorized_redirect
25 unauthorized_redirect
26 return false
26 return false
27 end
27 end
28 return true
28 return true
29 end
29 end
@@ -2,14 +2,13
2
2
3 before_filter :authenticate
3 before_filter :authenticate
4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
4 before_filter { |controller| controller.authorization_by_roles(['admin'])}
5
5
6
6
7 def index
7 def index
8 - @configurations = GraderConfiguration.find(:all,
8 + @configurations = GraderConfiguration.order(:key)
9 - :order => '`key`')
10 @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort
9 @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort
11 end
10 end
12
11
13 def reload
12 def reload
14 GraderConfiguration.reload
13 GraderConfiguration.reload
15 redirect_to :action => 'index'
14 redirect_to :action => 'index'
@@ -8,15 +8,15
8
8
9 def user_stat
9 def user_stat
10 if not GraderConfiguration.indv_contest_mode?
10 if not GraderConfiguration.indv_contest_mode?
11 redirect_to :action => 'index' and return
11 redirect_to :action => 'index' and return
12 end
12 end
13
13
14 - @users = User.find(:all)
14 + @users = User.all
15 @start_times = {}
15 @start_times = {}
16 - UserContestStat.find(:all).each do |stat|
16 + UserContestStat.all.each do |stat|
17 @start_times[stat.user_id] = stat.started_at
17 @start_times[stat.user_id] = stat.started_at
18 end
18 end
19 end
19 end
20
20
21 def clear_stat
21 def clear_stat
22 user = User.find(params[:id])
22 user = User.find(params[:id])
@@ -32,16 +32,14
32 def list
32 def list
33 @grader_processes = GraderProcess.find_running_graders
33 @grader_processes = GraderProcess.find_running_graders
34 @stalled_processes = GraderProcess.find_stalled_process
34 @stalled_processes = GraderProcess.find_stalled_process
35
35
36 @terminated_processes = GraderProcess.find_terminated_graders
36 @terminated_processes = GraderProcess.find_terminated_graders
37
37
38 - @last_task = Task.find(:first,
38 + @last_task = Task.last
39 - :order => 'created_at DESC')
39 + @last_test_request = TestRequest.last
40 - @last_test_request = TestRequest.find(:first,
41 - :order => 'created_at DESC')
42 @submission = Submission.order("id desc").limit(20)
40 @submission = Submission.order("id desc").limit(20)
43 @backlog_submission = Submission.where('graded_at is null')
41 @backlog_submission = Submission.where('graded_at is null')
44 end
42 end
45
43
46 def clear
44 def clear
47 grader_proc = GraderProcess.find(params[:id])
45 grader_proc = GraderProcess.find(params[:id])
@@ -54,13 +52,13
54 p.destroy
52 p.destroy
55 end
53 end
56 redirect_to :action => 'list'
54 redirect_to :action => 'list'
57 end
55 end
58
56
59 def clear_all
57 def clear_all
60 - GraderProcess.find(:all).each do |p|
58 + GraderProcess.all.each do |p|
61 p.destroy
59 p.destroy
62 end
60 end
63 redirect_to :action => 'list'
61 redirect_to :action => 'list'
64 end
62 end
65
63
66 def view
64 def view
@@ -42,13 +42,13
42 # logger.info "PATH: #{request.path}"
42 # logger.info "PATH: #{request.path}"
43 # if GraderConfiguration['system.single_user_mode'] and
43 # if GraderConfiguration['system.single_user_mode'] and
44 # request.path!='/main/login'
44 # request.path!='/main/login'
45 # @hidelogin = true
45 # @hidelogin = true
46 # end
46 # end
47
47
48 - @announcements = Announcement.find_for_frontpage
48 + @announcements = Announcement.frontpage
49 render :action => 'login', :layout => 'empty'
49 render :action => 'login', :layout => 'empty'
50 end
50 end
51
51
52 def list
52 def list
53 prepare_list_information
53 prepare_list_information
54 end
54 end
@@ -214,15 +214,15
214 end
214 end
215
215
216 protected
216 protected
217
217
218 def prepare_announcements(recent=nil)
218 def prepare_announcements(recent=nil)
219 if GraderConfiguration.show_tasks_to?(@user)
219 if GraderConfiguration.show_tasks_to?(@user)
220 - @announcements = Announcement.find_published(true)
220 + @announcements = Announcement.published(true)
221 else
221 else
222 - @announcements = Announcement.find_published
222 + @announcements = Announcement.published
223 end
223 end
224 if recent!=nil
224 if recent!=nil
225 recent_id = recent.to_i
225 recent_id = recent.to_i
226 @announcements = @announcements.find_all { |a| a.id > recent_id }
226 @announcements = @announcements.find_all { |a| a.id > recent_id }
227 end
227 end
228 end
228 end
@@ -4,13 +4,13
4
4
5 in_place_edit_for :problem, :name
5 in_place_edit_for :problem, :name
6 in_place_edit_for :problem, :full_name
6 in_place_edit_for :problem, :full_name
7 in_place_edit_for :problem, :full_score
7 in_place_edit_for :problem, :full_score
8
8
9 def index
9 def index
10 - @problems = Problem.find(:all, :order => 'date_added DESC')
10 + @problems = Problem.order(date_added: :desc)
11 end
11 end
12
12
13 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
13 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
14 verify :method => :post, :only => [ :create, :quick_create,
14 verify :method => :post, :only => [ :create, :quick_create,
15 :do_manage,
15 :do_manage,
16 :do_import,
16 :do_import,
@@ -132,23 +132,21
132 respond_to do |format|
132 respond_to do |format|
133 format.js { }
133 format.js { }
134 end
134 end
135 end
135 end
136
136
137 def turn_all_off
137 def turn_all_off
138 - Problem.find(:all,
138 + Problem.available.all.each do |problem|
139 - :conditions => "available = 1").each do |problem|
140 problem.available = false
139 problem.available = false
141 problem.save
140 problem.save
142 end
141 end
143 redirect_to action: :index
142 redirect_to action: :index
144 end
143 end
145
144
146 def turn_all_on
145 def turn_all_on
147 - Problem.find(:all,
146 + Problem.where.not(available: true).each do |problem|
148 - :conditions => "available = 0").each do |problem|
149 problem.available = true
147 problem.available = true
150 problem.save
148 problem.save
151 end
149 end
152 redirect_to action: :index
150 redirect_to action: :index
153 end
151 end
154
152
@@ -173,13 +171,13
173
171
174 @summary = { attempt: user.count, solve: 0 }
172 @summary = { attempt: user.count, solve: 0 }
175 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
173 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
176 end
174 end
177
175
178 def manage
176 def manage
179 - @problems = Problem.find(:all, :order => 'date_added DESC')
177 + @problems = Problem.order(date_added: :desc)
180 end
178 end
181
179
182 def do_manage
180 def do_manage
183 if params.has_key? 'change_date_added'
181 if params.has_key? 'change_date_added'
184 change_date_added
182 change_date_added
185 elsif params.has_key? 'add_to_contest'
183 elsif params.has_key? 'add_to_contest'
@@ -6,24 +6,20
6
6
7 before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score]
7 before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score]
8
8
9 before_filter(only: [:problem_hof]) { |c|
9 before_filter(only: [:problem_hof]) { |c|
10 return false unless authenticate
10 return false unless authenticate
11
11
12 - if GraderConfiguration["right.user_view_submission"]
12 + admin_authorization unless GraderConfiguration["right.user_view_submission"]
13 - return true;
14 - end
15 -
16 - admin_authorization
17 }
13 }
18
14
19 def max_score
15 def max_score
20 end
16 end
21
17
22 def current_score
18 def current_score
23 - @problems = Problem.find_available_problems
19 + @problems = Problem.available_problems
24 @users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
20 @users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
25 @scorearray = calculate_max_score(@problems, @users,0,0,true)
21 @scorearray = calculate_max_score(@problems, @users,0,0,true)
26
22
27 #rencer accordingly
23 #rencer accordingly
28 if params[:button] == 'download' then
24 if params[:button] == 'download' then
29 csv = gen_csv_from_scorearray(@scorearray,@problems)
25 csv = gen_csv_from_scorearray(@scorearray,@problems)
@@ -43,13 +39,13
43 pid = Problem.find_by_id(id.to_i)
39 pid = Problem.find_by_id(id.to_i)
44 @problems << pid if pid
40 @problems << pid if pid
45 end
41 end
46
42
47 #users
43 #users
48 @users = if params[:user] == "all" then
44 @users = if params[:user] == "all" then
49 - User.find(:all, :include => [:contests, :contest_stat])
45 + User.includes(:contests).includes(:contest_stat)
50 else
46 else
51 User.includes(:contests).includes(:contest_stat).where(enabled: true)
47 User.includes(:contests).includes(:contest_stat).where(enabled: true)
52 end
48 end
53
49
54 #set up range from param
50 #set up range from param
55 since_id = params.fetch(:from_id, 0).to_i
51 since_id = params.fetch(:from_id, 0).to_i
@@ -70,15 +66,15
70 end
66 end
71
67
72 def score
68 def score
73 if params[:commit] == 'download csv'
69 if params[:commit] == 'download csv'
74 @problems = Problem.all
70 @problems = Problem.all
75 else
71 else
76 - @problems = Problem.find_available_problems
72 + @problems = Problem.available_problems
77 end
73 end
78 - @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
74 + @users = User.includes(:contests, :contest_stat).where(enabled: true)
79 @scorearray = Array.new
75 @scorearray = Array.new
80 @users.each do |u|
76 @users.each do |u|
81 ustat = Array.new
77 ustat = Array.new
82 ustat[0] = u
78 ustat[0] = u
83 @problems.each do |p|
79 @problems.each do |p|
84 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
80 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
@@ -1,13 +1,13
1 class SiteController < ApplicationController
1 class SiteController < ApplicationController
2
2
3 before_filter :site_admin_authorization, :except => 'login'
3 before_filter :site_admin_authorization, :except => 'login'
4
4
5 def login
5 def login
6 # Site administrator login
6 # Site administrator login
7 - @countries = Country.find(:all, :include => :sites)
7 + @countries = Country.includes(:sites).all
8 @country_select = @countries.collect { |c| [c.name, c.id] }
8 @country_select = @countries.collect { |c| [c.name, c.id] }
9
9
10 @country_select_with_all = [['Any',0]]
10 @country_select_with_all = [['Any',0]]
11 @countries.each do |country|
11 @countries.each do |country|
12 @country_select_with_all << [country.name, country.id]
12 @country_select_with_all << [country.name, country.id]
13 end
13 end
@@ -2,13 +2,13
2
2
3 before_filter :admin_authorization
3 before_filter :admin_authorization
4
4
5 # GET /sites
5 # GET /sites
6 # GET /sites.xml
6 # GET /sites.xml
7 def index
7 def index
8 - @sites = Site.find(:all, :order => 'country_id')
8 + @sites = Site.order(:country_id)
9
9
10 respond_to do |format|
10 respond_to do |format|
11 format.html # index.html.erb
11 format.html # index.html.erb
12 format.xml { render :xml => @sites }
12 format.xml { render :xml => @sites }
13 end
13 end
14 end
14 end
@@ -26,13 +26,13
26 end
26 end
27 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
27 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
28 @contests = Contest.enabled
28 @contests = Contest.enabled
29 end
29 end
30
30
31 def active
31 def active
32 - sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
32 + sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago)
33 @users = []
33 @users = []
34 sessions.each do |session|
34 sessions.each do |session|
35 if session.data[:user_id]
35 if session.data[:user_id]
36 @users << User.find(session.data[:user_id])
36 @users << User.find(session.data[:user_id])
37 end
37 end
38 end
38 end
@@ -132,15 +132,15
132 end
132 end
133
133
134 def user_stat
134 def user_stat
135 if params[:commit] == 'download csv'
135 if params[:commit] == 'download csv'
136 @problems = Problem.all
136 @problems = Problem.all
137 else
137 else
138 - @problems = Problem.find_available_problems
138 + @problems = Problem.available_problems
139 end
139 end
140 - @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
140 + @users = User.includes(:contests, :contest_stat).where(enabled: true)
141 @scorearray = Array.new
141 @scorearray = Array.new
142 @users.each do |u|
142 @users.each do |u|
143 ustat = Array.new
143 ustat = Array.new
144 ustat[0] = u
144 ustat[0] = u
145 @problems.each do |p|
145 @problems.each do |p|
146 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
146 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
@@ -161,15 +161,15
161 end
161 end
162
162
163 def user_stat_max
163 def user_stat_max
164 if params[:commit] == 'download csv'
164 if params[:commit] == 'download csv'
165 @problems = Problem.all
165 @problems = Problem.all
166 else
166 else
167 - @problems = Problem.find_available_problems
167 + @problems = Problem.available_problems
168 end
168 end
169 - @users = User.find(:all, :include => [:contests, :contest_stat])
169 + @users = User.includes(:contests).includes(:contest_stat).all
170 @scorearray = Array.new
170 @scorearray = Array.new
171 #set up range from param
171 #set up range from param
172 since_id = params.fetch(:since_id, 0).to_i
172 since_id = params.fetch(:since_id, 0).to_i
173 until_id = params.fetch(:until_id, 0).to_i
173 until_id = params.fetch(:until_id, 0).to_i
174 @users.each do |u|
174 @users.each do |u|
175 ustat = Array.new
175 ustat = Array.new
@@ -198,13 +198,13
198 redirect_to :action => 'index' and return
198 redirect_to :action => 'index' and return
199 end
199 end
200 import_from_file(params[:file])
200 import_from_file(params[:file])
201 end
201 end
202
202
203 def random_all_passwords
203 def random_all_passwords
204 - users = User.find(:all)
204 + users = User.all
205 @prefix = params[:prefix] || ''
205 @prefix = params[:prefix] || ''
206 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
206 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
207 @changed = false
207 @changed = false
208 if request.request_method == 'POST'
208 if request.request_method == 'POST'
209 @non_admin_users.each do |user|
209 @non_admin_users.each do |user|
210 password = random_password
210 password = random_password
@@ -321,13 +321,13
321 redirect_to :action => 'contest_management'
321 redirect_to :action => 'contest_management'
322 end
322 end
323
323
324 # admin management
324 # admin management
325
325
326 def admin
326 def admin
327 - @admins = User.find(:all).find_all {|user| user.admin? }
327 + @admins = User.all.find_all {|user| user.admin? }
328 end
328 end
329
329
330 def grant_admin
330 def grant_admin
331 login = params[:login]
331 login = params[:login]
332 user = User.find_by_login(login)
332 user = User.find_by_login(login)
333 if user!=nil
333 if user!=nil
@@ -1,21 +1,15
1 class Announcement < ActiveRecord::Base
1 class Announcement < ActiveRecord::Base
2
2
3 - def self.find_published(contest_started=false)
3 + def self.published(contest_started=false)
4 if contest_started
4 if contest_started
5 - Announcement.find(:all,
5 + where(published: true).where(frontpage: false).order(created_at: :desc)
6 - :conditions => "(published = 1) AND (frontpage = 0)",
7 - :order => "created_at DESC")
8 else
6 else
9 - Announcement.find(:all,
7 + where(published: true).where(frontpage: false).where(contest_only: false).order(created_at: :desc)
10 - :conditions => "(published = 1) AND (frontpage = 0) AND (contest_only = 0)",
11 - :order => "created_at DESC")
12 end
8 end
13 end
9 end
14
10
15 - def self.find_for_frontpage
11 + def self.frontpage
16 - Announcement.find(:all,
12 + where(published: 1).where(frontpage: 1).order(created_at: :desc)
17 - :conditions => "(published = 1) AND (frontpage = 1)",
18 - :order => "created_at DESC")
19 end
13 end
20
14
21 end
15 end
@@ -149,13 +149,13
149 return (val=='true')
149 return (val=='true')
150 end
150 end
151 end
151 end
152
152
153 def self.read_config
153 def self.read_config
154 GraderConfiguration.config_cache = {}
154 GraderConfiguration.config_cache = {}
155 - GraderConfiguration.find(:all).each do |conf|
155 + GraderConfiguration.all.each do |conf|
156 key = conf.key
156 key = conf.key
157 val = conf.value
157 val = conf.value
158 GraderConfiguration.config_cache[key] = GraderConfiguration.convert_type(val,conf.value_type)
158 GraderConfiguration.config_cache[key] = GraderConfiguration.convert_type(val,conf.value_type)
159 end
159 end
160 end
160 end
161
161
@@ -1,14 +1,10
1 class GraderProcess < ActiveRecord::Base
1 class GraderProcess < ActiveRecord::Base
2
2
3 def self.find_by_host_and_pid(host,pid)
3 def self.find_by_host_and_pid(host,pid)
4 - return GraderProcess.find(:first,
4 + return GraderProcess.where(host:host).where(pid: pid).first
5 - :conditions => {
6 - :host => host,
7 - :pid => pid
8 - })
9 end
5 end
10
6
11 def self.register(host,pid,mode)
7 def self.register(host,pid,mode)
12 grader = GraderProcess.find_by_host_and_pid(host,pid)
8 grader = GraderProcess.find_by_host_and_pid(host,pid)
13 if grader
9 if grader
14 grader.mode = mode
10 grader.mode = mode
@@ -24,26 +20,21
24 :terminated => false)
20 :terminated => false)
25 end
21 end
26 grader
22 grader
27 end
23 end
28
24
29 def self.find_running_graders
25 def self.find_running_graders
30 - GraderProcess.find(:all,
26 + where(terminated: false)
31 - :conditions => {:terminated => 0})
32 end
27 end
33
28
34 def self.find_terminated_graders
29 def self.find_terminated_graders
35 - GraderProcess.find(:all,
30 + where(terminated: true)
36 - :conditions => "`terminated`")
37 end
31 end
38
32
39 def self.find_stalled_process
33 def self.find_stalled_process
40 - GraderProcess.find(:all,
34 + where(terminated: false).where(active: true).where("updated_at < ?",Time.now.gmtime - GraderProcess.stalled_time)
41 - :conditions => ["(`terminated` = 0) AND active AND " +
42 - "(updated_at < ?)",
43 - Time.now.gmtime - GraderProcess.stalled_time])
44 end
35 end
45
36
46 def report_active(task=nil)
37 def report_active(task=nil)
47 self.active = true
38 self.active = true
48 if task!=nil
39 if task!=nil
49 self.task_id = task.id
40 self.task_id = task.id
@@ -1,13 +1,13
1 class Language < ActiveRecord::Base
1 class Language < ActiveRecord::Base
2
2
3 @@languages_by_ext = {}
3 @@languages_by_ext = {}
4
4
5 def self.cache_ext_hash
5 def self.cache_ext_hash
6 @@languages_by_ext = {}
6 @@languages_by_ext = {}
7 - Language.find(:all).each do |language|
7 + Language.all.each do |language|
8 language.common_ext.split(',').each do |ext|
8 language.common_ext.split(',').each do |ext|
9 @@languages_by_ext[ext] = language
9 @@languages_by_ext[ext] = language
10 end
10 end
11 end
11 end
12 end
12 end
13
13
@@ -20,16 +20,14
20 replied_messages = user.replied_messages
20 replied_messages = user.replied_messages
21 Message.build_replying_message_hierarchy messages, replied_messages
21 Message.build_replying_message_hierarchy messages, replied_messages
22 return messages
22 return messages
23 end
23 end
24
24
25 def self.find_all_system_unreplied_messages
25 def self.find_all_system_unreplied_messages
26 - self.find(:all,
26 + where('ISNULL(receiver_id) ' +
27 - :conditions => 'ISNULL(receiver_id) ' +
27 + 'AND (ISNULL(replied) OR replied=0)')
28 - 'AND (ISNULL(replied) OR replied=0)',
29 - :order => 'created_at')
30 end
28 end
31
29
32 def self.build_replying_message_hierarchy(*args)
30 def self.build_replying_message_hierarchy(*args)
33 # manually build replies hierarchy (to improve efficiency)
31 # manually build replies hierarchy (to improve efficiency)
34 all_messages = {}
32 all_messages = {}
35
33
@@ -6,19 +6,20
6 has_many :testcases, :dependent => :destroy
6 has_many :testcases, :dependent => :destroy
7
7
8 validates_presence_of :name
8 validates_presence_of :name
9 validates_format_of :name, :with => /\A\w+\z/
9 validates_format_of :name, :with => /\A\w+\z/
10 validates_presence_of :full_name
10 validates_presence_of :full_name
11
11
12 - scope :available, :conditions => {:available => true}
12 + scope :available, -> { where(available: true) }
13
13
14 DEFAULT_TIME_LIMIT = 1
14 DEFAULT_TIME_LIMIT = 1
15 DEFAULT_MEMORY_LIMIT = 32
15 DEFAULT_MEMORY_LIMIT = 32
16
16
17 - def self.find_available_problems
17 + def self.available_problems
18 - Problem.available.all(:order => "date_added DESC, name ASC")
18 + available.order(date_added: :desc).order(:name)
19 + #Problem.available.all(:order => "date_added DESC, name ASC")
19 end
20 end
20
21
21 def self.create_from_import_form_params(params, old_problem=nil)
22 def self.create_from_import_form_params(params, old_problem=nil)
22 org_problem = old_problem || Problem.new
23 org_problem = old_problem || Problem.new
23 import_params, problem = Problem.extract_params_and_check(params,
24 import_params, problem = Problem.extract_params_and_check(params,
24 org_problem)
25 org_problem)
@@ -13,17 +13,13
13 validate :must_have_valid_problem
13 validate :must_have_valid_problem
14 validate :must_specify_language
14 validate :must_specify_language
15
15
16 before_save :assign_latest_number_if_new_recond
16 before_save :assign_latest_number_if_new_recond
17
17
18 def self.find_last_by_user_and_problem(user_id, problem_id)
18 def self.find_last_by_user_and_problem(user_id, problem_id)
19 - last_sub = find(:first,
19 + where("user_id = ? AND problem_id = ?",user_id,problem_id).last
20 - :conditions => {:user_id => user_id,
21 - :problem_id => problem_id},
22 - :order => 'number DESC')
23 - return last_sub
24 end
20 end
25
21
26 def self.find_all_last_by_problem(problem_id)
22 def self.find_all_last_by_problem(problem_id)
27 # need to put in SQL command, maybe there's a better way
23 # need to put in SQL command, maybe there's a better way
28 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
24 Submission.includes(:user).find_by_sql("SELECT * FROM submissions " +
29 "WHERE id = " +
25 "WHERE id = " +
@@ -40,35 +36,26
40 records = records.where('id <= ?',until_id) if until_id > 0
36 records = records.where('id <= ?',until_id) if until_id > 0
41 records.all
37 records.all
42 end
38 end
43
39
44 def self.find_last_for_all_available_problems(user_id)
40 def self.find_last_for_all_available_problems(user_id)
45 submissions = Array.new
41 submissions = Array.new
46 - problems = Problem.find_available_problems
42 + problems = Problem.available_problems
47 problems.each do |problem|
43 problems.each do |problem|
48 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
44 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
49 submissions << sub if sub!=nil
45 submissions << sub if sub!=nil
50 end
46 end
51 submissions
47 submissions
52 end
48 end
53
49
54 def self.find_by_user_problem_number(user_id, problem_id, number)
50 def self.find_by_user_problem_number(user_id, problem_id, number)
55 - Submission.find(:first,
51 + where("user_id = ? AND problem_id = ? AND number = ?",user_id,problem_id,number).first
56 - :conditions => {
57 - :user_id => user_id,
58 - :problem_id => problem_id,
59 - :number => number
60 - })
61 end
52 end
62
53
63 def self.find_all_by_user_problem(user_id, problem_id)
54 def self.find_all_by_user_problem(user_id, problem_id)
64 - Submission.find(:all,
55 + where("user_id = ? AND problem_id = ?",user_id,problem_id)
65 - :conditions => {
66 - :user_id => user_id,
67 - :problem_id => problem_id,
68 - })
69 end
56 end
70
57
71 def download_filename
58 def download_filename
72 if self.problem.output_only
59 if self.problem.output_only
73 return self.source_filename
60 return self.source_filename
74 else
61 else
@@ -45,16 +45,13
45 end
45 end
46
46
47 def self.get_inqueue_and_change_status(status)
47 def self.get_inqueue_and_change_status(status)
48 task = nil
48 task = nil
49 begin
49 begin
50 Task.transaction do
50 Task.transaction do
51 - task = Task.find(:first,
51 + task = Task.where(status: Task::STATUS_INQUEUE).where(lock: true).first
52 - :order => "created_at",
53 - :conditions => {:status=> Task::STATUS_INQUEUE},
54 - :lock => true)
55 if task!=nil
52 if task!=nil
56 task.status = status
53 task.status = status
57 task.save!
54 task.save!
58 end
55 end
59 end
56 end
60
57
@@ -34,15 +34,13
34 end
34 end
35
35
36 def self.get_inqueue_and_change_status(status)
36 def self.get_inqueue_and_change_status(status)
37 # since there will be only one grader grading TestRequest
37 # since there will be only one grader grading TestRequest
38 # we do not need locking (hopefully)
38 # we do not need locking (hopefully)
39
39
40 - test_request = TestRequest.find(:first,
40 + test_request = TestRequest.where(status: Task::STATUS_INQUEUE).first
41 - :order => "created_at",
42 - :conditions => {:status=> Task::STATUS_INQUEUE})
43 if test_request!=nil
41 if test_request!=nil
44 test_request.status = status
42 test_request.status = status
45 test_request.save!
43 test_request.save!
46 end
44 end
47
45
48 test_request
46 test_request
@@ -172,20 +172,20
172 password = ''
172 password = ''
173 length.times { password << chars[rand(chars.length - 1)] }
173 length.times { password << chars[rand(chars.length - 1)] }
174 password
174 password
175 end
175 end
176
176
177 def self.find_non_admin_with_prefix(prefix='')
177 def self.find_non_admin_with_prefix(prefix='')
178 - users = User.find(:all)
178 + users = User.all
179 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
179 return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 }
180 end
180 end
181
181
182 # Contest information
182 # Contest information
183
183
184 def self.find_users_with_no_contest()
184 def self.find_users_with_no_contest()
185 - users = User.find(:all)
185 + users = User.all
186 return users.find_all { |u| u.contests.length == 0 }
186 return users.find_all { |u| u.contests.length == 0 }
187 end
187 end
188
188
189
189
190 def contest_time_left
190 def contest_time_left
191 if GraderConfiguration.contest_mode?
191 if GraderConfiguration.contest_mode?
@@ -278,13 +278,13
278 }
278 }
279 return contest_problems
279 return contest_problems
280 end
280 end
281
281
282 def available_problems
282 def available_problems
283 if not GraderConfiguration.multicontests?
283 if not GraderConfiguration.multicontests?
284 - return Problem.find_available_problems
284 + return Problem.available_problems
285 else
285 else
286 contest_problems = []
286 contest_problems = []
287 pin = {}
287 pin = {}
288 contests.enabled.each do |contest|
288 contests.enabled.each do |contest|
289 contest.problems.available.each do |problem|
289 contest.problems.available.each do |problem|
290 if not pin.has_key? problem.id
290 if not pin.has_key? problem.id
@@ -14,13 +14,13
14 %tbody
14 %tbody
15 - @scorearray.each do |sc|
15 - @scorearray.each do |sc|
16 %tr
16 %tr
17 - total,num_passed = 0,0
17 - total,num_passed = 0,0
18 - sc.each_index do |i|
18 - sc.each_index do |i|
19 - if i == 0
19 - if i == 0
20 - %td= link_to sc[i].login, controller: 'users', action: 'profile', id: sc[i]
20 + %td= link_to sc[i].login, stat_user_path(sc[i])
21 %td= sc[i].full_name
21 %td= sc[i].full_name
22 / %td= sc[i].activated
22 / %td= sc[i].activated
23 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
23 / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no'
24 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
24 / %td= sc[i].contests.collect {|c| c.name}.join(', ')
25 %td= sc[i].remark
25 %td= sc[i].remark
26 - else
26 - else
@@ -1,11 +1,11
1 ENV["RAILS_ENV"] = "test"
1 ENV["RAILS_ENV"] = "test"
2 require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
2 require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
3
3
4 def clear_all_tasks
4 def clear_all_tasks
5 - Task.find(:all).each do |task|
5 + Task.all.each do |task|
6 task.destroy
6 task.destroy
7 end
7 end
8 end
8 end
9
9
10
10
11 clear_all_tasks
11 clear_all_tasks
@@ -1,14 +1,13
1 ENV["RAILS_ENV"] = "test"
1 ENV["RAILS_ENV"] = "test"
2 require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
2 require File.expand_path(File.dirname(__FILE__) + "/../../config/environment")
3
3
4 def clear_all_tasks
4 def clear_all_tasks
5 - Task.find(:all).each do |task|
5 + Task.all.each do |task|
6 task.destroy
6 task.destroy
7 end
7 end
8 end
8 end
9
9
10 - puts Task.find(:all,
10 + puts Task.where(status: Task::STATUS_COMPLETE).length
11 - :conditions => {:status => Task::STATUS_COMPLETE}).length
12
11
13 clear_all_tasks
12 clear_all_tasks
14
13
You need to be logged in to leave comments. Login now