Description:
add ip to front page, also fix seeds.rb
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r783:f1343ca4b141 - - 3 files changed: 3 inserted, 1 deleted

@@ -1,368 +1,369
1 class MainController < ApplicationController
1 class MainController < ApplicationController
2
2
3 before_action :check_valid_login, :except => [:login]
3 before_action :check_valid_login, :except => [:login]
4 before_action :check_viewability, :except => [:index, :login]
4 before_action :check_viewability, :except => [:index, :login]
5
5
6 append_before_action :confirm_and_update_start_time,
6 append_before_action :confirm_and_update_start_time,
7 :except => [:index,
7 :except => [:index,
8 :login,
8 :login,
9 :confirm_contest_start]
9 :confirm_contest_start]
10
10
11 # to prevent log in box to be shown when user logged out of the
11 # to prevent log in box to be shown when user logged out of the
12 # system only in some tab
12 # system only in some tab
13 prepend_before_action :reject_announcement_refresh_when_logged_out,
13 prepend_before_action :reject_announcement_refresh_when_logged_out,
14 :only => [:announcements]
14 :only => [:announcements]
15
15
16 before_action :authenticate_by_ip_address, :only => [:list]
16 before_action :authenticate_by_ip_address, :only => [:list]
17
17
18 #reset login, clear session
18 #reset login, clear session
19 #front page
19 #front page
20 def login
20 def login
21 saved_notice = flash[:notice]
21 saved_notice = flash[:notice]
22 reset_session
22 reset_session
23 flash.now[:notice] = saved_notice
23 flash.now[:notice] = saved_notice
24 + @remote_ip = request.remote_ip
24
25
25 # EXPERIMENT:
26 # EXPERIMENT:
26 # Hide login if in single user mode and the url does not
27 # Hide login if in single user mode and the url does not
27 # explicitly specify /login
28 # explicitly specify /login
28 #
29 #
29 # logger.info "PATH: #{request.path}"
30 # logger.info "PATH: #{request.path}"
30 # if GraderConfiguration['system.single_user_mode'] and
31 # if GraderConfiguration['system.single_user_mode'] and
31 # request.path!='/main/login'
32 # request.path!='/main/login'
32 # @hidelogin = true
33 # @hidelogin = true
33 # end
34 # end
34
35
35 @announcements = Announcement.frontpage
36 @announcements = Announcement.frontpage
36 render :action => 'login', :layout => 'empty'
37 render :action => 'login', :layout => 'empty'
37 end
38 end
38
39
39 def logout
40 def logout
40 reset_session
41 reset_session
41 redirect_to root_path
42 redirect_to root_path
42 end
43 end
43
44
44 def list
45 def list
45 prepare_list_information
46 prepare_list_information
46 end
47 end
47
48
48 def help
49 def help
49 @user = User.find(session[:user_id])
50 @user = User.find(session[:user_id])
50 end
51 end
51
52
52 def submit
53 def submit
53 user = User.find(session[:user_id])
54 user = User.find(session[:user_id])
54
55
55 @submission = Submission.new
56 @submission = Submission.new
56 @submission.problem_id = params[:submission][:problem_id]
57 @submission.problem_id = params[:submission][:problem_id]
57 @submission.user = user
58 @submission.user = user
58 @submission.language_id = 0
59 @submission.language_id = 0
59 if (params['file']) and (params['file']!='')
60 if (params['file']) and (params['file']!='')
60 @submission.source = File.open(params['file'].path,'r:UTF-8',&:read)
61 @submission.source = File.open(params['file'].path,'r:UTF-8',&:read)
61 @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '')
62 @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '')
62 @submission.source_filename = params['file'].original_filename
63 @submission.source_filename = params['file'].original_filename
63 end
64 end
64
65
65 if (params[:editor_text])
66 if (params[:editor_text])
66 language = Language.find_by_id(params[:language_id])
67 language = Language.find_by_id(params[:language_id])
67 @submission.source = params[:editor_text]
68 @submission.source = params[:editor_text]
68 @submission.source_filename = "live_edit.#{language.ext}"
69 @submission.source_filename = "live_edit.#{language.ext}"
69 @submission.language = language
70 @submission.language = language
70 end
71 end
71
72
72 @submission.submitted_at = Time.new.gmtime
73 @submission.submitted_at = Time.new.gmtime
73 @submission.ip_address = request.remote_ip
74 @submission.ip_address = request.remote_ip
74
75
75 if GraderConfiguration.time_limit_mode? and user.contest_finished?
76 if GraderConfiguration.time_limit_mode? and user.contest_finished?
76 @submission.errors.add(:base,"The contest is over.")
77 @submission.errors.add(:base,"The contest is over.")
77 prepare_list_information
78 prepare_list_information
78 render :action => 'list' and return
79 render :action => 'list' and return
79 end
80 end
80
81
81 if @submission.valid?(@current_user)
82 if @submission.valid?(@current_user)
82 if @submission.save == false
83 if @submission.save == false
83 flash[:notice] = 'Error saving your submission'
84 flash[:notice] = 'Error saving your submission'
84 elsif Task.create(:submission_id => @submission.id,
85 elsif Task.create(:submission_id => @submission.id,
85 :status => Task::STATUS_INQUEUE) == false
86 :status => Task::STATUS_INQUEUE) == false
86 flash[:notice] = 'Error adding your submission to task queue'
87 flash[:notice] = 'Error adding your submission to task queue'
87 end
88 end
88 else
89 else
89 prepare_list_information
90 prepare_list_information
90 render :action => 'list' and return
91 render :action => 'list' and return
91 end
92 end
92 redirect_to edit_submission_path(@submission)
93 redirect_to edit_submission_path(@submission)
93 end
94 end
94
95
95 def source
96 def source
96 submission = Submission.find(params[:id])
97 submission = Submission.find(params[:id])
97 if ((submission.user_id == session[:user_id]) and
98 if ((submission.user_id == session[:user_id]) and
98 (submission.problem != nil) and
99 (submission.problem != nil) and
99 (submission.problem.available))
100 (submission.problem.available))
100 send_data(submission.source,
101 send_data(submission.source,
101 {:filename => submission.download_filename,
102 {:filename => submission.download_filename,
102 :type => 'text/plain'})
103 :type => 'text/plain'})
103 else
104 else
104 flash[:notice] = 'Error viewing source'
105 flash[:notice] = 'Error viewing source'
105 redirect_to :action => 'list'
106 redirect_to :action => 'list'
106 end
107 end
107 end
108 end
108
109
109 def compiler_msg
110 def compiler_msg
110 @submission = Submission.find(params[:id])
111 @submission = Submission.find(params[:id])
111 if @submission.user_id == session[:user_id]
112 if @submission.user_id == session[:user_id]
112 render :action => 'compiler_msg', :layout => 'empty'
113 render :action => 'compiler_msg', :layout => 'empty'
113 else
114 else
114 flash[:notice] = 'Error viewing source'
115 flash[:notice] = 'Error viewing source'
115 redirect_to :action => 'list'
116 redirect_to :action => 'list'
116 end
117 end
117 end
118 end
118
119
119 def result
120 def result
120 if !GraderConfiguration.show_grading_result
121 if !GraderConfiguration.show_grading_result
121 redirect_to :action => 'list' and return
122 redirect_to :action => 'list' and return
122 end
123 end
123 @user = User.find(session[:user_id])
124 @user = User.find(session[:user_id])
124 @submission = Submission.find(params[:id])
125 @submission = Submission.find(params[:id])
125 if @submission.user!=@user
126 if @submission.user!=@user
126 flash[:notice] = 'You are not allowed to view result of other users.'
127 flash[:notice] = 'You are not allowed to view result of other users.'
127 redirect_to :action => 'list' and return
128 redirect_to :action => 'list' and return
128 end
129 end
129 prepare_grading_result(@submission)
130 prepare_grading_result(@submission)
130 end
131 end
131
132
132 def load_output
133 def load_output
133 if !GraderConfiguration.show_grading_result or params[:num]==nil
134 if !GraderConfiguration.show_grading_result or params[:num]==nil
134 redirect_to :action => 'list' and return
135 redirect_to :action => 'list' and return
135 end
136 end
136 @user = User.find(session[:user_id])
137 @user = User.find(session[:user_id])
137 @submission = Submission.find(params[:id])
138 @submission = Submission.find(params[:id])
138 if @submission.user!=@user
139 if @submission.user!=@user
139 flash[:notice] = 'You are not allowed to view result of other users.'
140 flash[:notice] = 'You are not allowed to view result of other users.'
140 redirect_to :action => 'list' and return
141 redirect_to :action => 'list' and return
141 end
142 end
142 case_num = params[:num].to_i
143 case_num = params[:num].to_i
143 out_filename = output_filename(@user.login,
144 out_filename = output_filename(@user.login,
144 @submission.problem.name,
145 @submission.problem.name,
145 @submission.id,
146 @submission.id,
146 case_num)
147 case_num)
147 if !FileTest.exists?(out_filename)
148 if !FileTest.exists?(out_filename)
148 flash[:notice] = 'Output not found.'
149 flash[:notice] = 'Output not found.'
149 redirect_to :action => 'list' and return
150 redirect_to :action => 'list' and return
150 end
151 end
151
152
152 if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
153 if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
153 response.headers['Content-Type'] = "application/force-download"
154 response.headers['Content-Type'] = "application/force-download"
154 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
155 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
155 response.headers["X-Sendfile"] = out_filename
156 response.headers["X-Sendfile"] = out_filename
156 response.headers['Content-length'] = File.size(out_filename)
157 response.headers['Content-length'] = File.size(out_filename)
157 render :nothing => true
158 render :nothing => true
158 else
159 else
159 send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain"
160 send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain"
160 end
161 end
161 end
162 end
162
163
163 def error
164 def error
164 @user = User.find(session[:user_id])
165 @user = User.find(session[:user_id])
165 end
166 end
166
167
167 # announcement refreshing and hiding methods
168 # announcement refreshing and hiding methods
168
169
169 def announcements
170 def announcements
170 if params.has_key? 'recent'
171 if params.has_key? 'recent'
171 prepare_announcements(params[:recent])
172 prepare_announcements(params[:recent])
172 else
173 else
173 prepare_announcements
174 prepare_announcements
174 end
175 end
175 render(:partial => 'announcement',
176 render(:partial => 'announcement',
176 :collection => @announcements,
177 :collection => @announcements,
177 :locals => {:announcement_effect => true})
178 :locals => {:announcement_effect => true})
178 end
179 end
179
180
180 def confirm_contest_start
181 def confirm_contest_start
181 user = User.find(session[:user_id])
182 user = User.find(session[:user_id])
182 if request.method == 'POST'
183 if request.method == 'POST'
183 user.update_start_time
184 user.update_start_time
184 redirect_to :action => 'list'
185 redirect_to :action => 'list'
185 else
186 else
186 @contests = user.contests
187 @contests = user.contests
187 @user = user
188 @user = user
188 end
189 end
189 end
190 end
190
191
191 protected
192 protected
192
193
193 def prepare_announcements(recent=nil)
194 def prepare_announcements(recent=nil)
194 if GraderConfiguration.show_tasks_to?(@user)
195 if GraderConfiguration.show_tasks_to?(@user)
195 @announcements = Announcement.published(true)
196 @announcements = Announcement.published(true)
196 else
197 else
197 @announcements = Announcement.published
198 @announcements = Announcement.published
198 end
199 end
199 if recent!=nil
200 if recent!=nil
200 recent_id = recent.to_i
201 recent_id = recent.to_i
201 @announcements = @announcements.find_all { |a| a.id > recent_id }
202 @announcements = @announcements.find_all { |a| a.id > recent_id }
202 end
203 end
203 end
204 end
204
205
205 def prepare_list_information
206 def prepare_list_information
206 @user = User.find(session[:user_id])
207 @user = User.find(session[:user_id])
207 if not GraderConfiguration.multicontests?
208 if not GraderConfiguration.multicontests?
208 @problems = @user.available_problems
209 @problems = @user.available_problems
209 else
210 else
210 @contest_problems = @user.available_problems_group_by_contests
211 @contest_problems = @user.available_problems_group_by_contests
211 @problems = @user.available_problems
212 @problems = @user.available_problems
212 end
213 end
213 @prob_submissions = {}
214 @prob_submissions = {}
214 @problems.each do |p|
215 @problems.each do |p|
215 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
216 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
216 if sub!=nil
217 if sub!=nil
217 @prob_submissions[p.id] = { :count => sub.number, :submission => sub }
218 @prob_submissions[p.id] = { :count => sub.number, :submission => sub }
218 else
219 else
219 @prob_submissions[p.id] = { :count => 0, :submission => nil }
220 @prob_submissions[p.id] = { :count => 0, :submission => nil }
220 end
221 end
221 end
222 end
222 prepare_announcements
223 prepare_announcements
223 end
224 end
224
225
225 def check_viewability
226 def check_viewability
226 @user = User.find(session[:user_id])
227 @user = User.find(session[:user_id])
227 if (!GraderConfiguration.show_tasks_to?(@user)) and
228 if (!GraderConfiguration.show_tasks_to?(@user)) and
228 ((action_name=='submission') or (action_name=='submit'))
229 ((action_name=='submission') or (action_name=='submit'))
229 redirect_to :action => 'list' and return
230 redirect_to :action => 'list' and return
230 end
231 end
231 end
232 end
232
233
233 def prepare_grading_result(submission)
234 def prepare_grading_result(submission)
234 if GraderConfiguration.task_grading_info.has_key? submission.problem.name
235 if GraderConfiguration.task_grading_info.has_key? submission.problem.name
235 grading_info = GraderConfiguration.task_grading_info[submission.problem.name]
236 grading_info = GraderConfiguration.task_grading_info[submission.problem.name]
236 else
237 else
237 # guess task info from problem.full_score
238 # guess task info from problem.full_score
238 cases = submission.problem.full_score / 10
239 cases = submission.problem.full_score / 10
239 grading_info = {
240 grading_info = {
240 'testruns' => cases,
241 'testruns' => cases,
241 'testcases' => cases
242 'testcases' => cases
242 }
243 }
243 end
244 end
244 @test_runs = []
245 @test_runs = []
245 if grading_info['testruns'].is_a? Integer
246 if grading_info['testruns'].is_a? Integer
246 trun_count = grading_info['testruns']
247 trun_count = grading_info['testruns']
247 trun_count.times do |i|
248 trun_count.times do |i|
248 @test_runs << [ read_grading_result(@user.login,
249 @test_runs << [ read_grading_result(@user.login,
249 submission.problem.name,
250 submission.problem.name,
250 submission.id,
251 submission.id,
251 i+1) ]
252 i+1) ]
252 end
253 end
253 else
254 else
254 grading_info['testruns'].keys.sort.each do |num|
255 grading_info['testruns'].keys.sort.each do |num|
255 run = []
256 run = []
256 testrun = grading_info['testruns'][num]
257 testrun = grading_info['testruns'][num]
257 testrun.each do |c|
258 testrun.each do |c|
258 run << read_grading_result(@user.login,
259 run << read_grading_result(@user.login,
259 submission.problem.name,
260 submission.problem.name,
260 submission.id,
261 submission.id,
261 c)
262 c)
262 end
263 end
263 @test_runs << run
264 @test_runs << run
264 end
265 end
265 end
266 end
266 end
267 end
267
268
268 def grading_result_dir(user_name, problem_name, submission_id, case_num)
269 def grading_result_dir(user_name, problem_name, submission_id, case_num)
269 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
270 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
270 end
271 end
271
272
272 def output_filename(user_name, problem_name, submission_id, case_num)
273 def output_filename(user_name, problem_name, submission_id, case_num)
273 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
274 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
274 return "#{dir}/output.txt"
275 return "#{dir}/output.txt"
275 end
276 end
276
277
277 def read_grading_result(user_name, problem_name, submission_id, case_num)
278 def read_grading_result(user_name, problem_name, submission_id, case_num)
278 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
279 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
279 result_file_name = "#{dir}/result"
280 result_file_name = "#{dir}/result"
280 if !FileTest.exists?(result_file_name)
281 if !FileTest.exists?(result_file_name)
281 return {:num => case_num, :msg => 'program did not run'}
282 return {:num => case_num, :msg => 'program did not run'}
282 else
283 else
283 results = File.open(result_file_name).readlines
284 results = File.open(result_file_name).readlines
284 run_stat = extract_running_stat(results)
285 run_stat = extract_running_stat(results)
285 output_filename = "#{dir}/output.txt"
286 output_filename = "#{dir}/output.txt"
286 if FileTest.exists?(output_filename)
287 if FileTest.exists?(output_filename)
287 output_file = true
288 output_file = true
288 output_size = File.size(output_filename)
289 output_size = File.size(output_filename)
289 else
290 else
290 output_file = false
291 output_file = false
291 output_size = 0
292 output_size = 0
292 end
293 end
293
294
294 return {
295 return {
295 :num => case_num,
296 :num => case_num,
296 :msg => results[0],
297 :msg => results[0],
297 :run_stat => run_stat,
298 :run_stat => run_stat,
298 :output => output_file,
299 :output => output_file,
299 :output_size => output_size
300 :output_size => output_size
300 }
301 }
301 end
302 end
302 end
303 end
303
304
304 # copied from grader/script/lib/test_request_helper.rb
305 # copied from grader/script/lib/test_request_helper.rb
305 def extract_running_stat(results)
306 def extract_running_stat(results)
306 running_stat_line = results[-1]
307 running_stat_line = results[-1]
307
308
308 # extract exit status line
309 # extract exit status line
309 run_stat = ""
310 run_stat = ""
310 if !(/[Cc]orrect/.match(results[0]))
311 if !(/[Cc]orrect/.match(results[0]))
311 run_stat = results[0].chomp
312 run_stat = results[0].chomp
312 else
313 else
313 run_stat = 'Program exited normally'
314 run_stat = 'Program exited normally'
314 end
315 end
315
316
316 logger.info "Stat line: #{running_stat_line}"
317 logger.info "Stat line: #{running_stat_line}"
317
318
318 # extract running time
319 # extract running time
319 if res = /r(.*)u(.*)s/.match(running_stat_line)
320 if res = /r(.*)u(.*)s/.match(running_stat_line)
320 seconds = (res[1].to_f + res[2].to_f)
321 seconds = (res[1].to_f + res[2].to_f)
321 time_stat = "Time used: #{seconds} sec."
322 time_stat = "Time used: #{seconds} sec."
322 else
323 else
323 seconds = nil
324 seconds = nil
324 time_stat = "Time used: n/a sec."
325 time_stat = "Time used: n/a sec."
325 end
326 end
326
327
327 # extract memory usage
328 # extract memory usage
328 if res = /s(.*)m/.match(running_stat_line)
329 if res = /s(.*)m/.match(running_stat_line)
329 memory_used = res[1].to_i
330 memory_used = res[1].to_i
330 else
331 else
331 memory_used = -1
332 memory_used = -1
332 end
333 end
333
334
334 return {
335 return {
335 :msg => "#{run_stat}\n#{time_stat}",
336 :msg => "#{run_stat}\n#{time_stat}",
336 :running_time => seconds,
337 :running_time => seconds,
337 :exit_status => run_stat,
338 :exit_status => run_stat,
338 :memory_usage => memory_used
339 :memory_usage => memory_used
339 }
340 }
340 end
341 end
341
342
342 def confirm_and_update_start_time
343 def confirm_and_update_start_time
343 user = User.find(session[:user_id])
344 user = User.find(session[:user_id])
344 if (GraderConfiguration.indv_contest_mode? and
345 if (GraderConfiguration.indv_contest_mode? and
345 GraderConfiguration['contest.confirm_indv_contest_start'] and
346 GraderConfiguration['contest.confirm_indv_contest_start'] and
346 !user.contest_started?)
347 !user.contest_started?)
347 redirect_to :action => 'confirm_contest_start' and return
348 redirect_to :action => 'confirm_contest_start' and return
348 end
349 end
349 if not GraderConfiguration.analysis_mode?
350 if not GraderConfiguration.analysis_mode?
350 user.update_start_time
351 user.update_start_time
351 end
352 end
352 end
353 end
353
354
354 def reject_announcement_refresh_when_logged_out
355 def reject_announcement_refresh_when_logged_out
355 if not session[:user_id]
356 if not session[:user_id]
356 render :text => 'Access forbidden', :status => 403
357 render :text => 'Access forbidden', :status => 403
357 end
358 end
358
359
359 if GraderConfiguration.multicontests?
360 if GraderConfiguration.multicontests?
360 user = User.find(session[:user_id])
361 user = User.find(session[:user_id])
361 if user.contest_stat.forced_logout
362 if user.contest_stat.forced_logout
362 render :text => 'Access forbidden', :status => 403
363 render :text => 'Access forbidden', :status => 403
363 end
364 end
364 end
365 end
365 end
366 end
366
367
367 end
368 end
368
369
@@ -1,11 +1,12
1 %h1= GraderConfiguration['ui.front.title']
1 %h1= GraderConfiguration['ui.front.title']
2
2
3 .row
3 .row
4 .col-md-6
4 .col-md-6
5 - if @announcements.length!=0
5 - if @announcements.length!=0
6 .announcementbox{:style => 'margin-top: 0px'}
6 .announcementbox{:style => 'margin-top: 0px'}
7 %span{:class => 'title'}
7 %span{:class => 'title'}
8 Announcements
8 Announcements
9 = render :partial => 'announcement', :collection => @announcements
9 = render :partial => 'announcement', :collection => @announcements
10 .col-md-4{style: "padding-left: 20px;"}
10 .col-md-4{style: "padding-left: 20px;"}
11 = render :partial => 'login_box'
11 = render :partial => 'login_box'
12 + = "current ip is #{@remote_ip}"
@@ -1,288 +1,288
1 CONFIGURATIONS =
1 CONFIGURATIONS =
2 [
2 [
3 {
3 {
4 :key => 'system.single_user_mode',
4 :key => 'system.single_user_mode',
5 :value_type => 'boolean',
5 :value_type => 'boolean',
6 :default_value => 'false',
6 :default_value => 'false',
7 :description => 'Only admins can log in to the system when running under single user mode.'
7 :description => 'Only admins can log in to the system when running under single user mode.'
8 },
8 },
9
9
10 {
10 {
11 :key => 'ui.front.title',
11 :key => 'ui.front.title',
12 :value_type => 'string',
12 :value_type => 'string',
13 :default_value => 'Grader'
13 :default_value => 'Grader'
14 },
14 },
15
15
16 {
16 {
17 :key => 'ui.front.welcome_message',
17 :key => 'ui.front.welcome_message',
18 :value_type => 'string',
18 :value_type => 'string',
19 :default_value => 'Welcome!'
19 :default_value => 'Welcome!'
20 },
20 },
21
21
22 {
22 {
23 :key => 'ui.show_score',
23 :key => 'ui.show_score',
24 :value_type => 'boolean',
24 :value_type => 'boolean',
25 :default_value => 'true'
25 :default_value => 'true'
26 },
26 },
27
27
28 {
28 {
29 :key => 'contest.time_limit',
29 :key => 'contest.time_limit',
30 :value_type => 'string',
30 :value_type => 'string',
31 :default_value => 'unlimited',
31 :default_value => 'unlimited',
32 :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.'
32 :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.'
33 },
33 },
34
34
35 {
35 {
36 :key => 'system.mode',
36 :key => 'system.mode',
37 :value_type => 'string',
37 :value_type => 'string',
38 :default_value => 'standard',
38 :default_value => 'standard',
39 :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".'
39 :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".'
40 },
40 },
41
41
42 {
42 {
43 :key => 'contest.name',
43 :key => 'contest.name',
44 :value_type => 'string',
44 :value_type => 'string',
45 :default_value => 'Grader',
45 :default_value => 'Grader',
46 :description => 'This name will be shown on the user header bar.'
46 :description => 'This name will be shown on the user header bar.'
47 },
47 },
48
48
49 {
49 {
50 :key => 'contest.multisites',
50 :key => 'contest.multisites',
51 :value_type => 'boolean',
51 :value_type => 'boolean',
52 :default_value => 'false',
52 :default_value => 'false',
53 :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.'
53 :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.'
54 },
54 },
55
55
56 #---------------------------- right --------------------------------
56 #---------------------------- right --------------------------------
57 {
57 {
58 :key => 'right.user_hall_of_fame',
58 :key => 'right.user_hall_of_fame',
59 :value_type => 'boolean',
59 :value_type => 'boolean',
60 :default_value => 'false',
60 :default_value => 'false',
61 :description => 'If true, any user can access hall of fame page.'
61 :description => 'If true, any user can access hall of fame page.'
62 },
62 },
63
63
64 {
64 {
65 :key => 'right.multiple_ip_login',
65 :key => 'right.multiple_ip_login',
66 :value_type => 'boolean',
66 :value_type => 'boolean',
67 :default_value => 'true',
67 :default_value => 'true',
68 :description => 'When change from true to false, a user can login from the first IP they logged into afterward.'
68 :description => 'When change from true to false, a user can login from the first IP they logged into afterward.'
69 },
69 },
70
70
71 {
71 {
72 :key => 'right.user_view_submission',
72 :key => 'right.user_view_submission',
73 :value_type => 'boolean',
73 :value_type => 'boolean',
74 :default_value => 'false',
74 :default_value => 'false',
75 :description => 'If true, any user can view submissions of every one.'
75 :description => 'If true, any user can view submissions of every one.'
76 },
76 },
77
77
78 {
78 {
79 :key => 'right.bypass_agreement',
79 :key => 'right.bypass_agreement',
80 :value_type => 'boolean',
80 :value_type => 'boolean',
81 :default_value => 'true',
81 :default_value => 'true',
82 :description => 'When false, a user must accept usage agreement before login'
82 :description => 'When false, a user must accept usage agreement before login'
83 },
83 },
84
84
85 {
85 {
86 :key => 'right.heartbeat_response',
86 :key => 'right.heartbeat_response',
87 :value_type => 'string',
87 :value_type => 'string',
88 :default_value => 'OK',
88 :default_value => 'OK',
89 :description => 'Heart beat response text'
89 :description => 'Heart beat response text'
90 },
90 },
91
91
92 {
92 {
93 :key => 'right.heartbeat_response_full',
93 :key => 'right.heartbeat_response_full',
94 :value_type => 'string',
94 :value_type => 'string',
95 :default_value => 'OK',
95 :default_value => 'OK',
96 :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)'
96 :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)'
97 },
97 },
98
98
99 {
99 {
100 :key => 'right.view_testcase',
100 :key => 'right.view_testcase',
101 :value_type => 'boolean',
101 :value_type => 'boolean',
102 :default_value => 'false',
102 :default_value => 'false',
103 :description => 'When true, any user can view/download test data'
103 :description => 'When true, any user can view/download test data'
104 },
104 },
105
105
106 {
106 {
107 :key => 'system.online_registration',
107 :key => 'system.online_registration',
108 :value_type => 'boolean',
108 :value_type => 'boolean',
109 :default_value => 'false',
109 :default_value => 'false',
110 :description => 'This option enables online registration.'
110 :description => 'This option enables online registration.'
111 },
111 },
112
112
113 # If Configuration['system.online_registration'] is true, the
113 # If Configuration['system.online_registration'] is true, the
114 # system allows online registration, and will use these
114 # system allows online registration, and will use these
115 # information for sending confirmation emails.
115 # information for sending confirmation emails.
116 {
116 {
117 :key => 'system.online_registration.smtp',
117 :key => 'system.online_registration.smtp',
118 :value_type => 'string',
118 :value_type => 'string',
119 :default_value => 'smtp.somehost.com'
119 :default_value => 'smtp.somehost.com'
120 },
120 },
121
121
122 {
122 {
123 :key => 'system.online_registration.from',
123 :key => 'system.online_registration.from',
124 :value_type => 'string',
124 :value_type => 'string',
125 :default_value => 'your.email@address'
125 :default_value => 'your.email@address'
126 },
126 },
127
127
128 {
128 {
129 :key => 'system.admin_email',
129 :key => 'system.admin_email',
130 :value_type => 'string',
130 :value_type => 'string',
131 :default_value => 'admin@admin.email'
131 :default_value => 'admin@admin.email'
132 },
132 },
133
133
134 {
134 {
135 :key => 'system.user_setting_enabled',
135 :key => 'system.user_setting_enabled',
136 :value_type => 'boolean',
136 :value_type => 'boolean',
137 :default_value => 'true',
137 :default_value => 'true',
138 :description => 'If this option is true, users can change their settings'
138 :description => 'If this option is true, users can change their settings'
139 },
139 },
140
140
141 {
141 {
142 :key => 'system.user_setting_enabled',
142 :key => 'system.user_setting_enabled',
143 :value_type => 'boolean',
143 :value_type => 'boolean',
144 :default_value => 'true',
144 :default_value => 'true',
145 :description => 'If this option is true, users can change their settings'
145 :description => 'If this option is true, users can change their settings'
146 },
146 },
147
147
148 # If Configuration['contest.test_request.early_timeout'] is true
148 # If Configuration['contest.test_request.early_timeout'] is true
149 # the user will not be able to use test request at 30 minutes
149 # the user will not be able to use test request at 30 minutes
150 # before the contest ends.
150 # before the contest ends.
151 {
151 {
152 :key => 'contest.test_request.early_timeout',
152 :key => 'contest.test_request.early_timeout',
153 :value_type => 'boolean',
153 :value_type => 'boolean',
154 :default_value => 'false'
154 :default_value => 'false'
155 },
155 },
156
156
157 {
157 {
158 :key => 'system.multicontests',
158 :key => 'system.multicontests',
159 :value_type => 'boolean',
159 :value_type => 'boolean',
160 :default_value => 'false'
160 :default_value => 'false'
161 },
161 },
162
162
163 {
163 {
164 :key => 'contest.confirm_indv_contest_start',
164 :key => 'contest.confirm_indv_contest_start',
165 :value_type => 'boolean',
165 :value_type => 'boolean',
166 :default_value => 'false'
166 :default_value => 'false'
167 },
167 },
168
168
169 {
169 {
170 :key => 'contest.default_contest_name',
170 :key => 'contest.default_contest_name',
171 :value_type => 'string',
171 :value_type => 'string',
172 :default_value => 'none',
172 :default_value => 'none',
173 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
173 :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest."
174 },
174 },
175
175
176 {
176 {
177 :key => 'system.use_problem_group',
177 :key => 'system.use_problem_group',
178 :value_type => 'boolean',
178 :value_type => 'boolean',
179 :default_value => 'false',
179 :default_value => 'false',
180 :description => "If true, available problem to the user will be only ones associated with the group of the user."
180 :description => "If true, available problem to the user will be only ones associated with the group of the user."
181 },
181 },
182
182
183
183
184 {
184 {
185 :key => 'right.whitelist_ip_only',
185 :key => 'right.whitelist_ip_only',
186 :value_type => 'boolean',
186 :value_type => 'boolean',
187 :default_value => 'false',
187 :default_value => 'false',
188 :description => "If true, non-admin user will be able to use the system only when their ip is in the 'whitelist_ip'."
188 :description => "If true, non-admin user will be able to use the system only when their ip is in the 'whitelist_ip'."
189 },
189 },
190
190
191 {
191 {
192 :key => 'right.whitelist_ip',
192 :key => 'right.whitelist_ip',
193 :value_type => 'string',
193 :value_type => 'string',
194 :default_value => '0.0.0.0/0',
194 :default_value => '0.0.0.0/0',
195 :description => "list of whitelist ip, given in comma separated CIDR notation. For example '161.200.92.0/23, 161.200.80.1/32'"
195 :description => "list of whitelist ip, given in comma separated CIDR notation. For example '161.200.92.0/23, 161.200.80.1/32'"
196 },
196 },
197
197
198 ]
198 ]
199
199
200
200
201 def create_configuration_key(key,
201 def create_configuration_key(key,
202 value_type,
202 value_type,
203 default_value,
203 default_value,
204 description='')
204 description='')
205 conf = (GraderConfiguration.find_by_key(key) ||
205 conf = (GraderConfiguration.find_by_key(key) ||
206 GraderConfiguration.new(:key => key,
206 GraderConfiguration.new(:key => key,
207 :value_type => value_type,
207 :value_type => value_type,
208 :value => default_value))
208 :value => default_value))
209 conf.description = description
209 conf.description = description
210 conf.save
210 conf.save
211 end
211 end
212
212
213 def seed_config
213 def seed_config
214 CONFIGURATIONS.each do |conf|
214 CONFIGURATIONS.each do |conf|
215 if conf.has_key? :description
215 if conf.has_key? :description
216 desc = conf[:description]
216 desc = conf[:description]
217 else
217 else
218 desc = ''
218 desc = ''
219 end
219 end
220 create_configuration_key(conf[:key],
220 create_configuration_key(conf[:key],
221 conf[:value_type],
221 conf[:value_type],
222 conf[:default_value],
222 conf[:default_value],
223 desc)
223 desc)
224 end
224 end
225 end
225 end
226
226
227 def seed_roles
227 def seed_roles
228 return if Role.find_by_name('admin')
228 return if Role.find_by_name('admin')
229
229
230 role = Role.create(:name => 'admin')
230 role = Role.create(:name => 'admin')
231 user_admin_right = Right.create(:name => 'user_admin',
231 user_admin_right = Right.create(:name => 'user_admin',
232 :controller => 'user_admin',
232 :controller => 'user_admin',
233 :action => 'all')
233 :action => 'all')
234 problem_admin_right = Right.create(:name=> 'problem_admin',
234 problem_admin_right = Right.create(:name=> 'problem_admin',
235 :controller => 'problems',
235 :controller => 'problems',
236 :action => 'all')
236 :action => 'all')
237
237
238 graders_right = Right.create(:name => 'graders_admin',
238 graders_right = Right.create(:name => 'graders_admin',
239 :controller => 'graders',
239 :controller => 'graders',
240 :action => 'all')
240 :action => 'all')
241
241
242 role.rights << user_admin_right;
242 role.rights << user_admin_right;
243 role.rights << problem_admin_right;
243 role.rights << problem_admin_right;
244 role.rights << graders_right;
244 role.rights << graders_right;
245 role.save
245 role.save
246 end
246 end
247
247
248 def seed_root
248 def seed_root
249 return if User.find_by_login('root')
249 return if User.find_by_login('root')
250
250
251 root = User.new(:login => 'root',
251 root = User.new(:login => 'root',
252 :full_name => 'Administrator',
252 :full_name => 'Administrator',
253 :alias => 'root')
253 :alias => 'root')
254 root.password = 'ioionrails';
254 root.password = 'ioionrails';
255
255
256 class << root
256 class << root
257 public :encrypt_new_password
257 public :encrypt_new_password
258 def valid?(context=nil)
258 def valid?(context=nil)
259 true
259 true
260 end
260 end
261 end
261 end
262
262
263 root.encrypt_new_password
263 root.encrypt_new_password
264
264
265 root.roles << Role.find_by_name('admin')
265 root.roles << Role.find_by_name('admin')
266
266
267 root.activated = true
267 root.activated = true
268 root.save
268 root.save
269 end
269 end
270
270
271 def seed_users_and_roles
271 def seed_users_and_roles
272 seed_roles
272 seed_roles
273 seed_root
273 seed_root
274 end
274 end
275
275
276 def seed_more_languages
276 def seed_more_languages
277 - Language.delete_all
277 + #Language.delete_all
278 Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
278 Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' )
279 Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
279 Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' )
280 Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
280 Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' )
281 Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
281 Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' )
282 Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
282 Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' )
283 Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
283 Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' )
284 end
284 end
285
285
286 seed_config
286 seed_config
287 seed_users_and_roles
287 seed_users_and_roles
288 seed_more_languages
288 seed_more_languages
You need to be logged in to leave comments. Login now