Description:
returns correct content type for task description download
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r273:0e765be64abb - - 1 file changed: 7 inserted, 1 deleted
@@ -10,45 +10,51 | |||||
|
10 | @problems = Problem.find_available_problems |
|
10 | @problems = Problem.find_available_problems |
|
11 | @user = User.find(session[:user_id]) |
|
11 | @user = User.find(session[:user_id]) |
|
12 | end |
|
12 | end |
|
13 |
|
13 | ||
|
14 | def view |
|
14 | def view |
|
15 | base_name = params[:file] |
|
15 | base_name = params[:file] |
|
16 | if !check_user_viewability(base_name) |
|
16 | if !check_user_viewability(base_name) |
|
17 | redirect_to :action => 'index' and return |
|
17 | redirect_to :action => 'index' and return |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
20 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
20 | base_filename = File.basename("#{base_name}.#{params[:ext]}") |
|
21 | filename = "#{Problem.download_file_basedir}/#{base_filename}" |
|
21 | filename = "#{Problem.download_file_basedir}/#{base_filename}" |
|
22 |
|
22 | ||
|
23 | if !check_user_viewability(base_name) or !FileTest.exists?(filename) |
|
23 | if !check_user_viewability(base_name) or !FileTest.exists?(filename) |
|
24 | redirect_to :action => 'index' and return |
|
24 | redirect_to :action => 'index' and return |
|
25 | end |
|
25 | end |
|
26 |
|
26 | ||
|
27 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
27 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
28 | response.headers['Content-Type'] = "application/force-download" |
|
28 | response.headers['Content-Type'] = "application/force-download" |
|
29 | response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" |
|
29 | response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" |
|
30 | response.headers["X-Sendfile"] = filename |
|
30 | response.headers["X-Sendfile"] = filename |
|
31 | response.headers['Content-length'] = File.size(filename) |
|
31 | response.headers['Content-length'] = File.size(filename) |
|
32 | render :nothing => true |
|
32 | render :nothing => true |
|
33 | else |
|
33 | else |
|
34 | - send_file filename, :stream => false, :filename => base_filename |
|
34 | + if params[:ext]=='pdf' |
|
|
35 | + content_type = 'application/pdf' | ||
|
|
36 | + else | ||
|
|
37 | + content_type = 'application/octet-stream' | ||
|
|
38 | + end | ||
|
|
39 | + | ||
|
|
40 | + send_file filename, :stream => false, :filename => base_filename, :type => content_type | ||
|
35 | end |
|
41 | end |
|
36 | end |
|
42 | end |
|
37 |
|
43 | ||
|
38 | protected |
|
44 | protected |
|
39 |
|
45 | ||
|
40 | def check_viewability |
|
46 | def check_viewability |
|
41 | @user = User.find(session[:user_id]) |
|
47 | @user = User.find(session[:user_id]) |
|
42 | if @user==nil or !Configuration.show_tasks_to?(@user) |
|
48 | if @user==nil or !Configuration.show_tasks_to?(@user) |
|
43 | redirect_to :controller => 'main', :action => 'list' |
|
49 | redirect_to :controller => 'main', :action => 'list' |
|
44 | return false |
|
50 | return false |
|
45 | end |
|
51 | end |
|
46 | end |
|
52 | end |
|
47 |
|
53 | ||
|
48 | def check_user_viewability(filename) |
|
54 | def check_user_viewability(filename) |
|
49 | # individual file access control shall be added here |
|
55 | # individual file access control shall be added here |
|
50 | return false if not @user |
|
56 | return false if not @user |
|
51 | return Configuration.show_tasks_to?(@user) |
|
57 | return Configuration.show_tasks_to?(@user) |
|
52 | end |
|
58 | end |
|
53 |
|
59 | ||
|
54 | end |
|
60 | end |
You need to be logged in to leave comments.
Login now