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
@@ -10,12 +10,13 | |||||
|
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' |
@@ -156,12 +156,16 | |||||
|
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) |
@@ -255,12 +259,13 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,10 +1,10 | |||||
|
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 |
@@ -1,10 +1,10 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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'], |
@@ -1,8 +1,8 | |||||
|
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 |
@@ -1,22 +1,22 | |||||
|
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 } |
@@ -1,9 +1,9 | |||||
|
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'] |
@@ -1,15 +1,15 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,9 +1,9 | |||||
|
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 |
@@ -1,13 +1,13 | |||||
|
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, |
@@ -1,25 +1,25 | |||||
|
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 |
@@ -2,13 +2,14 | |||||
|
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 |
@@ -5,36 +5,36 | |||||
|
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