Description:
more login test add grader configuration to fixture add minitest reporter
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r627:f6a768e3c391 - - 10 files changed: 400 inserted, 155 deleted

@@ -0,0 +1,41
1 + # Original from http://snippets.dzone.com/posts/show/4468 by MichaelBoutros
2 + #
3 + # Optimized version which uses to_yaml for content creation and checks
4 + # that models are ActiveRecord::Base models before trying to fetch
5 + # them from database.
6 + namespace :db do
7 + namespace :fixtures do
8 + desc 'Dumps all models into fixtures.'
9 + task :dump => :environment do
10 + puts "rails root = #{Rails.root}"
11 + models = Dir.glob(Rails.root.to_s + '/app/models/**.rb').map do |s|
12 + Pathname.new(s).basename.to_s.gsub(/\.rb$/,'').camelize
13 + end
14 +
15 + puts "Found models: " + models.join(', ')
16 +
17 + models.each do |m|
18 + model = m.constantize
19 + next unless model.ancestors.include?(ActiveRecord::Base)
20 +
21 + puts "Dumping model: " + m
22 + entries = model.all.order(id: :asc)
23 +
24 + increment = 1
25 +
26 + model_file = Rails.root.to_s + '/test/fixtures2/' + m.underscore.pluralize + '.yml'
27 + File.open(model_file, 'w') do |f|
28 + entries.each do |a|
29 + attrs = a.attributes
30 + attrs.delete_if{|k,v| v.blank?}
31 +
32 + output = {m + '_' + increment.to_s => attrs}
33 + f << output.to_yaml.gsub(/^--- \n/,'') + "\n"
34 +
35 + increment += 1
36 + end
37 + end
38 + end
39 + end
40 + end
41 + end
@@ -0,0 +1,144
1 + GraderConfiguration_1:
2 + key: system.single_user_mode
3 + value_type: boolean
4 + value: 'false'
5 + description: Only admins can log in to the system when running under single user mode.
6 +
7 + GraderConfiguration_2:
8 + key: ui.front.title
9 + value_type: string
10 + value: Grader
11 +
12 + GraderConfiguration_3:
13 + key: ui.front.welcome_message
14 + value_type: string
15 + value: Welcome!
16 +
17 + GraderConfiguration_4:
18 + key: ui.show_score
19 + value_type: boolean
20 + value: 'true'
21 +
22 + GraderConfiguration_5:
23 + key: contest.time_limit
24 + value_type: string
25 + value: unlimited
26 + description: Time limit in format hh:mm, or "unlimited" for contests with no time
27 + limits. This config is CACHED. Restart the server before the change can take
28 + effect.
29 +
30 + GraderConfiguration_6:
31 + key: system.mode
32 + value_type: string
33 + value: standard
34 + description: Current modes are "standard", "contest", "indv-contest", and "analysis".
35 +
36 +
37 + GraderConfiguration_7:
38 + key: contest.name
39 + value_type: string
40 + value: Grader
41 + description: This name will be shown on the user header bar.
42 +
43 +
44 + GraderConfiguration_8:
45 + key: contest.multisites
46 + value_type: boolean
47 + value: 'false'
48 + description: If the server is in contest mode and this option is true, on the log
49 + in of the admin a menu for site selections is shown.
50 +
51 +
52 + GraderConfiguration_9:
53 + key: right.user_hall_of_fame
54 + value_type: boolean
55 + value: 'false'
56 + description: If true, any user can access hall of fame page.
57 +
58 +
59 + GraderConfiguration_10:
60 + key: right.multiple_ip_login
61 + value_type: boolean
62 + value: 'true'
63 + description: When change from true to false, a user can login from the first IP
64 + they logged into afterward.
65 +
66 +
67 + GraderConfiguration_11:
68 + key: right.user_view_submission
69 + value_type: boolean
70 + value: 'false'
71 + description: If true, any user can view submissions of every one.
72 +
73 +
74 + GraderConfiguration_12:
75 + key: right.bypass_agreement
76 + value_type: boolean
77 + value: 'true'
78 + description: When false, a user must accept usage agreement before login
79 +
80 +
81 + GraderConfiguration_13:
82 + key: right.heartbeat_response
83 + value_type: string
84 + value: OK
85 + description: Heart beat response text
86 +
87 +
88 + GraderConfiguration_14:
89 + key: right.view_testcase
90 + value_type: boolean
91 + value: 'false'
92 + description: When true, any user can view/download test data
93 +
94 +
95 + GraderConfiguration_15:
96 + key: system.online_registration.smtp
97 + value_type: string
98 + value: smtp.somehost.com
99 +
100 +
101 + GraderConfiguration_16:
102 + key: system.online_registration.from
103 + value_type: string
104 + value: your.email@address
105 +
106 +
107 + GraderConfiguration_17:
108 + key: system.admin_email
109 + value_type: string
110 + value: admin@admin.email
111 +
112 +
113 + GraderConfiguration_18:
114 + key: system.user_setting_enabled
115 + value_type: boolean
116 + value: 'true'
117 + description: If this option is true, users can change their settings
118 +
119 +
120 + GraderConfiguration_19:
121 + key: contest.test_request.early_timeout
122 + value_type: boolean
123 + value: 'false'
124 +
125 +
126 + GraderConfiguration_20:
127 + key: system.multicontests
128 + value_type: boolean
129 + value: 'false'
130 +
131 +
132 + GraderConfiguration_21:
133 + key: contest.confirm_indv_contest_start
134 + value_type: boolean
135 + value: 'false'
136 +
137 +
138 + GraderConfiguration_22:
139 + key: contest.default_contest_name
140 + value_type: string
141 + value: none
142 + description: New user will be assigned to this contest automatically, if it exists. Set
143 + to 'none' if there is no default contest.
144 +
@@ -1,78 +1,88
1 1 source 'https://rubygems.org'
2 2
3 + #rails
3 4 gem 'rails', '~>4.2.0'
4 5 gem 'activerecord-session_store'
5 6
6 - gem 'select2-rails'
7 7
8 8 # Bundle edge Rails instead:
9 9 # gem 'rails', :git => 'git://github.com/rails/rails.git'
10 10
11 + #---------------- database ---------------------
12 + #the database
11 13 gem 'mysql2'
14 + #for testing
12 15 gem 'sqlite3'
16 + #for dumping database into yaml
17 + gem 'yaml_db'
13 18
14 19 # Gems used only for assets and not required
15 20 # in production environments by default.
16 21 gem 'sass-rails'
17 22 gem 'coffee-rails'
18 23
19 24 # See https://github.com/sstephenson/execjs#readme for more supported runtimes
20 25 # gem 'therubyracer', :platforms => :ruby
21 26
22 27 gem 'uglifier'
23 28
24 -
29 + gem 'haml'
30 + gem 'haml-rails'
25 31 # gem 'prototype-rails'
26 32
27 33 # To use ActiveModel has_secure_password
28 34 # gem 'bcrypt-ruby', '~> 3.0.0'
29 35
30 36 # To use Jbuilder templates for JSON
31 37 # gem 'jbuilder'
32 38
33 39 # Use unicorn as the app server
34 40 # gem 'unicorn'
35 41
36 42 # Deploy with Capistrano
37 43 # gem 'capistrano'
38 44
39 45 # To use debugger
40 46 # gem 'debugger'
41 47 #
42 48
43 49 #in-place editor
44 50 gem 'best_in_place', '~> 3.0.1'
45 51
46 52 # jquery addition
47 53 gem 'jquery-rails'
48 54 gem 'jquery-ui-rails'
49 55 gem 'jquery-timepicker-addon-rails'
50 56 gem 'jquery-tablesorter'
51 57 gem 'jquery-countdown-rails'
52 58
53 59 #syntax highlighter
54 60 gem 'rouge'
55 61
56 62 #add bootstrap
57 63 gem 'bootstrap-sass', '~> 3.2.0'
58 64 gem 'bootstrap-switch-rails'
59 65 gem 'bootstrap-toggle-rails'
60 66 gem 'autoprefixer-rails'
61 67
62 68 #bootstrap sortable
63 69 gem 'momentjs-rails'
64 70 gem 'rails_bootstrap_sortable'
65 71
72 + #----------- user interface -----------------
73 + #select 2
74 + gem 'select2-rails'
66 75 #ace editor
67 76 gem 'ace-rails-ap'
77 + #paginator
78 + gem 'will_paginate', '~> 3.0.7'
68 79
69 - gem 'haml'
70 - gem 'haml-rails'
71 80 gem 'mail'
72 81 gem 'rdiscount'
73 - #gem 'test-unit'
74 - gem 'will_paginate', '~> 3.0.7'
75 82 gem 'dynamic_form'
76 83 gem 'in_place_editing'
77 84 gem 'verification', :git => 'https://github.com/sikachu/verification.git'
78 85
86 +
87 + #---------------- testiing -----------------------
88 + gem 'minitest-reporters'
@@ -1,217 +1,229
1 1 GIT
2 2 remote: https://github.com/sikachu/verification.git
3 3 revision: ff31697b940d7b0e2ec65f08764215c96104e76d
4 4 specs:
5 5 verification (1.0.3)
6 6 actionpack (>= 3.0.0, < 5.1)
7 7 activesupport (>= 3.0.0, < 5.1)
8 8
9 9 GEM
10 10 remote: https://rubygems.org/
11 11 specs:
12 12 ace-rails-ap (4.1.1)
13 13 actionmailer (4.2.7.1)
14 14 actionpack (= 4.2.7.1)
15 15 actionview (= 4.2.7.1)
16 16 activejob (= 4.2.7.1)
17 17 mail (~> 2.5, >= 2.5.4)
18 18 rails-dom-testing (~> 1.0, >= 1.0.5)
19 19 actionpack (4.2.7.1)
20 20 actionview (= 4.2.7.1)
21 21 activesupport (= 4.2.7.1)
22 22 rack (~> 1.6)
23 23 rack-test (~> 0.6.2)
24 24 rails-dom-testing (~> 1.0, >= 1.0.5)
25 25 rails-html-sanitizer (~> 1.0, >= 1.0.2)
26 26 actionview (4.2.7.1)
27 27 activesupport (= 4.2.7.1)
28 28 builder (~> 3.1)
29 29 erubis (~> 2.7.0)
30 30 rails-dom-testing (~> 1.0, >= 1.0.5)
31 31 rails-html-sanitizer (~> 1.0, >= 1.0.2)
32 32 activejob (4.2.7.1)
33 33 activesupport (= 4.2.7.1)
34 34 globalid (>= 0.3.0)
35 35 activemodel (4.2.7.1)
36 36 activesupport (= 4.2.7.1)
37 37 builder (~> 3.1)
38 38 activerecord (4.2.7.1)
39 39 activemodel (= 4.2.7.1)
40 40 activesupport (= 4.2.7.1)
41 41 arel (~> 6.0)
42 42 activerecord-session_store (1.0.0)
43 43 actionpack (>= 4.0, < 5.1)
44 44 activerecord (>= 4.0, < 5.1)
45 45 multi_json (~> 1.11, >= 1.11.2)
46 46 rack (>= 1.5.2, < 3)
47 47 railties (>= 4.0, < 5.1)
48 48 activesupport (4.2.7.1)
49 49 i18n (~> 0.7)
50 50 json (~> 1.7, >= 1.7.7)
51 51 minitest (~> 5.1)
52 52 thread_safe (~> 0.3, >= 0.3.4)
53 53 tzinfo (~> 1.1)
54 + ansi (1.5.0)
54 55 arel (6.0.4)
55 56 autoprefixer-rails (6.6.0)
56 57 execjs
57 58 best_in_place (3.0.3)
58 59 actionpack (>= 3.2)
59 60 railties (>= 3.2)
60 61 bootstrap-sass (3.2.0.2)
61 62 sass (~> 3.2)
62 63 bootstrap-switch-rails (3.3.3)
63 64 bootstrap-toggle-rails (2.2.1.0)
64 65 builder (3.2.2)
65 66 coffee-rails (4.2.1)
66 67 coffee-script (>= 2.2.0)
67 68 railties (>= 4.0.0, < 5.2.x)
68 69 coffee-script (2.4.1)
69 70 coffee-script-source
70 71 execjs
71 72 coffee-script-source (1.12.2)
72 73 concurrent-ruby (1.0.4)
73 74 dynamic_form (1.1.4)
74 75 erubis (2.7.0)
75 76 execjs (2.7.0)
76 77 globalid (0.3.7)
77 78 activesupport (>= 4.1.0)
78 79 haml (4.0.7)
79 80 tilt
80 81 haml-rails (0.9.0)
81 82 actionpack (>= 4.0.1)
82 83 activesupport (>= 4.0.1)
83 84 haml (>= 4.0.6, < 5.0)
84 85 html2haml (>= 1.0.1)
85 86 railties (>= 4.0.1)
86 87 html2haml (2.0.0)
87 88 erubis (~> 2.7.0)
88 89 haml (~> 4.0.0)
89 90 nokogiri (~> 1.6.0)
90 91 ruby_parser (~> 3.5)
91 92 i18n (0.7.0)
92 93 in_place_editing (1.2.0)
93 94 jquery-countdown-rails (2.0.2)
94 95 jquery-rails (4.2.1)
95 96 rails-dom-testing (>= 1, < 3)
96 97 railties (>= 4.2.0)
97 98 thor (>= 0.14, < 2.0)
98 99 jquery-tablesorter (1.23.3)
99 100 railties (>= 3.2, < 6)
100 101 jquery-timepicker-addon-rails (1.4.1)
101 102 railties (>= 3.1)
102 103 jquery-ui-rails (6.0.1)
103 104 railties (>= 3.2.16)
104 105 json (1.8.3)
105 106 loofah (2.0.3)
106 107 nokogiri (>= 1.5.9)
107 108 mail (2.6.4)
108 109 mime-types (>= 1.16, < 4)
109 110 mime-types (3.1)
110 111 mime-types-data (~> 3.2015)
111 112 mime-types-data (3.2016.0521)
112 113 mini_portile2 (2.1.0)
113 114 minitest (5.10.1)
115 + minitest-reporters (1.1.13)
116 + ansi
117 + builder
118 + minitest (>= 5.0)
119 + ruby-progressbar
114 120 momentjs-rails (2.15.1)
115 121 railties (>= 3.1)
116 122 multi_json (1.12.1)
117 123 mysql2 (0.4.5)
118 124 nokogiri (1.6.8.1)
119 125 mini_portile2 (~> 2.1.0)
120 126 rack (1.6.5)
121 127 rack-test (0.6.3)
122 128 rack (>= 1.0)
123 129 rails (4.2.7.1)
124 130 actionmailer (= 4.2.7.1)
125 131 actionpack (= 4.2.7.1)
126 132 actionview (= 4.2.7.1)
127 133 activejob (= 4.2.7.1)
128 134 activemodel (= 4.2.7.1)
129 135 activerecord (= 4.2.7.1)
130 136 activesupport (= 4.2.7.1)
131 137 bundler (>= 1.3.0, < 2.0)
132 138 railties (= 4.2.7.1)
133 139 sprockets-rails
134 140 rails-deprecated_sanitizer (1.0.3)
135 141 activesupport (>= 4.2.0.alpha)
136 142 rails-dom-testing (1.0.8)
137 143 activesupport (>= 4.2.0.beta, < 5.0)
138 144 nokogiri (~> 1.6)
139 145 rails-deprecated_sanitizer (>= 1.0.1)
140 146 rails-html-sanitizer (1.0.3)
141 147 loofah (~> 2.0)
142 148 rails_bootstrap_sortable (2.0.1)
143 149 momentjs-rails (>= 2.8.3)
144 150 railties (4.2.7.1)
145 151 actionpack (= 4.2.7.1)
146 152 activesupport (= 4.2.7.1)
147 153 rake (>= 0.8.7)
148 154 thor (>= 0.18.1, < 2.0)
149 155 rake (12.0.0)
150 156 rdiscount (2.2.0.1)
151 157 rouge (2.0.7)
158 + ruby-progressbar (1.8.1)
152 159 ruby_parser (3.8.3)
153 160 sexp_processor (~> 4.1)
154 161 sass (3.4.23)
155 162 sass-rails (5.0.6)
156 163 railties (>= 4.0.0, < 6)
157 164 sass (~> 3.1)
158 165 sprockets (>= 2.8, < 4.0)
159 166 sprockets-rails (>= 2.0, < 4.0)
160 167 tilt (>= 1.1, < 3)
161 168 select2-rails (4.0.3)
162 169 thor (~> 0.14)
163 170 sexp_processor (4.7.0)
164 171 sprockets (3.7.1)
165 172 concurrent-ruby (~> 1.0)
166 173 rack (> 1, < 3)
167 174 sprockets-rails (3.2.0)
168 175 actionpack (>= 4.0)
169 176 activesupport (>= 4.0)
170 177 sprockets (>= 3.0.0)
171 178 sqlite3 (1.3.12)
172 179 thor (0.19.4)
173 180 thread_safe (0.3.5)
174 181 tilt (2.0.5)
175 182 tzinfo (1.2.2)
176 183 thread_safe (~> 0.1)
177 184 uglifier (3.0.4)
178 185 execjs (>= 0.3.0, < 3)
179 186 will_paginate (3.0.12)
187 + yaml_db (0.4.2)
188 + rails (>= 3.0, < 5.1)
189 + rake (>= 0.8.7)
180 190
181 191 PLATFORMS
182 192 ruby
183 193
184 194 DEPENDENCIES
185 195 ace-rails-ap
186 196 activerecord-session_store
187 197 autoprefixer-rails
188 198 best_in_place (~> 3.0.1)
189 199 bootstrap-sass (~> 3.2.0)
190 200 bootstrap-switch-rails
191 201 bootstrap-toggle-rails
192 202 coffee-rails
193 203 dynamic_form
194 204 haml
195 205 haml-rails
196 206 in_place_editing
197 207 jquery-countdown-rails
198 208 jquery-rails
199 209 jquery-tablesorter
200 210 jquery-timepicker-addon-rails
201 211 jquery-ui-rails
202 212 mail
213 + minitest-reporters
203 214 momentjs-rails
204 215 mysql2
205 216 rails (~> 4.2.0)
206 217 rails_bootstrap_sortable
207 218 rdiscount
208 219 rouge
209 220 sass-rails
210 221 select2-rails
211 222 sqlite3
212 223 uglifier
213 224 verification!
214 225 will_paginate (~> 3.0.7)
226 + yaml_db
215 227
216 228 BUNDLED WITH
217 229 1.13.6
@@ -1,137 +1,137
1 1 class ApplicationController < ActionController::Base
2 2 protect_from_forgery
3 3
4 - before_filter :current_user
4 + before_filter :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 if 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 # check if run in single user mode
62 62 if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY]
63 63 user = User.find_by_id(session[:user_id])
64 64 if user==nil or (not 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 unless user.enabled?
70 70 flash[:notice] = 'Your account is disabled'
71 71 redirect_to :controller => 'main', :action => 'login'
72 72 return false
73 73 end
74 74 return true
75 75 end
76 76
77 77 if GraderConfiguration.multicontests?
78 78 user = User.find(session[:user_id])
79 79 return true if user.admin?
80 80 begin
81 81 if user.contest_stat(true).forced_logout
82 82 flash[:notice] = 'You have been automatically logged out.'
83 83 redirect_to :controller => 'main', :action => 'index'
84 84 end
85 85 rescue
86 86 end
87 87 end
88 88 return true
89 89 end
90 90
91 91 def authenticate_by_ip_address
92 92 #this assume that we have already authenticate normally
93 93 unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY]
94 94 user = User.find(session[:user_id])
95 95 if (not user.admin? and user.last_ip and user.last_ip != request.remote_ip)
96 96 flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}"
97 97 redirect_to :controller => 'main', :action => 'login'
98 98 puts "CHEAT: user #{user.login} tried to login from '#{request.remote_ip}' while last ip is '#{user.last_ip}' at #{Time.zone.now}"
99 99 return false
100 100 end
101 101 unless user.last_ip
102 102 user.last_ip = request.remote_ip
103 103 user.save
104 104 end
105 105 end
106 106 return true
107 107 end
108 108
109 109 def authorization
110 110 return false unless authenticate
111 111 user = User.find(session[:user_id])
112 112 unless user.roles.detect { |role|
113 113 role.rights.detect{ |right|
114 114 right.controller == self.class.controller_name and
115 115 (right.action == 'all' or right.action == action_name)
116 116 }
117 117 }
118 118 flash[:notice] = 'You are not authorized to view the page you requested'
119 119 #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login')
120 120 redirect_to :controller => 'main', :action => 'login'
121 121 return false
122 122 end
123 123 end
124 124
125 125 def verify_time_limit
126 126 return true if session[:user_id]==nil
127 127 user = User.find(session[:user_id], :include => :site)
128 128 return true if user==nil or user.site == nil
129 129 if user.contest_finished?
130 130 flash[:notice] = 'Error: the contest you are participating is over.'
131 131 redirect_to :back
132 132 return false
133 133 end
134 134 return true
135 135 end
136 136
137 137 end
@@ -1,183 +1,183
1 1 require 'yaml'
2 2
3 3 #
4 4 # This class also contains various login of the system.
5 5 #
6 6 class GraderConfiguration < ActiveRecord::Base
7 7
8 8 SYSTEM_MODE_CONF_KEY = 'system.mode'
9 9 TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
10 10 MULTICONTESTS_KEY = 'system.multicontests'
11 11 CONTEST_TIME_LIMIT_KEY = 'contest.time_limit'
12 12 MULTIPLE_IP_LOGIN_KEY = 'right.multiple_ip_login'
13 13 VIEW_TESTCASE = 'right.view_testcase'
14 - SINGLE_USER_KEY = 'system.single_user'
14 + SINGLE_USER_KEY = 'system.single_user_mode'
15 15
16 16 cattr_accessor :config_cache
17 17 cattr_accessor :task_grading_info_cache
18 18 cattr_accessor :contest_time_str
19 19 cattr_accessor :contest_time
20 20
21 21 GraderConfiguration.config_cache = nil
22 22 GraderConfiguration.task_grading_info_cache = nil
23 23
24 24 def self.config_cached?
25 25 (defined? CONFIGURATION_CACHE_ENABLED) and (CONFIGURATION_CACHE_ENABLED)
26 26 end
27 27
28 28 def self.get(key)
29 29 if GraderConfiguration.config_cached?
30 30 if GraderConfiguration.config_cache == nil
31 31 self.read_config
32 32 end
33 33 return GraderConfiguration.config_cache[key]
34 34 else
35 35 return GraderConfiguration.read_one_key(key)
36 36 end
37 37 end
38 38
39 39 def self.[](key)
40 40 self.get(key)
41 41 end
42 42
43 43 def self.reload
44 44 self.read_config
45 45 end
46 46
47 47 def self.clear
48 48 GraderConfiguration.config_cache = nil
49 49 end
50 50
51 51 #
52 52 # View decision
53 53 #
54 54 def self.show_submitbox_to?(user)
55 55 mode = get(SYSTEM_MODE_CONF_KEY)
56 56 return false if mode=='analysis'
57 57 if (mode=='contest')
58 58 return false if (user.site!=nil) and
59 59 ((user.site.started!=true) or (user.site.finished?))
60 60 end
61 61 return true
62 62 end
63 63
64 64 def self.show_tasks_to?(user)
65 65 if time_limit_mode?
66 66 return false if not user.contest_started?
67 67 end
68 68 return true
69 69 end
70 70
71 71 def self.show_grading_result
72 72 return (get(SYSTEM_MODE_CONF_KEY)=='analysis')
73 73 end
74 74
75 75 def self.show_testcase
76 76 return get(VIEW_TESTCASE)
77 77 end
78 78
79 79 def self.allow_test_request(user)
80 80 mode = get(SYSTEM_MODE_CONF_KEY)
81 81 early_timeout = get(TEST_REQUEST_EARLY_TIMEOUT_KEY)
82 82 if (mode=='contest')
83 83 return false if ((user.site!=nil) and
84 84 ((user.site.started!=true) or
85 85 (early_timeout and (user.site.time_left < 30.minutes))))
86 86 end
87 87 return false if mode=='analysis'
88 88 return true
89 89 end
90 90
91 91 def self.task_grading_info
92 92 if GraderConfiguration.task_grading_info_cache==nil
93 93 read_grading_info
94 94 end
95 95 return GraderConfiguration.task_grading_info_cache
96 96 end
97 97
98 98 def self.standard_mode?
99 99 return get(SYSTEM_MODE_CONF_KEY) == 'standard'
100 100 end
101 101
102 102 def self.contest_mode?
103 103 return get(SYSTEM_MODE_CONF_KEY) == 'contest'
104 104 end
105 105
106 106 def self.indv_contest_mode?
107 107 return get(SYSTEM_MODE_CONF_KEY) == 'indv-contest'
108 108 end
109 109
110 110 def self.multicontests?
111 111 return get(MULTICONTESTS_KEY) == true
112 112 end
113 113
114 114 def self.time_limit_mode?
115 115 mode = get(SYSTEM_MODE_CONF_KEY)
116 116 return ((mode == 'contest') or (mode == 'indv-contest'))
117 117 end
118 118
119 119 def self.analysis_mode?
120 120 return get(SYSTEM_MODE_CONF_KEY) == 'analysis'
121 121 end
122 122
123 123 def self.contest_time_limit
124 124 contest_time_str = GraderConfiguration[CONTEST_TIME_LIMIT_KEY]
125 125
126 126 if not defined? GraderConfiguration.contest_time_str
127 127 GraderConfiguration.contest_time_str = nil
128 128 end
129 129
130 130 if GraderConfiguration.contest_time_str != contest_time_str
131 131 GraderConfiguration.contest_time_str = contest_time_str
132 132 if tmatch = /(\d+):(\d+)/.match(contest_time_str)
133 133 h = tmatch[1].to_i
134 134 m = tmatch[2].to_i
135 135
136 136 GraderConfiguration.contest_time = h.hour + m.minute
137 137 else
138 138 GraderConfiguration.contest_time = nil
139 139 end
140 140 end
141 141 return GraderConfiguration.contest_time
142 142 end
143 143
144 144 protected
145 145
146 146 def self.convert_type(val,type)
147 147 case type
148 148 when 'string'
149 149 return val
150 150
151 151 when 'integer'
152 152 return val.to_i
153 153
154 154 when 'boolean'
155 155 return (val=='true')
156 156 end
157 157 end
158 158
159 159 def self.read_config
160 160 GraderConfiguration.config_cache = {}
161 161 GraderConfiguration.all.each do |conf|
162 162 key = conf.key
163 163 val = conf.value
164 164 GraderConfiguration.config_cache[key] = GraderConfiguration.convert_type(val,conf.value_type)
165 165 end
166 166 end
167 167
168 168 def self.read_one_key(key)
169 169 conf = GraderConfiguration.find_by_key(key)
170 170 if conf
171 171 return GraderConfiguration.convert_type(conf.value,conf.value_type)
172 172 else
173 173 return nil
174 174 end
175 175 end
176 176
177 177 def self.read_grading_info
178 178 f = File.open(TASK_GRADING_INFO_FILENAME)
179 179 GraderConfiguration.task_grading_info_cache = YAML.load(f)
180 180 f.close
181 181 end
182 182
183 183 end
@@ -1,280 +1,280
1 1 # encoding: UTF-8
2 2 # This file is auto-generated from the current state of the database. Instead
3 3 # of editing this file, please use the migrations feature of Active Record to
4 4 # incrementally modify your database, and then regenerate this schema definition.
5 5 #
6 6 # Note that this schema.rb definition is the authoritative source for your
7 7 # database schema. If you need to create the application database on another
8 8 # system, you should be using db:schema:load, not running all the migrations
9 9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13
14 14 ActiveRecord::Schema.define(version: 20161031063337) do
15 15
16 16 create_table "announcements", force: :cascade do |t|
17 - t.string "author"
18 - t.text "body"
17 + t.string "author", limit: 255
18 + t.text "body", limit: 65535
19 19 t.boolean "published"
20 - t.datetime "created_at", null: false
21 - t.datetime "updated_at", null: false
22 - t.boolean "frontpage", default: false
23 - t.boolean "contest_only", default: false
24 - t.string "title"
25 - t.string "notes"
20 + t.datetime "created_at", null: false
21 + t.datetime "updated_at", null: false
22 + t.boolean "frontpage", default: false
23 + t.boolean "contest_only", default: false
24 + t.string "title", limit: 255
25 + t.string "notes", limit: 255
26 26 end
27 27
28 28 create_table "contests", force: :cascade do |t|
29 - t.string "title"
29 + t.string "title", limit: 255
30 30 t.boolean "enabled"
31 - t.datetime "created_at", null: false
32 - t.datetime "updated_at", null: false
33 - t.string "name"
31 + t.datetime "created_at", null: false
32 + t.datetime "updated_at", null: false
33 + t.string "name", limit: 255
34 34 end
35 35
36 36 create_table "contests_problems", id: false, force: :cascade do |t|
37 - t.integer "contest_id"
38 - t.integer "problem_id"
37 + t.integer "contest_id", limit: 4
38 + t.integer "problem_id", limit: 4
39 39 end
40 40
41 41 create_table "contests_users", id: false, force: :cascade do |t|
42 - t.integer "contest_id"
43 - t.integer "user_id"
42 + t.integer "contest_id", limit: 4
43 + t.integer "user_id", limit: 4
44 44 end
45 45
46 46 create_table "countries", force: :cascade do |t|
47 - t.string "name"
48 - t.datetime "created_at", null: false
49 - t.datetime "updated_at", null: false
47 + t.string "name", limit: 255
48 + t.datetime "created_at", null: false
49 + t.datetime "updated_at", null: false
50 50 end
51 51
52 52 create_table "descriptions", force: :cascade do |t|
53 - t.text "body"
53 + t.text "body", limit: 65535
54 54 t.boolean "markdowned"
55 - t.datetime "created_at", null: false
56 - t.datetime "updated_at", null: false
55 + t.datetime "created_at", null: false
56 + t.datetime "updated_at", null: false
57 57 end
58 58
59 59 create_table "grader_configurations", force: :cascade do |t|
60 - t.string "key"
61 - t.string "value_type"
62 - t.string "value"
63 - t.datetime "created_at", null: false
64 - t.datetime "updated_at", null: false
65 - t.text "description"
60 + t.string "key", limit: 255
61 + t.string "value_type", limit: 255
62 + t.string "value", limit: 255
63 + t.datetime "created_at", null: false
64 + t.datetime "updated_at", null: false
65 + t.text "description", limit: 65535
66 66 end
67 67
68 68 create_table "grader_processes", force: :cascade do |t|
69 - t.string "host"
70 - t.integer "pid"
71 - t.string "mode"
69 + t.string "host", limit: 255
70 + t.integer "pid", limit: 4
71 + t.string "mode", limit: 255
72 72 t.boolean "active"
73 - t.datetime "created_at", null: false
74 - t.datetime "updated_at", null: false
75 - t.integer "task_id"
76 - t.string "task_type"
73 + t.datetime "created_at", null: false
74 + t.datetime "updated_at", null: false
75 + t.integer "task_id", limit: 4
76 + t.string "task_type", limit: 255
77 77 t.boolean "terminated"
78 78 end
79 79
80 - add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_ip_and_pid"
80 + add_index "grader_processes", ["host", "pid"], name: "index_grader_processes_on_ip_and_pid", using: :btree
81 81
82 82 create_table "heart_beats", force: :cascade do |t|
83 - t.integer "user_id"
84 - t.string "ip_address"
85 - t.datetime "created_at", null: false
86 - t.datetime "updated_at", null: false
87 - t.string "status"
83 + t.integer "user_id", limit: 4
84 + t.string "ip_address", limit: 255
85 + t.datetime "created_at", null: false
86 + t.datetime "updated_at", null: false
87 + t.string "status", limit: 255
88 88 end
89 89
90 - add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at"
90 + add_index "heart_beats", ["updated_at"], name: "index_heart_beats_on_updated_at", using: :btree
91 91
92 92 create_table "languages", force: :cascade do |t|
93 93 t.string "name", limit: 10
94 - t.string "pretty_name"
94 + t.string "pretty_name", limit: 255
95 95 t.string "ext", limit: 10
96 - t.string "common_ext"
96 + t.string "common_ext", limit: 255
97 97 end
98 98
99 99 create_table "logins", force: :cascade do |t|
100 - t.integer "user_id"
101 - t.string "ip_address"
102 - t.datetime "created_at", null: false
103 - t.datetime "updated_at", null: false
100 + t.integer "user_id", limit: 4
101 + t.string "ip_address", limit: 255
102 + t.datetime "created_at", null: false
103 + t.datetime "updated_at", null: false
104 104 end
105 105
106 106 create_table "messages", force: :cascade do |t|
107 - t.integer "sender_id"
108 - t.integer "receiver_id"
109 - t.integer "replying_message_id"
110 - t.text "body"
107 + t.integer "sender_id", limit: 4
108 + t.integer "receiver_id", limit: 4
109 + t.integer "replying_message_id", limit: 4
110 + t.text "body", limit: 65535
111 111 t.boolean "replied"
112 - t.datetime "created_at", null: false
113 - t.datetime "updated_at", null: false
112 + t.datetime "created_at", null: false
113 + t.datetime "updated_at", null: false
114 114 end
115 115
116 116 create_table "problems", force: :cascade do |t|
117 117 t.string "name", limit: 30
118 - t.string "full_name"
119 - t.integer "full_score"
118 + t.string "full_name", limit: 255
119 + t.integer "full_score", limit: 4
120 120 t.date "date_added"
121 121 t.boolean "available"
122 - t.string "url"
123 - t.integer "description_id"
122 + t.string "url", limit: 255
123 + t.integer "description_id", limit: 4
124 124 t.boolean "test_allowed"
125 125 t.boolean "output_only"
126 - t.string "description_filename"
126 + t.string "description_filename", limit: 255
127 127 end
128 128
129 129 create_table "rights", force: :cascade do |t|
130 - t.string "name"
131 - t.string "controller"
132 - t.string "action"
130 + t.string "name", limit: 255
131 + t.string "controller", limit: 255
132 + t.string "action", limit: 255
133 133 end
134 134
135 135 create_table "rights_roles", id: false, force: :cascade do |t|
136 - t.integer "right_id"
137 - t.integer "role_id"
136 + t.integer "right_id", limit: 4
137 + t.integer "role_id", limit: 4
138 138 end
139 139
140 - add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id"
140 + add_index "rights_roles", ["role_id"], name: "index_rights_roles_on_role_id", using: :btree
141 141
142 142 create_table "roles", force: :cascade do |t|
143 - t.string "name"
143 + t.string "name", limit: 255
144 144 end
145 145
146 146 create_table "roles_users", id: false, force: :cascade do |t|
147 - t.integer "role_id"
148 - t.integer "user_id"
147 + t.integer "role_id", limit: 4
148 + t.integer "user_id", limit: 4
149 149 end
150 150
151 - add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id"
151 + add_index "roles_users", ["user_id"], name: "index_roles_users_on_user_id", using: :btree
152 152
153 153 create_table "sessions", force: :cascade do |t|
154 - t.string "session_id"
155 - t.text "data"
154 + t.string "session_id", limit: 255
155 + t.text "data", limit: 65535
156 156 t.datetime "updated_at"
157 157 end
158 158
159 - add_index "sessions", ["session_id"], name: "index_sessions_on_session_id"
160 - add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at"
159 + add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
160 + add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree
161 161
162 162 create_table "sites", force: :cascade do |t|
163 - t.string "name"
163 + t.string "name", limit: 255
164 164 t.boolean "started"
165 165 t.datetime "start_time"
166 - t.datetime "created_at", null: false
167 - t.datetime "updated_at", null: false
168 - t.integer "country_id"
169 - t.string "password"
166 + t.datetime "created_at", null: false
167 + t.datetime "updated_at", null: false
168 + t.integer "country_id", limit: 4
169 + t.string "password", limit: 255
170 170 end
171 171
172 172 create_table "submission_view_logs", force: :cascade do |t|
173 - t.integer "user_id"
174 - t.integer "submission_id"
175 - t.datetime "created_at", null: false
176 - t.datetime "updated_at", null: false
173 + t.integer "user_id", limit: 4
174 + t.integer "submission_id", limit: 4
175 + t.datetime "created_at", null: false
176 + t.datetime "updated_at", null: false
177 177 end
178 178
179 179 create_table "submissions", force: :cascade do |t|
180 - t.integer "user_id"
181 - t.integer "problem_id"
182 - t.integer "language_id"
183 - t.text "source"
184 - t.binary "binary"
180 + t.integer "user_id", limit: 4
181 + t.integer "problem_id", limit: 4
182 + t.integer "language_id", limit: 4
183 + t.text "source", limit: 65535
184 + t.binary "binary", limit: 65535
185 185 t.datetime "submitted_at"
186 186 t.datetime "compiled_at"
187 - t.text "compiler_message"
187 + t.text "compiler_message", limit: 65535
188 188 t.datetime "graded_at"
189 - t.integer "points"
190 - t.text "grader_comment"
191 - t.integer "number"
192 - t.string "source_filename"
193 - t.float "max_runtime"
194 - t.integer "peak_memory"
195 - t.integer "effective_code_length"
196 - t.string "ip_address"
189 + t.integer "points", limit: 4
190 + t.text "grader_comment", limit: 65535
191 + t.integer "number", limit: 4
192 + t.string "source_filename", limit: 255
193 + t.float "max_runtime", limit: 24
194 + t.integer "peak_memory", limit: 4
195 + t.integer "effective_code_length", limit: 4
196 + t.string "ip_address", limit: 255
197 197 end
198 198
199 - add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true
200 - add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id"
199 + add_index "submissions", ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true, using: :btree
200 + add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree
201 201
202 202 create_table "tasks", force: :cascade do |t|
203 - t.integer "submission_id"
203 + t.integer "submission_id", limit: 4
204 204 t.datetime "created_at"
205 - t.integer "status"
205 + t.integer "status", limit: 4
206 206 t.datetime "updated_at"
207 207 end
208 208
209 209 create_table "test_pairs", force: :cascade do |t|
210 - t.integer "problem_id"
210 + t.integer "problem_id", limit: 4
211 211 t.text "input", limit: 16777215
212 212 t.text "solution", limit: 16777215
213 213 t.datetime "created_at", null: false
214 214 t.datetime "updated_at", null: false
215 215 end
216 216
217 217 create_table "test_requests", force: :cascade do |t|
218 - t.integer "user_id"
219 - t.integer "problem_id"
220 - t.integer "submission_id"
221 - t.string "input_file_name"
222 - t.string "output_file_name"
223 - t.string "running_stat"
224 - t.integer "status"
225 - t.datetime "updated_at", null: false
218 + t.integer "user_id", limit: 4
219 + t.integer "problem_id", limit: 4
220 + t.integer "submission_id", limit: 4
221 + t.string "input_file_name", limit: 255
222 + t.string "output_file_name", limit: 255
223 + t.string "running_stat", limit: 255
224 + t.integer "status", limit: 4
225 + t.datetime "updated_at", null: false
226 226 t.datetime "submitted_at"
227 227 t.datetime "compiled_at"
228 - t.text "compiler_message"
228 + t.text "compiler_message", limit: 65535
229 229 t.datetime "graded_at"
230 - t.string "grader_comment"
231 - t.datetime "created_at", null: false
232 - t.float "running_time"
233 - t.string "exit_status"
234 - t.integer "memory_usage"
230 + t.string "grader_comment", limit: 255
231 + t.datetime "created_at", null: false
232 + t.float "running_time", limit: 24
233 + t.string "exit_status", limit: 255
234 + t.integer "memory_usage", limit: 4
235 235 end
236 236
237 - add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id"
237 + add_index "test_requests", ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id", using: :btree
238 238
239 239 create_table "testcases", force: :cascade do |t|
240 - t.integer "problem_id"
241 - t.integer "num"
242 - t.integer "group"
243 - t.integer "score"
244 - t.text "input"
245 - t.text "sol"
246 - t.datetime "created_at", null: false
247 - t.datetime "updated_at", null: false
240 + t.integer "problem_id", limit: 4
241 + t.integer "num", limit: 4
242 + t.integer "group", limit: 4
243 + t.integer "score", limit: 4
244 + t.text "input", limit: 65535
245 + t.text "sol", limit: 65535
246 + t.datetime "created_at"
247 + t.datetime "updated_at"
248 248 end
249 249
250 - add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id"
250 + add_index "testcases", ["problem_id"], name: "index_testcases_on_problem_id", using: :btree
251 251
252 252 create_table "user_contest_stats", force: :cascade do |t|
253 - t.integer "user_id"
253 + t.integer "user_id", limit: 4
254 254 t.datetime "started_at"
255 - t.datetime "created_at", null: false
256 - t.datetime "updated_at", null: false
255 + t.datetime "created_at", null: false
256 + t.datetime "updated_at", null: false
257 257 t.boolean "forced_logout"
258 258 end
259 259
260 260 create_table "users", force: :cascade do |t|
261 261 t.string "login", limit: 50
262 - t.string "full_name"
263 - t.string "hashed_password"
262 + t.string "full_name", limit: 255
263 + t.string "hashed_password", limit: 255
264 264 t.string "salt", limit: 5
265 - t.string "alias"
266 - t.string "email"
267 - t.integer "site_id"
268 - t.integer "country_id"
269 - t.boolean "activated", default: false
265 + t.string "alias", limit: 255
266 + t.string "email", limit: 255
267 + t.integer "site_id", limit: 4
268 + t.integer "country_id", limit: 4
269 + t.boolean "activated", default: false
270 270 t.datetime "created_at"
271 271 t.datetime "updated_at"
272 - t.boolean "enabled", default: true
273 - t.string "remark"
274 - t.string "last_ip"
275 - t.string "section"
272 + t.boolean "enabled", default: true
273 + t.string "remark", limit: 255
274 + t.string "last_ip", limit: 255
275 + t.string "section", limit: 255
276 276 end
277 277
278 - add_index "users", ["login"], name: "index_users_on_login", unique: true
278 + add_index "users", ["login"], name: "index_users_on_login", unique: true, using: :btree
279 279
280 280 end
@@ -1,5 +1,36
1 - # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
2 - one:
3 - id: 1
4 - two:
5 - id: 2
1 + Language_1:
2 + name: c
3 + pretty_name: C
4 + ext: c
5 + common_ext: c
6 +
7 + Language_2:
8 + name: cpp
9 + pretty_name: C++
10 + ext: cpp
11 + common_ext: cpp,cc
12 +
13 + Language_3:
14 + name: pas
15 + pretty_name: Pascal
16 + ext: pas
17 + common_ext: pas
18 +
19 + Language_4:
20 + name: ruby
21 + pretty_name: Ruby
22 + ext: rb
23 + common_ext: rb
24 +
25 + Language_5:
26 + name: python
27 + pretty_name: Python
28 + ext: py
29 + common_ext: py
30 +
31 + Language_6:
32 + name: java
33 + pretty_name: Java
34 + ext: java
35 + common_ext: java
36 +
@@ -1,37 +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 11 post login_login_path, 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 18 post login_login_path, {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 - GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true'
23 + GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true')
24 + GraderConfiguration.reload
24 25 get root_path
25 26 assert_response :success
26 27 post login_login_path, {login: "john", password: "hello" }
28 + follow_redirect!
27 29 assert_redirected_to root_path
28 30 end
29 31
30 32 test "root login in in single_user mode" do
31 - GraderConfiguration[GraderConfiguration::SINGLE_USER_KEY] = 'true'
33 + GraderConfiguration.find_by(key: GraderConfiguration::SINGLE_USER_KEY).update_attributes(value: 'true')
34 + GraderConfiguration.reload
32 35 get root_path
33 36 assert_response :success
34 37 post login_login_path, {login: "admin", password: "admin" }
35 38 assert_redirected_to main_list_path
36 39 end
37 40 end
@@ -1,16 +1,20
1 1 ENV["RAILS_ENV"] = "test"
2 2 require File.expand_path('../../config/environment', __FILE__)
3 3 require 'rails/test_help'
4 4
5 + #reporter
6 + require "minitest/reporters"
7 + Minitest::Reporters.use!
8 +
5 9 class ActiveSupport::TestCase
6 10 # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
7 11 #
8 12 # Note: You'll currently still have to declare fixtures explicitly in integration tests
9 13 # -- they do not yet inherit this setting
10 14 fixtures :all
11 15
12 16 # Add more helper methods to be used by all tests here...
13 17
14 18 self.use_transactional_fixtures = true
15 19 self.use_instantiated_fixtures = false
16 20 end
You need to be logged in to leave comments. Login now