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
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r131:e25d802c4aec - - 2 files changed: 13 inserted, 5 deleted

@@ -1,34 +1,40
1 class TasksController < ApplicationController
1 class TasksController < ApplicationController
2
2
3 before_filter :authenticate, :check_viewability
3 before_filter :authenticate, :check_viewability
4
4
5 def index
5 def index
6 redirect_to :action => 'list'
6 redirect_to :action => 'list'
7 end
7 end
8
8
9 def list
9 def list
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 - file_name = "#{RAILS_ROOT}/data/tasks/#{params[:file]}"
15 + base_filename = File.basename("#{params[:file]}.#{params[:ext]}")
16 - if !FileTest.exists?(file_name)
16 + filename = "#{RAILS_ROOT}/data/tasks/#{base_filename}"
17 + if !FileTest.exists?(filename)
17 redirect_to :action => 'index' and return
18 redirect_to :action => 'index' and return
18 end
19 end
19 - # ask Apache to send the file
20 + # ask Apache to send the file --- doesn't quite work...
20 - response.headers['X-Sendfile'] = file_name
21 + #response.headers['Content-Type'] = "application/force-download"
21 - render :nothing => true
22 + #response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\""
23 + #response.headers['Content-length'] = File.size(filename)
24 + #response.headers['X-Sendfile'] = filename
25 + #render :nothing => true
26 +
27 + send_file filename, :stream => false, :filename => base_filename
22 end
28 end
23
29
24 protected
30 protected
25
31
26 def check_viewability
32 def check_viewability
27 user = User.find(session[:user_id])
33 user = User.find(session[:user_id])
28 if user==nil or !Configuration.show_tasks_to?(user)
34 if user==nil or !Configuration.show_tasks_to?(user)
29 redirect_to :controller => 'main', :action => 'list'
35 redirect_to :controller => 'main', :action => 'list'
30 return false
36 return false
31 end
37 end
32 end
38 end
33
39
34 end
40 end
@@ -1,26 +1,28
1 ActionController::Routing::Routes.draw do |map|
1 ActionController::Routing::Routes.draw do |map|
2 map.resources :announcements
2 map.resources :announcements
3 map.resources :sites
3 map.resources :sites
4
4
5 # The priority is based upon order of creation: first created -> highest priority.
5 # The priority is based upon order of creation: first created -> highest priority.
6
6
7 # Sample of regular route:
7 # Sample of regular route:
8 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
8 # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
9 # Keep in mind you can assign values other than :controller and :action
9 # Keep in mind you can assign values other than :controller and :action
10
10
11 # Sample of named route:
11 # Sample of named route:
12 # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
12 # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
13 # This route can be invoked with purchase_url(:id => product.id)
13 # This route can be invoked with purchase_url(:id => product.id)
14
14
15 # You can have the root of your site routed by hooking up ''
15 # You can have the root of your site routed by hooking up ''
16 # -- just remember to delete public/index.html.
16 # -- just remember to delete public/index.html.
17 map.connect '', :controller => 'main', :action => 'login'
17 map.connect '', :controller => 'main', :action => 'login'
18
18
19 # Allow downloading Web Service WSDL as a file with an extension
19 # Allow downloading Web Service WSDL as a file with an extension
20 # instead of a file named 'wsdl'
20 # instead of a file named 'wsdl'
21 map.connect ':controller/service.wsdl', :action => 'wsdl'
21 map.connect ':controller/service.wsdl', :action => 'wsdl'
22
22
23 + map.connect 'tasks/view/:file.:ext', :controller => 'tasks', :action => 'view'
24 +
23 # Install the default route as the lowest priority.
25 # Install the default route as the lowest priority.
24 map.connect ':controller/:action/:id.:format'
26 map.connect ':controller/:action/:id.:format'
25 map.connect ':controller/:action/:id'
27 map.connect ':controller/:action/:id'
26 end
28 end
You need to be logged in to leave comments. Login now