Description:
change find(:xxx) to correct syntax for rails 4
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r619:35d86016ce86 - - 26 files changed: 108 inserted, 147 deleted
@@ -1,15 +1,15 | |||
|
1 | 1 | source 'https://rubygems.org' |
|
2 | 2 | |
|
3 |
- gem 'rails', '~>4. |
|
|
3 | + gem 'rails', '~>4.1.0' | |
|
4 | 4 | gem 'activerecord-session_store' |
|
5 | 5 | |
|
6 | 6 | gem 'select2-rails' |
|
7 | 7 | |
|
8 | 8 | # Bundle edge Rails instead: |
|
9 | 9 | # gem 'rails', :git => 'git://github.com/rails/rails.git' |
|
10 | 10 | |
|
11 | 11 | gem 'mysql2', '~> 0.3.0' |
|
12 | 12 | |
|
13 | 13 | # Gems used only for assets and not required |
|
14 | 14 | # in production environments by default. |
|
15 | 15 | group :assets do |
@@ -1,142 +1,147 | |||
|
1 | 1 | GIT |
|
2 | 2 | remote: https://github.com/sikachu/verification.git |
|
3 | 3 | revision: e6fe084ce16b7b5a4b1cdfca5374d125fd034a0f |
|
4 | 4 | specs: |
|
5 | 5 | verification (1.0.3) |
|
6 | 6 | actionpack (>= 3.0.0, < 5.0) |
|
7 | 7 | activesupport (>= 3.0.0, < 5.0) |
|
8 | 8 | |
|
9 | 9 | GEM |
|
10 | 10 | remote: https://rubygems.org/ |
|
11 | 11 | specs: |
|
12 | 12 | ace-rails-ap (4.1.1) |
|
13 |
- actionmailer (4. |
|
|
14 |
- actionpack (= 4. |
|
|
13 | + actionmailer (4.1.16) | |
|
14 | + actionpack (= 4.1.16) | |
|
15 | + actionview (= 4.1.16) | |
|
15 | 16 | mail (~> 2.5, >= 2.5.4) |
|
16 |
- actionpack (4. |
|
|
17 |
- acti |
|
|
18 | - builder (~> 3.1.0) | |
|
19 | - erubis (~> 2.7.0) | |
|
17 | + actionpack (4.1.16) | |
|
18 | + actionview (= 4.1.16) | |
|
19 | + activesupport (= 4.1.16) | |
|
20 | 20 | rack (~> 1.5.2) |
|
21 | 21 | rack-test (~> 0.6.2) |
|
22 |
- acti |
|
|
23 |
- activesupport (= 4. |
|
|
24 |
- builder (~> 3.1 |
|
|
25 | - activerecord (4.0.13) | |
|
26 |
- |
|
|
27 | - activerecord-deprecated_finders (~> 1.0.2) | |
|
28 | - activesupport (= 4.0.13) | |
|
29 | - arel (~> 4.0.0) | |
|
30 | - activerecord-deprecated_finders (1.0.4) | |
|
22 | + actionview (4.1.16) | |
|
23 | + activesupport (= 4.1.16) | |
|
24 | + builder (~> 3.1) | |
|
25 | + erubis (~> 2.7.0) | |
|
26 | + activemodel (4.1.16) | |
|
27 | + activesupport (= 4.1.16) | |
|
28 | + builder (~> 3.1) | |
|
29 | + activerecord (4.1.16) | |
|
30 | + activemodel (= 4.1.16) | |
|
31 | + activesupport (= 4.1.16) | |
|
32 | + arel (~> 5.0.0) | |
|
31 | 33 | activerecord-session_store (1.0.0) |
|
32 | 34 | actionpack (>= 4.0, < 5.1) |
|
33 | 35 | activerecord (>= 4.0, < 5.1) |
|
34 | 36 | multi_json (~> 1.11, >= 1.11.2) |
|
35 | 37 | rack (>= 1.5.2, < 3) |
|
36 | 38 | railties (>= 4.0, < 5.1) |
|
37 |
- activesupport (4. |
|
|
39 | + activesupport (4.1.16) | |
|
38 | 40 | i18n (~> 0.6, >= 0.6.9) |
|
39 | - minitest (~> 4.2) | |
|
40 |
- m |
|
|
41 | + json (~> 1.7, >= 1.7.7) | |
|
42 | + minitest (~> 5.1) | |
|
41 | 43 | thread_safe (~> 0.1) |
|
42 |
- tzinfo (~> |
|
|
43 |
- arel ( |
|
|
44 |
- autoprefixer-rails (6.5. |
|
|
44 | + tzinfo (~> 1.1) | |
|
45 | + arel (5.0.1.20140414130214) | |
|
46 | + autoprefixer-rails (6.5.3.1) | |
|
45 | 47 | execjs |
|
46 | 48 | best_in_place (3.0.3) |
|
47 | 49 | actionpack (>= 3.2) |
|
48 | 50 | railties (>= 3.2) |
|
49 | 51 | bootstrap-sass (3.2.0.2) |
|
50 | 52 | sass (~> 3.2) |
|
51 | 53 | bootstrap-switch-rails (3.3.3) |
|
52 | 54 | bootstrap-toggle-rails (2.2.1.0) |
|
53 |
- builder (3. |
|
|
55 | + builder (3.2.2) | |
|
54 | 56 | coffee-rails (4.2.1) |
|
55 | 57 | coffee-script (>= 2.2.0) |
|
56 | 58 | railties (>= 4.0.0, < 5.2.x) |
|
57 | 59 | coffee-script (2.4.1) |
|
58 | 60 | coffee-script-source |
|
59 | 61 | execjs |
|
60 |
- coffee-script-source (1.1 |
|
|
62 | + coffee-script-source (1.11.1) | |
|
61 | 63 | concurrent-ruby (1.0.2) |
|
62 | 64 | diff-lcs (1.2.5) |
|
63 | 65 | dynamic_form (1.1.4) |
|
64 | 66 | erubis (2.7.0) |
|
65 | 67 | execjs (2.7.0) |
|
66 | 68 | haml (4.0.7) |
|
67 | 69 | tilt |
|
68 | 70 | haml-rails (0.9.0) |
|
69 | 71 | actionpack (>= 4.0.1) |
|
70 | 72 | activesupport (>= 4.0.1) |
|
71 | 73 | haml (>= 4.0.6, < 5.0) |
|
72 | 74 | html2haml (>= 1.0.1) |
|
73 | 75 | railties (>= 4.0.1) |
|
74 | 76 | html2haml (2.0.0) |
|
75 | 77 | erubis (~> 2.7.0) |
|
76 | 78 | haml (~> 4.0.0) |
|
77 | 79 | nokogiri (~> 1.6.0) |
|
78 | 80 | ruby_parser (~> 3.5) |
|
79 | 81 | i18n (0.7.0) |
|
80 | 82 | in_place_editing (1.2.0) |
|
81 | 83 | jquery-countdown-rails (2.0.2) |
|
82 | 84 | jquery-rails (3.1.4) |
|
83 | 85 | railties (>= 3.0, < 5.0) |
|
84 | 86 | thor (>= 0.14, < 2.0) |
|
85 |
- jquery-tablesorter (1.2 |
|
|
87 | + jquery-tablesorter (1.23.1) | |
|
86 | 88 | railties (>= 3.2, < 6) |
|
87 | 89 | jquery-timepicker-addon-rails (1.4.1) |
|
88 | 90 | railties (>= 3.1) |
|
89 | 91 | jquery-ui-rails (4.0.3) |
|
90 | 92 | jquery-rails |
|
91 | 93 | railties (>= 3.1.0) |
|
92 | 94 | jquery-ui-sass-rails (4.0.3.0) |
|
93 | 95 | jquery-rails |
|
94 | 96 | jquery-ui-rails (= 4.0.3) |
|
95 | 97 | railties (>= 3.1.0) |
|
98 | + json (1.8.3) | |
|
96 | 99 | mail (2.6.4) |
|
97 | 100 | mime-types (>= 1.16, < 4) |
|
98 | 101 | mime-types (3.1) |
|
99 | 102 | mime-types-data (~> 3.2015) |
|
100 | 103 | mime-types-data (3.2016.0521) |
|
101 | 104 | mini_portile2 (2.1.0) |
|
102 |
- minitest ( |
|
|
105 | + minitest (5.10.1) | |
|
103 | 106 | momentjs-rails (2.15.1) |
|
104 | 107 | railties (>= 3.1) |
|
105 | 108 | multi_json (1.12.1) |
|
106 | 109 | mysql2 (0.3.21) |
|
107 | 110 | nokogiri (1.6.8.1) |
|
108 | 111 | mini_portile2 (~> 2.1.0) |
|
109 |
- power_assert (0. |
|
|
112 | + power_assert (0.4.1) | |
|
110 | 113 | rack (1.5.5) |
|
111 | 114 | rack-test (0.6.3) |
|
112 | 115 | rack (>= 1.0) |
|
113 |
- rails (4. |
|
|
114 |
- actionmailer (= 4. |
|
|
115 |
- actionpack (= 4. |
|
|
116 |
- acti |
|
|
117 |
- active |
|
|
116 | + rails (4.1.16) | |
|
117 | + actionmailer (= 4.1.16) | |
|
118 | + actionpack (= 4.1.16) | |
|
119 | + actionview (= 4.1.16) | |
|
120 | + activemodel (= 4.1.16) | |
|
121 | + activerecord (= 4.1.16) | |
|
122 | + activesupport (= 4.1.16) | |
|
118 | 123 | bundler (>= 1.3.0, < 2.0) |
|
119 |
- railties (= 4. |
|
|
124 | + railties (= 4.1.16) | |
|
120 | 125 | sprockets-rails (~> 2.0) |
|
121 | 126 | rails_bootstrap_sortable (2.0.1) |
|
122 | 127 | momentjs-rails (>= 2.8.3) |
|
123 |
- railties (4. |
|
|
124 |
- actionpack (= 4. |
|
|
125 |
- activesupport (= 4. |
|
|
128 | + railties (4.1.16) | |
|
129 | + actionpack (= 4.1.16) | |
|
130 | + activesupport (= 4.1.16) | |
|
126 | 131 | rake (>= 0.8.7) |
|
127 | 132 | thor (>= 0.18.1, < 2.0) |
|
128 |
- rake (1 |
|
|
133 | + rake (12.0.0) | |
|
129 | 134 | rdiscount (2.2.0.1) |
|
130 |
- rouge (2.0. |
|
|
135 | + rouge (2.0.7) | |
|
131 | 136 | rspec-collection_matchers (1.1.2) |
|
132 | 137 | rspec-expectations (>= 2.99.0.beta1) |
|
133 | 138 | rspec-core (2.99.2) |
|
134 | 139 | rspec-expectations (2.99.2) |
|
135 | 140 | diff-lcs (>= 1.1.3, < 2.0) |
|
136 | 141 | rspec-mocks (2.99.4) |
|
137 | 142 | rspec-rails (2.99.0) |
|
138 | 143 | actionpack (>= 3.0) |
|
139 | 144 | activemodel (>= 3.0) |
|
140 | 145 | activesupport (>= 3.0) |
|
141 | 146 | railties (>= 3.0) |
|
142 | 147 | rspec-collection_matchers |
@@ -153,31 +158,32 | |||
|
153 | 158 | sprockets-rails (>= 2.0, < 4.0) |
|
154 | 159 | tilt (>= 1.1, < 3) |
|
155 | 160 | select2-rails (4.0.3) |
|
156 | 161 | thor (~> 0.14) |
|
157 | 162 | sexp_processor (4.7.0) |
|
158 | 163 | sprockets (3.7.0) |
|
159 | 164 | concurrent-ruby (~> 1.0) |
|
160 | 165 | rack (> 1, < 3) |
|
161 | 166 | sprockets-rails (2.3.3) |
|
162 | 167 | actionpack (>= 3.0) |
|
163 | 168 | activesupport (>= 3.0) |
|
164 | 169 | sprockets (>= 2.8, < 4.0) |
|
165 |
- test-unit (3.2. |
|
|
170 | + test-unit (3.2.3) | |
|
166 | 171 | power_assert |
|
167 |
- thor (0.19. |
|
|
172 | + thor (0.19.4) | |
|
168 | 173 | thread_safe (0.3.5) |
|
169 | 174 | tilt (2.0.5) |
|
170 |
- tzinfo ( |
|
|
171 | - uglifier (3.0.3) | |
|
175 | + tzinfo (1.2.2) | |
|
176 | + thread_safe (~> 0.1) | |
|
177 | + uglifier (3.0.4) | |
|
172 | 178 | execjs (>= 0.3.0, < 3) |
|
173 | 179 | will_paginate (3.0.12) |
|
174 | 180 | |
|
175 | 181 | PLATFORMS |
|
176 | 182 | ruby |
|
177 | 183 | |
|
178 | 184 | DEPENDENCIES |
|
179 | 185 | ace-rails-ap |
|
180 | 186 | activerecord-session_store |
|
181 | 187 | autoprefixer-rails |
|
182 | 188 | best_in_place (~> 3.0.1) |
|
183 | 189 | bootstrap-sass (~> 3.2.0) |
@@ -187,25 +193,25 | |||
|
187 | 193 | dynamic_form |
|
188 | 194 | haml |
|
189 | 195 | haml-rails |
|
190 | 196 | in_place_editing |
|
191 | 197 | jquery-countdown-rails |
|
192 | 198 | jquery-rails |
|
193 | 199 | jquery-tablesorter |
|
194 | 200 | jquery-timepicker-addon-rails |
|
195 | 201 | jquery-ui-sass-rails |
|
196 | 202 | |
|
197 | 203 | momentjs-rails |
|
198 | 204 | mysql2 (~> 0.3.0) |
|
199 |
- rails (~> 4. |
|
|
205 | + rails (~> 4.1.0) | |
|
200 | 206 | rails_bootstrap_sortable |
|
201 | 207 | rdiscount |
|
202 | 208 | rouge |
|
203 | 209 | rspec-rails (~> 2.99.0) |
|
204 | 210 | sass-rails |
|
205 | 211 | select2-rails |
|
206 | 212 | test-unit |
|
207 | 213 | uglifier |
|
208 | 214 | verification! |
|
209 | 215 | will_paginate (~> 3.0.7) |
|
210 | 216 | |
|
211 | 217 | BUNDLED WITH |
@@ -1,23 +1,22 | |||
|
1 | 1 | class AnnouncementsController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | in_place_edit_for :announcement, :published |
|
6 | 6 | |
|
7 | 7 | # GET /announcements |
|
8 | 8 | # GET /announcements.xml |
|
9 | 9 | def index |
|
10 |
- @announcements = Announcement. |
|
|
11 | - :order => "created_at DESC") | |
|
10 | + @announcements = Announcement.order(created_at: :desc) | |
|
12 | 11 | |
|
13 | 12 | respond_to do |format| |
|
14 | 13 | format.html # index.html.erb |
|
15 | 14 | format.xml { render :xml => @announcements } |
|
16 | 15 | end |
|
17 | 16 | end |
|
18 | 17 | |
|
19 | 18 | # GET /announcements/1 |
|
20 | 19 | # GET /announcements/1.xml |
|
21 | 20 | def show |
|
22 | 21 | @announcement = Announcement.find(params[:id]) |
|
23 | 22 |
@@ -11,25 +11,25 | |||
|
11 | 11 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
12 | 12 | redirect_to :controller => 'main', :action => 'login' |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | # Returns the current logged-in user (if any). |
|
16 | 16 | def current_user |
|
17 | 17 | return nil unless session[:user_id] |
|
18 | 18 | @current_user ||= User.find(session[:user_id]) |
|
19 | 19 | end |
|
20 | 20 | |
|
21 | 21 | def admin_authorization |
|
22 | 22 | return false unless authenticate |
|
23 |
- user = User.find(session[:user_id] |
|
|
23 | + user = User.includes(:roles).find(session[:user_id]) | |
|
24 | 24 | unless user.admin? |
|
25 | 25 | unauthorized_redirect |
|
26 | 26 | return false |
|
27 | 27 | end |
|
28 | 28 | return true |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def authorization_by_roles(allowed_roles) |
|
32 | 32 | return false unless authenticate |
|
33 | 33 | user = User.find(session[:user_id]) |
|
34 | 34 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
35 | 35 | unauthorized_redirect |
@@ -1,21 +1,20 | |||
|
1 | 1 | class ConfigurationsController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate |
|
4 | 4 | before_filter { |controller| controller.authorization_by_roles(['admin'])} |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | def index |
|
8 |
- @configurations = GraderConfiguration. |
|
|
9 | - :order => '`key`') | |
|
8 | + @configurations = GraderConfiguration.order(:key) | |
|
10 | 9 | @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort |
|
11 | 10 | end |
|
12 | 11 | |
|
13 | 12 | def reload |
|
14 | 13 | GraderConfiguration.reload |
|
15 | 14 | redirect_to :action => 'index' |
|
16 | 15 | end |
|
17 | 16 | |
|
18 | 17 | def update |
|
19 | 18 | @config = GraderConfiguration.find(params[:id]) |
|
20 | 19 | User.clear_last_login if @config.key == GraderConfiguration::MULTIPLE_IP_LOGIN_KEY and @config.value == 'true' and params[:grader_configuration][:value] == 'false' |
|
21 | 20 | respond_to do |format| |
@@ -2,27 +2,27 | |||
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | @num_contests = Contest.count() |
|
7 | 7 | end |
|
8 | 8 | |
|
9 | 9 | def user_stat |
|
10 | 10 | if not GraderConfiguration.indv_contest_mode? |
|
11 | 11 | redirect_to :action => 'index' and return |
|
12 | 12 | end |
|
13 | 13 | |
|
14 |
- @users = User. |
|
|
14 | + @users = User.all | |
|
15 | 15 | @start_times = {} |
|
16 |
- UserContestStat. |
|
|
16 | + UserContestStat.all.each do |stat| | |
|
17 | 17 | @start_times[stat.user_id] = stat.started_at |
|
18 | 18 | end |
|
19 | 19 | end |
|
20 | 20 | |
|
21 | 21 | def clear_stat |
|
22 | 22 | user = User.find(params[:id]) |
|
23 | 23 | if user.contest_stat!=nil |
|
24 | 24 | user.contest_stat.destroy |
|
25 | 25 | end |
|
26 | 26 | redirect_to :action => 'user_stat' |
|
27 | 27 | end |
|
28 | 28 |
@@ -26,47 +26,45 | |||
|
26 | 26 | :redirect_to => {:action => 'index'} |
|
27 | 27 | |
|
28 | 28 | def index |
|
29 | 29 | redirect_to :action => 'list' |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def list |
|
33 | 33 | @grader_processes = GraderProcess.find_running_graders |
|
34 | 34 | @stalled_processes = GraderProcess.find_stalled_process |
|
35 | 35 | |
|
36 | 36 | @terminated_processes = GraderProcess.find_terminated_graders |
|
37 | 37 | |
|
38 |
- @last_task = Task. |
|
|
39 | - :order => 'created_at DESC') | |
|
40 | - @last_test_request = TestRequest.find(:first, | |
|
41 | - :order => 'created_at DESC') | |
|
38 | + @last_task = Task.last | |
|
39 | + @last_test_request = TestRequest.last | |
|
42 | 40 | @submission = Submission.order("id desc").limit(20) |
|
43 | 41 | @backlog_submission = Submission.where('graded_at is null') |
|
44 | 42 | end |
|
45 | 43 | |
|
46 | 44 | def clear |
|
47 | 45 | grader_proc = GraderProcess.find(params[:id]) |
|
48 | 46 | grader_proc.destroy if grader_proc!=nil |
|
49 | 47 | redirect_to :action => 'list' |
|
50 | 48 | end |
|
51 | 49 | |
|
52 | 50 | def clear_terminated |
|
53 | 51 | GraderProcess.find_terminated_graders.each do |p| |
|
54 | 52 | p.destroy |
|
55 | 53 | end |
|
56 | 54 | redirect_to :action => 'list' |
|
57 | 55 | end |
|
58 | 56 | |
|
59 | 57 | def clear_all |
|
60 |
- GraderProcess. |
|
|
58 | + GraderProcess.all.each do |p| | |
|
61 | 59 | p.destroy |
|
62 | 60 | end |
|
63 | 61 | redirect_to :action => 'list' |
|
64 | 62 | end |
|
65 | 63 | |
|
66 | 64 | def view |
|
67 | 65 | if params[:type]=='Task' |
|
68 | 66 | redirect_to :action => 'task', :id => params[:id] |
|
69 | 67 | else |
|
70 | 68 | redirect_to :action => 'test_request', :id => params[:id] |
|
71 | 69 | end |
|
72 | 70 | end |
@@ -36,25 +36,25 | |||
|
36 | 36 | flash.now[:notice] = saved_notice |
|
37 | 37 | |
|
38 | 38 | # EXPERIMENT: |
|
39 | 39 | # Hide login if in single user mode and the url does not |
|
40 | 40 | # explicitly specify /login |
|
41 | 41 | # |
|
42 | 42 | # logger.info "PATH: #{request.path}" |
|
43 | 43 | # if GraderConfiguration['system.single_user_mode'] and |
|
44 | 44 | # request.path!='/main/login' |
|
45 | 45 | # @hidelogin = true |
|
46 | 46 | # end |
|
47 | 47 | |
|
48 |
- @announcements = Announcement. |
|
|
48 | + @announcements = Announcement.frontpage | |
|
49 | 49 | render :action => 'login', :layout => 'empty' |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def list |
|
53 | 53 | prepare_list_information |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | def help |
|
57 | 57 | @user = User.find(session[:user_id]) |
|
58 | 58 | end |
|
59 | 59 | |
|
60 | 60 | def submit |
@@ -208,27 +208,27 | |||
|
208 | 208 | user.update_start_time |
|
209 | 209 | redirect_to :action => 'list' |
|
210 | 210 | else |
|
211 | 211 | @contests = user.contests |
|
212 | 212 | @user = user |
|
213 | 213 | end |
|
214 | 214 | end |
|
215 | 215 | |
|
216 | 216 | protected |
|
217 | 217 | |
|
218 | 218 | def prepare_announcements(recent=nil) |
|
219 | 219 | if GraderConfiguration.show_tasks_to?(@user) |
|
220 |
- @announcements = Announcement. |
|
|
220 | + @announcements = Announcement.published(true) | |
|
221 | 221 | else |
|
222 |
- @announcements = Announcement. |
|
|
222 | + @announcements = Announcement.published | |
|
223 | 223 | end |
|
224 | 224 | if recent!=nil |
|
225 | 225 | recent_id = recent.to_i |
|
226 | 226 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
227 | 227 | end |
|
228 | 228 | end |
|
229 | 229 | |
|
230 | 230 | def prepare_list_information |
|
231 | 231 | @user = User.find(session[:user_id]) |
|
232 | 232 | if not GraderConfiguration.multicontests? |
|
233 | 233 | @problems = @user.available_problems |
|
234 | 234 | else |
@@ -1,22 +1,22 | |||
|
1 | 1 | class ProblemsController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :authenticate, :authorization |
|
4 | 4 | |
|
5 | 5 | in_place_edit_for :problem, :name |
|
6 | 6 | in_place_edit_for :problem, :full_name |
|
7 | 7 | in_place_edit_for :problem, :full_score |
|
8 | 8 | |
|
9 | 9 | def index |
|
10 |
- @problems = Problem. |
|
|
10 | + @problems = Problem.order(date_added: :desc) | |
|
11 | 11 | end |
|
12 | 12 | |
|
13 | 13 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
14 | 14 | verify :method => :post, :only => [ :create, :quick_create, |
|
15 | 15 | :do_manage, |
|
16 | 16 | :do_import, |
|
17 | 17 | ], |
|
18 | 18 | :redirect_to => { :action => :index } |
|
19 | 19 | |
|
20 | 20 | def show |
|
21 | 21 | @problem = Problem.find(params[:id]) |
|
22 | 22 | end |
@@ -126,35 +126,33 | |||
|
126 | 126 | end |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def toggle_test |
|
130 | 130 | @problem = Problem.find(params[:id]) |
|
131 | 131 | @problem.update_attributes(test_allowed: !(@problem.test_allowed?) ) |
|
132 | 132 | respond_to do |format| |
|
133 | 133 | format.js { } |
|
134 | 134 | end |
|
135 | 135 | end |
|
136 | 136 | |
|
137 | 137 | def turn_all_off |
|
138 | - Problem.find(:all, | |
|
139 | - :conditions => "available = 1").each do |problem| | |
|
138 | + Problem.available.all.each do |problem| | |
|
140 | 139 | problem.available = false |
|
141 | 140 | problem.save |
|
142 | 141 | end |
|
143 | 142 | redirect_to action: :index |
|
144 | 143 | end |
|
145 | 144 | |
|
146 | 145 | def turn_all_on |
|
147 | - Problem.find(:all, | |
|
148 | - :conditions => "available = 0").each do |problem| | |
|
146 | + Problem.where.not(available: true).each do |problem| | |
|
149 | 147 | problem.available = true |
|
150 | 148 | problem.save |
|
151 | 149 | end |
|
152 | 150 | redirect_to action: :index |
|
153 | 151 | end |
|
154 | 152 | |
|
155 | 153 | def stat |
|
156 | 154 | @problem = Problem.find(params[:id]) |
|
157 | 155 | unless @problem.available or session[:admin] |
|
158 | 156 | redirect_to :controller => 'main', :action => 'list' |
|
159 | 157 | return |
|
160 | 158 | end |
@@ -167,25 +165,25 | |||
|
167 | 165 | @submissions.find_each do |sub| |
|
168 | 166 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
169 | 167 | @histogram[:data][d.to_i] += 1 if d < range |
|
170 | 168 | user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max |
|
171 | 169 | end |
|
172 | 170 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
173 | 171 | |
|
174 | 172 | @summary = { attempt: user.count, solve: 0 } |
|
175 | 173 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
176 | 174 | end |
|
177 | 175 | |
|
178 | 176 | def manage |
|
179 |
- @problems = Problem. |
|
|
177 | + @problems = Problem.order(date_added: :desc) | |
|
180 | 178 | end |
|
181 | 179 | |
|
182 | 180 | def do_manage |
|
183 | 181 | if params.has_key? 'change_date_added' |
|
184 | 182 | change_date_added |
|
185 | 183 | elsif params.has_key? 'add_to_contest' |
|
186 | 184 | add_to_contest |
|
187 | 185 | elsif params.has_key? 'enable_problem' |
|
188 | 186 | set_available(true) |
|
189 | 187 | elsif params.has_key? 'disable_problem' |
|
190 | 188 | set_available(false) |
|
191 | 189 | end |
@@ -1,35 +1,31 | |||
|
1 | 1 | require 'csv' |
|
2 | 2 | |
|
3 | 3 | class ReportController < ApplicationController |
|
4 | 4 | |
|
5 | 5 | before_filter :authenticate |
|
6 | 6 | |
|
7 | 7 | before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score] |
|
8 | 8 | |
|
9 | 9 | before_filter(only: [:problem_hof]) { |c| |
|
10 | 10 | return false unless authenticate |
|
11 | 11 | |
|
12 |
- |
|
|
13 | - return true; | |
|
14 | - end | |
|
15 | - | |
|
16 | - admin_authorization | |
|
12 | + admin_authorization unless GraderConfiguration["right.user_view_submission"] | |
|
17 | 13 | } |
|
18 | 14 | |
|
19 | 15 | def max_score |
|
20 | 16 | end |
|
21 | 17 | |
|
22 | 18 | def current_score |
|
23 |
- @problems = Problem. |
|
|
19 | + @problems = Problem.available_problems | |
|
24 | 20 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
25 | 21 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
26 | 22 | |
|
27 | 23 | #rencer accordingly |
|
28 | 24 | if params[:button] == 'download' then |
|
29 | 25 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
30 | 26 | send_data csv, filename: 'max_score.csv' |
|
31 | 27 | else |
|
32 | 28 | #render template: 'user_admin/user_stat' |
|
33 | 29 | render 'current_score' |
|
34 | 30 | end |
|
35 | 31 | end |
@@ -37,25 +33,25 | |||
|
37 | 33 | def show_max_score |
|
38 | 34 | #process parameters |
|
39 | 35 | #problems |
|
40 | 36 | @problems = [] |
|
41 | 37 | params[:problem_id].each do |id| |
|
42 | 38 | next unless id.strip != "" |
|
43 | 39 | pid = Problem.find_by_id(id.to_i) |
|
44 | 40 | @problems << pid if pid |
|
45 | 41 | end |
|
46 | 42 | |
|
47 | 43 | #users |
|
48 | 44 | @users = if params[:user] == "all" then |
|
49 |
- User. |
|
|
45 | + User.includes(:contests).includes(:contest_stat) | |
|
50 | 46 | else |
|
51 | 47 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
52 | 48 | end |
|
53 | 49 | |
|
54 | 50 | #set up range from param |
|
55 | 51 | since_id = params.fetch(:from_id, 0).to_i |
|
56 | 52 | until_id = params.fetch(:to_id, 0).to_i |
|
57 | 53 | |
|
58 | 54 | #calculate the routine |
|
59 | 55 | @scorearray = calculate_max_score(@problems, @users,since_id,until_id) |
|
60 | 56 | |
|
61 | 57 | #rencer accordingly |
@@ -64,27 +60,27 | |||
|
64 | 60 | send_data csv, filename: 'max_score.csv' |
|
65 | 61 | else |
|
66 | 62 | #render template: 'user_admin/user_stat' |
|
67 | 63 | render 'max_score' |
|
68 | 64 | end |
|
69 | 65 | |
|
70 | 66 | end |
|
71 | 67 | |
|
72 | 68 | def score |
|
73 | 69 | if params[:commit] == 'download csv' |
|
74 | 70 | @problems = Problem.all |
|
75 | 71 | else |
|
76 |
- @problems = Problem. |
|
|
72 | + @problems = Problem.available_problems | |
|
77 | 73 | end |
|
78 |
- @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
|
74 | + @users = User.includes(:contests, :contest_stat).where(enabled: true) | |
|
79 | 75 | @scorearray = Array.new |
|
80 | 76 | @users.each do |u| |
|
81 | 77 | ustat = Array.new |
|
82 | 78 | ustat[0] = u |
|
83 | 79 | @problems.each do |p| |
|
84 | 80 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
85 | 81 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
86 | 82 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
87 | 83 | else |
|
88 | 84 | ustat << [0,false] |
|
89 | 85 | end |
|
90 | 86 | end |
@@ -1,19 +1,19 | |||
|
1 | 1 | class SiteController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :site_admin_authorization, :except => 'login' |
|
4 | 4 | |
|
5 | 5 | def login |
|
6 | 6 | # Site administrator login |
|
7 |
- @countries = Country. |
|
|
7 | + @countries = Country.includes(:sites).all | |
|
8 | 8 | @country_select = @countries.collect { |c| [c.name, c.id] } |
|
9 | 9 | |
|
10 | 10 | @country_select_with_all = [['Any',0]] |
|
11 | 11 | @countries.each do |country| |
|
12 | 12 | @country_select_with_all << [country.name, country.id] |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | @site_select = [] |
|
16 | 16 | @countries.each do |country| |
|
17 | 17 | country.sites.each do |site| |
|
18 | 18 | @site_select << ["#{site.name}, #{country.name}", site.id] |
|
19 | 19 | end |
@@ -1,20 +1,20 | |||
|
1 | 1 | class SitesController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization |
|
4 | 4 | |
|
5 | 5 | # GET /sites |
|
6 | 6 | # GET /sites.xml |
|
7 | 7 | def index |
|
8 |
- @sites = Site. |
|
|
8 | + @sites = Site.order(:country_id) | |
|
9 | 9 | |
|
10 | 10 | respond_to do |format| |
|
11 | 11 | format.html # index.html.erb |
|
12 | 12 | format.xml { render :xml => @sites } |
|
13 | 13 | end |
|
14 | 14 | end |
|
15 | 15 | |
|
16 | 16 | # GET /sites/1 |
|
17 | 17 | # GET /sites/1.xml |
|
18 | 18 | def show |
|
19 | 19 | @site = Site.find(params[:id]) |
|
20 | 20 |
@@ -20,25 +20,25 | |||
|
20 | 20 | if params[:page] == 'all' |
|
21 | 21 | @users = User.all |
|
22 | 22 | @paginated = false |
|
23 | 23 | else |
|
24 | 24 | @users = User.paginate :page => params[:page] |
|
25 | 25 | @paginated = true |
|
26 | 26 | end |
|
27 | 27 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | 28 | @contests = Contest.enabled |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def active |
|
32 |
- sessions = ActiveRecord::SessionStore::Session. |
|
|
32 | + sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) | |
|
33 | 33 | @users = [] |
|
34 | 34 | sessions.each do |session| |
|
35 | 35 | if session.data[:user_id] |
|
36 | 36 | @users << User.find(session.data[:user_id]) |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | end |
|
40 | 40 | |
|
41 | 41 | def show |
|
42 | 42 | @user = User.find(params[:id]) |
|
43 | 43 | end |
|
44 | 44 | |
@@ -126,27 +126,27 | |||
|
126 | 126 | end |
|
127 | 127 | end |
|
128 | 128 | |
|
129 | 129 | def destroy |
|
130 | 130 | User.find(params[:id]).destroy |
|
131 | 131 | redirect_to :action => 'index' |
|
132 | 132 | end |
|
133 | 133 | |
|
134 | 134 | def user_stat |
|
135 | 135 | if params[:commit] == 'download csv' |
|
136 | 136 | @problems = Problem.all |
|
137 | 137 | else |
|
138 |
- @problems = Problem. |
|
|
138 | + @problems = Problem.available_problems | |
|
139 | 139 | end |
|
140 |
- @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
|
140 | + @users = User.includes(:contests, :contest_stat).where(enabled: true) | |
|
141 | 141 | @scorearray = Array.new |
|
142 | 142 | @users.each do |u| |
|
143 | 143 | ustat = Array.new |
|
144 | 144 | ustat[0] = u |
|
145 | 145 | @problems.each do |p| |
|
146 | 146 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
147 | 147 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
148 | 148 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
149 | 149 | else |
|
150 | 150 | ustat << [0,false] |
|
151 | 151 | end |
|
152 | 152 | end |
@@ -155,27 +155,27 | |||
|
155 | 155 | if params[:commit] == 'download csv' then |
|
156 | 156 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
157 | 157 | send_data csv, filename: 'last_score.csv' |
|
158 | 158 | else |
|
159 | 159 | render template: 'user_admin/user_stat' |
|
160 | 160 | end |
|
161 | 161 | end |
|
162 | 162 | |
|
163 | 163 | def user_stat_max |
|
164 | 164 | if params[:commit] == 'download csv' |
|
165 | 165 | @problems = Problem.all |
|
166 | 166 | else |
|
167 |
- @problems = Problem. |
|
|
167 | + @problems = Problem.available_problems | |
|
168 | 168 | end |
|
169 |
- @users = User. |
|
|
169 | + @users = User.includes(:contests).includes(:contest_stat).all | |
|
170 | 170 | @scorearray = Array.new |
|
171 | 171 | #set up range from param |
|
172 | 172 | since_id = params.fetch(:since_id, 0).to_i |
|
173 | 173 | until_id = params.fetch(:until_id, 0).to_i |
|
174 | 174 | @users.each do |u| |
|
175 | 175 | ustat = Array.new |
|
176 | 176 | ustat[0] = u |
|
177 | 177 | @problems.each do |p| |
|
178 | 178 | max_points = 0 |
|
179 | 179 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
180 | 180 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
181 | 181 | end |
@@ -192,25 +192,25 | |||
|
192 | 192 | end |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | def import |
|
196 | 196 | if params[:file]=='' |
|
197 | 197 | flash[:notice] = 'Error importing no file' |
|
198 | 198 | redirect_to :action => 'index' and return |
|
199 | 199 | end |
|
200 | 200 | import_from_file(params[:file]) |
|
201 | 201 | end |
|
202 | 202 | |
|
203 | 203 | def random_all_passwords |
|
204 |
- users = User. |
|
|
204 | + users = User.all | |
|
205 | 205 | @prefix = params[:prefix] || '' |
|
206 | 206 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
207 | 207 | @changed = false |
|
208 | 208 | if request.request_method == 'POST' |
|
209 | 209 | @non_admin_users.each do |user| |
|
210 | 210 | password = random_password |
|
211 | 211 | user.password = password |
|
212 | 212 | user.password_confirmation = password |
|
213 | 213 | user.save |
|
214 | 214 | end |
|
215 | 215 | @changed = true |
|
216 | 216 | end |
@@ -315,25 +315,25 | |||
|
315 | 315 | if params[:reset_timer] |
|
316 | 316 | logout_users(users) |
|
317 | 317 | end |
|
318 | 318 | |
|
319 | 319 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
320 | 320 | ' were successfully modified. ' |
|
321 | 321 | redirect_to :action => 'contest_management' |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | # admin management |
|
325 | 325 | |
|
326 | 326 | def admin |
|
327 |
- @admins = User. |
|
|
327 | + @admins = User.all.find_all {|user| user.admin? } | |
|
328 | 328 | end |
|
329 | 329 | |
|
330 | 330 | def grant_admin |
|
331 | 331 | login = params[:login] |
|
332 | 332 | user = User.find_by_login(login) |
|
333 | 333 | if user!=nil |
|
334 | 334 | admin_role = Role.find_by_name('admin') |
|
335 | 335 | user.roles << admin_role |
|
336 | 336 | else |
|
337 | 337 | flash[:notice] = 'Unknown user' |
|
338 | 338 | end |
|
339 | 339 | flash[:notice] = 'User added as admins' |
@@ -1,21 +1,15 | |||
|
1 | 1 | class Announcement < ActiveRecord::Base |
|
2 | 2 | |
|
3 |
- def self. |
|
|
3 | + def self.published(contest_started=false) | |
|
4 | 4 | if contest_started |
|
5 | - Announcement.find(:all, | |
|
6 | - :conditions => "(published = 1) AND (frontpage = 0)", | |
|
7 | - :order => "created_at DESC") | |
|
5 | + where(published: true).where(frontpage: false).order(created_at: :desc) | |
|
8 | 6 | else |
|
9 | - Announcement.find(:all, | |
|
10 | - :conditions => "(published = 1) AND (frontpage = 0) AND (contest_only = 0)", | |
|
11 | - :order => "created_at DESC") | |
|
7 | + where(published: true).where(frontpage: false).where(contest_only: false).order(created_at: :desc) | |
|
12 | 8 | end |
|
13 | 9 | end |
|
14 | 10 | |
|
15 |
- def self. |
|
|
16 | - Announcement.find(:all, | |
|
17 | - :conditions => "(published = 1) AND (frontpage = 1)", | |
|
18 | - :order => "created_at DESC") | |
|
11 | + def self.frontpage | |
|
12 | + where(published: 1).where(frontpage: 1).order(created_at: :desc) | |
|
19 | 13 | end |
|
20 | 14 | |
|
21 | 15 | end |
@@ -143,25 +143,25 | |||
|
143 | 143 | return val |
|
144 | 144 | |
|
145 | 145 | when 'integer' |
|
146 | 146 | return val.to_i |
|
147 | 147 | |
|
148 | 148 | when 'boolean' |
|
149 | 149 | return (val=='true') |
|
150 | 150 | end |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | def self.read_config |
|
154 | 154 | GraderConfiguration.config_cache = {} |
|
155 |
- GraderConfiguration. |
|
|
155 | + GraderConfiguration.all.each do |conf| | |
|
156 | 156 | key = conf.key |
|
157 | 157 | val = conf.value |
|
158 | 158 | GraderConfiguration.config_cache[key] = GraderConfiguration.convert_type(val,conf.value_type) |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def self.read_one_key(key) |
|
163 | 163 | conf = GraderConfiguration.find_by_key(key) |
|
164 | 164 | if conf |
|
165 | 165 | return GraderConfiguration.convert_type(conf.value,conf.value_type) |
|
166 | 166 | else |
|
167 | 167 | return nil |
@@ -1,55 +1,46 | |||
|
1 | 1 | class GraderProcess < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | def self.find_by_host_and_pid(host,pid) |
|
4 |
- return GraderProcess. |
|
|
5 | - :conditions => { | |
|
6 | - :host => host, | |
|
7 | - :pid => pid | |
|
8 | - }) | |
|
4 | + return GraderProcess.where(host:host).where(pid: pid).first | |
|
9 | 5 | end |
|
10 | 6 | |
|
11 | 7 | def self.register(host,pid,mode) |
|
12 | 8 | grader = GraderProcess.find_by_host_and_pid(host,pid) |
|
13 | 9 | if grader |
|
14 | 10 | grader.mode = mode |
|
15 | 11 | grader.active = nil |
|
16 | 12 | grader.task_id = nil |
|
17 | 13 | grader.task_type = nil |
|
18 | 14 | grader.terminated = false |
|
19 | 15 | grader.save |
|
20 | 16 | else |
|
21 | 17 | grader = GraderProcess.create(:host => host, |
|
22 | 18 | :pid => pid, |
|
23 | 19 | :mode => mode, |
|
24 | 20 | :terminated => false) |
|
25 | 21 | end |
|
26 | 22 | grader |
|
27 | 23 | end |
|
28 | 24 | |
|
29 | 25 | def self.find_running_graders |
|
30 | - GraderProcess.find(:all, | |
|
31 | - :conditions => {:terminated => 0}) | |
|
26 | + where(terminated: false) | |
|
32 | 27 | end |
|
33 | 28 | |
|
34 | 29 | def self.find_terminated_graders |
|
35 | - GraderProcess.find(:all, | |
|
36 | - :conditions => "`terminated`") | |
|
30 | + where(terminated: true) | |
|
37 | 31 | end |
|
38 | 32 | |
|
39 | 33 | def self.find_stalled_process |
|
40 | - GraderProcess.find(:all, | |
|
41 | - :conditions => ["(`terminated` = 0) AND active AND " + | |
|
42 | - "(updated_at < ?)", | |
|
43 | - Time.now.gmtime - GraderProcess.stalled_time]) | |
|
34 | + where(terminated: false).where(active: true).where("updated_at < ?",Time.now.gmtime - GraderProcess.stalled_time) | |
|
44 | 35 | end |
|
45 | 36 | |
|
46 | 37 | def report_active(task=nil) |
|
47 | 38 | self.active = true |
|
48 | 39 | if task!=nil |
|
49 | 40 | self.task_id = task.id |
|
50 | 41 | self.task_type = task.class.to_s |
|
51 | 42 | else |
|
52 | 43 | self.task_id = nil |
|
53 | 44 | self.task_type = nil |
|
54 | 45 | end |
|
55 | 46 | self.save |
@@ -1,19 +1,19 | |||
|
1 | 1 | class Language < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | @@languages_by_ext = {} |
|
4 | 4 | |
|
5 | 5 | def self.cache_ext_hash |
|
6 | 6 | @@languages_by_ext = {} |
|
7 |
- Language. |
|
|
7 | + Language.all.each do |language| | |
|
8 | 8 | language.common_ext.split(',').each do |ext| |
|
9 | 9 | @@languages_by_ext[ext] = language |
|
10 | 10 | end |
|
11 | 11 | end |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def self.find_by_extension(ext) |
|
15 | 15 | if @@languages_by_ext.length == 0 |
|
16 | 16 | Language.cache_ext_hash |
|
17 | 17 | end |
|
18 | 18 | if @@languages_by_ext.has_key? ext |
|
19 | 19 | return @@languages_by_ext[ext] |
@@ -14,28 +14,26 | |||
|
14 | 14 | # |
|
15 | 15 | |
|
16 | 16 | attr_accessor :replied_messages |
|
17 | 17 | |
|
18 | 18 | def self.find_all_sent_by_user(user) |
|
19 | 19 | messages = user.messages |
|
20 | 20 | replied_messages = user.replied_messages |
|
21 | 21 | Message.build_replying_message_hierarchy messages, replied_messages |
|
22 | 22 | return messages |
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def self.find_all_system_unreplied_messages |
|
26 | - self.find(:all, | |
|
27 | - :conditions => 'ISNULL(receiver_id) ' + | |
|
28 | - 'AND (ISNULL(replied) OR replied=0)', | |
|
29 | - :order => 'created_at') | |
|
26 | + where('ISNULL(receiver_id) ' + | |
|
27 | + 'AND (ISNULL(replied) OR replied=0)') | |
|
30 | 28 | end |
|
31 | 29 | |
|
32 | 30 | def self.build_replying_message_hierarchy(*args) |
|
33 | 31 | # manually build replies hierarchy (to improve efficiency) |
|
34 | 32 | all_messages = {} |
|
35 | 33 | |
|
36 | 34 | args.each do |collection| |
|
37 | 35 | collection.each do |m| |
|
38 | 36 | all_messages[m.id] = m |
|
39 | 37 | m.replied_messages = [] |
|
40 | 38 | end |
|
41 | 39 | end |
@@ -1,30 +1,31 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | has_many :test_pairs, :dependent => :delete_all |
|
6 | 6 | has_many :testcases, :dependent => :destroy |
|
7 | 7 | |
|
8 | 8 | validates_presence_of :name |
|
9 | 9 | validates_format_of :name, :with => /\A\w+\z/ |
|
10 | 10 | validates_presence_of :full_name |
|
11 | 11 | |
|
12 |
- scope :available, |
|
|
12 | + scope :available, -> { where(available: true) } | |
|
13 | 13 | |
|
14 | 14 | DEFAULT_TIME_LIMIT = 1 |
|
15 | 15 | DEFAULT_MEMORY_LIMIT = 32 |
|
16 | 16 | |
|
17 |
- def self. |
|
|
18 |
- |
|
|
17 | + def self.available_problems | |
|
18 | + available.order(date_added: :desc).order(:name) | |
|
19 | + #Problem.available.all(:order => "date_added DESC, name ASC") | |
|
19 | 20 | end |
|
20 | 21 | |
|
21 | 22 | def self.create_from_import_form_params(params, old_problem=nil) |
|
22 | 23 | org_problem = old_problem || Problem.new |
|
23 | 24 | import_params, problem = Problem.extract_params_and_check(params, |
|
24 | 25 | org_problem) |
|
25 | 26 | |
|
26 | 27 | if !problem.errors.empty? |
|
27 | 28 | return problem, 'Error importing' |
|
28 | 29 | end |
|
29 | 30 | |
|
30 | 31 | problem.full_score = 100 |
@@ -7,74 +7,61 | |||
|
7 | 7 | before_validation :assign_problem |
|
8 | 8 | before_validation :assign_language |
|
9 | 9 | |
|
10 | 10 | validates_presence_of :source |
|
11 | 11 | validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' |
|
12 | 12 | validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too short' |
|
13 | 13 | validate :must_have_valid_problem |
|
14 | 14 | validate :must_specify_language |
|
15 | 15 | |
|
16 | 16 | before_save :assign_latest_number_if_new_recond |
|
17 | 17 | |
|
18 | 18 | def self.find_last_by_user_and_problem(user_id, problem_id) |
|
19 | - last_sub = find(:first, | |
|
20 | - :conditions => {:user_id => user_id, | |
|
21 | - :problem_id => problem_id}, | |
|
22 | - :order => 'number DESC') | |
|
23 | - return last_sub | |
|
19 | + where("user_id = ? AND problem_id = ?",user_id,problem_id).last | |
|
24 | 20 | end |
|
25 | 21 | |
|
26 | 22 | def self.find_all_last_by_problem(problem_id) |
|
27 | 23 | # need to put in SQL command, maybe there's a better way |
|
28 | 24 | Submission.includes(:user).find_by_sql("SELECT * FROM submissions " + |
|
29 | 25 | "WHERE id = " + |
|
30 | 26 | "(SELECT MAX(id) FROM submissions AS subs " + |
|
31 | 27 | "WHERE subs.user_id = submissions.user_id AND " + |
|
32 | 28 | "problem_id = " + problem_id.to_s + " " + |
|
33 | 29 | "GROUP BY user_id) " + |
|
34 | 30 | "ORDER BY user_id") |
|
35 | 31 | end |
|
36 | 32 | |
|
37 | 33 | def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id) |
|
38 | 34 | records = Submission.where(problem_id: problem_id,user_id: user_id) |
|
39 | 35 | records = records.where('id >= ?',since_id) if since_id > 0 |
|
40 | 36 | records = records.where('id <= ?',until_id) if until_id > 0 |
|
41 | 37 | records.all |
|
42 | 38 | end |
|
43 | 39 | |
|
44 | 40 | def self.find_last_for_all_available_problems(user_id) |
|
45 | 41 | submissions = Array.new |
|
46 |
- problems = Problem. |
|
|
42 | + problems = Problem.available_problems | |
|
47 | 43 | problems.each do |problem| |
|
48 | 44 | sub = Submission.find_last_by_user_and_problem(user_id, problem.id) |
|
49 | 45 | submissions << sub if sub!=nil |
|
50 | 46 | end |
|
51 | 47 | submissions |
|
52 | 48 | end |
|
53 | 49 | |
|
54 | 50 | def self.find_by_user_problem_number(user_id, problem_id, number) |
|
55 | - Submission.find(:first, | |
|
56 | - :conditions => { | |
|
57 | - :user_id => user_id, | |
|
58 | - :problem_id => problem_id, | |
|
59 | - :number => number | |
|
60 | - }) | |
|
51 | + where("user_id = ? AND problem_id = ? AND number = ?",user_id,problem_id,number).first | |
|
61 | 52 | end |
|
62 | 53 | |
|
63 | 54 | def self.find_all_by_user_problem(user_id, problem_id) |
|
64 | - Submission.find(:all, | |
|
65 | - :conditions => { | |
|
66 | - :user_id => user_id, | |
|
67 | - :problem_id => problem_id, | |
|
68 | - }) | |
|
55 | + where("user_id = ? AND problem_id = ?",user_id,problem_id) | |
|
69 | 56 | end |
|
70 | 57 | |
|
71 | 58 | def download_filename |
|
72 | 59 | if self.problem.output_only |
|
73 | 60 | return self.source_filename |
|
74 | 61 | else |
|
75 | 62 | timestamp = self.submitted_at.localtime.strftime("%H%M%S") |
|
76 | 63 | return "#{self.problem.name}-#{timestamp}.#{self.language.ext}" |
|
77 | 64 | end |
|
78 | 65 | end |
|
79 | 66 | |
|
80 | 67 | protected |
@@ -39,28 +39,25 | |||
|
39 | 39 | "inqueue" |
|
40 | 40 | when Task::STATUS_GRADING |
|
41 | 41 | "grading" |
|
42 | 42 | when Task::STATUS_COMPLETE |
|
43 | 43 | "complete" |
|
44 | 44 | end |
|
45 | 45 | end |
|
46 | 46 | |
|
47 | 47 | def self.get_inqueue_and_change_status(status) |
|
48 | 48 | task = nil |
|
49 | 49 | begin |
|
50 | 50 | Task.transaction do |
|
51 | - task = Task.find(:first, | |
|
52 | - :order => "created_at", | |
|
53 | - :conditions => {:status=> Task::STATUS_INQUEUE}, | |
|
54 | - :lock => true) | |
|
51 | + task = Task.where(status: Task::STATUS_INQUEUE).where(lock: true).first | |
|
55 | 52 | if task!=nil |
|
56 | 53 | task.status = status |
|
57 | 54 | task.save! |
|
58 | 55 | end |
|
59 | 56 | end |
|
60 | 57 | |
|
61 | 58 | rescue |
|
62 | 59 | task = nil |
|
63 | 60 | |
|
64 | 61 | end |
|
65 | 62 | task |
|
66 | 63 | end |
@@ -28,27 +28,25 | |||
|
28 | 28 | def problem_name |
|
29 | 29 | TestRequest.name_of(self.problem) |
|
30 | 30 | end |
|
31 | 31 | |
|
32 | 32 | def language |
|
33 | 33 | self.submission.language |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def self.get_inqueue_and_change_status(status) |
|
37 | 37 | # since there will be only one grader grading TestRequest |
|
38 | 38 | # we do not need locking (hopefully) |
|
39 | 39 | |
|
40 |
- test_request = TestRequest. |
|
|
41 | - :order => "created_at", | |
|
42 | - :conditions => {:status=> Task::STATUS_INQUEUE}) | |
|
40 | + test_request = TestRequest.where(status: Task::STATUS_INQUEUE).first | |
|
43 | 41 | if test_request!=nil |
|
44 | 42 | test_request.status = status |
|
45 | 43 | test_request.save! |
|
46 | 44 | end |
|
47 | 45 | |
|
48 | 46 | test_request |
|
49 | 47 | end |
|
50 | 48 | |
|
51 | 49 | # interfacing with form |
|
52 | 50 | def self.new_from_form_params(user,params) |
|
53 | 51 | test_request = TestRequest.new |
|
54 | 52 | test_request.user = user |
@@ -166,32 +166,32 | |||
|
166 | 166 | def verify_activation_key(key) |
|
167 | 167 | key == activation_key |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def self.random_password(length=5) |
|
171 | 171 | chars = 'abcdefghjkmnopqrstuvwxyz' |
|
172 | 172 | password = '' |
|
173 | 173 | length.times { password << chars[rand(chars.length - 1)] } |
|
174 | 174 | password |
|
175 | 175 | end |
|
176 | 176 | |
|
177 | 177 | def self.find_non_admin_with_prefix(prefix='') |
|
178 |
- users = User. |
|
|
178 | + users = User.all | |
|
179 | 179 | return users.find_all { |u| !(u.admin?) and u.login.index(prefix)==0 } |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | # Contest information |
|
183 | 183 | |
|
184 | 184 | def self.find_users_with_no_contest() |
|
185 |
- users = User. |
|
|
185 | + users = User.all | |
|
186 | 186 | return users.find_all { |u| u.contests.length == 0 } |
|
187 | 187 | end |
|
188 | 188 | |
|
189 | 189 | |
|
190 | 190 | def contest_time_left |
|
191 | 191 | if GraderConfiguration.contest_mode? |
|
192 | 192 | return nil if site==nil |
|
193 | 193 | return site.time_left |
|
194 | 194 | elsif GraderConfiguration.indv_contest_mode? |
|
195 | 195 | time_limit = GraderConfiguration.contest_time_limit |
|
196 | 196 | if time_limit == nil |
|
197 | 197 | return nil |
@@ -272,25 +272,25 | |||
|
272 | 272 | available_problems.each {|p| pin[p.id] = true} |
|
273 | 273 | end |
|
274 | 274 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
275 | 275 | contest_problems << { |
|
276 | 276 | :contest => nil, |
|
277 | 277 | :problems => other_avaiable_problems |
|
278 | 278 | } |
|
279 | 279 | return contest_problems |
|
280 | 280 | end |
|
281 | 281 | |
|
282 | 282 | def available_problems |
|
283 | 283 | if not GraderConfiguration.multicontests? |
|
284 |
- return Problem. |
|
|
284 | + return Problem.available_problems | |
|
285 | 285 | else |
|
286 | 286 | contest_problems = [] |
|
287 | 287 | pin = {} |
|
288 | 288 | contests.enabled.each do |contest| |
|
289 | 289 | contest.problems.available.each do |problem| |
|
290 | 290 | if not pin.has_key? problem.id |
|
291 | 291 | contest_problems << problem |
|
292 | 292 | end |
|
293 | 293 | pin[problem.id] = true |
|
294 | 294 | end |
|
295 | 295 | end |
|
296 | 296 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
@@ -8,25 +8,25 | |||
|
8 | 8 | / %th Contest(s) |
|
9 | 9 | %th Remark |
|
10 | 10 | - @problems.each do |p| |
|
11 | 11 | %th.text-right= p.name.gsub('_',' ') |
|
12 | 12 | %th.text-right Total |
|
13 | 13 | %th.text-right Passed |
|
14 | 14 | %tbody |
|
15 | 15 | - @scorearray.each do |sc| |
|
16 | 16 | %tr |
|
17 | 17 | - total,num_passed = 0,0 |
|
18 | 18 | - sc.each_index do |i| |
|
19 | 19 | - if i == 0 |
|
20 |
- %td= link_to sc[i].login, |
|
|
20 | + %td= link_to sc[i].login, stat_user_path(sc[i]) | |
|
21 | 21 | %td= sc[i].full_name |
|
22 | 22 | / %td= sc[i].activated |
|
23 | 23 | / %td= sc[i].try(:contest_stat).try(:started_at) ? 'yes' : 'no' |
|
24 | 24 | / %td= sc[i].contests.collect {|c| c.name}.join(', ') |
|
25 | 25 | %td= sc[i].remark |
|
26 | 26 | - else |
|
27 | 27 | %td.text-right= sc[i][0] |
|
28 | 28 | - total += sc[i][0] |
|
29 | 29 | - num_passed += 1 if sc[i][1] |
|
30 | 30 | %td.text-right= total |
|
31 | 31 | %td.text-right= num_passed |
|
32 | 32 |
@@ -1,17 +1,17 | |||
|
1 | 1 | ENV["RAILS_ENV"] = "test" |
|
2 | 2 | require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") |
|
3 | 3 | |
|
4 | 4 | def clear_all_tasks |
|
5 |
- Task. |
|
|
5 | + Task.all.each do |task| | |
|
6 | 6 | task.destroy |
|
7 | 7 | end |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | clear_all_tasks |
|
12 | 12 | |
|
13 | 13 | (1..1000).each do |i| |
|
14 | 14 | Task.create(:id => i, |
|
15 | 15 | :submission_id => i, |
|
16 | 16 | :status => Task::STATUS_INQUEUE) |
|
17 | 17 | end |
@@ -1,14 +1,13 | |||
|
1 | 1 | ENV["RAILS_ENV"] = "test" |
|
2 | 2 | require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") |
|
3 | 3 | |
|
4 | 4 | def clear_all_tasks |
|
5 |
- Task. |
|
|
5 | + Task.all.each do |task| | |
|
6 | 6 | task.destroy |
|
7 | 7 | end |
|
8 | 8 | end |
|
9 | 9 | |
|
10 | - puts Task.find(:all, | |
|
11 | - :conditions => {:status => Task::STATUS_COMPLETE}).length | |
|
10 | + puts Task.where(status: Task::STATUS_COMPLETE).length | |
|
12 | 11 | |
|
13 | 12 | clear_all_tasks |
|
14 | 13 |
You need to be logged in to leave comments.
Login now