Show More
Commit Description:
merge
Commit Description:
merge
References:
File last commit:
Show/Diff file:
Action:
app/controllers/test_controller.rb
| 111 lines
| 2.8 KiB
| text/x-ruby
| RubyLexer
|
|
r44 | class TestController < ApplicationController | ||
r756 | before_action :check_valid_login, :check_viewability | |||
|
r44 | |||
def index | ||||
prepare_index_information | ||||
end | ||||
def submit | ||||
@user = User.find(session[:user_id]) | ||||
|
r85 | |||
|
r86 | @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request]) | ||
|
r341 | if ! @submitted_test_request.errors.empty? | ||
|
r86 | prepare_index_information | ||
render :action => 'index' and return | ||||
|
r85 | end | ||
|
r320 | if GraderConfiguration.time_limit_mode? | ||
|
r217 | if @user.contest_finished? | ||
r347 | @submitted_test_request.errors.add(:base,'Contest is over.') | |||
|
r128 | prepare_index_information | ||
render :action => 'index' and return | ||||
end | ||||
|
r320 | if !GraderConfiguration.allow_test_request(@user) | ||
|
r128 | prepare_index_information | ||
flash[:notice] = 'Test request is not allowed during the last 30 minutes' | ||||
redirect_to :action => 'index' and return | ||||
end | ||||
|
r86 | end | ||
if @submitted_test_request.save | ||||
|
r44 | redirect_to :action => 'index' | ||
else | ||||
|
r86 | prepare_index_information | ||
render :action => 'index' | ||||
|
r44 | end | ||
end | ||||
def read | ||||
user = User.find(session[:user_id]) | ||||
|
r79 | begin | ||
test_request = TestRequest.find(params[:id]) | ||||
rescue | ||||
test_request = nil | ||||
end | ||||
if test_request==nil or test_request.user_id != user.id | ||||
|
r44 | flash[:notice] = 'Invalid output' | ||
redirect_to :action => 'index' | ||||
return | ||||
end | ||||
if test_request.output_file_name!=nil | ||||
data = File.open(test_request.output_file_name).read(2048) | ||||
|
r49 | if data==nil | ||
data="" | ||||
end | ||||
|
r44 | send_data(data, | ||
{:filename => 'output.txt', | ||||
:type => 'text/plain'}) | ||||
return | ||||
end | ||||
redirect_to :action => 'index' | ||||
end | ||||
|
r79 | |||
def result | ||||
@user = User.find(session[:user_id]) | ||||
begin | ||||
@test_request = TestRequest.find(params[:id]) | ||||
rescue | ||||
@test_request = nil | ||||
end | ||||
if @test_request==nil or @test_request.user_id != @user.id | ||||
flash[:notice] = 'Invalid request' | ||||
redirect_to :action => 'index' | ||||
return | ||||
end | ||||
end | ||||
|
r44 | |||
protected | ||||
def prepare_index_information | ||||
|
r86 | @user = User.find(session[:user_id]) | ||
|
r44 | @submissions = Submission.find_last_for_all_available_problems(@user.id) | ||
|
r94 | all_problems = @submissions.collect { |submission| submission.problem } | ||
@problems = [] | ||||
all_problems.each do |problem| | ||||
if problem.test_allowed | ||||
@problems << problem | ||||
end | ||||
end | ||||
|
r162 | @test_requests = [] | ||
@user.test_requests.each do |ts| | ||||
|
r205 | if ts.problem and ts.problem.available | ||
|
r162 | @test_requests << ts | ||
end | ||||
end | ||||
|
r44 | end | ||
|
r122 | def check_viewability | ||
user = User.find(session[:user_id]) | ||||
|
r320 | if !GraderConfiguration.show_tasks_to?(user) | ||
|
r122 | redirect_to :controller => 'main', :action => 'list' | ||
end | ||||
|
r320 | if (!GraderConfiguration.show_submitbox_to?(user)) and (action_name=='submit') | ||
|
r122 | redirect_to :controller => 'test', :action => 'index' | ||
end | ||||
end | ||||
|
r44 | end | ||