Description:
more test and clean up authorization
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r756:aa79958f6521 - - 13 files changed: 53 inserted, 38 deleted
@@ -85,24 +85,25 | |||||
|
85 | xpath (~> 3.2) |
|
85 | xpath (~> 3.2) |
|
86 | childprocess (1.0.1) |
|
86 | childprocess (1.0.1) |
|
87 | rake (< 13.0) |
|
87 | rake (< 13.0) |
|
88 | coffee-rails (4.2.2) |
|
88 | coffee-rails (4.2.2) |
|
89 | coffee-script (>= 2.2.0) |
|
89 | coffee-script (>= 2.2.0) |
|
90 | railties (>= 4.0.0) |
|
90 | railties (>= 4.0.0) |
|
91 | coffee-script (2.4.1) |
|
91 | coffee-script (2.4.1) |
|
92 | coffee-script-source |
|
92 | coffee-script-source |
|
93 | execjs |
|
93 | execjs |
|
94 | coffee-script-source (1.12.2) |
|
94 | coffee-script-source (1.12.2) |
|
95 | concurrent-ruby (1.1.5) |
|
95 | concurrent-ruby (1.1.5) |
|
96 | crass (1.0.4) |
|
96 | crass (1.0.4) |
|
|
97 | + diff-lcs (1.3) | ||
|
97 | dynamic_form (1.1.4) |
|
98 | dynamic_form (1.1.4) |
|
98 | erubi (1.8.0) |
|
99 | erubi (1.8.0) |
|
99 | erubis (2.7.0) |
|
100 | erubis (2.7.0) |
|
100 | execjs (2.7.0) |
|
101 | execjs (2.7.0) |
|
101 | ffi (1.11.1) |
|
102 | ffi (1.11.1) |
|
102 | fuzzy-string-match (1.0.1) |
|
103 | fuzzy-string-match (1.0.1) |
|
103 | RubyInline (>= 3.8.6) |
|
104 | RubyInline (>= 3.8.6) |
|
104 | globalid (0.4.2) |
|
105 | globalid (0.4.2) |
|
105 | activesupport (>= 4.2.0) |
|
106 | activesupport (>= 4.2.0) |
|
106 | haml (5.1.0) |
|
107 | haml (5.1.0) |
|
107 | temple (>= 0.8.0) |
|
108 | temple (>= 0.8.0) |
|
108 | tilt |
|
109 | tilt |
@@ -201,24 +202,41 | |||||
|
201 | actionpack (= 5.2.3) |
|
202 | actionpack (= 5.2.3) |
|
202 | activesupport (= 5.2.3) |
|
203 | activesupport (= 5.2.3) |
|
203 | method_source |
|
204 | method_source |
|
204 | rake (>= 0.8.7) |
|
205 | rake (>= 0.8.7) |
|
205 | thor (>= 0.19.0, < 2.0) |
|
206 | thor (>= 0.19.0, < 2.0) |
|
206 | rake (12.3.2) |
|
207 | rake (12.3.2) |
|
207 | rb-fsevent (0.10.3) |
|
208 | rb-fsevent (0.10.3) |
|
208 | rb-inotify (0.10.0) |
|
209 | rb-inotify (0.10.0) |
|
209 | ffi (~> 1.0) |
|
210 | ffi (~> 1.0) |
|
210 | rdiscount (2.2.0.1) |
|
211 | rdiscount (2.2.0.1) |
|
211 | regexp_parser (1.5.1) |
|
212 | regexp_parser (1.5.1) |
|
212 | rouge (3.3.0) |
|
213 | rouge (3.3.0) |
|
|
214 | + rspec-core (3.8.2) | ||
|
|
215 | + rspec-support (~> 3.8.0) | ||
|
|
216 | + rspec-expectations (3.8.4) | ||
|
|
217 | + diff-lcs (>= 1.2.0, < 2.0) | ||
|
|
218 | + rspec-support (~> 3.8.0) | ||
|
|
219 | + rspec-mocks (3.8.1) | ||
|
|
220 | + diff-lcs (>= 1.2.0, < 2.0) | ||
|
|
221 | + rspec-support (~> 3.8.0) | ||
|
|
222 | + rspec-rails (3.8.2) | ||
|
|
223 | + actionpack (>= 3.0) | ||
|
|
224 | + activesupport (>= 3.0) | ||
|
|
225 | + railties (>= 3.0) | ||
|
|
226 | + rspec-core (~> 3.8.0) | ||
|
|
227 | + rspec-expectations (~> 3.8.0) | ||
|
|
228 | + rspec-mocks (~> 3.8.0) | ||
|
|
229 | + rspec-support (~> 3.8.0) | ||
|
|
230 | + rspec-support (3.8.2) | ||
|
213 | ruby-progressbar (1.10.0) |
|
231 | ruby-progressbar (1.10.0) |
|
214 | ruby_dep (1.5.0) |
|
232 | ruby_dep (1.5.0) |
|
215 | ruby_parser (3.13.1) |
|
233 | ruby_parser (3.13.1) |
|
216 | sexp_processor (~> 4.9) |
|
234 | sexp_processor (~> 4.9) |
|
217 | rubyzip (1.2.3) |
|
235 | rubyzip (1.2.3) |
|
218 | sass (3.7.4) |
|
236 | sass (3.7.4) |
|
219 | sass-listen (~> 4.0.0) |
|
237 | sass-listen (~> 4.0.0) |
|
220 | sass-listen (4.0.0) |
|
238 | sass-listen (4.0.0) |
|
221 | rb-fsevent (~> 0.9, >= 0.9.4) |
|
239 | rb-fsevent (~> 0.9, >= 0.9.4) |
|
222 | rb-inotify (~> 0.9, >= 0.9.7) |
|
240 | rb-inotify (~> 0.9, >= 0.9.7) |
|
223 | sass-rails (5.0.7) |
|
241 | sass-rails (5.0.7) |
|
224 | railties (>= 4.0.0, < 6) |
|
242 | railties (>= 4.0.0, < 6) |
@@ -311,24 +329,25 | |||||
|
311 | jquery-ui-rails |
|
329 | jquery-ui-rails |
|
312 | listen (>= 3.0.5, < 3.2) |
|
330 | listen (>= 3.0.5, < 3.2) |
|
313 |
|
331 | ||
|
314 | minitest-reporters |
|
332 | minitest-reporters |
|
315 | momentjs-rails |
|
333 | momentjs-rails |
|
316 | mysql2 |
|
334 | mysql2 |
|
317 | puma |
|
335 | puma |
|
318 | rails (~> 5.2) |
|
336 | rails (~> 5.2) |
|
319 | rails-controller-testing |
|
337 | rails-controller-testing |
|
320 | rails_bootstrap_sortable |
|
338 | rails_bootstrap_sortable |
|
321 | rdiscount |
|
339 | rdiscount |
|
322 | rouge |
|
340 | rouge |
|
|
341 | + rspec-rails | ||
|
323 | sassc-rails |
|
342 | sassc-rails |
|
324 | select2-rails |
|
343 | select2-rails |
|
325 | selenium-webdriver |
|
344 | selenium-webdriver |
|
326 | simple_form |
|
345 | simple_form |
|
327 | spring |
|
346 | spring |
|
328 | spring-watcher-listen (~> 2.0.0) |
|
347 | spring-watcher-listen (~> 2.0.0) |
|
329 | sqlite3 |
|
348 | sqlite3 |
|
330 | uglifier |
|
349 | uglifier |
|
331 | web-console (>= 3.3.0) |
|
350 | web-console (>= 3.3.0) |
|
332 | webdriver |
|
351 | webdriver |
|
333 | will_paginate (~> 3.0.7) |
|
352 | will_paginate (~> 3.0.7) |
|
334 | yaml_db |
|
353 | yaml_db |
@@ -2,99 +2,98 | |||||
|
2 |
|
2 | ||
|
3 | class ApplicationController < ActionController::Base |
|
3 | class ApplicationController < ActionController::Base |
|
4 | protect_from_forgery |
|
4 | protect_from_forgery |
|
5 |
|
5 | ||
|
6 | before_action :current_user |
|
6 | before_action :current_user |
|
7 |
|
7 | ||
|
8 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
8 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
9 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
9 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
10 | ALLOW_WHITELIST_IP_ONLY_CONF_KEY = 'right.allow_whitelist_ip_only' |
|
10 | ALLOW_WHITELIST_IP_ONLY_CONF_KEY = 'right.allow_whitelist_ip_only' |
|
11 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
11 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
12 |
|
12 | ||
|
13 | #report and redirect for unauthorized activities |
|
13 | #report and redirect for unauthorized activities |
|
14 | - def unauthorized_redirect |
|
14 | + def unauthorized_redirect(notice = 'You are not authorized to view the page you requested') |
|
15 | - flash[:notice] = 'You are not authorized to view the page you requested' |
|
15 | + flash[:notice] = notice |
|
16 | - redirect_to :controller => 'main', :action => 'login' |
|
16 | + redirect_to login_main_path |
|
17 | end |
|
17 | end |
|
18 |
|
18 | ||
|
19 | # Returns the current logged-in user (if any). |
|
19 | # Returns the current logged-in user (if any). |
|
20 | def current_user |
|
20 | def current_user |
|
21 | return nil unless session[:user_id] |
|
21 | return nil unless session[:user_id] |
|
22 | @current_user ||= User.find(session[:user_id]) |
|
22 | @current_user ||= User.find(session[:user_id]) |
|
23 | end |
|
23 | end |
|
24 |
|
24 | ||
|
25 | def admin_authorization |
|
25 | def admin_authorization |
|
26 |
- return false unless |
|
26 | + return false unless check_valid_login |
|
27 | user = User.includes(:roles).find(session[:user_id]) |
|
27 | user = User.includes(:roles).find(session[:user_id]) |
|
28 | unless user.admin? |
|
28 | unless user.admin? |
|
29 | unauthorized_redirect |
|
29 | unauthorized_redirect |
|
30 | return false |
|
30 | return false |
|
31 | end |
|
31 | end |
|
32 | return true |
|
32 | return true |
|
33 | end |
|
33 | end |
|
34 |
|
34 | ||
|
35 | def authorization_by_roles(allowed_roles) |
|
35 | def authorization_by_roles(allowed_roles) |
|
36 |
- return false unless |
|
36 | + return false unless check_valid_login |
|
37 | user = User.find(session[:user_id]) |
|
37 | user = User.find(session[:user_id]) |
|
38 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
38 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
39 | unauthorized_redirect |
|
39 | unauthorized_redirect |
|
40 | return false |
|
40 | return false |
|
41 | end |
|
41 | end |
|
42 | end |
|
42 | end |
|
43 |
|
43 | ||
|
44 | def testcase_authorization |
|
44 | def testcase_authorization |
|
45 | #admin always has privileged |
|
45 | #admin always has privileged |
|
46 | if @current_user.admin? |
|
46 | if @current_user.admin? |
|
47 | return true |
|
47 | return true |
|
48 | end |
|
48 | end |
|
49 |
|
49 | ||
|
50 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
50 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 |
|
53 | ||
|
54 | protected |
|
54 | protected |
|
55 |
|
55 | ||
|
56 | #redirect to root (and also force logout) |
|
56 | #redirect to root (and also force logout) |
|
57 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
57 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
58 | - def authenticate |
|
58 | + def check_valid_login |
|
|
59 | + #check if logged in | ||
|
59 | unless session[:user_id] |
|
60 | unless session[:user_id] |
|
60 | - flash[:notice] = 'You need to login' |
|
||
|
61 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
61 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
62 |
- |
|
62 | + unauthorized_redirect('You need to login but you cannot log in at this time') |
|
|
63 | + else | ||
|
|
64 | + unauthorized_redirect('You need to login') | ||
|
63 | end |
|
65 | end |
|
64 | - redirect_to :controller => 'main', :action => 'login' |
|
||
|
65 | return false |
|
66 | return false |
|
66 | end |
|
67 | end |
|
67 |
|
68 | ||
|
68 | # check if run in single user mode |
|
69 | # check if run in single user mode |
|
69 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
70 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
70 | if @current_user==nil || (not @current_user.admin?) |
|
71 | if @current_user==nil || (not @current_user.admin?) |
|
71 |
- |
|
72 | + unauthorized_redirect('You cannot log in at this time') |
|
72 | - redirect_to :controller => 'main', :action => 'login' |
|
||
|
73 | return false |
|
73 | return false |
|
74 | end |
|
74 | end |
|
75 | end |
|
75 | end |
|
76 |
|
76 | ||
|
77 | # check if the user is enabled |
|
77 | # check if the user is enabled |
|
78 | unless @current_user.enabled? || @current_user.admin? |
|
78 | unless @current_user.enabled? || @current_user.admin? |
|
79 |
- |
|
79 | + unauthorized_redirect 'Your account is disabled' |
|
80 | - redirect_to :controller => 'main', :action => 'login' |
|
||
|
81 | return false |
|
80 | return false |
|
82 | end |
|
81 | end |
|
83 |
|
82 | ||
|
84 | # check if user ip is allowed |
|
83 | # check if user ip is allowed |
|
85 | unless @current_user.admin? || !GraderConfiguration[ALLOW_WHITELIST_IP_ONLY_CONF_KEY] |
|
84 | unless @current_user.admin? || !GraderConfiguration[ALLOW_WHITELIST_IP_ONLY_CONF_KEY] |
|
86 | unless is_request_ip_allowed? |
|
85 | unless is_request_ip_allowed? |
|
87 |
- |
|
86 | + unauthorized_redirect 'Your IP is not allowed' |
|
88 | - redirect_to root_path |
|
87 | + return false |
|
89 | end |
|
88 | end |
|
90 | end |
|
89 | end |
|
91 |
|
90 | ||
|
92 | if GraderConfiguration.multicontests? |
|
91 | if GraderConfiguration.multicontests? |
|
93 | return true if @current_user.admin? |
|
92 | return true if @current_user.admin? |
|
94 | begin |
|
93 | begin |
|
95 | if @current_user.contest_stat(true).forced_logout |
|
94 | if @current_user.contest_stat(true).forced_logout |
|
96 | flash[:notice] = 'You have been automatically logged out.' |
|
95 | flash[:notice] = 'You have been automatically logged out.' |
|
97 | redirect_to :controller => 'main', :action => 'index' |
|
96 | redirect_to :controller => 'main', :action => 'index' |
|
98 | end |
|
97 | end |
|
99 | rescue |
|
98 | rescue |
|
100 | end |
|
99 | end |
@@ -115,25 +114,25 | |||||
|
115 | puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}" |
|
114 | puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}" |
|
116 | return false |
|
115 | return false |
|
117 | end |
|
116 | end |
|
118 | unless user.last_ip |
|
117 | unless user.last_ip |
|
119 | user.last_ip = request.remote_ip |
|
118 | user.last_ip = request.remote_ip |
|
120 | user.save |
|
119 | user.save |
|
121 | end |
|
120 | end |
|
122 | end |
|
121 | end |
|
123 | return true |
|
122 | return true |
|
124 | end |
|
123 | end |
|
125 |
|
124 | ||
|
126 | def authorization |
|
125 | def authorization |
|
127 |
- return false unless |
|
126 | + return false unless check_valid_login |
|
128 | user = User.find(session[:user_id]) |
|
127 | user = User.find(session[:user_id]) |
|
129 | unless user.roles.detect { |role| |
|
128 | unless user.roles.detect { |role| |
|
130 | role.rights.detect{ |right| |
|
129 | role.rights.detect{ |right| |
|
131 | right.controller == self.class.controller_name and |
|
130 | right.controller == self.class.controller_name and |
|
132 | (right.action == 'all' || right.action == action_name) |
|
131 | (right.action == 'all' || right.action == action_name) |
|
133 | } |
|
132 | } |
|
134 | } |
|
133 | } |
|
135 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
134 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
136 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
135 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
137 | redirect_to :controller => 'main', :action => 'login' |
|
136 | redirect_to :controller => 'main', :action => 'login' |
|
138 | return false |
|
137 | return false |
|
139 | end |
|
138 | end |
@@ -1,17 +1,15 | |||||
|
1 | class ConfigurationsController < ApplicationController |
|
1 | class ConfigurationsController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_action :a |
|
3 | + before_action :admin_authorization |
|
4 | - before_action { |controller| controller.authorization_by_roles(['admin'])} |
|
||
|
5 | - |
|
||
|
6 |
|
4 | ||
|
7 | def index |
|
5 | def index |
|
8 | @configurations = GraderConfiguration.order(:key) |
|
6 | @configurations = GraderConfiguration.order(:key) |
|
9 | @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort |
|
7 | @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort |
|
10 | end |
|
8 | end |
|
11 |
|
9 | ||
|
12 | def reload |
|
10 | def reload |
|
13 | GraderConfiguration.reload |
|
11 | GraderConfiguration.reload |
|
14 | redirect_to :action => 'index' |
|
12 | redirect_to :action => 'index' |
|
15 | end |
|
13 | end |
|
16 |
|
14 | ||
|
17 | def update |
|
15 | def update |
@@ -1,18 +1,18 | |||||
|
1 | class GroupsController < ApplicationController |
|
1 | class GroupsController < ApplicationController |
|
2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
2 | before_action :set_group, only: [:show, :edit, :update, :destroy, |
|
3 | :add_user, :remove_user,:remove_all_user, |
|
3 | :add_user, :remove_user,:remove_all_user, |
|
4 | :add_problem, :remove_problem,:remove_all_problem, |
|
4 | :add_problem, :remove_problem,:remove_all_problem, |
|
5 | ] |
|
5 | ] |
|
6 |
- before_action |
|
6 | + before_action :admin_authorization |
|
7 |
|
7 | ||
|
8 | # GET /groups |
|
8 | # GET /groups |
|
9 | def index |
|
9 | def index |
|
10 | @groups = Group.all |
|
10 | @groups = Group.all |
|
11 | end |
|
11 | end |
|
12 |
|
12 | ||
|
13 | # GET /groups/1 |
|
13 | # GET /groups/1 |
|
14 | def show |
|
14 | def show |
|
15 | end |
|
15 | end |
|
16 |
|
16 | ||
|
17 | # GET /groups/new |
|
17 | # GET /groups/new |
|
18 | def new |
|
18 | def new |
@@ -1,36 +1,31 | |||||
|
1 | class MainController < ApplicationController |
|
1 | class MainController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_action : |
|
3 | + before_action :check_valid_login, :except => [:login] |
|
4 | before_action :check_viewability, :except => [:index, :login] |
|
4 | before_action :check_viewability, :except => [:index, :login] |
|
5 |
|
5 | ||
|
6 | append_before_action :confirm_and_update_start_time, |
|
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_action :reject_announcement_refresh_when_logged_out, |
|
13 | prepend_before_action :reject_announcement_refresh_when_logged_out, |
|
14 | :only => [:announcements] |
|
14 | :only => [:announcements] |
|
15 |
|
15 | ||
|
16 | before_action :authenticate_by_ip_address, :only => [:list] |
|
16 | before_action :authenticate_by_ip_address, :only => [:list] |
|
17 |
|
17 | ||
|
18 | - # NOTE: This method is not actually needed, 'config/routes.rb' has |
|
||
|
19 | - # assigned action login as a default action. |
|
||
|
20 | - def index |
|
||
|
21 | - redirect_to :action => 'login' |
|
||
|
22 | - end |
|
||
|
23 | - |
|
||
|
24 | #reset login, clear session |
|
18 | #reset login, clear session |
|
|
19 | + #front page | ||
|
25 | def login |
|
20 | def login |
|
26 | saved_notice = flash[:notice] |
|
21 | saved_notice = flash[:notice] |
|
27 | reset_session |
|
22 | reset_session |
|
28 | flash.now[:notice] = saved_notice |
|
23 | flash.now[:notice] = saved_notice |
|
29 |
|
24 | ||
|
30 | # EXPERIMENT: |
|
25 | # EXPERIMENT: |
|
31 | # Hide login if in single user mode and the url does not |
|
26 | # Hide login if in single user mode and the url does not |
|
32 | # explicitly specify /login |
|
27 | # explicitly specify /login |
|
33 | # |
|
28 | # |
|
34 | # logger.info "PATH: #{request.path}" |
|
29 | # logger.info "PATH: #{request.path}" |
|
35 | # if GraderConfiguration['system.single_user_mode'] and |
|
30 | # if GraderConfiguration['system.single_user_mode'] and |
|
36 | # request.path!='/main/login' |
|
31 | # request.path!='/main/login' |
@@ -1,16 +1,19 | |||||
|
1 | class ProblemsController < ApplicationController |
|
1 | class ProblemsController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_action :a |
|
3 | + before_action :admin_authorization |
|
4 | - before_action :testcase_authorization, only: [:show_testcase] |
|
4 | + |
|
|
5 | + #NOTE: ghost from the past? | ||
|
|
6 | + #before_action :testcase_authorization, only: [:show_testcase] | ||
|
|
7 | + | ||
|
5 |
|
8 | ||
|
6 | in_place_edit_for :problem, :name |
|
9 | in_place_edit_for :problem, :name |
|
7 | in_place_edit_for :problem, :full_name |
|
10 | in_place_edit_for :problem, :full_name |
|
8 | in_place_edit_for :problem, :full_score |
|
11 | in_place_edit_for :problem, :full_score |
|
9 |
|
12 | ||
|
10 | def index |
|
13 | def index |
|
11 | @problems = Problem.order(date_added: :desc) |
|
14 | @problems = Problem.order(date_added: :desc) |
|
12 | end |
|
15 | end |
|
13 |
|
16 | ||
|
14 |
|
17 | ||
|
15 | def show |
|
18 | def show |
|
16 | @problem = Problem.find(params[:id]) |
|
19 | @problem = Problem.find(params[:id]) |
@@ -1,22 +1,22 | |||||
|
1 | require 'csv' |
|
1 | require 'csv' |
|
2 |
|
2 | ||
|
3 | class ReportController < ApplicationController |
|
3 | class ReportController < ApplicationController |
|
4 |
|
4 | ||
|
5 |
- before_action : |
|
5 | + before_action :check_valid_login |
|
6 |
|
6 | ||
|
7 | before_action :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score, :current_score] |
|
7 | before_action :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score, :current_score] |
|
8 |
|
8 | ||
|
9 | before_action(only: [:problem_hof]) { |c| |
|
9 | before_action(only: [:problem_hof]) { |c| |
|
10 |
- return false unless |
|
10 | + return false unless check_valid_login |
|
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 |
@@ -1,14 +1,14 | |||||
|
1 | class SubmissionsController < ApplicationController |
|
1 | class SubmissionsController < ApplicationController |
|
2 |
- before_action : |
|
2 | + before_action :check_valid_login |
|
3 | before_action :submission_authorization, only: [:show, :download, :edit] |
|
3 | before_action :submission_authorization, only: [:show, :download, :edit] |
|
4 | before_action :admin_authorization, only: [:rejudge] |
|
4 | before_action :admin_authorization, only: [:rejudge] |
|
5 |
|
5 | ||
|
6 | # GET /submissions |
|
6 | # GET /submissions |
|
7 | # GET /submissions.json |
|
7 | # GET /submissions.json |
|
8 | # Show problem selection and user's submission of that problem |
|
8 | # Show problem selection and user's submission of that problem |
|
9 | def index |
|
9 | def index |
|
10 | @user = @current_user |
|
10 | @user = @current_user |
|
11 | @problems = @user.available_problems |
|
11 | @problems = @user.available_problems |
|
12 |
|
12 | ||
|
13 | if params[:problem_id]==nil |
|
13 | if params[:problem_id]==nil |
|
14 | @problem = nil |
|
14 | @problem = nil |
@@ -1,13 +1,14 | |||||
|
1 | class TagsController < ApplicationController |
|
1 | class TagsController < ApplicationController |
|
|
2 | + before_action :admin_authorization | ||
|
2 | before_action :set_tag, only: [:show, :edit, :update, :destroy] |
|
3 | before_action :set_tag, only: [:show, :edit, :update, :destroy] |
|
3 |
|
4 | ||
|
4 | # GET /tags |
|
5 | # GET /tags |
|
5 | def index |
|
6 | def index |
|
6 | @tags = Tag.all |
|
7 | @tags = Tag.all |
|
7 | end |
|
8 | end |
|
8 |
|
9 | ||
|
9 | # GET /tags/1 |
|
10 | # GET /tags/1 |
|
10 | def show |
|
11 | def show |
|
11 | end |
|
12 | end |
|
12 |
|
13 | ||
|
13 | # GET /tags/new |
|
14 | # GET /tags/new |
@@ -1,15 +1,15 | |||||
|
1 | class TasksController < ApplicationController |
|
1 | class TasksController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_action : |
|
3 | + before_action :check_valid_login, :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] |
@@ -1,15 +1,15 | |||||
|
1 | class TestController < ApplicationController |
|
1 | class TestController < ApplicationController |
|
2 |
|
2 | ||
|
3 |
- before_action : |
|
3 | + before_action :check_valid_login, :check_viewability |
|
4 |
|
4 | ||
|
5 |
|
5 | ||
|
6 | def index |
|
6 | def index |
|
7 | prepare_index_information |
|
7 | prepare_index_information |
|
8 | end |
|
8 | end |
|
9 |
|
9 | ||
|
10 | def submit |
|
10 | def submit |
|
11 | @user = User.find(session[:user_id]) |
|
11 | @user = User.find(session[:user_id]) |
|
12 |
|
12 | ||
|
13 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
13 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) |
|
14 |
|
14 | ||
|
15 | if ! @submitted_test_request.errors.empty? |
|
15 | if ! @submitted_test_request.errors.empty? |
@@ -1,29 +1,29 | |||||
|
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_action : |
|
7 | + before_action :check_valid_login, :except => [:new, |
|
8 | :register, |
|
8 | :register, |
|
9 | :confirm, |
|
9 | :confirm, |
|
10 | :forget, |
|
10 | :forget, |
|
11 | :retrieve_password] |
|
11 | :retrieve_password] |
|
12 |
|
12 | ||
|
13 | before_action :verify_online_registration, :only => [:new, |
|
13 | before_action :verify_online_registration, :only => [:new, |
|
14 | :register, |
|
14 | :register, |
|
15 | :forget, |
|
15 | :forget, |
|
16 | :retrieve_password] |
|
16 | :retrieve_password] |
|
17 |
- before_action : |
|
17 | + before_action :check_valid_login, :profile_authorization, only: [:profile] |
|
18 |
|
18 | ||
|
19 | before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
19 | before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
20 |
|
20 | ||
|
21 |
|
21 | ||
|
22 | #in_place_edit_for :user, :alias_for_editing |
|
22 | #in_place_edit_for :user, :alias_for_editing |
|
23 | #in_place_edit_for :user, :email_for_editing |
|
23 | #in_place_edit_for :user, :email_for_editing |
|
24 |
|
24 | ||
|
25 | def index |
|
25 | def index |
|
26 | if !GraderConfiguration['system.user_setting_enabled'] |
|
26 | if !GraderConfiguration['system.user_setting_enabled'] |
|
27 | redirect_to :controller => 'main', :action => 'list' |
|
27 | redirect_to :controller => 'main', :action => 'list' |
|
28 | else |
|
28 | else |
|
29 | @user = User.find(session[:user_id]) |
|
29 | @user = User.find(session[:user_id]) |
@@ -75,28 +75,28 | |||||
|
75 | end |
|
75 | end |
|
76 | assert_text "Turn off all problems" |
|
76 | assert_text "Turn off all problems" |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | test "try using admin from normal user" do |
|
79 | test "try using admin from normal user" do |
|
80 | login 'admin','admin' |
|
80 | login 'admin','admin' |
|
81 | visit bulk_manage_user_admin_index_path |
|
81 | visit bulk_manage_user_admin_index_path |
|
82 | assert_current_path bulk_manage_user_admin_index_path |
|
82 | assert_current_path bulk_manage_user_admin_index_path |
|
83 | visit logout_main_path |
|
83 | visit logout_main_path |
|
84 |
|
84 | ||
|
85 | login 'jack','morning' |
|
85 | login 'jack','morning' |
|
86 | visit bulk_manage_user_admin_index_path |
|
86 | visit bulk_manage_user_admin_index_path |
|
87 | - assert_current_path root_path |
|
||
|
88 | assert_text 'You are not authorized' |
|
87 | assert_text 'You are not authorized' |
|
|
88 | + assert_current_path login_main_path | ||
|
89 |
|
89 | ||
|
90 | login 'james','morning' |
|
90 | login 'james','morning' |
|
91 | visit new_list_user_admin_index_path |
|
91 | visit new_list_user_admin_index_path |
|
92 | - assert_current_path root_path |
|
||
|
93 | assert_text 'You are not authorized' |
|
92 | assert_text 'You are not authorized' |
|
|
93 | + assert_current_path login_main_path | ||
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | def login(username,password) |
|
96 | def login(username,password) |
|
97 | visit root_path |
|
97 | visit root_path |
|
98 | fill_in "Login", with: username |
|
98 | fill_in "Login", with: username |
|
99 | fill_in "Password", with: password |
|
99 | fill_in "Password", with: password |
|
100 | click_on "Login" |
|
100 | click_on "Login" |
|
101 | end |
|
101 | end |
|
102 | end |
|
102 | end |
You need to be logged in to leave comments.
Login now