Show More
Commit Description:
fixed seed script
Commit Description:
fixed seed script
References:
File last commit:
Show/Diff file:
Action:
app/controllers/tasks_controller.rb
| 54 lines
| 1.5 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 | ||
|
r271 | base_name = params[:file] | ||
if !check_user_viewability(base_name) | ||||
redirect_to :action => 'index' and return | ||||
end | ||||
base_filename = File.basename("#{base_name}.#{params[:ext]}") | ||||
filename = "#{Problem.download_file_basedir}/#{base_filename}" | ||||
if !check_user_viewability(base_name) or !FileTest.exists?(filename) | ||||
|
r130 | redirect_to :action => 'index' and return | ||
end | ||||
|
r133 | |||
|
r172 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE | ||
response.headers['Content-Type'] = "application/force-download" | ||||
response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" | ||||
response.headers["X-Sendfile"] = filename | ||||
response.headers['Content-length'] = File.size(filename) | ||||
render :nothing => true | ||||
else | ||||
send_file filename, :stream => false, :filename => base_filename | ||||
end | ||||
|
r130 | end | ||
|
r122 | protected | ||
def check_viewability | ||||
|
r271 | @user = User.find(session[:user_id]) | ||
if @user==nil or !Configuration.show_tasks_to?(@user) | ||||
|
r122 | redirect_to :controller => 'main', :action => 'list' | ||
return false | ||||
end | ||||
end | ||||
|
r271 | def check_user_viewability(filename) | ||
# individual file access control shall be added here | ||||
return false if not @user | ||||
return Configuration.show_tasks_to?(@user) | ||||
end | ||||
|
r88 | end | ||