Description:
change depricated before_filter to before_action
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r745:75264caa616f - - 20 files changed: 38 inserted, 31 deleted
@@ -1,63 +1,64 | |||||
|
1 | source 'https://rubygems.org' |
|
1 | source 'https://rubygems.org' |
|
2 |
|
2 | ||
|
3 | #rails |
|
3 | #rails |
|
4 | gem 'rails', '~>5.0' |
|
4 | gem 'rails', '~>5.0' |
|
5 | gem 'activerecord-session_store' |
|
5 | gem 'activerecord-session_store' |
|
6 |
|
6 | ||
|
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' |
|
10 |
|
10 | ||
|
11 | #---------------- database --------------------- |
|
11 | #---------------- database --------------------- |
|
12 | #the database |
|
12 | #the database |
|
13 | gem 'mysql2' |
|
13 | gem 'mysql2' |
|
14 | #for testing |
|
14 | #for testing |
|
15 | gem 'sqlite3' |
|
15 | gem 'sqlite3' |
|
|
16 | + gem 'rails-controller-testing' | ||
|
16 | #for dumping database into yaml |
|
17 | #for dumping database into yaml |
|
17 | gem 'yaml_db' |
|
18 | gem 'yaml_db' |
|
18 |
|
19 | ||
|
19 | # Gems used only for assets and not required |
|
20 | # Gems used only for assets and not required |
|
20 | # in production environments by default. |
|
21 | # in production environments by default. |
|
21 | gem 'sass-rails' |
|
22 | gem 'sass-rails' |
|
22 | gem 'coffee-rails' |
|
23 | gem 'coffee-rails' |
|
23 |
|
24 | ||
|
24 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes |
|
25 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes |
|
25 | # gem 'therubyracer', :platforms => :ruby |
|
26 | # gem 'therubyracer', :platforms => :ruby |
|
26 |
|
27 | ||
|
27 | gem 'uglifier' |
|
28 | gem 'uglifier' |
|
28 |
|
29 | ||
|
29 | gem 'haml' |
|
30 | gem 'haml' |
|
30 | gem 'haml-rails' |
|
31 | gem 'haml-rails' |
|
31 | # gem 'prototype-rails' |
|
32 | # gem 'prototype-rails' |
|
32 |
|
33 | ||
|
33 | # To use ActiveModel has_secure_password |
|
34 | # To use ActiveModel has_secure_password |
|
34 | # gem 'bcrypt-ruby', '~> 3.0.0' |
|
35 | # gem 'bcrypt-ruby', '~> 3.0.0' |
|
35 |
|
36 | ||
|
36 | # To use Jbuilder templates for JSON |
|
37 | # To use Jbuilder templates for JSON |
|
37 | # gem 'jbuilder' |
|
38 | # gem 'jbuilder' |
|
38 |
|
39 | ||
|
39 | # Use unicorn as the app server |
|
40 | # Use unicorn as the app server |
|
40 | # gem 'unicorn' |
|
41 | # gem 'unicorn' |
|
41 |
|
42 | ||
|
42 | # Deploy with Capistrano |
|
43 | # Deploy with Capistrano |
|
43 | # gem 'capistrano' |
|
44 | # gem 'capistrano' |
|
44 |
|
45 | ||
|
45 | # To use debugger |
|
46 | # To use debugger |
|
46 | # gem 'debugger' |
|
47 | # gem 'debugger' |
|
47 | # |
|
48 | # |
|
48 |
|
49 | ||
|
49 | #in-place editor |
|
50 | #in-place editor |
|
50 | gem 'best_in_place', '~> 3.0.1' |
|
51 | gem 'best_in_place', '~> 3.0.1' |
|
51 |
|
52 | ||
|
52 | # jquery addition |
|
53 | # jquery addition |
|
53 | gem 'jquery-rails' |
|
54 | gem 'jquery-rails' |
|
54 | gem 'jquery-ui-rails' |
|
55 | gem 'jquery-ui-rails' |
|
55 | gem 'jquery-timepicker-addon-rails' |
|
56 | gem 'jquery-timepicker-addon-rails' |
|
56 | gem 'jquery-tablesorter' |
|
57 | gem 'jquery-tablesorter' |
|
57 | gem 'jquery-countdown-rails' |
|
58 | gem 'jquery-countdown-rails' |
|
58 |
|
59 | ||
|
59 | #syntax highlighter |
|
60 | #syntax highlighter |
|
60 | gem 'rouge' |
|
61 | gem 'rouge' |
|
61 |
|
62 | ||
|
62 | #bootstrap add-ons |
|
63 | #bootstrap add-ons |
|
63 | gem 'bootstrap-sass', '~> 3.4.1' |
|
64 | gem 'bootstrap-sass', '~> 3.4.1' |
@@ -114,96 +114,100 | |||||
|
114 | railties (>= 3.1) |
|
114 | railties (>= 3.1) |
|
115 | sass-rails |
|
115 | sass-rails |
|
116 | jquery-rails (4.3.3) |
|
116 | jquery-rails (4.3.3) |
|
117 | rails-dom-testing (>= 1, < 3) |
|
117 | rails-dom-testing (>= 1, < 3) |
|
118 | railties (>= 4.2.0) |
|
118 | railties (>= 4.2.0) |
|
119 | thor (>= 0.14, < 2.0) |
|
119 | thor (>= 0.14, < 2.0) |
|
120 | jquery-tablesorter (1.26.1) |
|
120 | jquery-tablesorter (1.26.1) |
|
121 | railties (>= 3.2, < 6) |
|
121 | railties (>= 3.2, < 6) |
|
122 | jquery-timepicker-addon-rails (1.4.1) |
|
122 | jquery-timepicker-addon-rails (1.4.1) |
|
123 | railties (>= 3.1) |
|
123 | railties (>= 3.1) |
|
124 | jquery-ui-rails (6.0.1) |
|
124 | jquery-ui-rails (6.0.1) |
|
125 | railties (>= 3.2.16) |
|
125 | railties (>= 3.2.16) |
|
126 | loofah (2.2.3) |
|
126 | loofah (2.2.3) |
|
127 | crass (~> 1.0.2) |
|
127 | crass (~> 1.0.2) |
|
128 | nokogiri (>= 1.5.9) |
|
128 | nokogiri (>= 1.5.9) |
|
129 | mail (2.7.1) |
|
129 | mail (2.7.1) |
|
130 | mini_mime (>= 0.1.1) |
|
130 | mini_mime (>= 0.1.1) |
|
131 | method_source (0.9.2) |
|
131 | method_source (0.9.2) |
|
132 | mini_mime (1.0.1) |
|
132 | mini_mime (1.0.1) |
|
133 | mini_portile2 (2.4.0) |
|
133 | mini_portile2 (2.4.0) |
|
134 | minitest (5.11.3) |
|
134 | minitest (5.11.3) |
|
135 | minitest-reporters (1.3.6) |
|
135 | minitest-reporters (1.3.6) |
|
136 | ansi |
|
136 | ansi |
|
137 | builder |
|
137 | builder |
|
138 | minitest (>= 5.0) |
|
138 | minitest (>= 5.0) |
|
139 | ruby-progressbar |
|
139 | ruby-progressbar |
|
140 | momentjs-rails (2.20.1) |
|
140 | momentjs-rails (2.20.1) |
|
141 | railties (>= 3.1) |
|
141 | railties (>= 3.1) |
|
142 | multi_json (1.13.1) |
|
142 | multi_json (1.13.1) |
|
143 | mysql2 (0.5.2) |
|
143 | mysql2 (0.5.2) |
|
144 | nio4r (2.3.1) |
|
144 | nio4r (2.3.1) |
|
145 | nokogiri (1.10.3) |
|
145 | nokogiri (1.10.3) |
|
146 | mini_portile2 (~> 2.4.0) |
|
146 | mini_portile2 (~> 2.4.0) |
|
147 | rack (2.0.7) |
|
147 | rack (2.0.7) |
|
148 | rack-test (0.6.3) |
|
148 | rack-test (0.6.3) |
|
149 | rack (>= 1.0) |
|
149 | rack (>= 1.0) |
|
150 | rails (5.0.7.2) |
|
150 | rails (5.0.7.2) |
|
151 | actioncable (= 5.0.7.2) |
|
151 | actioncable (= 5.0.7.2) |
|
152 | actionmailer (= 5.0.7.2) |
|
152 | actionmailer (= 5.0.7.2) |
|
153 | actionpack (= 5.0.7.2) |
|
153 | actionpack (= 5.0.7.2) |
|
154 | actionview (= 5.0.7.2) |
|
154 | actionview (= 5.0.7.2) |
|
155 | activejob (= 5.0.7.2) |
|
155 | activejob (= 5.0.7.2) |
|
156 | activemodel (= 5.0.7.2) |
|
156 | activemodel (= 5.0.7.2) |
|
157 | activerecord (= 5.0.7.2) |
|
157 | activerecord (= 5.0.7.2) |
|
158 | activesupport (= 5.0.7.2) |
|
158 | activesupport (= 5.0.7.2) |
|
159 | bundler (>= 1.3.0) |
|
159 | bundler (>= 1.3.0) |
|
160 | railties (= 5.0.7.2) |
|
160 | railties (= 5.0.7.2) |
|
161 | sprockets-rails (>= 2.0.0) |
|
161 | sprockets-rails (>= 2.0.0) |
|
|
162 | + rails-controller-testing (1.0.4) | ||
|
|
163 | + actionpack (>= 5.0.1.x) | ||
|
|
164 | + actionview (>= 5.0.1.x) | ||
|
|
165 | + activesupport (>= 5.0.1.x) | ||
|
162 | rails-dom-testing (2.0.3) |
|
166 | rails-dom-testing (2.0.3) |
|
163 | activesupport (>= 4.2.0) |
|
167 | activesupport (>= 4.2.0) |
|
164 | nokogiri (>= 1.6) |
|
168 | nokogiri (>= 1.6) |
|
165 | rails-html-sanitizer (1.0.4) |
|
169 | rails-html-sanitizer (1.0.4) |
|
166 | loofah (~> 2.2, >= 2.2.2) |
|
170 | loofah (~> 2.2, >= 2.2.2) |
|
167 | rails_bootstrap_sortable (2.0.6) |
|
171 | rails_bootstrap_sortable (2.0.6) |
|
168 | momentjs-rails (>= 2.8.3) |
|
172 | momentjs-rails (>= 2.8.3) |
|
169 | railties (5.0.7.2) |
|
173 | railties (5.0.7.2) |
|
170 | actionpack (= 5.0.7.2) |
|
174 | actionpack (= 5.0.7.2) |
|
171 | activesupport (= 5.0.7.2) |
|
175 | activesupport (= 5.0.7.2) |
|
172 | method_source |
|
176 | method_source |
|
173 | rake (>= 0.8.7) |
|
177 | rake (>= 0.8.7) |
|
174 | thor (>= 0.18.1, < 2.0) |
|
178 | thor (>= 0.18.1, < 2.0) |
|
175 | rake (12.3.2) |
|
179 | rake (12.3.2) |
|
176 | rb-fsevent (0.10.3) |
|
180 | rb-fsevent (0.10.3) |
|
177 | rb-inotify (0.10.0) |
|
181 | rb-inotify (0.10.0) |
|
178 | ffi (~> 1.0) |
|
182 | ffi (~> 1.0) |
|
179 | rdiscount (2.2.0.1) |
|
183 | rdiscount (2.2.0.1) |
|
180 | rouge (3.3.0) |
|
184 | rouge (3.3.0) |
|
181 | ruby-progressbar (1.10.0) |
|
185 | ruby-progressbar (1.10.0) |
|
182 | ruby_parser (3.13.1) |
|
186 | ruby_parser (3.13.1) |
|
183 | sexp_processor (~> 4.9) |
|
187 | sexp_processor (~> 4.9) |
|
184 | sass (3.7.4) |
|
188 | sass (3.7.4) |
|
185 | sass-listen (~> 4.0.0) |
|
189 | sass-listen (~> 4.0.0) |
|
186 | sass-listen (4.0.0) |
|
190 | sass-listen (4.0.0) |
|
187 | rb-fsevent (~> 0.9, >= 0.9.4) |
|
191 | rb-fsevent (~> 0.9, >= 0.9.4) |
|
188 | rb-inotify (~> 0.9, >= 0.9.7) |
|
192 | rb-inotify (~> 0.9, >= 0.9.7) |
|
189 | sass-rails (5.0.7) |
|
193 | sass-rails (5.0.7) |
|
190 | railties (>= 4.0.0, < 6) |
|
194 | railties (>= 4.0.0, < 6) |
|
191 | sass (~> 3.1) |
|
195 | sass (~> 3.1) |
|
192 | sprockets (>= 2.8, < 4.0) |
|
196 | sprockets (>= 2.8, < 4.0) |
|
193 | sprockets-rails (>= 2.0, < 4.0) |
|
197 | sprockets-rails (>= 2.0, < 4.0) |
|
194 | tilt (>= 1.1, < 3) |
|
198 | tilt (>= 1.1, < 3) |
|
195 | sassc (2.0.1) |
|
199 | sassc (2.0.1) |
|
196 | ffi (~> 1.9) |
|
200 | ffi (~> 1.9) |
|
197 | rake |
|
201 | rake |
|
198 | sassc-rails (2.1.1) |
|
202 | sassc-rails (2.1.1) |
|
199 | railties (>= 4.0.0) |
|
203 | railties (>= 4.0.0) |
|
200 | sassc (>= 2.0) |
|
204 | sassc (>= 2.0) |
|
201 | sprockets (> 3.0) |
|
205 | sprockets (> 3.0) |
|
202 | sprockets-rails |
|
206 | sprockets-rails |
|
203 | tilt |
|
207 | tilt |
|
204 | select2-rails (4.0.3) |
|
208 | select2-rails (4.0.3) |
|
205 | thor (~> 0.14) |
|
209 | thor (~> 0.14) |
|
206 | sexp_processor (4.12.0) |
|
210 | sexp_processor (4.12.0) |
|
207 | sprockets (3.7.2) |
|
211 | sprockets (3.7.2) |
|
208 | concurrent-ruby (~> 1.0) |
|
212 | concurrent-ruby (~> 1.0) |
|
209 | rack (> 1, < 3) |
|
213 | rack (> 1, < 3) |
@@ -213,62 +217,63 | |||||
|
213 | sprockets (>= 3.0.0) |
|
217 | sprockets (>= 3.0.0) |
|
214 | sqlite3 (1.4.1) |
|
218 | sqlite3 (1.4.1) |
|
215 | temple (0.8.1) |
|
219 | temple (0.8.1) |
|
216 | thor (0.20.3) |
|
220 | thor (0.20.3) |
|
217 | thread_safe (0.3.6) |
|
221 | thread_safe (0.3.6) |
|
218 | tilt (2.0.9) |
|
222 | tilt (2.0.9) |
|
219 | tzinfo (1.2.5) |
|
223 | tzinfo (1.2.5) |
|
220 | thread_safe (~> 0.1) |
|
224 | thread_safe (~> 0.1) |
|
221 | uglifier (4.1.20) |
|
225 | uglifier (4.1.20) |
|
222 | execjs (>= 0.3.0, < 3) |
|
226 | execjs (>= 0.3.0, < 3) |
|
223 | websocket-driver (0.6.5) |
|
227 | websocket-driver (0.6.5) |
|
224 | websocket-extensions (>= 0.1.0) |
|
228 | websocket-extensions (>= 0.1.0) |
|
225 | websocket-extensions (0.1.4) |
|
229 | websocket-extensions (0.1.4) |
|
226 | will_paginate (3.0.12) |
|
230 | will_paginate (3.0.12) |
|
227 | yaml_db (0.7.0) |
|
231 | yaml_db (0.7.0) |
|
228 | rails (>= 3.0) |
|
232 | rails (>= 3.0) |
|
229 | rake (>= 0.8.7) |
|
233 | rake (>= 0.8.7) |
|
230 |
|
234 | ||
|
231 | PLATFORMS |
|
235 | PLATFORMS |
|
232 | ruby |
|
236 | ruby |
|
233 |
|
237 | ||
|
234 | DEPENDENCIES |
|
238 | DEPENDENCIES |
|
235 | ace-rails-ap |
|
239 | ace-rails-ap |
|
236 | activerecord-session_store |
|
240 | activerecord-session_store |
|
237 | autoprefixer-rails |
|
241 | autoprefixer-rails |
|
238 | best_in_place (~> 3.0.1) |
|
242 | best_in_place (~> 3.0.1) |
|
239 | bootstrap-datepicker-rails |
|
243 | bootstrap-datepicker-rails |
|
240 | bootstrap-sass (~> 3.4.1) |
|
244 | bootstrap-sass (~> 3.4.1) |
|
241 | bootstrap-switch-rails |
|
245 | bootstrap-switch-rails |
|
242 | bootstrap-toggle-rails |
|
246 | bootstrap-toggle-rails |
|
243 | bootstrap3-datetimepicker-rails |
|
247 | bootstrap3-datetimepicker-rails |
|
244 | coffee-rails |
|
248 | coffee-rails |
|
245 | dynamic_form |
|
249 | dynamic_form |
|
246 | fuzzy-string-match |
|
250 | fuzzy-string-match |
|
247 | haml |
|
251 | haml |
|
248 | haml-rails |
|
252 | haml-rails |
|
249 | in_place_editing |
|
253 | in_place_editing |
|
250 | jquery-countdown-rails |
|
254 | jquery-countdown-rails |
|
251 | jquery-datatables-rails |
|
255 | jquery-datatables-rails |
|
252 | jquery-rails |
|
256 | jquery-rails |
|
253 | jquery-tablesorter |
|
257 | jquery-tablesorter |
|
254 | jquery-timepicker-addon-rails |
|
258 | jquery-timepicker-addon-rails |
|
255 | jquery-ui-rails |
|
259 | jquery-ui-rails |
|
256 |
|
260 | ||
|
257 | minitest-reporters |
|
261 | minitest-reporters |
|
258 | momentjs-rails |
|
262 | momentjs-rails |
|
259 | mysql2 |
|
263 | mysql2 |
|
260 | rails (~> 5.0) |
|
264 | rails (~> 5.0) |
|
|
265 | + rails-controller-testing | ||
|
261 | rails_bootstrap_sortable |
|
266 | rails_bootstrap_sortable |
|
262 | rdiscount |
|
267 | rdiscount |
|
263 | rouge |
|
268 | rouge |
|
264 | sass-rails |
|
269 | sass-rails |
|
265 | sassc-rails (>= 2.1.0) |
|
270 | sassc-rails (>= 2.1.0) |
|
266 | select2-rails |
|
271 | select2-rails |
|
267 | sqlite3 |
|
272 | sqlite3 |
|
268 | uglifier |
|
273 | uglifier |
|
269 | verification! |
|
274 | verification! |
|
270 | will_paginate (~> 3.0.7) |
|
275 | will_paginate (~> 3.0.7) |
|
271 | yaml_db |
|
276 | yaml_db |
|
272 |
|
277 | ||
|
273 | BUNDLED WITH |
|
278 | BUNDLED WITH |
|
274 | 1.17.2 |
|
279 | 1.17.2 |
@@ -1,51 +1,51 | |||||
|
1 | class AnnouncementsController < ApplicationController |
|
1 | class AnnouncementsController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :admin_authorization |
|
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.order(created_at: :desc) |
|
10 | @announcements = Announcement.order(created_at: :desc) |
|
11 |
|
11 | ||
|
12 | respond_to do |format| |
|
12 | respond_to do |format| |
|
13 | format.html # index.html.erb |
|
13 | format.html # index.html.erb |
|
14 | format.xml { render :xml => @announcements } |
|
14 | format.xml { render :xml => @announcements } |
|
15 | end |
|
15 | end |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | # GET /announcements/1 |
|
18 | # GET /announcements/1 |
|
19 | # GET /announcements/1.xml |
|
19 | # GET /announcements/1.xml |
|
20 | def show |
|
20 | def show |
|
21 | @announcement = Announcement.find(params[:id]) |
|
21 | @announcement = Announcement.find(params[:id]) |
|
22 |
|
22 | ||
|
23 | respond_to do |format| |
|
23 | respond_to do |format| |
|
24 | format.html # show.html.erb |
|
24 | format.html # show.html.erb |
|
25 | format.xml { render :xml => @announcement } |
|
25 | format.xml { render :xml => @announcement } |
|
26 | end |
|
26 | end |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | # GET /announcements/new |
|
29 | # GET /announcements/new |
|
30 | # GET /announcements/new.xml |
|
30 | # GET /announcements/new.xml |
|
31 | def new |
|
31 | def new |
|
32 | @announcement = Announcement.new |
|
32 | @announcement = Announcement.new |
|
33 |
|
33 | ||
|
34 | respond_to do |format| |
|
34 | respond_to do |format| |
|
35 | format.html # new.html.erb |
|
35 | format.html # new.html.erb |
|
36 | format.xml { render :xml => @announcement } |
|
36 | format.xml { render :xml => @announcement } |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | # GET /announcements/1/edit |
|
40 | # GET /announcements/1/edit |
|
41 | def edit |
|
41 | def edit |
|
42 | @announcement = Announcement.find(params[:id]) |
|
42 | @announcement = Announcement.find(params[:id]) |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | # POST /announcements |
|
45 | # POST /announcements |
|
46 | # POST /announcements.xml |
|
46 | # POST /announcements.xml |
|
47 | def create |
|
47 | def create |
|
48 | @announcement = Announcement.new(announcement_params) |
|
48 | @announcement = Announcement.new(announcement_params) |
|
49 |
|
49 | ||
|
50 | respond_to do |format| |
|
50 | respond_to do |format| |
|
51 | if @announcement.save |
|
51 | if @announcement.save |
@@ -1,52 +1,52 | |||||
|
1 | class ApplicationController < ActionController::Base |
|
1 | class ApplicationController < ActionController::Base |
|
2 | protect_from_forgery |
|
2 | protect_from_forgery |
|
3 |
|
3 | ||
|
4 |
- before_ |
|
4 | + before_action :current_user |
|
5 |
|
5 | ||
|
6 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
6 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
7 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
7 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
8 |
|
8 | ||
|
9 | #report and redirect for unauthorized activities |
|
9 | #report and redirect for unauthorized activities |
|
10 | def unauthorized_redirect |
|
10 | def unauthorized_redirect |
|
11 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
11 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
12 | redirect_to :controller => 'main', :action => 'login' |
|
12 | redirect_to :controller => 'main', :action => 'login' |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | # Returns the current logged-in user (if any). |
|
15 | # Returns the current logged-in user (if any). |
|
16 | def current_user |
|
16 | def current_user |
|
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.includes(:roles).find(session[:user_id]) |
|
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 |
|
30 |
|
30 | ||
|
31 | def authorization_by_roles(allowed_roles) |
|
31 | def authorization_by_roles(allowed_roles) |
|
32 | return false unless authenticate |
|
32 | return false unless authenticate |
|
33 | user = User.find(session[:user_id]) |
|
33 | user = User.find(session[:user_id]) |
|
34 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
34 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
35 | unauthorized_redirect |
|
35 | unauthorized_redirect |
|
36 | return false |
|
36 | return false |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | def testcase_authorization |
|
40 | def testcase_authorization |
|
41 | #admin always has privileged |
|
41 | #admin always has privileged |
|
42 | if @current_user.admin? |
|
42 | if @current_user.admin? |
|
43 | return true |
|
43 | return true |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
46 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | protected |
|
49 | protected |
|
50 |
|
50 | ||
|
51 | def authenticate |
|
51 | def authenticate |
|
52 | unless session[:user_id] |
|
52 | unless session[:user_id] |
@@ -1,34 +1,34 | |||||
|
1 | class ConfigurationsController < ApplicationController |
|
1 | class ConfigurationsController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :authenticate |
|
4 |
- before_ |
|
4 | + before_action { |controller| controller.authorization_by_roles(['admin'])} |
|
5 |
|
5 | ||
|
6 |
|
6 | ||
|
7 | def index |
|
7 | def index |
|
8 | @configurations = GraderConfiguration.order(:key) |
|
8 | @configurations = GraderConfiguration.order(:key) |
|
9 | @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 |
|
10 | end |
|
10 | end |
|
11 |
|
11 | ||
|
12 | def reload |
|
12 | def reload |
|
13 | GraderConfiguration.reload |
|
13 | GraderConfiguration.reload |
|
14 | redirect_to :action => 'index' |
|
14 | redirect_to :action => 'index' |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def update |
|
17 | def update |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
18 | @config = GraderConfiguration.find(params[:id]) |
|
19 | User.clear_last_login if @config.key == GraderConfiguration::MULTIPLE_IP_LOGIN_KEY and @config.value == 'true' and params[:grader_configuration][:value] == 'false' |
|
19 | User.clear_last_login if @config.key == GraderConfiguration::MULTIPLE_IP_LOGIN_KEY and @config.value == 'true' and params[:grader_configuration][:value] == 'false' |
|
20 | respond_to do |format| |
|
20 | respond_to do |format| |
|
21 | if @config.update_attributes(configuration_params) |
|
21 | if @config.update_attributes(configuration_params) |
|
22 | format.json { head :ok } |
|
22 | format.json { head :ok } |
|
23 | else |
|
23 | else |
|
24 | format.json { respond_with_bip(@config) } |
|
24 | format.json { respond_with_bip(@config) } |
|
25 | end |
|
25 | end |
|
26 | end |
|
26 | end |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | private |
|
29 | private |
|
30 | def configuration_params |
|
30 | def configuration_params |
|
31 | params.require(:grader_configuration).permit(:key,:value_type,:value,:description) |
|
31 | params.require(:grader_configuration).permit(:key,:value_type,:value,:description) |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | end |
|
34 | end |
@@ -1,50 +1,50 | |||||
|
1 | class ContestManagementController < ApplicationController |
|
1 | class ContestManagementController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :admin_authorization |
|
4 |
|
4 | ||
|
5 | def index |
|
5 | def index |
|
6 | @num_contests = Contest.count() |
|
6 | @num_contests = Contest.count() |
|
7 | end |
|
7 | end |
|
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.all |
|
14 | @users = User.all |
|
15 | @start_times = {} |
|
15 | @start_times = {} |
|
16 | UserContestStat.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]) |
|
23 | if user.contest_stat!=nil |
|
23 | if user.contest_stat!=nil |
|
24 | user.contest_stat.destroy |
|
24 | user.contest_stat.destroy |
|
25 | end |
|
25 | end |
|
26 | redirect_to :action => 'user_stat' |
|
26 | redirect_to :action => 'user_stat' |
|
27 | end |
|
27 | end |
|
28 |
|
28 | ||
|
29 | def clear_all_stat |
|
29 | def clear_all_stat |
|
30 | if not GraderConfiguration.indv_contest_mode? |
|
30 | if not GraderConfiguration.indv_contest_mode? |
|
31 | redirect_to :action => 'index' and return |
|
31 | redirect_to :action => 'index' and return |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | UserContestStat.delete_all() |
|
34 | UserContestStat.delete_all() |
|
35 | flash[:notice] = 'All start time statistic cleared.' |
|
35 | flash[:notice] = 'All start time statistic cleared.' |
|
36 | redirect_to :action => 'index' |
|
36 | redirect_to :action => 'index' |
|
37 | end |
|
37 | end |
|
38 |
|
38 | ||
|
39 | def change_contest_mode |
|
39 | def change_contest_mode |
|
40 | if ['standard', 'contest', 'indv-contest', 'analysis'].include? params[:id] |
|
40 | if ['standard', 'contest', 'indv-contest', 'analysis'].include? params[:id] |
|
41 | config = GraderConfiguration.find_by_key('system.mode') |
|
41 | config = GraderConfiguration.find_by_key('system.mode') |
|
42 | config.value = params[:id] |
|
42 | config.value = params[:id] |
|
43 | config.save |
|
43 | config.save |
|
44 | else |
|
44 | else |
|
45 | flash[:notice] = 'Wrong contest mode value' |
|
45 | flash[:notice] = 'Wrong contest mode value' |
|
46 | end |
|
46 | end |
|
47 | redirect_to :action => 'index' |
|
47 | redirect_to :action => 'index' |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | end |
|
50 | end |
@@ -1,51 +1,51 | |||||
|
1 | class ContestsController < ApplicationController |
|
1 | class ContestsController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :admin_authorization |
|
4 |
|
4 | ||
|
5 | in_place_edit_for :contest, :title |
|
5 | in_place_edit_for :contest, :title |
|
6 | in_place_edit_for :contest, :enabled |
|
6 | in_place_edit_for :contest, :enabled |
|
7 |
|
7 | ||
|
8 | # GET /contests |
|
8 | # GET /contests |
|
9 | # GET /contests.xml |
|
9 | # GET /contests.xml |
|
10 | def index |
|
10 | def index |
|
11 | @contests = Contest.all |
|
11 | @contests = Contest.all |
|
12 |
|
12 | ||
|
13 | respond_to do |format| |
|
13 | respond_to do |format| |
|
14 | format.html # index.html.erb |
|
14 | format.html # index.html.erb |
|
15 | format.xml { render :xml => @contests } |
|
15 | format.xml { render :xml => @contests } |
|
16 | end |
|
16 | end |
|
17 | end |
|
17 | end |
|
18 |
|
18 | ||
|
19 | # GET /contests/1 |
|
19 | # GET /contests/1 |
|
20 | # GET /contests/1.xml |
|
20 | # GET /contests/1.xml |
|
21 | def show |
|
21 | def show |
|
22 | @contest = Contest.find(params[:id]) |
|
22 | @contest = Contest.find(params[:id]) |
|
23 |
|
23 | ||
|
24 | respond_to do |format| |
|
24 | respond_to do |format| |
|
25 | format.html # show.html.erb |
|
25 | format.html # show.html.erb |
|
26 | format.xml { render :xml => @contest } |
|
26 | format.xml { render :xml => @contest } |
|
27 | end |
|
27 | end |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | # GET /contests/new |
|
30 | # GET /contests/new |
|
31 | # GET /contests/new.xml |
|
31 | # GET /contests/new.xml |
|
32 | def new |
|
32 | def new |
|
33 | @contest = Contest.new |
|
33 | @contest = Contest.new |
|
34 |
|
34 | ||
|
35 | respond_to do |format| |
|
35 | respond_to do |format| |
|
36 | format.html # new.html.erb |
|
36 | format.html # new.html.erb |
|
37 | format.xml { render :xml => @contest } |
|
37 | format.xml { render :xml => @contest } |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | # GET /contests/1/edit |
|
41 | # GET /contests/1/edit |
|
42 | def edit |
|
42 | def edit |
|
43 | @contest = Contest.find(params[:id]) |
|
43 | @contest = Contest.find(params[:id]) |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | # POST /contests |
|
46 | # POST /contests |
|
47 | # POST /contests.xml |
|
47 | # POST /contests.xml |
|
48 | def create |
|
48 | def create |
|
49 | @contest = Contest.new(params[:contest]) |
|
49 | @contest = Contest.new(params[:contest]) |
|
50 |
|
50 | ||
|
51 | respond_to do |format| |
|
51 | respond_to do |format| |
@@ -1,51 +1,51 | |||||
|
1 | class GradersController < ApplicationController |
|
1 | class GradersController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :admin_authorization |
|
4 |
|
4 | ||
|
5 | verify :method => :post, :only => ['clear_all', |
|
5 | verify :method => :post, :only => ['clear_all', |
|
6 | 'start_exam', |
|
6 | 'start_exam', |
|
7 | 'start_grading', |
|
7 | 'start_grading', |
|
8 | 'stop_all', |
|
8 | 'stop_all', |
|
9 | 'clear_terminated'], |
|
9 | 'clear_terminated'], |
|
10 | :redirect_to => {:action => 'index'} |
|
10 | :redirect_to => {:action => 'index'} |
|
11 |
|
11 | ||
|
12 | def index |
|
12 | def index |
|
13 | redirect_to :action => 'list' |
|
13 | redirect_to :action => 'list' |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | def list |
|
16 | def list |
|
17 | @grader_processes = GraderProcess.find_running_graders |
|
17 | @grader_processes = GraderProcess.find_running_graders |
|
18 | @stalled_processes = GraderProcess.find_stalled_process |
|
18 | @stalled_processes = GraderProcess.find_stalled_process |
|
19 |
|
19 | ||
|
20 | @terminated_processes = GraderProcess.find_terminated_graders |
|
20 | @terminated_processes = GraderProcess.find_terminated_graders |
|
21 |
|
21 | ||
|
22 | @last_task = Task.last |
|
22 | @last_task = Task.last |
|
23 | @last_test_request = TestRequest.last |
|
23 | @last_test_request = TestRequest.last |
|
24 | @submission = Submission.order("id desc").limit(20) |
|
24 | @submission = Submission.order("id desc").limit(20) |
|
25 | @backlog_submission = Submission.where('graded_at is null') |
|
25 | @backlog_submission = Submission.where('graded_at is null') |
|
26 | end |
|
26 | end |
|
27 |
|
27 | ||
|
28 | def clear |
|
28 | def clear |
|
29 | grader_proc = GraderProcess.find(params[:id]) |
|
29 | grader_proc = GraderProcess.find(params[:id]) |
|
30 | grader_proc.destroy if grader_proc!=nil |
|
30 | grader_proc.destroy if grader_proc!=nil |
|
31 | redirect_to :action => 'list' |
|
31 | redirect_to :action => 'list' |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | def clear_terminated |
|
34 | def clear_terminated |
|
35 | GraderProcess.find_terminated_graders.each do |p| |
|
35 | GraderProcess.find_terminated_graders.each do |p| |
|
36 | p.destroy |
|
36 | p.destroy |
|
37 | end |
|
37 | end |
|
38 | redirect_to :action => 'list' |
|
38 | redirect_to :action => 'list' |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | def clear_all |
|
41 | def clear_all |
|
42 | GraderProcess.all.each do |p| |
|
42 | GraderProcess.all.each do |p| |
|
43 | p.destroy |
|
43 | p.destroy |
|
44 | end |
|
44 | end |
|
45 | redirect_to :action => 'list' |
|
45 | redirect_to :action => 'list' |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | def view |
|
48 | def view |
|
49 | if params[:type]=='Task' |
|
49 | if params[:type]=='Task' |
|
50 | redirect_to :action => 'task', :id => params[:id] |
|
50 | redirect_to :action => 'task', :id => params[:id] |
|
51 | else |
|
51 | else |
@@ -1,46 +1,46 | |||||
|
1 | class HeartbeatController < ApplicationController |
|
1 | class HeartbeatController < ApplicationController |
|
2 |
- before_ |
|
2 | + before_action :admin_authorization, :only => ['index'] |
|
3 |
|
3 | ||
|
4 | def edit |
|
4 | def edit |
|
5 | #@user = User.find_by_login(params[:id]) |
|
5 | #@user = User.find_by_login(params[:id]) |
|
6 | #unless @user |
|
6 | #unless @user |
|
7 | # render text: "LOGIN_NOT_FOUND" |
|
7 | # render text: "LOGIN_NOT_FOUND" |
|
8 | # return |
|
8 | # return |
|
9 | #end |
|
9 | #end |
|
10 |
|
10 | ||
|
11 | #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first |
|
11 | #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first |
|
12 | #puts "status = #{params[:status]}" |
|
12 | #puts "status = #{params[:status]}" |
|
13 | #if hb |
|
13 | #if hb |
|
14 | # if params[:status] |
|
14 | # if params[:status] |
|
15 | # hb.status = params[:status] |
|
15 | # hb.status = params[:status] |
|
16 | # hb.save |
|
16 | # hb.save |
|
17 | # end |
|
17 | # end |
|
18 | # hb.touch |
|
18 | # hb.touch |
|
19 | #else |
|
19 | #else |
|
20 | # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) |
|
20 | # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) |
|
21 | #end |
|
21 | #end |
|
22 | #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) |
|
22 | #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) |
|
23 |
|
23 | ||
|
24 | res = GraderConfiguration['right.heartbeat_response'] |
|
24 | res = GraderConfiguration['right.heartbeat_response'] |
|
25 | res.strip! if res |
|
25 | res.strip! if res |
|
26 | full = GraderConfiguration['right.heartbeat_response_full'] |
|
26 | full = GraderConfiguration['right.heartbeat_response_full'] |
|
27 | full.strip! if full |
|
27 | full.strip! if full |
|
28 |
|
28 | ||
|
29 | if full and full != '' |
|
29 | if full and full != '' |
|
30 | l = Login.where(ip_address: request.remote_ip).last |
|
30 | l = Login.where(ip_address: request.remote_ip).last |
|
31 | @user = l.user |
|
31 | @user = l.user |
|
32 | if @user.solve_all_available_problems? |
|
32 | if @user.solve_all_available_problems? |
|
33 | render text: (full || 'OK') |
|
33 | render text: (full || 'OK') |
|
34 | else |
|
34 | else |
|
35 | render text: (res || 'OK') |
|
35 | render text: (res || 'OK') |
|
36 | end |
|
36 | end |
|
37 | else |
|
37 | else |
|
38 | render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') |
|
38 | render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') |
|
39 | end |
|
39 | end |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def index |
|
42 | def index |
|
43 | @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all |
|
43 | @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all |
|
44 | @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true) |
|
44 | @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true) |
|
45 | end |
|
45 | end |
|
46 | end |
|
46 | end |
@@ -1,64 +1,64 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :authenticate, :except => [:index, :login] |
|
4 |
- before_ |
|
4 | + before_action :check_viewability, :except => [:index, :login] |
|
5 |
|
5 | ||
|
6 |
- append_before_ |
|
6 | + append_before_action :confirm_and_update_start_time, |
|
7 | :except => [:index, |
|
7 | :except => [:index, |
|
8 | :login, |
|
8 | :login, |
|
9 | :confirm_contest_start] |
|
9 | :confirm_contest_start] |
|
10 |
|
10 | ||
|
11 | # to prevent log in box to be shown when user logged out of the |
|
11 | # to prevent log in box to be shown when user logged out of the |
|
12 | # system only in some tab |
|
12 | # system only in some tab |
|
13 |
- prepend_before_ |
|
13 | + prepend_before_action :reject_announcement_refresh_when_logged_out, |
|
14 | :only => [:announcements] |
|
14 | :only => [:announcements] |
|
15 |
|
15 | ||
|
16 |
- before_ |
|
16 | + before_action :authenticate_by_ip_address, :only => [:list] |
|
17 |
|
17 | ||
|
18 | # COMMENTED OUT: filter in each action instead |
|
18 | # COMMENTED OUT: filter in each action instead |
|
19 | # before_filter :verify_time_limit, :only => [:submit] |
|
19 | # before_filter :verify_time_limit, :only => [:submit] |
|
20 |
|
20 | ||
|
21 | verify :method => :post, :only => [:submit], |
|
21 | verify :method => :post, :only => [:submit], |
|
22 | :redirect_to => { :action => :index } |
|
22 | :redirect_to => { :action => :index } |
|
23 |
|
23 | ||
|
24 | # COMMENT OUT: only need when having high load |
|
24 | # COMMENT OUT: only need when having high load |
|
25 | # caches_action :index, :login |
|
25 | # caches_action :index, :login |
|
26 |
|
26 | ||
|
27 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
27 | # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
28 | # assigned action login as a default action. |
|
28 | # assigned action login as a default action. |
|
29 | def index |
|
29 | def index |
|
30 | redirect_to :action => 'login' |
|
30 | redirect_to :action => 'login' |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | def login |
|
33 | def login |
|
34 | saved_notice = flash[:notice] |
|
34 | saved_notice = flash[:notice] |
|
35 | reset_session |
|
35 | reset_session |
|
36 | flash.now[:notice] = saved_notice |
|
36 | flash.now[:notice] = saved_notice |
|
37 |
|
37 | ||
|
38 | # EXPERIMENT: |
|
38 | # EXPERIMENT: |
|
39 | # Hide login if in single user mode and the url does not |
|
39 | # Hide login if in single user mode and the url does not |
|
40 | # explicitly specify /login |
|
40 | # explicitly specify /login |
|
41 | # |
|
41 | # |
|
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.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 |
|
55 |
|
55 | ||
|
56 | def help |
|
56 | def help |
|
57 | @user = User.find(session[:user_id]) |
|
57 | @user = User.find(session[:user_id]) |
|
58 | end |
|
58 | end |
|
59 |
|
59 | ||
|
60 | def submit |
|
60 | def submit |
|
61 | user = User.find(session[:user_id]) |
|
61 | user = User.find(session[:user_id]) |
|
62 |
|
62 | ||
|
63 | @submission = Submission.new |
|
63 | @submission = Submission.new |
|
64 | @submission.problem_id = params[:submission][:problem_id] |
|
64 | @submission.problem_id = params[:submission][:problem_id] |
@@ -1,51 +1,51 | |||||
|
1 | class MessagesController < ApplicationController |
|
1 | class MessagesController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :authenticate |
|
4 |
|
4 | ||
|
5 | verify :method => :post, :only => ['create'], |
|
5 | verify :method => :post, :only => ['create'], |
|
6 | :redirect_to => { :action => 'list' } |
|
6 | :redirect_to => { :action => 'list' } |
|
7 |
|
7 | ||
|
8 | before_filter :admin_authorization, :only => ['console','show', |
|
8 | before_filter :admin_authorization, :only => ['console','show', |
|
9 | 'reply','hide','list_all'] |
|
9 | 'reply','hide','list_all'] |
|
10 |
|
10 | ||
|
11 | def list |
|
11 | def list |
|
12 | @user = User.find(session[:user_id]) |
|
12 | @user = User.find(session[:user_id]) |
|
13 | @messages = Message.find_all_sent_by_user(@user) |
|
13 | @messages = Message.find_all_sent_by_user(@user) |
|
14 | end |
|
14 | end |
|
15 |
|
15 | ||
|
16 | def console |
|
16 | def console |
|
17 | @user = User.find(session[:user_id]) |
|
17 | @user = User.find(session[:user_id]) |
|
18 | @messages = Message.find_all_system_unreplied_messages |
|
18 | @messages = Message.find_all_system_unreplied_messages |
|
19 | end |
|
19 | end |
|
20 |
|
20 | ||
|
21 | def show |
|
21 | def show |
|
22 | @message = Message.find(params[:id]) |
|
22 | @message = Message.find(params[:id]) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def list_all |
|
25 | def list_all |
|
26 | @user = User.find(session[:user_id]) |
|
26 | @user = User.find(session[:user_id]) |
|
27 | @messages = Message.where(receiver_id: nil).order(:created_at) |
|
27 | @messages = Message.where(receiver_id: nil).order(:created_at) |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def create |
|
30 | def create |
|
31 | user = User.find(session[:user_id]) |
|
31 | user = User.find(session[:user_id]) |
|
32 | @message = Message.new(params[:message]) |
|
32 | @message = Message.new(params[:message]) |
|
33 | @message.sender = user |
|
33 | @message.sender = user |
|
34 | if @message.body == '' or !@message.save |
|
34 | if @message.body == '' or !@message.save |
|
35 | flash[:notice] = 'An error occurred' |
|
35 | flash[:notice] = 'An error occurred' |
|
36 | else |
|
36 | else |
|
37 | flash[:notice] = 'New message posted' |
|
37 | flash[:notice] = 'New message posted' |
|
38 | end |
|
38 | end |
|
39 | redirect_to :action => 'list' |
|
39 | redirect_to :action => 'list' |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def reply |
|
42 | def reply |
|
43 | user = User.find(session[:user_id]) |
|
43 | user = User.find(session[:user_id]) |
|
44 | @message = Message.new(params[:r_message]) |
|
44 | @message = Message.new(params[:r_message]) |
|
45 | @message.sender = user |
|
45 | @message.sender = user |
|
46 | if @message.body == '' or !@message.save |
|
46 | if @message.body == '' or !@message.save |
|
47 | flash[:notice] = 'An error occurred' |
|
47 | flash[:notice] = 'An error occurred' |
|
48 | redirect_to :action => 'show', :id => @message.replying_message_id |
|
48 | redirect_to :action => 'show', :id => @message.replying_message_id |
|
49 | else |
|
49 | else |
|
50 | flash[:notice] = 'Message replied' |
|
50 | flash[:notice] = 'Message replied' |
|
51 | rep_msg = @message.replying_message |
|
51 | rep_msg = @message.replying_message |
@@ -1,57 +1,57 | |||||
|
1 | require 'csv' |
|
1 | require 'csv' |
|
2 |
|
2 | ||
|
3 | class ReportController < ApplicationController |
|
3 | class ReportController < ApplicationController |
|
4 |
|
4 | ||
|
5 |
- before_ |
|
5 | + before_action :authenticate |
|
6 |
|
6 | ||
|
7 |
- before_ |
|
7 | + before_action :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score, :current_score] |
|
8 |
|
8 | ||
|
9 |
- before_ |
|
9 | + before_action(only: [:problem_hof]) { |c| |
|
10 | return false unless authenticate |
|
10 | return false unless authenticate |
|
11 |
|
11 | ||
|
12 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
12 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
13 | } |
|
13 | } |
|
14 |
|
14 | ||
|
15 | def max_score |
|
15 | def max_score |
|
16 | end |
|
16 | end |
|
17 |
|
17 | ||
|
18 | def current_score |
|
18 | def current_score |
|
19 | @problems = Problem.available_problems |
|
19 | @problems = Problem.available_problems |
|
20 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
20 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
21 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
21 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
22 |
|
22 | ||
|
23 | #rencer accordingly |
|
23 | #rencer accordingly |
|
24 | if params[:button] == 'download' then |
|
24 | if params[:button] == 'download' then |
|
25 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
25 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
26 | send_data csv, filename: 'max_score.csv' |
|
26 | send_data csv, filename: 'max_score.csv' |
|
27 | else |
|
27 | else |
|
28 | #render template: 'user_admin/user_stat' |
|
28 | #render template: 'user_admin/user_stat' |
|
29 | render 'current_score' |
|
29 | render 'current_score' |
|
30 | end |
|
30 | end |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | def show_max_score |
|
33 | def show_max_score |
|
34 | #process parameters |
|
34 | #process parameters |
|
35 | #problems |
|
35 | #problems |
|
36 | @problems = [] |
|
36 | @problems = [] |
|
37 | if params[:problem_id] |
|
37 | if params[:problem_id] |
|
38 | params[:problem_id].each do |id| |
|
38 | params[:problem_id].each do |id| |
|
39 | next unless id.strip != "" |
|
39 | next unless id.strip != "" |
|
40 | pid = Problem.find_by_id(id.to_i) |
|
40 | pid = Problem.find_by_id(id.to_i) |
|
41 | @problems << pid if pid |
|
41 | @problems << pid if pid |
|
42 | end |
|
42 | end |
|
43 | end |
|
43 | end |
|
44 |
|
44 | ||
|
45 | #users |
|
45 | #users |
|
46 | @users = if params[:users] == "all" then |
|
46 | @users = if params[:users] == "all" then |
|
47 | User.includes(:contests).includes(:contest_stat) |
|
47 | User.includes(:contests).includes(:contest_stat) |
|
48 | else |
|
48 | else |
|
49 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
49 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | #set up range from param |
|
52 | #set up range from param |
|
53 | @since_id = params.fetch(:from_id, 0).to_i |
|
53 | @since_id = params.fetch(:from_id, 0).to_i |
|
54 | @until_id = params.fetch(:to_id, 0).to_i |
|
54 | @until_id = params.fetch(:to_id, 0).to_i |
|
55 | @since_id = nil if @since_id == 0 |
|
55 | @since_id = nil if @since_id == 0 |
|
56 | @until_id = nil if @until_id == 0 |
|
56 | @until_id = nil if @until_id == 0 |
|
57 |
|
57 |
@@ -1,51 +1,51 | |||||
|
1 | class SiteController < ApplicationController |
|
1 | class SiteController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :site_admin_authorization, :except => 'login' |
|
4 |
|
4 | ||
|
5 | def login |
|
5 | def login |
|
6 | # Site administrator login |
|
6 | # Site administrator login |
|
7 | @countries = Country.includes(:sites).all |
|
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 |
|
14 |
|
14 | ||
|
15 | @site_select = [] |
|
15 | @site_select = [] |
|
16 | @countries.each do |country| |
|
16 | @countries.each do |country| |
|
17 | country.sites.each do |site| |
|
17 | country.sites.each do |site| |
|
18 | @site_select << ["#{site.name}, #{country.name}", site.id] |
|
18 | @site_select << ["#{site.name}, #{country.name}", site.id] |
|
19 | end |
|
19 | end |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | @default_site = Site.first if !GraderConfiguration['contest.multisites'] |
|
22 | @default_site = Site.first if !GraderConfiguration['contest.multisites'] |
|
23 |
|
23 | ||
|
24 | render :action => 'login', :layout => 'empty' |
|
24 | render :action => 'login', :layout => 'empty' |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | def index |
|
27 | def index |
|
28 | if @site.started |
|
28 | if @site.started |
|
29 | render :action => 'started', :layout => 'empty' |
|
29 | render :action => 'started', :layout => 'empty' |
|
30 | else |
|
30 | else |
|
31 | render :action => 'prompt', :layout => 'empty' |
|
31 | render :action => 'prompt', :layout => 'empty' |
|
32 | end |
|
32 | end |
|
33 | end |
|
33 | end |
|
34 |
|
34 | ||
|
35 | def start |
|
35 | def start |
|
36 | @site.started = true |
|
36 | @site.started = true |
|
37 | @site.start_time = Time.new.gmtime |
|
37 | @site.start_time = Time.new.gmtime |
|
38 | @site.save |
|
38 | @site.save |
|
39 | redirect_to :action => 'index' |
|
39 | redirect_to :action => 'index' |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def logout |
|
42 | def logout |
|
43 | reset_session |
|
43 | reset_session |
|
44 | redirect_to :controller => 'main', :action => 'login' |
|
44 | redirect_to :controller => 'main', :action => 'login' |
|
45 | end |
|
45 | end |
|
46 |
|
46 | ||
|
47 | protected |
|
47 | protected |
|
48 | def site_admin_authorization |
|
48 | def site_admin_authorization |
|
49 | if session[:site_id]==nil |
|
49 | if session[:site_id]==nil |
|
50 | redirect_to :controller => 'site', :action => 'login' and return |
|
50 | redirect_to :controller => 'site', :action => 'login' and return |
|
51 | end |
|
51 | end |
@@ -1,51 +1,51 | |||||
|
1 | class SitesController < ApplicationController |
|
1 | class SitesController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :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.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 |
|
15 |
|
15 | ||
|
16 | # GET /sites/1 |
|
16 | # GET /sites/1 |
|
17 | # GET /sites/1.xml |
|
17 | # GET /sites/1.xml |
|
18 | def show |
|
18 | def show |
|
19 | @site = Site.find(params[:id]) |
|
19 | @site = Site.find(params[:id]) |
|
20 |
|
20 | ||
|
21 | respond_to do |format| |
|
21 | respond_to do |format| |
|
22 | format.html # show.html.erb |
|
22 | format.html # show.html.erb |
|
23 | format.xml { render :xml => @site } |
|
23 | format.xml { render :xml => @site } |
|
24 | end |
|
24 | end |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | # GET /sites/new |
|
27 | # GET /sites/new |
|
28 | # GET /sites/new.xml |
|
28 | # GET /sites/new.xml |
|
29 | def new |
|
29 | def new |
|
30 | @site = Site.new |
|
30 | @site = Site.new |
|
31 |
|
31 | ||
|
32 | respond_to do |format| |
|
32 | respond_to do |format| |
|
33 | format.html # new.html.erb |
|
33 | format.html # new.html.erb |
|
34 | format.xml { render :xml => @site } |
|
34 | format.xml { render :xml => @site } |
|
35 | end |
|
35 | end |
|
36 | end |
|
36 | end |
|
37 |
|
37 | ||
|
38 | # GET /sites/1/edit |
|
38 | # GET /sites/1/edit |
|
39 | def edit |
|
39 | def edit |
|
40 | @site = Site.find(params[:id]) |
|
40 | @site = Site.find(params[:id]) |
|
41 | end |
|
41 | end |
|
42 |
|
42 | ||
|
43 | # POST /sites |
|
43 | # POST /sites |
|
44 | # POST /sites.xml |
|
44 | # POST /sites.xml |
|
45 | def create |
|
45 | def create |
|
46 | @site = Site.new(params[:site]) |
|
46 | @site = Site.new(params[:site]) |
|
47 | @site.clear_start_time_if_not_started |
|
47 | @site.clear_start_time_if_not_started |
|
48 |
|
48 | ||
|
49 | respond_to do |format| |
|
49 | respond_to do |format| |
|
50 | if @site.save |
|
50 | if @site.save |
|
51 | flash[:notice] = 'Site was successfully created.' |
|
51 | flash[:notice] = 'Site was successfully created.' |
@@ -1,51 +1,51 | |||||
|
1 | class TasksController < ApplicationController |
|
1 | class TasksController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :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 = @user.available_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 | ||
|
23 | send_file_to_user(filename, base_filename) |
|
23 | send_file_to_user(filename, base_filename) |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | # this has problem-level access control |
|
26 | # this has problem-level access control |
|
27 | def download |
|
27 | def download |
|
28 | problem = Problem.find(params[:id]) |
|
28 | problem = Problem.find(params[:id]) |
|
29 | unless @current_user.can_view_problem? problem |
|
29 | unless @current_user.can_view_problem? problem |
|
30 | redirect_to :action => 'index' and return |
|
30 | redirect_to :action => 'index' and return |
|
31 | end |
|
31 | end |
|
32 |
|
32 | ||
|
33 | base_name = params[:file] |
|
33 | base_name = params[:file] |
|
34 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
34 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
35 | filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}" |
|
35 | filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}" |
|
36 | puts "SENDING: #{filename}" |
|
36 | puts "SENDING: #{filename}" |
|
37 |
|
37 | ||
|
38 | if !FileTest.exists?(filename) |
|
38 | if !FileTest.exists?(filename) |
|
39 | redirect_to :action => 'index' and return |
|
39 | redirect_to :action => 'index' and return |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | puts "SENDING: #{filename}" |
|
42 | puts "SENDING: #{filename}" |
|
43 |
|
43 | ||
|
44 | send_file_to_user(filename, base_filename) |
|
44 | send_file_to_user(filename, base_filename) |
|
45 | end |
|
45 | end |
|
46 |
|
46 | ||
|
47 | protected |
|
47 | protected |
|
48 |
|
48 | ||
|
49 | def send_file_to_user(filename, base_filename) |
|
49 | def send_file_to_user(filename, base_filename) |
|
50 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
50 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
51 | response.headers['Content-Type'] = "application/force-download" |
|
51 | response.headers['Content-Type'] = "application/force-download" |
@@ -1,51 +1,51 | |||||
|
1 | class TestController < ApplicationController |
|
1 | class TestController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_ |
|
3 | + before_action :authenticate, :check_viewability |
|
4 |
|
4 | ||
|
5 | # |
|
5 | # |
|
6 | # COMMENT OUT: filter in each action instead |
|
6 | # COMMENT OUT: filter in each action instead |
|
7 | # |
|
7 | # |
|
8 | # before_filter :verify_time_limit, :only => [:submit] |
|
8 | # before_filter :verify_time_limit, :only => [:submit] |
|
9 |
|
9 | ||
|
10 | verify :method => :post, :only => [:submit], |
|
10 | verify :method => :post, :only => [:submit], |
|
11 | :redirect_to => { :action => :index } |
|
11 | :redirect_to => { :action => :index } |
|
12 |
|
12 | ||
|
13 | def index |
|
13 | def index |
|
14 | prepare_index_information |
|
14 | prepare_index_information |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | def submit |
|
17 | def submit |
|
18 | @user = User.find(session[:user_id]) |
|
18 | @user = User.find(session[:user_id]) |
|
19 |
|
19 | ||
|
20 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
20 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
21 |
|
21 | ||
|
22 | if ! @submitted_test_request.errors.empty? |
|
22 | if ! @submitted_test_request.errors.empty? |
|
23 | prepare_index_information |
|
23 | prepare_index_information |
|
24 | render :action => 'index' and return |
|
24 | render :action => 'index' and return |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | if GraderConfiguration.time_limit_mode? |
|
27 | if GraderConfiguration.time_limit_mode? |
|
28 | if @user.contest_finished? |
|
28 | if @user.contest_finished? |
|
29 | @submitted_test_request.errors.add(:base,'Contest is over.') |
|
29 | @submitted_test_request.errors.add(:base,'Contest is over.') |
|
30 | prepare_index_information |
|
30 | prepare_index_information |
|
31 | render :action => 'index' and return |
|
31 | render :action => 'index' and return |
|
32 | end |
|
32 | end |
|
33 |
|
33 | ||
|
34 | if !GraderConfiguration.allow_test_request(@user) |
|
34 | if !GraderConfiguration.allow_test_request(@user) |
|
35 | prepare_index_information |
|
35 | prepare_index_information |
|
36 | flash[:notice] = 'Test request is not allowed during the last 30 minutes' |
|
36 | flash[:notice] = 'Test request is not allowed during the last 30 minutes' |
|
37 | redirect_to :action => 'index' and return |
|
37 | redirect_to :action => 'index' and return |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
41 | if @submitted_test_request.save |
|
41 | if @submitted_test_request.save |
|
42 | redirect_to :action => 'index' |
|
42 | redirect_to :action => 'index' |
|
43 | else |
|
43 | else |
|
44 | prepare_index_information |
|
44 | prepare_index_information |
|
45 | render :action => 'index' |
|
45 | render :action => 'index' |
|
46 | end |
|
46 | end |
|
47 | end |
|
47 | end |
|
48 |
|
48 | ||
|
49 | def read |
|
49 | def read |
|
50 | user = User.find(session[:user_id]) |
|
50 | user = User.find(session[:user_id]) |
|
51 | begin |
|
51 | begin |
@@ -1,55 +1,55 | |||||
|
1 | require 'csv' |
|
1 | require 'csv' |
|
2 |
|
2 | ||
|
3 | class UserAdminController < ApplicationController |
|
3 | class UserAdminController < ApplicationController |
|
4 |
|
4 | ||
|
5 | include MailHelperMethods |
|
5 | include MailHelperMethods |
|
6 |
|
6 | ||
|
7 |
- before_ |
|
7 | + before_action :admin_authorization |
|
8 |
|
8 | ||
|
9 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
9 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
10 | verify :method => :post, :only => [ |
|
10 | verify :method => :post, :only => [ |
|
11 | :create, :create_from_list, |
|
11 | :create, :create_from_list, |
|
12 | :update, |
|
12 | :update, |
|
13 | :manage_contest, |
|
13 | :manage_contest, |
|
14 | :bulk_mail |
|
14 | :bulk_mail |
|
15 | ], |
|
15 | ], |
|
16 | :redirect_to => { :action => :list } |
|
16 | :redirect_to => { :action => :list } |
|
17 |
|
17 | ||
|
18 | def index |
|
18 | def index |
|
19 | @user_count = User.count |
|
19 | @user_count = User.count |
|
20 | if params[:page] == 'all' |
|
20 | if params[:page] == 'all' |
|
21 | @users = User.all |
|
21 | @users = User.all |
|
22 | @paginated = false |
|
22 | @paginated = false |
|
23 | else |
|
23 | else |
|
24 | @users = User.paginate :page => params[:page] |
|
24 | @users = User.paginate :page => params[:page] |
|
25 | @paginated = true |
|
25 | @paginated = true |
|
26 | end |
|
26 | end |
|
27 | @users = User.all |
|
27 | @users = User.all |
|
28 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
28 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] |
|
29 | @contests = Contest.enabled |
|
29 | @contests = Contest.enabled |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | def active |
|
32 | def active |
|
33 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
33 | sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago) |
|
34 | @users = [] |
|
34 | @users = [] |
|
35 | sessions.each do |session| |
|
35 | sessions.each do |session| |
|
36 | if session.data[:user_id] |
|
36 | if session.data[:user_id] |
|
37 | @users << User.find(session.data[:user_id]) |
|
37 | @users << User.find(session.data[:user_id]) |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | def show |
|
42 | def show |
|
43 | @user = User.find(params[:id]) |
|
43 | @user = User.find(params[:id]) |
|
44 | end |
|
44 | end |
|
45 |
|
45 | ||
|
46 | def new |
|
46 | def new |
|
47 | @user = User.new |
|
47 | @user = User.new |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | def create |
|
50 | def create |
|
51 | @user = User.new(user_params) |
|
51 | @user = User.new(user_params) |
|
52 | @user.activated = true |
|
52 | @user.activated = true |
|
53 | if @user.save |
|
53 | if @user.save |
|
54 | flash[:notice] = 'User was successfully created.' |
|
54 | flash[:notice] = 'User was successfully created.' |
|
55 | redirect_to :action => 'index' |
|
55 | redirect_to :action => 'index' |
@@ -1,67 +1,67 | |||||
|
1 | require 'net/smtp' |
|
1 | require 'net/smtp' |
|
2 |
|
2 | ||
|
3 | class UsersController < ApplicationController |
|
3 | class UsersController < ApplicationController |
|
4 |
|
4 | ||
|
5 | include MailHelperMethods |
|
5 | include MailHelperMethods |
|
6 |
|
6 | ||
|
7 |
- before_ |
|
7 | + before_action :authenticate, :except => [:new, |
|
8 | :register, |
|
8 | :register, |
|
9 | :confirm, |
|
9 | :confirm, |
|
10 | :forget, |
|
10 | :forget, |
|
11 | :retrieve_password] |
|
11 | :retrieve_password] |
|
12 |
|
12 | ||
|
13 |
- before_ |
|
13 | + before_action :verify_online_registration, :only => [:new, |
|
14 | :register, |
|
14 | :register, |
|
15 | :forget, |
|
15 | :forget, |
|
16 | :retrieve_password] |
|
16 | :retrieve_password] |
|
17 |
- before_ |
|
17 | + before_action :authenticate, :profile_authorization, only: [:profile] |
|
18 |
|
18 | ||
|
19 |
- before_ |
|
19 | + before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
20 |
|
20 | ||
|
21 |
|
21 | ||
|
22 | verify :method => :post, :only => [:chg_passwd], |
|
22 | verify :method => :post, :only => [:chg_passwd], |
|
23 | :redirect_to => { :action => :index } |
|
23 | :redirect_to => { :action => :index } |
|
24 |
|
24 | ||
|
25 | #in_place_edit_for :user, :alias_for_editing |
|
25 | #in_place_edit_for :user, :alias_for_editing |
|
26 | #in_place_edit_for :user, :email_for_editing |
|
26 | #in_place_edit_for :user, :email_for_editing |
|
27 |
|
27 | ||
|
28 | def index |
|
28 | def index |
|
29 | if !GraderConfiguration['system.user_setting_enabled'] |
|
29 | if !GraderConfiguration['system.user_setting_enabled'] |
|
30 | redirect_to :controller => 'main', :action => 'list' |
|
30 | redirect_to :controller => 'main', :action => 'list' |
|
31 | else |
|
31 | else |
|
32 | @user = User.find(session[:user_id]) |
|
32 | @user = User.find(session[:user_id]) |
|
33 | end |
|
33 | end |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | def chg_passwd |
|
36 | def chg_passwd |
|
37 | user = User.find(session[:user_id]) |
|
37 | user = User.find(session[:user_id]) |
|
38 | user.password = params[:passwd] |
|
38 | user.password = params[:passwd] |
|
39 | user.password_confirmation = params[:passwd_verify] |
|
39 | user.password_confirmation = params[:passwd_verify] |
|
40 | if user.save |
|
40 | if user.save |
|
41 | flash[:notice] = 'password changed' |
|
41 | flash[:notice] = 'password changed' |
|
42 | else |
|
42 | else |
|
43 | flash[:notice] = 'Error: password changing failed' |
|
43 | flash[:notice] = 'Error: password changing failed' |
|
44 | end |
|
44 | end |
|
45 | redirect_to :action => 'index' |
|
45 | redirect_to :action => 'index' |
|
46 | end |
|
46 | end |
|
47 |
|
47 | ||
|
48 | def new |
|
48 | def new |
|
49 | @user = User.new |
|
49 | @user = User.new |
|
50 | render :action => 'new', :layout => 'empty' |
|
50 | render :action => 'new', :layout => 'empty' |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 | def register |
|
53 | def register |
|
54 | if(params[:cancel]) |
|
54 | if(params[:cancel]) |
|
55 | redirect_to :controller => 'main', :action => 'login' |
|
55 | redirect_to :controller => 'main', :action => 'login' |
|
56 | return |
|
56 | return |
|
57 | end |
|
57 | end |
|
58 | @user = User.new(user_params) |
|
58 | @user = User.new(user_params) |
|
59 | @user.password_confirmation = @user.password = User.random_password |
|
59 | @user.password_confirmation = @user.password = User.random_password |
|
60 | @user.activated = false |
|
60 | @user.activated = false |
|
61 | if (@user.valid?) and (@user.save) |
|
61 | if (@user.valid?) and (@user.save) |
|
62 | if send_confirmation_email(@user) |
|
62 | if send_confirmation_email(@user) |
|
63 | render :action => 'new_splash', :layout => 'empty' |
|
63 | render :action => 'new_splash', :layout => 'empty' |
|
64 | else |
|
64 | else |
|
65 | @admin_email = GraderConfiguration['system.admin_email'] |
|
65 | @admin_email = GraderConfiguration['system.admin_email'] |
|
66 | render :action => 'email_error', :layout => 'empty' |
|
66 | render :action => 'email_error', :layout => 'empty' |
|
67 | end |
|
67 | end |
@@ -1,56 +1,57 | |||||
|
1 | CafeGrader::Application.routes.draw do |
|
1 | CafeGrader::Application.routes.draw do |
|
2 | resources :tags |
|
2 | resources :tags |
|
3 | get "sources/direct_edit" |
|
3 | get "sources/direct_edit" |
|
4 |
|
4 | ||
|
5 | root :to => 'main#login' |
|
5 | root :to => 'main#login' |
|
6 |
|
6 | ||
|
7 | #logins |
|
7 | #logins |
|
8 |
- |
|
8 | + match 'login/login', to: 'login#login', via: [:get,:post] |
|
|
9 | + | ||
|
9 |
|
10 | ||
|
10 | resources :contests |
|
11 | resources :contests |
|
11 |
|
12 | ||
|
12 | resources :sites |
|
13 | resources :sites |
|
13 |
|
14 | ||
|
14 | resources :announcements do |
|
15 | resources :announcements do |
|
15 | member do |
|
16 | member do |
|
16 | get 'toggle','toggle_front' |
|
17 | get 'toggle','toggle_front' |
|
17 | end |
|
18 | end |
|
18 | end |
|
19 | end |
|
19 |
|
20 | ||
|
20 | resources :problems do |
|
21 | resources :problems do |
|
21 | member do |
|
22 | member do |
|
22 | get 'toggle' |
|
23 | get 'toggle' |
|
23 | get 'toggle_test' |
|
24 | get 'toggle_test' |
|
24 | get 'toggle_view_testcase' |
|
25 | get 'toggle_view_testcase' |
|
25 | get 'stat' |
|
26 | get 'stat' |
|
26 | end |
|
27 | end |
|
27 | collection do |
|
28 | collection do |
|
28 | get 'turn_all_off' |
|
29 | get 'turn_all_off' |
|
29 | get 'turn_all_on' |
|
30 | get 'turn_all_on' |
|
30 | get 'import' |
|
31 | get 'import' |
|
31 | get 'manage' |
|
32 | get 'manage' |
|
32 | end |
|
33 | end |
|
33 | end |
|
34 | end |
|
34 |
|
35 | ||
|
35 | resources :groups do |
|
36 | resources :groups do |
|
36 | member do |
|
37 | member do |
|
37 | post 'add_user', to: 'groups#add_user', as: 'add_user' |
|
38 | post 'add_user', to: 'groups#add_user', as: 'add_user' |
|
38 | delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user' |
|
39 | delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user' |
|
39 | delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user' |
|
40 | delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user' |
|
40 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
41 | post 'add_problem', to: 'groups#add_problem', as: 'add_problem' |
|
41 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
42 | delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem' |
|
42 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
43 | delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem' |
|
43 | end |
|
44 | end |
|
44 | collection do |
|
45 | collection do |
|
45 |
|
46 | ||
|
46 | end |
|
47 | end |
|
47 | end |
|
48 | end |
|
48 |
|
49 | ||
|
49 | resources :testcases, only: [] do |
|
50 | resources :testcases, only: [] do |
|
50 | member do |
|
51 | member do |
|
51 | get 'download_input' |
|
52 | get 'download_input' |
|
52 | get 'download_sol' |
|
53 | get 'download_sol' |
|
53 | end |
|
54 | end |
|
54 | collection do |
|
55 | collection do |
|
55 | get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem' |
|
56 | get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem' |
|
56 | end |
|
57 | end |
@@ -1,40 +1,40 | |||||
|
1 | require 'test_helper' |
|
1 | require 'test_helper' |
|
2 |
|
2 | ||
|
3 | class LoginTest < ActionDispatch::IntegrationTest |
|
3 | class LoginTest < ActionDispatch::IntegrationTest |
|
4 | # test "the truth" do |
|
4 | # test "the truth" do |
|
5 | # assert true |
|
5 | # assert true |
|
6 | # end |
|
6 | # end |
|
7 |
|
7 | ||
|
8 | test "login with invalid information" do |
|
8 | test "login with invalid information" do |
|
9 | get root_path |
|
9 | get root_path |
|
10 | assert_response :success |
|
10 | assert_response :success |
|
11 | - post login_login_path, login: "root", password: "hahaha" |
|
11 | + post login_login_path, params: {login: "root", password: "hahaha"} |
|
12 | assert_redirected_to root_path |
|
12 | assert_redirected_to root_path |
|
13 | end |
|
13 | end |
|
14 |
|
14 | ||
|
15 | test "normal user login" do |
|
15 | test "normal user login" do |
|
16 | get root_path |
|
16 | get root_path |
|
17 | assert_response :success |
|
17 | assert_response :success |
|
18 | - post login_login_path, {login: "john", password: "hello" } |
|
18 | + post login_login_path, params: {login: "john", password: "hello" } |
|
19 | assert_redirected_to main_list_path |
|
19 | assert_redirected_to main_list_path |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | test "normal user login in single_user mode" do |
|
22 | test "normal user login in single_user mode" do |
|
23 | GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true') |
|
23 | GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true') |
|
24 | GraderConfiguration.reload |
|
24 | GraderConfiguration.reload |
|
25 | get root_path |
|
25 | get root_path |
|
26 | assert_response :success |
|
26 | assert_response :success |
|
27 | - post login_login_path, {login: "john", password: "hello" } |
|
27 | + post login_login_path, params: {login: "john", password: "hello" } |
|
28 | follow_redirect! |
|
28 | follow_redirect! |
|
29 | assert_redirected_to root_path |
|
29 | assert_redirected_to root_path |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | test "root login in in single_user mode" do |
|
32 | test "root login in in single_user mode" do |
|
33 | GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true') |
|
33 | GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true') |
|
34 | GraderConfiguration.reload |
|
34 | GraderConfiguration.reload |
|
35 | get root_path |
|
35 | get root_path |
|
36 | assert_response :success |
|
36 | assert_response :success |
|
37 | - post login_login_path, {login: "admin", password: "admin" } |
|
37 | + post login_login_path, params: {login: "admin", password: "admin" } |
|
38 | assert_redirected_to main_list_path |
|
38 | assert_redirected_to main_list_path |
|
39 | end |
|
39 | end |
|
40 | end |
|
40 | end |
You need to be logged in to leave comments.
Login now