diff options
-rw-r--r-- | app/controllers/request_controller.rb | 41 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 4 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 33 | ||||
-rw-r--r-- | app/views/request/_bubble.rhtml | 13 | ||||
-rw-r--r-- | app/views/request/_view_html_prefix.rhtml | 14 | ||||
-rw-r--r-- | app/views/request/_view_html_stylesheet.rhtml | 1 | ||||
-rw-r--r-- | config/routes.rb | 3 | ||||
-rw-r--r-- | public/stylesheets/main.css | 17 | ||||
-rw-r--r-- | todo.txt | 6 |
9 files changed, 113 insertions, 19 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 0a195e30a..2789fed97 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.123 2008-10-17 16:51:40 francis Exp $ +# $Id: request_controller.rb,v 1.124 2008-10-17 20:32:42 francis Exp $ class RequestController < ApplicationController @@ -391,24 +391,51 @@ class RequestController < ApplicationController # Download an attachment caches_page :get_attachment def get_attachment + get_attachment_internal + + response.content_type = 'application/octet-stream' + if !@attachment.content_type.nil? + response.content_type = @attachment.content_type + end + render :text => @attachment.body + end + + def get_attachment_as_html + get_attachment_internal + html = @attachment.body_as_html + + view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet" + html.sub!("<head>", "<head>" + view_html_stylesheet) + + view_html_prefix = render_to_string :partial => "request/view_html_prefix" + html.sub!("<!--Section Begins-->", view_html_prefix + "<!--Section Begins-->") + + html.sub!("<!--Section Begins-->", '<!--Section Begins--><div class="view_html_content">') + html.sub!("<!--Section Ends->", '</div><!--Section Begins-->') + + # 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 = IncomingMessage.binary_mask_all_emails(html) + + response.content_type = 'text/html' + render :text => html + end + + # Internal function + def get_attachment_internal @incoming_message = IncomingMessage.find(params[:incoming_message_id]) @info_request = @incoming_message.info_request if @incoming_message.info_request_id != params[:id].to_i raise sprintf("Incoming message %d does not belong to request %d", @incoming_message.info_request_id, params[:id]) end @part_number = params[:part].to_i + @filename = params[:file_name] @attachment = IncomingMessage.get_attachment_by_url_part_number(@incoming_message.get_attachments_for_display, @part_number) # 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 = IncomingMessage.binary_mask_all_emails(@attachment.body) - - response.content_type = 'application/octet-stream' - if !@attachment.content_type.nil? - response.content_type = @attachment.content_type - end - render :text => @attachment.body end # FOI officers can upload a response diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index e8be14162..d64ce253d 100644 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -5,12 +5,12 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: link_to_helper.rb,v 1.44 2008-10-03 17:09:06 francis Exp $ +# $Id: link_to_helper.rb,v 1.45 2008-10-17 20:32:42 francis Exp $ module LinkToHelper # Links to various models - + # Requests def request_url(info_request) return show_request_url(:url_title => info_request.url_title, :only_path => true) diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 0b01f18d1..f76479f65 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.152 2008-10-17 07:02:01 francis Exp $ +# $Id: incoming_message.rb,v 1.153 2008-10-17 20:32:42 francis Exp $ # TODO # Move some of the (e.g. quoting) functions here into rblib, as they feel @@ -161,6 +161,37 @@ class FOIAttachment return (s / 1024).to_s + 'K' end end + + def body_as_html + tempfile = Tempfile.new('foiextract') + tempfile.print body + tempfile.flush + + if content_type == 'application/vnd.ms-word' + # XXX do something with PNG files this spits out so they view too :) + system("/usr/bin/wvHtml " + tempfile.path + " " + tempfile.path + ".html") + html = File.read(tempfile.path + ".html") + File.unlink(tempfile.path + ".html") +# elsif content_type == 'application/pdf' +# IO.popen("/usr/bin/pdftohtml " + tempfile.path + " -", "r") do |child| +# html = child.read() + "\n\n" +# end + else + raise "No HTML conversion available for type " + content_type + end + + tempfile.close + return html + end + + def has_body_as_html? + if content_type == 'application/vnd.ms-word' + return true +# elsif content_type == 'application/pdf' +# return true + end + return false + end end class IncomingMessage < ActiveRecord::Base diff --git a/app/views/request/_bubble.rhtml b/app/views/request/_bubble.rhtml index 4787fcdcd..438925d51 100644 --- a/app/views/request/_bubble.rhtml +++ b/app/views/request/_bubble.rhtml @@ -4,8 +4,14 @@ <hr class="top"> <% attachments.each do |a| %> <p class="attachment"> - <% attachment_url = get_attachment_url(:id => incoming_message.info_request_id, - :incoming_message_id => incoming_message.id, :part => a.url_part_number, :file_name => a.display_filename) %> + <% + attachment_url = get_attachment_url(:id => incoming_message.info_request_id, + :incoming_message_id => incoming_message.id, :part => a.url_part_number, + :file_name => a.display_filename) + attachment_as_html_url = get_attachment_as_html_url(:id => incoming_message.info_request_id, + :incoming_message_id => incoming_message.id, :part => a.url_part_number, + :file_name => a.display_filename) + %> <% img_filename = "icon_" + a.content_type.sub('/', '_') + "_large.png" full_filename = File.join(File.dirname(__FILE__), "../../../public/images", img_filename) if File.exist?(full_filename) %> @@ -18,6 +24,9 @@ <br> <%= a.display_size %> <%= link_to "Download", attachment_url %> + <% if a.has_body_as_html? %> + <%= link_to "View as HTML", attachment_as_html_url %> + <% end %> <!-- (<%= a.content_type %>) --> </p> <% end %> diff --git a/app/views/request/_view_html_prefix.rhtml b/app/views/request/_view_html_prefix.rhtml new file mode 100644 index 000000000..ac620ffb9 --- /dev/null +++ b/app/views/request/_view_html_prefix.rhtml @@ -0,0 +1,14 @@ +<% + 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 %> + </div> + Attachment to FOI request '<%=link_to h(@info_request.title), incoming_message_url(@incoming_message)%>' (HTML version) +</div> + diff --git a/app/views/request/_view_html_stylesheet.rhtml b/app/views/request/_view_html_stylesheet.rhtml new file mode 100644 index 000000000..d6cb932a8 --- /dev/null +++ b/app/views/request/_view_html_stylesheet.rhtml @@ -0,0 +1 @@ +<%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet" %> diff --git a/config/routes.rb b/config/routes.rb index edda39af1..6d27b2dd7 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.75 2008-10-17 11:38:00 francis Exp $ +# $Id: routes.rb,v 1.76 2008-10-17 20:32:43 francis Exp $ ActionController::Routing::Routes.draw do |map| @@ -39,6 +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 '/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' diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index 223581025..5d84e2427 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -724,6 +724,23 @@ a img.attachment_image { #followup { clear: both; float: left; } +/*------------------------------------------------ view attachment as HTML */ + +.view_html_content { + margin-left: 1em; + margin-right: 1em; +} + +.view_html_download_link { + float: right; +} +.view_html_prefix { + text-align: left; + background-color: #E7E7E7; + border-bottom: 1px solid #5f5f5f; + padding: 0.5em 1em 0.5em 1em; +} + /*------------------------------------------------ authority listings */ #body_sidebar { font-size: 0.85em; @@ -3,10 +3,6 @@ Test data for Tony Next ==== -Make it so signin link from being emailed that you have new response -goes to the # link on main page rather than the describe page that -needs login - Performance: Remove loading of public body tags from every info request load Completed in 15.53564 (0 reqs/sec) | Rendering: 1.03024 (6%) | DB: 14.46186 (93%) | 200 OK [http://www.whatdotheyknow.com/body/list/n] @@ -35,9 +31,7 @@ link on page when it is late? Clear out all the need admin attention requests -Merge workflow into one stream - find information, if you can't find it then request it. Show similar requests after you have filed yours - maybe on preview too. -Fit google search and website search better into flow somehow, but how :( Add "I have a large file" to FOI office FAQ Add "Who should I make my request to?" |