Show More
Commit Description:
[web] fixed tasks viewing, changed routes for it...
Commit Description:
[web] fixed tasks viewing, changed routes for it
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@261 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
app/controllers/tasks_controller.rb
| 40 lines
| 1.1 KiB
| text/x-ruby
| RubyLexer
|
|
r88 | class TasksController < ApplicationController | ||
|
r122 | before_filter :authenticate, :check_viewability | ||
|
r88 | |||
def index | ||||
redirect_to :action => 'list' | ||||
end | ||||
def list | ||||
@problems = Problem.find_available_problems | ||||
@user = User.find(session[:user_id]) | ||||
end | ||||
|
r130 | def view | ||
|
r131 | base_filename = File.basename("#{params[:file]}.#{params[:ext]}") | ||
filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}" | ||||
if !FileTest.exists?(filename) | ||||
|
r130 | redirect_to :action => 'index' and return | ||
end | ||||
|
r131 | # ask Apache to send the file --- doesn't quite work... | ||
#response.headers['Content-Type'] = "application/force-download" | ||||
#response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" | ||||
#response.headers['Content-length'] = File.size(filename) | ||||
#response.headers['X-Sendfile'] = filename | ||||
#render :nothing => true | ||||
send_file filename, :stream => false, :filename => base_filename | ||||
|
r130 | end | ||
|
r122 | protected | ||
def check_viewability | ||||
user = User.find(session[:user_id]) | ||||
if user==nil or !Configuration.show_tasks_to?(user) | ||||
redirect_to :controller => 'main', :action => 'list' | ||||
return false | ||||
end | ||||
end | ||||
|
r88 | end | ||