diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb --- a/app/controllers/test_controller.rb +++ b/app/controllers/test_controller.rb @@ -2,7 +2,7 @@ before_filter :authenticate - verify :method => :post, :only => [:test_submit], + verify :method => :post, :only => [:submit], :redirect_to => { :action => :index } def index @@ -24,8 +24,12 @@ def read user = User.find(session[:user_id]) - test_request = TestRequest.find(params[:id]) - if test_request.user_id != 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 output' redirect_to :action => 'index' return @@ -42,6 +46,20 @@ end redirect_to :action => 'index' end + + 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 protected diff --git a/app/helpers/test_helper.rb b/app/helpers/test_helper.rb --- a/app/helpers/test_helper.rb +++ b/app/helpers/test_helper.rb @@ -1,2 +1,11 @@ module TestHelper + + def read_textfile(fname,max_size=2048) + begin + File.open(fname).read(max_size) + rescue + nil + end + end + end diff --git a/app/views/test/_test_request.html.haml b/app/views/test/_test_request.html.haml --- a/app/views/test/_test_request.html.haml +++ b/app/views/test/_test_request.html.haml @@ -12,3 +12,4 @@ = link_to '[output]', :action => 'read', :id => test_request.id %td= test_request.grader_comment or '' %td= simple_format((test_request.compiler_message or '')) + %td= link_to '[view]', :action => 'result', :id => test_request.id diff --git a/app/views/test/index.html.erb b/app/views/test/index.html.erb --- a/app/views/test/index.html.erb +++ b/app/views/test/index.html.erb @@ -74,6 +74,7 @@