Show More
Commit Description:
add more error message to user list upgrade. Fix #9
Commit Description:
add more error message to user list upgrade. Fix #9
References:
File last commit:
Show/Diff file:
Action:
app/controllers/tasks_controller.rb
| 74 lines
| 2.1 KiB
| text/x-ruby
| RubyLexer
|
|
r88 | class TasksController < ApplicationController | ||
r756 | before_action :check_valid_login, :check_viewability | |||
|
r88 | |||
def index | ||||
redirect_to :action => 'list' | ||||
end | ||||
def list | ||||
|
r288 | @problems = @user.available_problems | ||
|
r88 | end | ||
|
r282 | # this has contest-wide access control | ||
|
r130 | def view | ||
|
r271 | base_name = params[:file] | ||
|
r282 | base_filename = File.basename("#{base_name}.#{params[:ext]}") | ||
filename = "#{Problem.download_file_basedir}/#{base_filename}" | ||||
if !FileTest.exists?(filename) | ||||
|
r271 | redirect_to :action => 'index' and return | ||
end | ||||
|
r282 | send_file_to_user(filename, base_filename) | ||
end | ||||
|
r271 | |||
|
r282 | # this has problem-level access control | ||
def download | ||||
problem = Problem.find(params[:id]) | ||||
r680 | unless @current_user.can_view_problem? problem | |||
r762 | flash[:notice] = 'You are not authorized to access this file' | |||
|
r130 | redirect_to :action => 'index' and return | ||
end | ||||
|
r133 | |||
|
r282 | base_name = params[:file] | ||
base_filename = File.basename("#{base_name}.#{params[:ext]}") | ||||
filename = "#{Problem.download_file_basedir}/#{params[:id]}/#{base_filename}" | ||||
if !FileTest.exists?(filename) | ||||
r762 | flash[:notice] = 'File does not exists' | |||
|
r282 | redirect_to :action => 'index' and return | ||
end | ||||
send_file_to_user(filename, base_filename) | ||||
end | ||||
protected | ||||
def send_file_to_user(filename, base_filename) | ||||
|
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 | ||||
|
r273 | if params[:ext]=='pdf' | ||
content_type = 'application/pdf' | ||||
else | ||||
content_type = 'application/octet-stream' | ||||
end | ||||
r367 | send_file filename, :stream => false, :disposition => 'inline', :filename => base_filename, :type => content_type | |||
|
r172 | end | ||
|
r130 | end | ||
|
r122 | def check_viewability | ||
|
r271 | @user = User.find(session[:user_id]) | ||
|
r320 | if @user==nil or !GraderConfiguration.show_tasks_to?(@user) | ||
|
r122 | redirect_to :controller => 'main', :action => 'list' | ||
return false | ||||
end | ||||
end | ||||
|
r88 | end | ||