Description:
change depricated before_filter to before_action
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r745:75264caa616f - - 20 files changed: 38 inserted, 31 deleted

@@ -1,93 +1,94
1 1 source 'https://rubygems.org'
2 2
3 3 #rails
4 4 gem 'rails', '~>5.0'
5 5 gem 'activerecord-session_store'
6 6
7 7
8 8 # Bundle edge Rails instead:
9 9 # gem 'rails', :git => 'git://github.com/rails/rails.git'
10 10
11 11 #---------------- database ---------------------
12 12 #the database
13 13 gem 'mysql2'
14 14 #for testing
15 15 gem 'sqlite3'
16 + gem 'rails-controller-testing'
16 17 #for dumping database into yaml
17 18 gem 'yaml_db'
18 19
19 20 # Gems used only for assets and not required
20 21 # in production environments by default.
21 22 gem 'sass-rails'
22 23 gem 'coffee-rails'
23 24
24 25 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
25 26 # gem 'therubyracer', :platforms => :ruby
26 27
27 28 gem 'uglifier'
28 29
29 30 gem 'haml'
30 31 gem 'haml-rails'
31 32 # gem 'prototype-rails'
32 33
33 34 # To use ActiveModel has_secure_password
34 35 # gem 'bcrypt-ruby', '~> 3.0.0'
35 36
36 37 # To use Jbuilder templates for JSON
37 38 # gem 'jbuilder'
38 39
39 40 # Use unicorn as the app server
40 41 # gem 'unicorn'
41 42
42 43 # Deploy with Capistrano
43 44 # gem 'capistrano'
44 45
45 46 # To use debugger
46 47 # gem 'debugger'
47 48 #
48 49
49 50 #in-place editor
50 51 gem 'best_in_place', '~> 3.0.1'
51 52
52 53 # jquery addition
53 54 gem 'jquery-rails'
54 55 gem 'jquery-ui-rails'
55 56 gem 'jquery-timepicker-addon-rails'
56 57 gem 'jquery-tablesorter'
57 58 gem 'jquery-countdown-rails'
58 59
59 60 #syntax highlighter
60 61 gem 'rouge'
61 62
62 63 #bootstrap add-ons
63 64 gem 'bootstrap-sass', '~> 3.4.1'
64 65 gem 'sassc-rails', '>= 2.1.0'
65 66 gem 'bootstrap-switch-rails'
66 67 gem 'bootstrap-toggle-rails'
67 68 gem 'autoprefixer-rails'
68 69 gem 'momentjs-rails'
69 70 gem 'rails_bootstrap_sortable'
70 71 gem 'bootstrap-datepicker-rails'
71 72 gem 'bootstrap3-datetimepicker-rails'
72 73 gem 'jquery-datatables-rails'
73 74
74 75 #----------- user interface -----------------
75 76 #select 2
76 77 gem 'select2-rails'
77 78 #ace editor
78 79 gem 'ace-rails-ap'
79 80 #paginator
80 81 gem 'will_paginate', '~> 3.0.7'
81 82
82 83 gem 'mail'
83 84 gem 'rdiscount'
84 85 gem 'dynamic_form'
85 86 gem 'in_place_editing'
86 87 gem 'verification', :git => 'https://github.com/sikachu/verification.git'
87 88
88 89
89 90 #---------------- testiing -----------------------
90 91 gem 'minitest-reporters'
91 92
92 93 #---------------- for console --------------------
93 94 gem 'fuzzy-string-match'
@@ -66,209 +66,214
66 66 bootstrap-datepicker-rails (1.8.0.1)
67 67 railties (>= 3.0)
68 68 bootstrap-sass (3.4.1)
69 69 autoprefixer-rails (>= 5.2.1)
70 70 sassc (>= 2.0.0)
71 71 bootstrap-switch-rails (3.3.4)
72 72 bootstrap-toggle-rails (2.2.1.0)
73 73 bootstrap3-datetimepicker-rails (4.17.47)
74 74 momentjs-rails (>= 2.8.1)
75 75 builder (3.2.3)
76 76 coffee-rails (4.2.2)
77 77 coffee-script (>= 2.2.0)
78 78 railties (>= 4.0.0)
79 79 coffee-script (2.4.1)
80 80 coffee-script-source
81 81 execjs
82 82 coffee-script-source (1.12.2)
83 83 concurrent-ruby (1.1.5)
84 84 crass (1.0.4)
85 85 dynamic_form (1.1.4)
86 86 erubis (2.7.0)
87 87 execjs (2.7.0)
88 88 ffi (1.11.1)
89 89 fuzzy-string-match (1.0.1)
90 90 RubyInline (>= 3.8.6)
91 91 globalid (0.4.2)
92 92 activesupport (>= 4.2.0)
93 93 haml (5.1.0)
94 94 temple (>= 0.8.0)
95 95 tilt
96 96 haml-rails (1.0.0)
97 97 actionpack (>= 4.0.1)
98 98 activesupport (>= 4.0.1)
99 99 haml (>= 4.0.6, < 6.0)
100 100 html2haml (>= 1.0.1)
101 101 railties (>= 4.0.1)
102 102 html2haml (2.2.0)
103 103 erubis (~> 2.7.0)
104 104 haml (>= 4.0, < 6)
105 105 nokogiri (>= 1.6.0)
106 106 ruby_parser (~> 3.5)
107 107 i18n (1.6.0)
108 108 concurrent-ruby (~> 1.0)
109 109 in_place_editing (1.2.0)
110 110 jquery-countdown-rails (2.0.2)
111 111 jquery-datatables-rails (3.4.0)
112 112 actionpack (>= 3.1)
113 113 jquery-rails
114 114 railties (>= 3.1)
115 115 sass-rails
116 116 jquery-rails (4.3.3)
117 117 rails-dom-testing (>= 1, < 3)
118 118 railties (>= 4.2.0)
119 119 thor (>= 0.14, < 2.0)
120 120 jquery-tablesorter (1.26.1)
121 121 railties (>= 3.2, < 6)
122 122 jquery-timepicker-addon-rails (1.4.1)
123 123 railties (>= 3.1)
124 124 jquery-ui-rails (6.0.1)
125 125 railties (>= 3.2.16)
126 126 loofah (2.2.3)
127 127 crass (~> 1.0.2)
128 128 nokogiri (>= 1.5.9)
129 129 mail (2.7.1)
130 130 mini_mime (>= 0.1.1)
131 131 method_source (0.9.2)
132 132 mini_mime (1.0.1)
133 133 mini_portile2 (2.4.0)
134 134 minitest (5.11.3)
135 135 minitest-reporters (1.3.6)
136 136 ansi
137 137 builder
138 138 minitest (>= 5.0)
139 139 ruby-progressbar
140 140 momentjs-rails (2.20.1)
141 141 railties (>= 3.1)
142 142 multi_json (1.13.1)
143 143 mysql2 (0.5.2)
144 144 nio4r (2.3.1)
145 145 nokogiri (1.10.3)
146 146 mini_portile2 (~> 2.4.0)
147 147 rack (2.0.7)
148 148 rack-test (0.6.3)
149 149 rack (>= 1.0)
150 150 rails (5.0.7.2)
151 151 actioncable (= 5.0.7.2)
152 152 actionmailer (= 5.0.7.2)
153 153 actionpack (= 5.0.7.2)
154 154 actionview (= 5.0.7.2)
155 155 activejob (= 5.0.7.2)
156 156 activemodel (= 5.0.7.2)
157 157 activerecord (= 5.0.7.2)
158 158 activesupport (= 5.0.7.2)
159 159 bundler (>= 1.3.0)
160 160 railties (= 5.0.7.2)
161 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 166 rails-dom-testing (2.0.3)
163 167 activesupport (>= 4.2.0)
164 168 nokogiri (>= 1.6)
165 169 rails-html-sanitizer (1.0.4)
166 170 loofah (~> 2.2, >= 2.2.2)
167 171 rails_bootstrap_sortable (2.0.6)
168 172 momentjs-rails (>= 2.8.3)
169 173 railties (5.0.7.2)
170 174 actionpack (= 5.0.7.2)
171 175 activesupport (= 5.0.7.2)
172 176 method_source
173 177 rake (>= 0.8.7)
174 178 thor (>= 0.18.1, < 2.0)
175 179 rake (12.3.2)
176 180 rb-fsevent (0.10.3)
177 181 rb-inotify (0.10.0)
178 182 ffi (~> 1.0)
179 183 rdiscount (2.2.0.1)
180 184 rouge (3.3.0)
181 185 ruby-progressbar (1.10.0)
182 186 ruby_parser (3.13.1)
183 187 sexp_processor (~> 4.9)
184 188 sass (3.7.4)
185 189 sass-listen (~> 4.0.0)
186 190 sass-listen (4.0.0)
187 191 rb-fsevent (~> 0.9, >= 0.9.4)
188 192 rb-inotify (~> 0.9, >= 0.9.7)
189 193 sass-rails (5.0.7)
190 194 railties (>= 4.0.0, < 6)
191 195 sass (~> 3.1)
192 196 sprockets (>= 2.8, < 4.0)
193 197 sprockets-rails (>= 2.0, < 4.0)
194 198 tilt (>= 1.1, < 3)
195 199 sassc (2.0.1)
196 200 ffi (~> 1.9)
197 201 rake
198 202 sassc-rails (2.1.1)
199 203 railties (>= 4.0.0)
200 204 sassc (>= 2.0)
201 205 sprockets (> 3.0)
202 206 sprockets-rails
203 207 tilt
204 208 select2-rails (4.0.3)
205 209 thor (~> 0.14)
206 210 sexp_processor (4.12.0)
207 211 sprockets (3.7.2)
208 212 concurrent-ruby (~> 1.0)
209 213 rack (> 1, < 3)
210 214 sprockets-rails (3.2.1)
211 215 actionpack (>= 4.0)
212 216 activesupport (>= 4.0)
213 217 sprockets (>= 3.0.0)
214 218 sqlite3 (1.4.1)
215 219 temple (0.8.1)
216 220 thor (0.20.3)
217 221 thread_safe (0.3.6)
218 222 tilt (2.0.9)
219 223 tzinfo (1.2.5)
220 224 thread_safe (~> 0.1)
221 225 uglifier (4.1.20)
222 226 execjs (>= 0.3.0, < 3)
223 227 websocket-driver (0.6.5)
224 228 websocket-extensions (>= 0.1.0)
225 229 websocket-extensions (0.1.4)
226 230 will_paginate (3.0.12)
227 231 yaml_db (0.7.0)
228 232 rails (>= 3.0)
229 233 rake (>= 0.8.7)
230 234
231 235 PLATFORMS
232 236 ruby
233 237
234 238 DEPENDENCIES
235 239 ace-rails-ap
236 240 activerecord-session_store
237 241 autoprefixer-rails
238 242 best_in_place (~> 3.0.1)
239 243 bootstrap-datepicker-rails
240 244 bootstrap-sass (~> 3.4.1)
241 245 bootstrap-switch-rails
242 246 bootstrap-toggle-rails
243 247 bootstrap3-datetimepicker-rails
244 248 coffee-rails
245 249 dynamic_form
246 250 fuzzy-string-match
247 251 haml
248 252 haml-rails
249 253 in_place_editing
250 254 jquery-countdown-rails
251 255 jquery-datatables-rails
252 256 jquery-rails
253 257 jquery-tablesorter
254 258 jquery-timepicker-addon-rails
255 259 jquery-ui-rails
256 260 mail
257 261 minitest-reporters
258 262 momentjs-rails
259 263 mysql2
260 264 rails (~> 5.0)
265 + rails-controller-testing
261 266 rails_bootstrap_sortable
262 267 rdiscount
263 268 rouge
264 269 sass-rails
265 270 sassc-rails (>= 2.1.0)
266 271 select2-rails
267 272 sqlite3
268 273 uglifier
269 274 verification!
270 275 will_paginate (~> 3.0.7)
271 276 yaml_db
272 277
273 278 BUNDLED WITH
274 279 1.17.2
@@ -1,99 +1,99
1 1 class AnnouncementsController < ApplicationController
2 2
3 - before_filter :admin_authorization
3 + before_action :admin_authorization
4 4
5 5 in_place_edit_for :announcement, :published
6 6
7 7 # GET /announcements
8 8 # GET /announcements.xml
9 9 def index
10 10 @announcements = Announcement.order(created_at: :desc)
11 11
12 12 respond_to do |format|
13 13 format.html # index.html.erb
14 14 format.xml { render :xml => @announcements }
15 15 end
16 16 end
17 17
18 18 # GET /announcements/1
19 19 # GET /announcements/1.xml
20 20 def show
21 21 @announcement = Announcement.find(params[:id])
22 22
23 23 respond_to do |format|
24 24 format.html # show.html.erb
25 25 format.xml { render :xml => @announcement }
26 26 end
27 27 end
28 28
29 29 # GET /announcements/new
30 30 # GET /announcements/new.xml
31 31 def new
32 32 @announcement = Announcement.new
33 33
34 34 respond_to do |format|
35 35 format.html # new.html.erb
36 36 format.xml { render :xml => @announcement }
37 37 end
38 38 end
39 39
40 40 # GET /announcements/1/edit
41 41 def edit
42 42 @announcement = Announcement.find(params[:id])
43 43 end
44 44
45 45 # POST /announcements
46 46 # POST /announcements.xml
47 47 def create
48 48 @announcement = Announcement.new(announcement_params)
49 49
50 50 respond_to do |format|
51 51 if @announcement.save
52 52 flash[:notice] = 'Announcement was successfully created.'
53 53 format.html { redirect_to(@announcement) }
54 54 format.xml { render :xml => @announcement, :status => :created, :location => @announcement }
55 55 else
56 56 format.html { render :action => "new" }
57 57 format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
58 58 end
59 59 end
60 60 end
61 61
62 62 # PUT /announcements/1
63 63 # PUT /announcements/1.xml
64 64 def update
65 65 @announcement = Announcement.find(params[:id])
66 66
67 67 respond_to do |format|
68 68 if @announcement.update_attributes(announcement_params)
69 69 flash[:notice] = 'Announcement was successfully updated.'
70 70 format.html { redirect_to(@announcement) }
71 71 format.js {}
72 72 format.xml { head :ok }
73 73 else
74 74 format.html { render :action => "edit" }
75 75 format.js {}
76 76 format.xml { render :xml => @announcement.errors, :status => :unprocessable_entity }
77 77 end
78 78 end
79 79 end
80 80
81 81 def toggle
82 82 @announcement = Announcement.find(params[:id])
83 83 @announcement.update_attributes( published: !@announcement.published? )
84 84 respond_to do |format|
85 85 format.js { render partial: 'toggle_button',
86 86 locals: {button_id: "#announcement_toggle_#{@announcement.id}",button_on: @announcement.published? } }
87 87 end
88 88 end
89 89
90 90 def toggle_front
91 91 @announcement = Announcement.find(params[:id])
92 92 @announcement.update_attributes( frontpage: !@announcement.frontpage? )
93 93 respond_to do |format|
94 94 format.js { render partial: 'toggle_button',
95 95 locals: {button_id: "#announcement_toggle_front_#{@announcement.id}",button_on: @announcement.frontpage? } }
96 96 end
97 97 end
98 98
99 99 # DELETE /announcements/1
@@ -1,100 +1,100
1 1 class ApplicationController < ActionController::Base
2 2 protect_from_forgery
3 3
4 - before_filter :current_user
4 + before_action :current_user
5 5
6 6 SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
7 7 MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login'
8 8
9 9 #report and redirect for unauthorized activities
10 10 def unauthorized_redirect
11 11 flash[:notice] = 'You are not authorized to view the page you requested'
12 12 redirect_to :controller => 'main', :action => 'login'
13 13 end
14 14
15 15 # Returns the current logged-in user (if any).
16 16 def current_user
17 17 return nil unless session[:user_id]
18 18 @current_user ||= User.find(session[:user_id])
19 19 end
20 20
21 21 def admin_authorization
22 22 return false unless authenticate
23 23 user = User.includes(:roles).find(session[:user_id])
24 24 unless user.admin?
25 25 unauthorized_redirect
26 26 return false
27 27 end
28 28 return true
29 29 end
30 30
31 31 def authorization_by_roles(allowed_roles)
32 32 return false unless authenticate
33 33 user = User.find(session[:user_id])
34 34 unless user.roles.detect { |role| allowed_roles.member?(role.name) }
35 35 unauthorized_redirect
36 36 return false
37 37 end
38 38 end
39 39
40 40 def testcase_authorization
41 41 #admin always has privileged
42 42 if @current_user.admin?
43 43 return true
44 44 end
45 45
46 46 unauthorized_redirect unless GraderConfiguration["right.view_testcase"]
47 47 end
48 48
49 49 protected
50 50
51 51 def authenticate
52 52 unless session[:user_id]
53 53 flash[:notice] = 'You need to login'
54 54 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
55 55 flash[:notice] = 'You need to login but you cannot log in at this time'
56 56 end
57 57 redirect_to :controller => 'main', :action => 'login'
58 58 return false
59 59 end
60 60
61 61
62 62 # check if run in single user mode
63 63 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
64 64 if @current_user==nil or (not @current_user.admin?)
65 65 flash[:notice] = 'You cannot log in at this time'
66 66 redirect_to :controller => 'main', :action => 'login'
67 67 return false
68 68 end
69 69 return true
70 70 end
71 71
72 72 # check if the user is enabled
73 73 unless @current_user.enabled? or @current_user.admin?
74 74 flash[:notice] = 'Your account is disabled'
75 75 redirect_to :controller => 'main', :action => 'login'
76 76 return false
77 77 end
78 78
79 79 if GraderConfiguration.multicontests?
80 80 return true if @current_user.admin?
81 81 begin
82 82 if @current_user.contest_stat(true).forced_logout
83 83 flash[:notice] = 'You have been automatically logged out.'
84 84 redirect_to :controller => 'main', :action => 'index'
85 85 end
86 86 rescue
87 87 end
88 88 end
89 89 return true
90 90 end
91 91
92 92 def authenticate_by_ip_address
93 93 #this assume that we have already authenticate normally
94 94 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
95 95 user = User.find(session[:user_id])
96 96 if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip)
97 97 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
98 98 redirect_to :controller => 'main', :action => 'login'
99 99 puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}"
100 100 return false
@@ -1,34 +1,34
1 1 class ConfigurationsController < ApplicationController
2 2
3 - before_filter :authenticate
4 - before_filter { |controller| controller.authorization_by_roles(['admin'])}
3 + before_action :authenticate
4 + before_action { |controller| controller.authorization_by_roles(['admin'])}
5 5
6 6
7 7 def index
8 8 @configurations = GraderConfiguration.order(:key)
9 9 @group = GraderConfiguration.pluck("grader_configurations.key").map{ |x| x[0...(x.index('.'))] }.uniq.sort
10 10 end
11 11
12 12 def reload
13 13 GraderConfiguration.reload
14 14 redirect_to :action => 'index'
15 15 end
16 16
17 17 def update
18 18 @config = GraderConfiguration.find(params[:id])
19 19 User.clear_last_login if @config.key == GraderConfiguration::MULTIPLE_IP_LOGIN_KEY and @config.value == 'true' and params[:grader_configuration][:value] == 'false'
20 20 respond_to do |format|
21 21 if @config.update_attributes(configuration_params)
22 22 format.json { head :ok }
23 23 else
24 24 format.json { respond_with_bip(@config) }
25 25 end
26 26 end
27 27 end
28 28
29 29 private
30 30 def configuration_params
31 31 params.require(:grader_configuration).permit(:key,:value_type,:value,:description)
32 32 end
33 33
34 34 end
@@ -1,50 +1,50
1 1 class ContestManagementController < ApplicationController
2 2
3 - before_filter :admin_authorization
3 + before_action :admin_authorization
4 4
5 5 def index
6 6 @num_contests = Contest.count()
7 7 end
8 8
9 9 def user_stat
10 10 if not GraderConfiguration.indv_contest_mode?
11 11 redirect_to :action => 'index' and return
12 12 end
13 13
14 14 @users = User.all
15 15 @start_times = {}
16 16 UserContestStat.all.each do |stat|
17 17 @start_times[stat.user_id] = stat.started_at
18 18 end
19 19 end
20 20
21 21 def clear_stat
22 22 user = User.find(params[:id])
23 23 if user.contest_stat!=nil
24 24 user.contest_stat.destroy
25 25 end
26 26 redirect_to :action => 'user_stat'
27 27 end
28 28
29 29 def clear_all_stat
30 30 if not GraderConfiguration.indv_contest_mode?
31 31 redirect_to :action => 'index' and return
32 32 end
33 33
34 34 UserContestStat.delete_all()
35 35 flash[:notice] = 'All start time statistic cleared.'
36 36 redirect_to :action => 'index'
37 37 end
38 38
39 39 def change_contest_mode
40 40 if ['standard', 'contest', 'indv-contest', 'analysis'].include? params[:id]
41 41 config = GraderConfiguration.find_by_key('system.mode')
42 42 config.value = params[:id]
43 43 config.save
44 44 else
45 45 flash[:notice] = 'Wrong contest mode value'
46 46 end
47 47 redirect_to :action => 'index'
48 48 end
49 49
50 50 end
@@ -1,98 +1,98
1 1 class ContestsController < ApplicationController
2 2
3 - before_filter :admin_authorization
3 + before_action :admin_authorization
4 4
5 5 in_place_edit_for :contest, :title
6 6 in_place_edit_for :contest, :enabled
7 7
8 8 # GET /contests
9 9 # GET /contests.xml
10 10 def index
11 11 @contests = Contest.all
12 12
13 13 respond_to do |format|
14 14 format.html # index.html.erb
15 15 format.xml { render :xml => @contests }
16 16 end
17 17 end
18 18
19 19 # GET /contests/1
20 20 # GET /contests/1.xml
21 21 def show
22 22 @contest = Contest.find(params[:id])
23 23
24 24 respond_to do |format|
25 25 format.html # show.html.erb
26 26 format.xml { render :xml => @contest }
27 27 end
28 28 end
29 29
30 30 # GET /contests/new
31 31 # GET /contests/new.xml
32 32 def new
33 33 @contest = Contest.new
34 34
35 35 respond_to do |format|
36 36 format.html # new.html.erb
37 37 format.xml { render :xml => @contest }
38 38 end
39 39 end
40 40
41 41 # GET /contests/1/edit
42 42 def edit
43 43 @contest = Contest.find(params[:id])
44 44 end
45 45
46 46 # POST /contests
47 47 # POST /contests.xml
48 48 def create
49 49 @contest = Contest.new(params[:contest])
50 50
51 51 respond_to do |format|
52 52 if @contest.save
53 53 flash[:notice] = 'Contest was successfully created.'
54 54 format.html { redirect_to(@contest) }
55 55 format.xml { render :xml => @contest, :status => :created, :location => @contest }
56 56 else
57 57 format.html { render :action => "new" }
58 58 format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
59 59 end
60 60 end
61 61 end
62 62
63 63 # PUT /contests/1
64 64 # PUT /contests/1.xml
65 65 def update
66 66 @contest = Contest.find(params[:id])
67 67
68 68 respond_to do |format|
69 69 if @contest.update_attributes(contests_params)
70 70 flash[:notice] = 'Contest was successfully updated.'
71 71 format.html { redirect_to(@contest) }
72 72 format.xml { head :ok }
73 73 else
74 74 format.html { render :action => "edit" }
75 75 format.xml { render :xml => @contest.errors, :status => :unprocessable_entity }
76 76 end
77 77 end
78 78 end
79 79
80 80 # DELETE /contests/1
81 81 # DELETE /contests/1.xml
82 82 def destroy
83 83 @contest = Contest.find(params[:id])
84 84 @contest.destroy
85 85
86 86 respond_to do |format|
87 87 format.html { redirect_to(contests_url) }
88 88 format.xml { head :ok }
89 89 end
90 90 end
91 91
92 92 private
93 93
94 94 def contests_params
95 95 params.require(:contest).permit(:title,:enabled,:name)
96 96 end
97 97
98 98 end
@@ -1,93 +1,93
1 1 class GradersController < ApplicationController
2 2
3 - before_filter :admin_authorization
3 + before_action :admin_authorization
4 4
5 5 verify :method => :post, :only => ['clear_all',
6 6 'start_exam',
7 7 'start_grading',
8 8 'stop_all',
9 9 'clear_terminated'],
10 10 :redirect_to => {:action => 'index'}
11 11
12 12 def index
13 13 redirect_to :action => 'list'
14 14 end
15 15
16 16 def list
17 17 @grader_processes = GraderProcess.find_running_graders
18 18 @stalled_processes = GraderProcess.find_stalled_process
19 19
20 20 @terminated_processes = GraderProcess.find_terminated_graders
21 21
22 22 @last_task = Task.last
23 23 @last_test_request = TestRequest.last
24 24 @submission = Submission.order("id desc").limit(20)
25 25 @backlog_submission = Submission.where('graded_at is null')
26 26 end
27 27
28 28 def clear
29 29 grader_proc = GraderProcess.find(params[:id])
30 30 grader_proc.destroy if grader_proc!=nil
31 31 redirect_to :action => 'list'
32 32 end
33 33
34 34 def clear_terminated
35 35 GraderProcess.find_terminated_graders.each do |p|
36 36 p.destroy
37 37 end
38 38 redirect_to :action => 'list'
39 39 end
40 40
41 41 def clear_all
42 42 GraderProcess.all.each do |p|
43 43 p.destroy
44 44 end
45 45 redirect_to :action => 'list'
46 46 end
47 47
48 48 def view
49 49 if params[:type]=='Task'
50 50 redirect_to :action => 'task', :id => params[:id]
51 51 else
52 52 redirect_to :action => 'test_request', :id => params[:id]
53 53 end
54 54 end
55 55
56 56 def test_request
57 57 @test_request = TestRequest.find(params[:id])
58 58 end
59 59
60 60 def task
61 61 @task = Task.find(params[:id])
62 62 end
63 63
64 64
65 65 # various grader controls
66 66
67 67 def stop
68 68 grader_proc = GraderProcess.find(params[:id])
69 69 GraderScript.stop_grader(grader_proc.pid)
70 70 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
71 71 redirect_to :action => 'list'
72 72 end
73 73
74 74 def stop_all
75 75 GraderScript.stop_graders(GraderProcess.find_running_graders +
76 76 GraderProcess.find_stalled_process)
77 77 flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
78 78 redirect_to :action => 'list'
79 79 end
80 80
81 81 def start_grading
82 82 GraderScript.start_grader('grading')
83 83 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
84 84 redirect_to :action => 'list'
85 85 end
86 86
87 87 def start_exam
88 88 GraderScript.start_grader('exam')
89 89 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
90 90 redirect_to :action => 'list'
91 91 end
92 92
93 93 end
@@ -1,46 +1,46
1 1 class HeartbeatController < ApplicationController
2 - before_filter :admin_authorization, :only => ['index']
2 + before_action :admin_authorization, :only => ['index']
3 3
4 4 def edit
5 5 #@user = User.find_by_login(params[:id])
6 6 #unless @user
7 7 # render text: "LOGIN_NOT_FOUND"
8 8 # return
9 9 #end
10 10
11 11 #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
12 12 #puts "status = #{params[:status]}"
13 13 #if hb
14 14 # if params[:status]
15 15 # hb.status = params[:status]
16 16 # hb.save
17 17 # end
18 18 # hb.touch
19 19 #else
20 20 # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
21 21 #end
22 22 #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status])
23 23
24 24 res = GraderConfiguration['right.heartbeat_response']
25 25 res.strip! if res
26 26 full = GraderConfiguration['right.heartbeat_response_full']
27 27 full.strip! if full
28 28
29 29 if full and full != ''
30 30 l = Login.where(ip_address: request.remote_ip).last
31 31 @user = l.user
32 32 if @user.solve_all_available_problems?
33 33 render text: (full || 'OK')
34 34 else
35 35 render text: (res || 'OK')
36 36 end
37 37 else
38 38 render text: (GraderConfiguration['right.heartbeat_response'] || 'OK')
39 39 end
40 40 end
41 41
42 42 def index
43 43 @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all
44 44 @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true)
45 45 end
46 46 end
@@ -1,112 +1,112
1 1 class MainController < ApplicationController
2 2
3 - before_filter :authenticate, :except => [:index, :login]
4 - before_filter :check_viewability, :except => [:index, :login]
3 + before_action :authenticate, :except => [:index, :login]
4 + before_action :check_viewability, :except => [:index, :login]
5 5
6 - append_before_filter :confirm_and_update_start_time,
6 + append_before_action :confirm_and_update_start_time,
7 7 :except => [:index,
8 8 :login,
9 9 :confirm_contest_start]
10 10
11 11 # to prevent log in box to be shown when user logged out of the
12 12 # system only in some tab
13 - prepend_before_filter :reject_announcement_refresh_when_logged_out,
13 + prepend_before_action :reject_announcement_refresh_when_logged_out,
14 14 :only => [:announcements]
15 15
16 - before_filter :authenticate_by_ip_address, :only => [:list]
16 + before_action :authenticate_by_ip_address, :only => [:list]
17 17
18 18 # COMMENTED OUT: filter in each action instead
19 19 # before_filter :verify_time_limit, :only => [:submit]
20 20
21 21 verify :method => :post, :only => [:submit],
22 22 :redirect_to => { :action => :index }
23 23
24 24 # COMMENT OUT: only need when having high load
25 25 # caches_action :index, :login
26 26
27 27 # NOTE: This method is not actually needed, 'config/routes.rb' has
28 28 # assigned action login as a default action.
29 29 def index
30 30 redirect_to :action => 'login'
31 31 end
32 32
33 33 def login
34 34 saved_notice = flash[:notice]
35 35 reset_session
36 36 flash.now[:notice] = saved_notice
37 37
38 38 # EXPERIMENT:
39 39 # Hide login if in single user mode and the url does not
40 40 # explicitly specify /login
41 41 #
42 42 # logger.info "PATH: #{request.path}"
43 43 # if GraderConfiguration['system.single_user_mode'] and
44 44 # request.path!='/main/login'
45 45 # @hidelogin = true
46 46 # end
47 47
48 48 @announcements = Announcement.frontpage
49 49 render :action => 'login', :layout => 'empty'
50 50 end
51 51
52 52 def list
53 53 prepare_list_information
54 54 end
55 55
56 56 def help
57 57 @user = User.find(session[:user_id])
58 58 end
59 59
60 60 def submit
61 61 user = User.find(session[:user_id])
62 62
63 63 @submission = Submission.new
64 64 @submission.problem_id = params[:submission][:problem_id]
65 65 @submission.user = user
66 66 @submission.language_id = 0
67 67 if (params['file']) and (params['file']!='')
68 68 @submission.source = File.open(params['file'].path,'r:UTF-8',&:read)
69 69 @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '')
70 70 @submission.source_filename = params['file'].original_filename
71 71 end
72 72
73 73 if (params[:editor_text])
74 74 language = Language.find_by_id(params[:language_id])
75 75 @submission.source = params[:editor_text]
76 76 @submission.source_filename = "live_edit.#{language.ext}"
77 77 @submission.language = language
78 78 end
79 79
80 80 @submission.submitted_at = Time.new.gmtime
81 81 @submission.ip_address = request.remote_ip
82 82
83 83 if GraderConfiguration.time_limit_mode? and user.contest_finished?
84 84 @submission.errors.add(:base,"The contest is over.")
85 85 prepare_list_information
86 86 render :action => 'list' and return
87 87 end
88 88
89 89 if @submission.valid?(@current_user)
90 90 if @submission.save == false
91 91 flash[:notice] = 'Error saving your submission'
92 92 elsif Task.create(:submission_id => @submission.id,
93 93 :status => Task::STATUS_INQUEUE) == false
94 94 flash[:notice] = 'Error adding your submission to task queue'
95 95 end
96 96 else
97 97 prepare_list_information
98 98 render :action => 'list' and return
99 99 end
100 100 redirect_to edit_submission_path(@submission)
101 101 end
102 102
103 103 def source
104 104 submission = Submission.find(params[:id])
105 105 if ((submission.user_id == session[:user_id]) and
106 106 (submission.problem != nil) and
107 107 (submission.problem.available))
108 108 send_data(submission.source,
109 109 {:filename => submission.download_filename,
110 110 :type => 'text/plain'})
111 111 else
112 112 flash[:notice] = 'Error viewing source'
@@ -1,86 +1,86
1 1 class MessagesController < ApplicationController
2 2
3 - before_filter :authenticate
3 + before_action :authenticate
4 4
5 5 verify :method => :post, :only => ['create'],
6 6 :redirect_to => { :action => 'list' }
7 7
8 8 before_filter :admin_authorization, :only => ['console','show',
9 9 'reply','hide','list_all']
10 10
11 11 def list
12 12 @user = User.find(session[:user_id])
13 13 @messages = Message.find_all_sent_by_user(@user)
14 14 end
15 15
16 16 def console
17 17 @user = User.find(session[:user_id])
18 18 @messages = Message.find_all_system_unreplied_messages
19 19 end
20 20
21 21 def show
22 22 @message = Message.find(params[:id])
23 23 end
24 24
25 25 def list_all
26 26 @user = User.find(session[:user_id])
27 27 @messages = Message.where(receiver_id: nil).order(:created_at)
28 28 end
29 29
30 30 def create
31 31 user = User.find(session[:user_id])
32 32 @message = Message.new(params[:message])
33 33 @message.sender = user
34 34 if @message.body == '' or !@message.save
35 35 flash[:notice] = 'An error occurred'
36 36 else
37 37 flash[:notice] = 'New message posted'
38 38 end
39 39 redirect_to :action => 'list'
40 40 end
41 41
42 42 def reply
43 43 user = User.find(session[:user_id])
44 44 @message = Message.new(params[:r_message])
45 45 @message.sender = user
46 46 if @message.body == '' or !@message.save
47 47 flash[:notice] = 'An error occurred'
48 48 redirect_to :action => 'show', :id => @message.replying_message_id
49 49 else
50 50 flash[:notice] = 'Message replied'
51 51 rep_msg = @message.replying_message
52 52 rep_msg.replied = true
53 53 rep_msg.save
54 54 redirect_to :action => 'console'
55 55 end
56 56 end
57 57
58 58 def hide
59 59 message = Message.find(params[:id])
60 60 message.replied = true
61 61 message.save
62 62 flash[:notice] = 'Message hidden (just marked replied)'
63 63 redirect_to :action => 'console'
64 64 end
65 65
66 66 protected
67 67 def build_replying_message_hierarchy(user)
68 68 @all_messages = {}
69 69
70 70
71 71 # manually build replies hierarchy (to improve efficiency)
72 72 [@messages, @replied_messages].each do |collection|
73 73 collection.each do |m|
74 74 @all_messages[m.id] = {:msg => m, :replies => []}
75 75 end
76 76 end
77 77
78 78 @all_messages.each do |m|
79 79 rep_id = m.replying_message_id
80 80 if @all_messages[rep_id]!=nil
81 81 @all_messages[rep_id][:replies] << m
82 82 end
83 83 end
84 84 end
85 85
86 86 end
@@ -1,105 +1,105
1 1 require 'csv'
2 2
3 3 class ReportController < ApplicationController
4 4
5 - before_filter :authenticate
5 + before_action :authenticate
6 6
7 - before_filter :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_filter(only: [:problem_hof]) { |c|
9 + before_action(only: [:problem_hof]) { |c|
10 10 return false unless authenticate
11 11
12 12 admin_authorization unless GraderConfiguration["right.user_view_submission"]
13 13 }
14 14
15 15 def max_score
16 16 end
17 17
18 18 def current_score
19 19 @problems = Problem.available_problems
20 20 @users = User.includes(:contests).includes(:contest_stat).where(enabled: true)
21 21 @scorearray = calculate_max_score(@problems, @users,0,0,true)
22 22
23 23 #rencer accordingly
24 24 if params[:button] == 'download' then
25 25 csv = gen_csv_from_scorearray(@scorearray,@problems)
26 26 send_data csv, filename: 'max_score.csv'
27 27 else
28 28 #render template: 'user_admin/user_stat'
29 29 render 'current_score'
30 30 end
31 31 end
32 32
33 33 def show_max_score
34 34 #process parameters
35 35 #problems
36 36 @problems = []
37 37 if params[:problem_id]
38 38 params[:problem_id].each do |id|
39 39 next unless id.strip != ""
40 40 pid = Problem.find_by_id(id.to_i)
41 41 @problems << pid if pid
42 42 end
43 43 end
44 44
45 45 #users
46 46 @users = if params[:users] == "all" then
47 47 User.includes(:contests).includes(:contest_stat)
48 48 else
49 49 User.includes(:contests).includes(:contest_stat).where(enabled: true)
50 50 end
51 51
52 52 #set up range from param
53 53 @since_id = params.fetch(:from_id, 0).to_i
54 54 @until_id = params.fetch(:to_id, 0).to_i
55 55 @since_id = nil if @since_id == 0
56 56 @until_id = nil if @until_id == 0
57 57
58 58 #calculate the routine
59 59 @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id)
60 60
61 61 #rencer accordingly
62 62 if params[:button] == 'download' then
63 63 csv = gen_csv_from_scorearray(@scorearray,@problems)
64 64 send_data csv, filename: 'max_score.csv'
65 65 else
66 66 #render template: 'user_admin/user_stat'
67 67 render 'max_score'
68 68 end
69 69
70 70 end
71 71
72 72 def score
73 73 if params[:commit] == 'download csv'
74 74 @problems = Problem.all
75 75 else
76 76 @problems = Problem.available_problems
77 77 end
78 78 @users = User.includes(:contests, :contest_stat).where(enabled: true)
79 79 @scorearray = Array.new
80 80 @users.each do |u|
81 81 ustat = Array.new
82 82 ustat[0] = u
83 83 @problems.each do |p|
84 84 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
85 85 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
86 86 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
87 87 else
88 88 ustat << [0,false]
89 89 end
90 90 end
91 91 @scorearray << ustat
92 92 end
93 93 if params[:commit] == 'download csv' then
94 94 csv = gen_csv_from_scorearray(@scorearray,@problems)
95 95 send_data csv, filename: 'last_score.csv'
96 96 else
97 97 render template: 'user_admin/user_stat'
98 98 end
99 99
100 100 end
101 101
102 102 def login_stat
103 103 @logins = Array.new
104 104
105 105 date_and_time = '%Y-%m-%d %H:%M'
@@ -1,67 +1,67
1 1 class SiteController < ApplicationController
2 2
3 - before_filter :site_admin_authorization, :except => 'login'
3 + before_action :site_admin_authorization, :except => 'login'
4 4
5 5 def login
6 6 # Site administrator login
7 7 @countries = Country.includes(:sites).all
8 8 @country_select = @countries.collect { |c| [c.name, c.id] }
9 9
10 10 @country_select_with_all = [['Any',0]]
11 11 @countries.each do |country|
12 12 @country_select_with_all << [country.name, country.id]
13 13 end
14 14
15 15 @site_select = []
16 16 @countries.each do |country|
17 17 country.sites.each do |site|
18 18 @site_select << ["#{site.name}, #{country.name}", site.id]
19 19 end
20 20 end
21 21
22 22 @default_site = Site.first if !GraderConfiguration['contest.multisites']
23 23
24 24 render :action => 'login', :layout => 'empty'
25 25 end
26 26
27 27 def index
28 28 if @site.started
29 29 render :action => 'started', :layout => 'empty'
30 30 else
31 31 render :action => 'prompt', :layout => 'empty'
32 32 end
33 33 end
34 34
35 35 def start
36 36 @site.started = true
37 37 @site.start_time = Time.new.gmtime
38 38 @site.save
39 39 redirect_to :action => 'index'
40 40 end
41 41
42 42 def logout
43 43 reset_session
44 44 redirect_to :controller => 'main', :action => 'login'
45 45 end
46 46
47 47 protected
48 48 def site_admin_authorization
49 49 if session[:site_id]==nil
50 50 redirect_to :controller => 'site', :action => 'login' and return
51 51 end
52 52 begin
53 53 @site = Site.find(session[:site_id], :include => :country)
54 54 rescue ActiveRecord::RecordNotFound
55 55 @site = nil
56 56 end
57 57 if @site==nil
58 58 redirect_to :controller => 'site', :action => 'login' and return
59 59 end
60 60 end
61 61
62 62 private
63 63 def site_params
64 64 params.require(:site).permit()
65 65 end
66 66
67 67 end
@@ -1,97 +1,97
1 1 class SitesController < ApplicationController
2 2
3 - before_filter :admin_authorization
3 + before_action :admin_authorization
4 4
5 5 # GET /sites
6 6 # GET /sites.xml
7 7 def index
8 8 @sites = Site.order(:country_id)
9 9
10 10 respond_to do |format|
11 11 format.html # index.html.erb
12 12 format.xml { render :xml => @sites }
13 13 end
14 14 end
15 15
16 16 # GET /sites/1
17 17 # GET /sites/1.xml
18 18 def show
19 19 @site = Site.find(params[:id])
20 20
21 21 respond_to do |format|
22 22 format.html # show.html.erb
23 23 format.xml { render :xml => @site }
24 24 end
25 25 end
26 26
27 27 # GET /sites/new
28 28 # GET /sites/new.xml
29 29 def new
30 30 @site = Site.new
31 31
32 32 respond_to do |format|
33 33 format.html # new.html.erb
34 34 format.xml { render :xml => @site }
35 35 end
36 36 end
37 37
38 38 # GET /sites/1/edit
39 39 def edit
40 40 @site = Site.find(params[:id])
41 41 end
42 42
43 43 # POST /sites
44 44 # POST /sites.xml
45 45 def create
46 46 @site = Site.new(params[:site])
47 47 @site.clear_start_time_if_not_started
48 48
49 49 respond_to do |format|
50 50 if @site.save
51 51 flash[:notice] = 'Site was successfully created.'
52 52 format.html { redirect_to(@site) }
53 53 format.xml { render :xml => @site, :status => :created, :location => @site }
54 54 else
55 55 format.html { render :action => "new" }
56 56 format.xml { render :xml => @site.errors, :status => :unprocessable_entity }
57 57 end
58 58 end
59 59 end
60 60
61 61 # PUT /sites/1
62 62 # PUT /sites/1.xml
63 63 def update
64 64 @site = Site.find(params[:id])
65 65 @site.clear_start_time_if_not_started
66 66
67 67 respond_to do |format|
68 68 if @site.update_attributes(site_params)
69 69 flash[:notice] = 'Site was successfully updated.'
70 70 format.html { redirect_to(@site) }
71 71 format.xml { head :ok }
72 72 else
73 73 format.html { render :action => "edit" }
74 74 format.xml { render :xml => @site.errors, :status => :unprocessable_entity }
75 75 end
76 76 end
77 77 end
78 78
79 79 # DELETE /sites/1
80 80 # DELETE /sites/1.xml
81 81 def destroy
82 82 @site = Site.find(params[:id])
83 83 @site.destroy
84 84
85 85 respond_to do |format|
86 86 format.html { redirect_to(sites_url) }
87 87 format.xml { head :ok }
88 88 end
89 89 end
90 90
91 91 private
92 92
93 93 def site_params
94 94 params.require(:site).permit(:name,:started,:start_time,:country_id,:password)
95 95 end
96 96
97 97 end
@@ -1,75 +1,75
1 1 class TasksController < ApplicationController
2 2
3 - before_filter :authenticate, :check_viewability
3 + before_action :authenticate, :check_viewability
4 4
5 5 def index
6 6 redirect_to :action => 'list'
7 7 end
8 8
9 9 def list
10 10 @problems = @user.available_problems
11 11 end
12 12
13 13 # this has contest-wide access control
14 14 def view
15 15 base_name = params[:file]
16 16 base_filename = File.basename("#{base_name}.#{params[:ext]}")
17 17 filename = "#{Problem.download_file_basedir}/#{base_filename}"
18 18
19 19 if !FileTest.exists?(filename)
20 20 redirect_to :action => 'index' and return
21 21 end
22 22
23 23 send_file_to_user(filename, base_filename)
24 24 end
25 25
26 26 # this has problem-level access control
27 27 def download
28 28 problem = Problem.find(params[:id])
29 29 unless @current_user.can_view_problem? problem
30 30 redirect_to :action => 'index' and return
31 31 end
32 32
33 33 base_name = params[:file]
34 34 base_filename = File.basename("#{base_name}.#{params[:ext]}")
35 35 filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}"
36 36 puts "SENDING: #{filename}"
37 37
38 38 if !FileTest.exists?(filename)
39 39 redirect_to :action => 'index' and return
40 40 end
41 41
42 42 puts "SENDING: #{filename}"
43 43
44 44 send_file_to_user(filename, base_filename)
45 45 end
46 46
47 47 protected
48 48
49 49 def send_file_to_user(filename, base_filename)
50 50 if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
51 51 response.headers['Content-Type'] = "application/force-download"
52 52 response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
53 53 response.headers["X-Sendfile"] = filename
54 54 response.headers['Content-length'] = File.size(filename)
55 55 render :nothing => true
56 56 else
57 57 if params[:ext]=='pdf'
58 58 content_type = 'application/pdf'
59 59 else
60 60 content_type = 'application/octet-stream'
61 61 end
62 62
63 63 send_file filename, :stream => false, :disposition => 'inline', :filename => base_filename, :type => content_type
64 64 end
65 65 end
66 66
67 67 def check_viewability
68 68 @user = User.find(session[:user_id])
69 69 if @user==nil or !GraderConfiguration.show_tasks_to?(@user)
70 70 redirect_to :controller => 'main', :action => 'list'
71 71 return false
72 72 end
73 73 end
74 74
75 75 end
@@ -1,99 +1,99
1 1 class TestController < ApplicationController
2 2
3 - before_filter :authenticate, :check_viewability
3 + before_action :authenticate, :check_viewability
4 4
5 5 #
6 6 # COMMENT OUT: filter in each action instead
7 7 #
8 8 # before_filter :verify_time_limit, :only => [:submit]
9 9
10 10 verify :method => :post, :only => [:submit],
11 11 :redirect_to => { :action => :index }
12 12
13 13 def index
14 14 prepare_index_information
15 15 end
16 16
17 17 def submit
18 18 @user = User.find(session[:user_id])
19 19
20 20 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
21 21
22 22 if ! @submitted_test_request.errors.empty?
23 23 prepare_index_information
24 24 render :action => 'index' and return
25 25 end
26 26
27 27 if GraderConfiguration.time_limit_mode?
28 28 if @user.contest_finished?
29 29 @submitted_test_request.errors.add(:base,'Contest is over.')
30 30 prepare_index_information
31 31 render :action => 'index' and return
32 32 end
33 33
34 34 if !GraderConfiguration.allow_test_request(@user)
35 35 prepare_index_information
36 36 flash[:notice] = 'Test request is not allowed during the last 30 minutes'
37 37 redirect_to :action => 'index' and return
38 38 end
39 39 end
40 40
41 41 if @submitted_test_request.save
42 42 redirect_to :action => 'index'
43 43 else
44 44 prepare_index_information
45 45 render :action => 'index'
46 46 end
47 47 end
48 48
49 49 def read
50 50 user = User.find(session[:user_id])
51 51 begin
52 52 test_request = TestRequest.find(params[:id])
53 53 rescue
54 54 test_request = nil
55 55 end
56 56 if test_request==nil or test_request.user_id != user.id
57 57 flash[:notice] = 'Invalid output'
58 58 redirect_to :action => 'index'
59 59 return
60 60 end
61 61 if test_request.output_file_name!=nil
62 62 data = File.open(test_request.output_file_name).read(2048)
63 63 if data==nil
64 64 data=""
65 65 end
66 66 send_data(data,
67 67 {:filename => 'output.txt',
68 68 :type => 'text/plain'})
69 69 return
70 70 end
71 71 redirect_to :action => 'index'
72 72 end
73 73
74 74 def result
75 75 @user = User.find(session[:user_id])
76 76 begin
77 77 @test_request = TestRequest.find(params[:id])
78 78 rescue
79 79 @test_request = nil
80 80 end
81 81 if @test_request==nil or @test_request.user_id != @user.id
82 82 flash[:notice] = 'Invalid request'
83 83 redirect_to :action => 'index'
84 84 return
85 85 end
86 86 end
87 87
88 88 protected
89 89
90 90 def prepare_index_information
91 91 @user = User.find(session[:user_id])
92 92 @submissions = Submission.find_last_for_all_available_problems(@user.id)
93 93 all_problems = @submissions.collect { |submission| submission.problem }
94 94 @problems = []
95 95 all_problems.each do |problem|
96 96 if problem.test_allowed
97 97 @problems << problem
98 98 end
99 99 end
@@ -1,103 +1,103
1 1 require 'csv'
2 2
3 3 class UserAdminController < ApplicationController
4 4
5 5 include MailHelperMethods
6 6
7 - before_filter :admin_authorization
7 + before_action :admin_authorization
8 8
9 9 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
10 10 verify :method => :post, :only => [
11 11 :create, :create_from_list,
12 12 :update,
13 13 :manage_contest,
14 14 :bulk_mail
15 15 ],
16 16 :redirect_to => { :action => :list }
17 17
18 18 def index
19 19 @user_count = User.count
20 20 if params[:page] == 'all'
21 21 @users = User.all
22 22 @paginated = false
23 23 else
24 24 @users = User.paginate :page => params[:page]
25 25 @paginated = true
26 26 end
27 27 @users = User.all
28 28 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
29 29 @contests = Contest.enabled
30 30 end
31 31
32 32 def active
33 33 sessions = ActiveRecord::SessionStore::Session.where("updated_at >= ?", 60.minutes.ago)
34 34 @users = []
35 35 sessions.each do |session|
36 36 if session.data[:user_id]
37 37 @users << User.find(session.data[:user_id])
38 38 end
39 39 end
40 40 end
41 41
42 42 def show
43 43 @user = User.find(params[:id])
44 44 end
45 45
46 46 def new
47 47 @user = User.new
48 48 end
49 49
50 50 def create
51 51 @user = User.new(user_params)
52 52 @user.activated = true
53 53 if @user.save
54 54 flash[:notice] = 'User was successfully created.'
55 55 redirect_to :action => 'index'
56 56 else
57 57 render :action => 'new'
58 58 end
59 59 end
60 60
61 61 def clear_last_ip
62 62 @user = User.find(params[:id])
63 63 @user.last_ip = nil
64 64 @user.save
65 65 redirect_to action: 'index', page: params[:page]
66 66 end
67 67
68 68 def create_from_list
69 69 lines = params[:user_list]
70 70
71 71 note = []
72 72
73 73 lines.split("\n").each do |line|
74 74 items = line.chomp.split(',')
75 75 if items.length>=2
76 76 login = items[0]
77 77 full_name = items[1]
78 78 remark =''
79 79 user_alias = ''
80 80
81 81 added_random_password = false
82 82 if items.length >= 3 and items[2].chomp(" ").length > 0;
83 83 password = items[2].chomp(" ")
84 84 else
85 85 password = random_password
86 86 add_random_password=true;
87 87 end
88 88
89 89 if items.length>= 4 and items[3].chomp(" ").length > 0;
90 90 user_alias = items[3].chomp(" ")
91 91 else
92 92 user_alias = login
93 93 end
94 94
95 95 if items.length>=5
96 96 remark = items[4].strip;
97 97 end
98 98
99 99 user = User.find_by_login(login)
100 100 if (user)
101 101 user.full_name = full_name
102 102 user.password = password
103 103 user.remark = remark
@@ -1,115 +1,115
1 1 require 'net/smtp'
2 2
3 3 class UsersController < ApplicationController
4 4
5 5 include MailHelperMethods
6 6
7 - before_filter :authenticate, :except => [:new,
7 + before_action :authenticate, :except => [:new,
8 8 :register,
9 9 :confirm,
10 10 :forget,
11 11 :retrieve_password]
12 12
13 - before_filter :verify_online_registration, :only => [:new,
13 + before_action :verify_online_registration, :only => [:new,
14 14 :register,
15 15 :forget,
16 16 :retrieve_password]
17 - before_filter :authenticate, :profile_authorization, only: [:profile]
17 + before_action :authenticate, :profile_authorization, only: [:profile]
18 18
19 - before_filter :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable]
19 + before_action :admin_authorization, only: [:stat, :toggle_activate, :toggle_enable]
20 20
21 21
22 22 verify :method => :post, :only => [:chg_passwd],
23 23 :redirect_to => { :action => :index }
24 24
25 25 #in_place_edit_for :user, :alias_for_editing
26 26 #in_place_edit_for :user, :email_for_editing
27 27
28 28 def index
29 29 if !GraderConfiguration['system.user_setting_enabled']
30 30 redirect_to :controller => 'main', :action => 'list'
31 31 else
32 32 @user = User.find(session[:user_id])
33 33 end
34 34 end
35 35
36 36 def chg_passwd
37 37 user = User.find(session[:user_id])
38 38 user.password = params[:passwd]
39 39 user.password_confirmation = params[:passwd_verify]
40 40 if user.save
41 41 flash[:notice] = 'password changed'
42 42 else
43 43 flash[:notice] = 'Error: password changing failed'
44 44 end
45 45 redirect_to :action => 'index'
46 46 end
47 47
48 48 def new
49 49 @user = User.new
50 50 render :action => 'new', :layout => 'empty'
51 51 end
52 52
53 53 def register
54 54 if(params[:cancel])
55 55 redirect_to :controller => 'main', :action => 'login'
56 56 return
57 57 end
58 58 @user = User.new(user_params)
59 59 @user.password_confirmation = @user.password = User.random_password
60 60 @user.activated = false
61 61 if (@user.valid?) and (@user.save)
62 62 if send_confirmation_email(@user)
63 63 render :action => 'new_splash', :layout => 'empty'
64 64 else
65 65 @admin_email = GraderConfiguration['system.admin_email']
66 66 render :action => 'email_error', :layout => 'empty'
67 67 end
68 68 else
69 69 @user.errors.add(:base,"Email cannot be blank") if @user.email==''
70 70 render :action => 'new', :layout => 'empty'
71 71 end
72 72 end
73 73
74 74 def confirm
75 75 login = params[:login]
76 76 key = params[:activation]
77 77 @user = User.find_by_login(login)
78 78 if (@user) and (@user.verify_activation_key(key))
79 79 if @user.valid? # check uniquenss of email
80 80 @user.activated = true
81 81 @user.save
82 82 @result = :successful
83 83 else
84 84 @result = :email_used
85 85 end
86 86 else
87 87 @result = :failed
88 88 end
89 89 render :action => 'confirm', :layout => 'empty'
90 90 end
91 91
92 92 def forget
93 93 render :action => 'forget', :layout => 'empty'
94 94 end
95 95
96 96 def retrieve_password
97 97 email = params[:email]
98 98 user = User.find_by_email(email)
99 99 if user
100 100 last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour)
101 101 if last_updated_time > Time.now.gmtime - 5.minutes
102 102 flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes'
103 103 else
104 104 user.password = user.password_confirmation = User.random_password
105 105 user.save
106 106 send_new_password_email(user)
107 107 flash[:notice] = 'New password has been mailed to you.'
108 108 end
109 109 else
110 110 flash[:notice] = I18n.t 'registration.password_retrieval.no_email'
111 111 end
112 112 redirect_to :action => 'forget'
113 113 end
114 114
115 115 def stat
@@ -1,104 +1,105
1 1 CafeGrader::Application.routes.draw do
2 2 resources :tags
3 3 get "sources/direct_edit"
4 4
5 5 root :to => 'main#login'
6 6
7 7 #logins
8 - get 'login/login', to: 'login#login'
8 + match 'login/login', to: 'login#login', via: [:get,:post]
9 +
9 10
10 11 resources :contests
11 12
12 13 resources :sites
13 14
14 15 resources :announcements do
15 16 member do
16 17 get 'toggle','toggle_front'
17 18 end
18 19 end
19 20
20 21 resources :problems do
21 22 member do
22 23 get 'toggle'
23 24 get 'toggle_test'
24 25 get 'toggle_view_testcase'
25 26 get 'stat'
26 27 end
27 28 collection do
28 29 get 'turn_all_off'
29 30 get 'turn_all_on'
30 31 get 'import'
31 32 get 'manage'
32 33 end
33 34 end
34 35
35 36 resources :groups do
36 37 member do
37 38 post 'add_user', to: 'groups#add_user', as: 'add_user'
38 39 delete 'remove_user/:user_id', to: 'groups#remove_user', as: 'remove_user'
39 40 delete 'remove_all_user', to: 'groups#remove_all_user', as: 'remove_all_user'
40 41 post 'add_problem', to: 'groups#add_problem', as: 'add_problem'
41 42 delete 'remove_problem/:problem_id', to: 'groups#remove_problem', as: 'remove_problem'
42 43 delete 'remove_all_problem', to: 'groups#remove_all_problem', as: 'remove_all_problem'
43 44 end
44 45 collection do
45 46
46 47 end
47 48 end
48 49
49 50 resources :testcases, only: [] do
50 51 member do
51 52 get 'download_input'
52 53 get 'download_sol'
53 54 end
54 55 collection do
55 56 get 'show_problem/:problem_id(/:test_num)' => 'testcases#show_problem', as: 'show_problem'
56 57 end
57 58 end
58 59
59 60 resources :grader_configuration, controller: 'configurations'
60 61
61 62 resources :users do
62 63 member do
63 64 get 'toggle_activate', 'toggle_enable'
64 65 get 'stat'
65 66 end
66 67 end
67 68
68 69 resources :submissions do
69 70 member do
70 71 get 'download'
71 72 get 'compiler_msg'
72 73 get 'rejudge'
73 74 end
74 75 collection do
75 76 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
76 77 get 'direct_edit_problem/:problem_id(/:user_id)', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
77 78 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
78 79 end
79 80 end
80 81
81 82
82 83
83 84 #main
84 85 get "main/list"
85 86 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
86 87
87 88 #user admin
88 89 get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
89 90 post 'user_admin', to: 'user_admin#create'
90 91 delete 'user_admin/:id', to: 'user_admin#destroy', as: 'user_admin_destroy'
91 92
92 93 #report
93 94 get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
94 95 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
95 96 get "report/login"
96 97 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
97 98 post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
98 99
99 100
100 101 #
101 102 get 'tasks/view/:file.:ext' => 'tasks#view'
102 103 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
103 104 get 'heartbeat/:id/edit' => 'heartbeat#edit'
104 105
@@ -1,40 +1,40
1 1 require 'test_helper'
2 2
3 3 class LoginTest < ActionDispatch::IntegrationTest
4 4 # test "the truth" do
5 5 # assert true
6 6 # end
7 7
8 8 test "login with invalid information" do
9 9 get root_path
10 10 assert_response :success
11 - post login_login_path, login: "root", password: "hahaha"
11 + post login_login_path, params: {login: "root", password: "hahaha"}
12 12 assert_redirected_to root_path
13 13 end
14 14
15 15 test "normal user login" do
16 16 get root_path
17 17 assert_response :success
18 - post login_login_path, {login: "john", password: "hello" }
18 + post login_login_path, params: {login: "john", password: "hello" }
19 19 assert_redirected_to main_list_path
20 20 end
21 21
22 22 test "normal user login in single_user mode" do
23 23 GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true')
24 24 GraderConfiguration.reload
25 25 get root_path
26 26 assert_response :success
27 - post login_login_path, {login: "john", password: "hello" }
27 + post login_login_path, params: {login: "john", password: "hello" }
28 28 follow_redirect!
29 29 assert_redirected_to root_path
30 30 end
31 31
32 32 test "root login in in single_user mode" do
33 33 GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true')
34 34 GraderConfiguration.reload
35 35 get root_path
36 36 assert_response :success
37 - post login_login_path, {login: "admin", password: "admin" }
37 + post login_login_path, params: {login: "admin", password: "admin" }
38 38 assert_redirected_to main_list_path
39 39 end
40 40 end
You need to be logged in to leave comments. Login now