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
@@ -94,6 +94,7 | |||
|
94 | 94 | coffee-script-source (1.12.2) |
|
95 | 95 | concurrent-ruby (1.1.5) |
|
96 | 96 | crass (1.0.4) |
|
97 | + diff-lcs (1.3) | |
|
97 | 98 | dynamic_form (1.1.4) |
|
98 | 99 | erubi (1.8.0) |
|
99 | 100 | erubis (2.7.0) |
@@ -210,6 +211,23 | |||
|
210 | 211 | rdiscount (2.2.0.1) |
|
211 | 212 | regexp_parser (1.5.1) |
|
212 | 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 | 231 | ruby-progressbar (1.10.0) |
|
214 | 232 | ruby_dep (1.5.0) |
|
215 | 233 | ruby_parser (3.13.1) |
@@ -320,6 +338,7 | |||
|
320 | 338 | rails_bootstrap_sortable |
|
321 | 339 | rdiscount |
|
322 | 340 | rouge |
|
341 | + rspec-rails | |
|
323 | 342 | sassc-rails |
|
324 | 343 | select2-rails |
|
325 | 344 | selenium-webdriver |
@@ -11,9 +11,9 | |||
|
11 | 11 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
12 | 12 | |
|
13 | 13 | #report and redirect for unauthorized activities |
|
14 | - def unauthorized_redirect | |
|
15 | - flash[:notice] = 'You are not authorized to view the page you requested' | |
|
16 | - redirect_to :controller => 'main', :action => 'login' | |
|
14 | + def unauthorized_redirect(notice = 'You are not authorized to view the page you requested') | |
|
15 | + flash[:notice] = notice | |
|
16 | + redirect_to login_main_path | |
|
17 | 17 | end |
|
18 | 18 | |
|
19 | 19 | # Returns the current logged-in user (if any). |
@@ -23,7 +23,7 | |||
|
23 | 23 | end |
|
24 | 24 | |
|
25 | 25 | def admin_authorization |
|
26 |
- return false unless |
|
|
26 | + return false unless check_valid_login | |
|
27 | 27 | user = User.includes(:roles).find(session[:user_id]) |
|
28 | 28 | unless user.admin? |
|
29 | 29 | unauthorized_redirect |
@@ -33,7 +33,7 | |||
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | def authorization_by_roles(allowed_roles) |
|
36 |
- return false unless |
|
|
36 | + return false unless check_valid_login | |
|
37 | 37 | user = User.find(session[:user_id]) |
|
38 | 38 | unless user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
39 | 39 | unauthorized_redirect |
@@ -55,37 +55,36 | |||
|
55 | 55 | |
|
56 | 56 | #redirect to root (and also force logout) |
|
57 | 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 | 60 | unless session[:user_id] |
|
60 | - flash[:notice] = 'You need to login' | |
|
61 | 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 | 65 | end |
|
64 | - redirect_to :controller => 'main', :action => 'login' | |
|
65 | 66 | return false |
|
66 | 67 | end |
|
67 | 68 | |
|
68 | 69 | # check if run in single user mode |
|
69 | 70 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
70 | 71 | if @current_user==nil || (not @current_user.admin?) |
|
71 |
- |
|
|
72 | - redirect_to :controller => 'main', :action => 'login' | |
|
72 | + unauthorized_redirect('You cannot log in at this time') | |
|
73 | 73 | return false |
|
74 | 74 | end |
|
75 | 75 | end |
|
76 | 76 | |
|
77 | 77 | # check if the user is enabled |
|
78 | 78 | unless @current_user.enabled? || @current_user.admin? |
|
79 |
- |
|
|
80 | - redirect_to :controller => 'main', :action => 'login' | |
|
79 | + unauthorized_redirect 'Your account is disabled' | |
|
81 | 80 | return false |
|
82 | 81 | end |
|
83 | 82 | |
|
84 | 83 | # check if user ip is allowed |
|
85 | 84 | unless @current_user.admin? || !GraderConfiguration[ALLOW_WHITELIST_IP_ONLY_CONF_KEY] |
|
86 | 85 | unless is_request_ip_allowed? |
|
87 |
- |
|
|
88 | - redirect_to root_path | |
|
86 | + unauthorized_redirect 'Your IP is not allowed' | |
|
87 | + return false | |
|
89 | 88 | end |
|
90 | 89 | end |
|
91 | 90 | |
@@ -124,7 +123,7 | |||
|
124 | 123 | end |
|
125 | 124 | |
|
126 | 125 | def authorization |
|
127 |
- return false unless |
|
|
126 | + return false unless check_valid_login | |
|
128 | 127 | user = User.find(session[:user_id]) |
|
129 | 128 | unless user.roles.detect { |role| |
|
130 | 129 | role.rights.detect{ |right| |
@@ -1,8 +1,6 | |||
|
1 | 1 | class ConfigurationsController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action :a |
|
|
4 | - before_action { |controller| controller.authorization_by_roles(['admin'])} | |
|
5 | - | |
|
3 | + before_action :admin_authorization | |
|
6 | 4 | |
|
7 | 5 | def index |
|
8 | 6 | @configurations = GraderConfiguration.order(:key) |
@@ -3,7 +3,7 | |||
|
3 | 3 | :add_user, :remove_user,:remove_all_user, |
|
4 | 4 | :add_problem, :remove_problem,:remove_all_problem, |
|
5 | 5 | ] |
|
6 |
- before_action |
|
|
6 | + before_action :admin_authorization | |
|
7 | 7 | |
|
8 | 8 | # GET /groups |
|
9 | 9 | def index |
@@ -1,6 +1,6 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action : |
|
|
3 | + before_action :check_valid_login, :except => [:login] | |
|
4 | 4 | before_action :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | 6 | append_before_action :confirm_and_update_start_time, |
@@ -15,13 +15,8 | |||
|
15 | 15 | |
|
16 | 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 | 18 | #reset login, clear session |
|
19 | + #front page | |
|
25 | 20 | def login |
|
26 | 21 | saved_notice = flash[:notice] |
|
27 | 22 | reset_session |
@@ -1,7 +1,10 | |||
|
1 | 1 | class ProblemsController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action :a |
|
|
4 | - before_action :testcase_authorization, only: [:show_testcase] | |
|
3 | + before_action :admin_authorization | |
|
4 | + | |
|
5 | + #NOTE: ghost from the past? | |
|
6 | + #before_action :testcase_authorization, only: [:show_testcase] | |
|
7 | + | |
|
5 | 8 | |
|
6 | 9 | in_place_edit_for :problem, :name |
|
7 | 10 | in_place_edit_for :problem, :full_name |
@@ -2,12 +2,12 | |||
|
2 | 2 | |
|
3 | 3 | class ReportController < ApplicationController |
|
4 | 4 | |
|
5 |
- before_action : |
|
|
5 | + before_action :check_valid_login | |
|
6 | 6 | |
|
7 | 7 | before_action :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score, :current_score] |
|
8 | 8 | |
|
9 | 9 | before_action(only: [:problem_hof]) { |c| |
|
10 |
- return false unless |
|
|
10 | + return false unless check_valid_login | |
|
11 | 11 | |
|
12 | 12 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
13 | 13 | } |
@@ -1,5 +1,5 | |||
|
1 | 1 | class SubmissionsController < ApplicationController |
|
2 |
- before_action : |
|
|
2 | + before_action :check_valid_login | |
|
3 | 3 | before_action :submission_authorization, only: [:show, :download, :edit] |
|
4 | 4 | before_action :admin_authorization, only: [:rejudge] |
|
5 | 5 |
@@ -1,4 +1,5 | |||
|
1 | 1 | class TagsController < ApplicationController |
|
2 | + before_action :admin_authorization | |
|
2 | 3 | before_action :set_tag, only: [:show, :edit, :update, :destroy] |
|
3 | 4 | |
|
4 | 5 | # GET /tags |
@@ -1,6 +1,6 | |||
|
1 | 1 | class TasksController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action : |
|
|
3 | + before_action :check_valid_login, :check_viewability | |
|
4 | 4 | |
|
5 | 5 | def index |
|
6 | 6 | redirect_to :action => 'list' |
@@ -1,6 +1,6 | |||
|
1 | 1 | class TestController < ApplicationController |
|
2 | 2 | |
|
3 |
- before_action : |
|
|
3 | + before_action :check_valid_login, :check_viewability | |
|
4 | 4 | |
|
5 | 5 | |
|
6 | 6 | def index |
@@ -4,7 +4,7 | |||
|
4 | 4 | |
|
5 | 5 | include MailHelperMethods |
|
6 | 6 | |
|
7 |
- before_action : |
|
|
7 | + before_action :check_valid_login, :except => [:new, | |
|
8 | 8 | :register, |
|
9 | 9 | :confirm, |
|
10 | 10 | :forget, |
@@ -14,7 +14,7 | |||
|
14 | 14 | :register, |
|
15 | 15 | :forget, |
|
16 | 16 | :retrieve_password] |
|
17 |
- before_action : |
|
|
17 | + before_action :check_valid_login, :profile_authorization, only: [:profile] | |
|
18 | 18 | |
|
19 | 19 | before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable] |
|
20 | 20 |
@@ -84,13 +84,13 | |||
|
84 | 84 | |
|
85 | 85 | login 'jack','morning' |
|
86 | 86 | visit bulk_manage_user_admin_index_path |
|
87 | - assert_current_path root_path | |
|
88 | 87 | assert_text 'You are not authorized' |
|
88 | + assert_current_path login_main_path | |
|
89 | 89 | |
|
90 | 90 | login 'james','morning' |
|
91 | 91 | visit new_list_user_admin_index_path |
|
92 | - assert_current_path root_path | |
|
93 | 92 | assert_text 'You are not authorized' |
|
93 | + assert_current_path login_main_path | |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def login(username,password) |
You need to be logged in to leave comments.
Login now