diff options
author | francis <francis> | 2008-10-28 17:58:47 +0000 |
---|---|---|
committer | francis <francis> | 2008-10-28 17:58:47 +0000 |
commit | fd61d6e1c05f60e472910a70dfe3ac103f99db97 (patch) | |
tree | 3a84bcb0de73708b8a347bce7558b61149519381 | |
parent | 378d4cee4e8bfb093d882c292ddd25511c23184a (diff) |
Cache HTML versions of attachments
-rw-r--r-- | app/controllers/admin_censor_rule_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 11 | ||||
-rw-r--r-- | app/views/request/_view_html_prefix.rhtml | 9 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | todo.txt | 1 |
5 files changed, 21 insertions, 17 deletions
diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb index 82e6f5e68..26642d8e6 100644 --- a/app/controllers/admin_censor_rule_controller.rb +++ b/app/controllers/admin_censor_rule_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: admin_censor_rule_controller.rb,v 1.2 2008-10-28 13:03:52 francis Exp $ +# $Id: admin_censor_rule_controller.rb,v 1.3 2008-10-28 17:58:48 francis Exp $ class AdminCensorRuleController < ApplicationController layout "admin" @@ -70,6 +70,17 @@ class AdminCensorRuleController < ApplicationController expire_page :controller => 'request', :action => "get_attachment", :id => info_request.id, :incoming_message_id => incoming_message.id, :part => attachment.url_part_number, :file_name => attachment.display_filename + expire_page :controller => 'request', :action => "get_attachment_as_html", :id => info_request.id, + :incoming_message_id => incoming_message.id, + :part => attachment.url_part_number, :file_name => attachment.display_filename + end + end + end + + private + +end + end end end diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index bb0d7f9bd..6b9ad780b 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: request_controller.rb,v 1.130 2008-10-27 18:18:30 francis Exp $ +# $Id: request_controller.rb,v 1.131 2008-10-28 17:58:48 francis Exp $ class RequestController < ApplicationController @@ -402,14 +402,11 @@ class RequestController < ApplicationController render :text => @attachment.body end + caches_page :get_attachment_as_html def get_attachment_as_html get_attachment_internal html = @attachment.body_as_html - # Mask any more emails that have now been exposed (e.g. in PDFs - ones in - # .doc will have been got in get_attachment_internal below) - html = @incoming_message.binary_mask_stuff(html) - view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet" html.sub!(/<head>/i, "<head>" + view_html_stylesheet) html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="wrapper"><div id="view_html_content">' + view_html_stylesheet) @@ -437,6 +434,10 @@ class RequestController < ApplicationController # Prevent spam to magic request address. # XXX Bit dodgy modifying a binary like this but hey. Maybe only do for some mime types? @attachment.body = @incoming_message.binary_mask_stuff(@attachment.body) + + @attachment_url = get_attachment_url(:id => @incoming_message.info_request_id, + :incoming_message_id => @incoming_message.id, :part => @part_number, + :file_name => @filename ) end # FOI officers can upload a response diff --git a/app/views/request/_view_html_prefix.rhtml b/app/views/request/_view_html_prefix.rhtml index ac620ffb9..f62291725 100644 --- a/app/views/request/_view_html_prefix.rhtml +++ b/app/views/request/_view_html_prefix.rhtml @@ -1,13 +1,6 @@ -<% - attachment_url = get_attachment_url(:id => @incoming_message.info_request_id, - :incoming_message_id => @incoming_message.id, :part => @part_number, - :file_name => @filename ) - -%> - <div class="view_html_prefix"> <div class="view_html_download_link"> - <%=link_to "Download original attachment", attachment_url %> + <%=link_to "Download original attachment", @attachment_url %> </div> Attachment to FOI request '<%=link_to h(@info_request.title), incoming_message_url(@incoming_message)%>' (HTML version) </div> diff --git a/config/routes.rb b/config/routes.rb index 1f70bee8e..b4f3e3a62 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,7 +4,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: routes.rb,v 1.77 2008-10-27 18:18:31 francis Exp $ +# $Id: routes.rb,v 1.78 2008-10-28 17:58:48 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -39,7 +39,7 @@ ActionController::Routing::Routes.draw do |map| request.describe_state '/request/:id/describe', :action => 'describe_state' request.show_response_no_followup '/request/:id/response', :action => 'show_response' request.show_response '/request/:id/response/:incoming_message_id', :action => 'show_response' - request.get_attachment_as_html '/request/:id/response/:incoming_message_id/attach/html/:part/*file_name', :action => 'get_attachment_as_html' + request.get_attachment_as_html '/request/:id/response/:incoming_message_id/attach/html/:part/*file_name.html', :action => 'get_attachment_as_html' request.get_attachment '/request/:id/response/:incoming_message_id/attach/:part/*file_name', :action => 'get_attachment' request.info_request_event '/request_event/:info_request_event_id', :action => 'show_request_event' @@ -47,7 +47,6 @@ http://www.whatdotheyknow.com/request/monitoring_of_foi_internal_revie Awaiting internal review overdue? -Make HTML load read from cache file if present Do something about <title> of views Knackered view as HTML: http://www.whatdotheyknow.com/request/statistics_for_allocation_of_dut#incoming-4793 |