diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 7 | ||||
-rw-r--r-- | app/controllers/services_controller.rb | 20 | ||||
-rw-r--r-- | app/models/foi_attachment.rb | 23 | ||||
m--------- | commonlib | 0 | ||||
-rw-r--r-- | config/httpd.conf | 13 | ||||
l--------- | public/views_cache | 1 | ||||
-rwxr-xr-x | script/load-exim-logs | 5 | ||||
-rw-r--r-- | spec/controllers/services_controller_spec.rb | 14 |
9 files changed, 65 insertions, 20 deletions
@@ -1,5 +1,5 @@ # Work around bug in Debian Squeeze - see https://github.com/sebbacon/alaveteli/pull/297#issuecomment-4101012 -if File.exist? "/etc/debian_version" and File.open("/etc/debian_version").read.strip =~ /^6\.0\.[45]$/ +if File.exist? "/etc/debian_version" and File.open("/etc/debian_version").read.strip =~ /^(squeeze|6\.0\.[45])$/ if File.exist? "/lib/libuuid.so.1" require 'dl' DL::dlopen('/lib/libuuid.so.1') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 11f21025c..a124743b2 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -134,6 +134,10 @@ class ApplicationController < ActionController::Base # Make sure expiry time for session is set (before_filters are # otherwise missed by this override) session_remember_me + + # Make sure the locale is set correctly too + set_gettext_locale + case exception when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError @status = 404 @@ -157,6 +161,9 @@ class ApplicationController < ActionController::Base # otherwise missed by this override) session_remember_me + # Make sure the locale is set correctly too + set_gettext_locale + # Display default, detailed error for developers original_rescue_action_locally(exception) end diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 00c0e61bd..8fa860fb2 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -9,15 +9,19 @@ class ServicesController < ApplicationController if country_from_ip.downcase != iso_country_code found_country = WorldFOIWebsites.by_code(country_from_ip) found_country_name = !found_country.nil? && found_country[:country_name] - old_locale = FastGettext.locale - FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE']) - if found_country_name - text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") - else - current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name] - text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country) + + old_fgt_locale = FastGettext.locale + begin + FastGettext.locale = FastGettext.best_locale_in(request.env['HTTP_ACCEPT_LANGUAGE']) + if found_country_name + text = _("Hello! You can make Freedom of Information requests within {{country_name}} at {{link_to_website}}", :country_name => found_country_name, :link_to_website => "<a href=\"#{found_country[:url]}\">#{found_country[:name]}</a>") + else + current_country = WorldFOIWebsites.by_code(iso_country_code)[:country_name] + text = _("Hello! We have an <a href=\"/help/alaveteli?country_name=#{CGI.escape(current_country)}\">important message</a> for visitors outside {{country_name}}", :country_name => current_country) + end + ensure + FastGettext.locale = old_fgt_locale end - FastGettext.locale = old_locale end if !text.empty? text += ' <span class="close-button">X</span>' diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 9bbf0988f..a40898aef 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -1,3 +1,5 @@ +# encoding: UTF-8 + # == Schema Information # Schema version: 114 # @@ -14,8 +16,6 @@ # hexdigest :string(32) # -# encoding: UTF-8 - # models/foi_attachment.rb: # An attachment to an email (IncomingMessage) # @@ -315,14 +315,21 @@ class FoiAttachment < ActiveRecord::Base tempfile.print self.body tempfile.flush + html = nil if self.content_type == 'application/pdf' - html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path) + # We set a timeout here, because pdftohtml can spiral out of control + # on some PDF files and we don’t want to crash the whole server. + html = AlaveteliExternalCommand.run("pdftohtml", "-nodrm", "-zoom", "1.0", "-stdout", "-enc", "UTF-8", "-noframes", tempfile.path, :timeout => 30) elsif self.content_type == 'application/rtf' - html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path) - elsif self.has_google_docs_viewer? - html = '' # force error and using Google docs viewer - else - raise "No HTML conversion available for type " + self.content_type + html = AlaveteliExternalCommand.run("unrtf", "--html", tempfile.path, :timeout => 120) + end + + if html.nil? + if self.has_google_docs_viewer? + html = '' # force error and using Google docs viewer + else + raise "No HTML conversion available for type " + self.content_type + end end tempfile.close diff --git a/commonlib b/commonlib -Subproject 9e1d29721b9dba232c251ef4b8b79f8505422de +Subproject 131375c752c02aa20f1644240fe69720275da42 diff --git a/config/httpd.conf b/config/httpd.conf index 3bbe50fb3..6428a2006 100644 --- a/config/httpd.conf +++ b/config/httpd.conf @@ -32,6 +32,19 @@ RequestHeader add X-Forwarded-User %{RU}e # files for archiving. RewriteRule /files/(.+) http://files.whatdotheyknow.com/$1 +# Serve attachments directly from the cache, if possible. +# +# The file names are URL-encoded on disk, and sharded by the first +# three digits of the request id, which is why this is as complicated +# as it is. The RewriteMap directive makes the URL-escaping function +# available to use in the other directives. +# +# The condition means that the rule will fire only if the cached +# file exists. +RewriteMap escape int:escape +RewriteCond %{DOCUMENT_ROOT}/views_cache/request/$2/$1/${escape:$3} -f +RewriteRule ^/request/((\d{1,3})\d*)/(response/\d+/attach/\d+/.+) /views_cache/request/$2/$1/${escape:$3} [L] + <IfModule mod_passenger.c> # Set this to something like 100 if you have memory leak issues PassengerMaxRequests 20 diff --git a/public/views_cache b/public/views_cache new file mode 120000 index 000000000..ea65934d2 --- /dev/null +++ b/public/views_cache @@ -0,0 +1 @@ +../cache/views
\ No newline at end of file diff --git a/script/load-exim-logs b/script/load-exim-logs index 5ca0c66f8..00b6b9825 100755 --- a/script/load-exim-logs +++ b/script/load-exim-logs @@ -5,7 +5,10 @@ LOC=`dirname "$0"` # Specific file if specified if [ x$1 != x ] then - f=`abspath "$1"` + case "$1" in + /*) f=$1 ;; + *) f=$(pwd)/$1 ;; + esac cd "$LOC" bundle exec ./runner 'EximLog.load_file("'$f'")' exit diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 2be382258..a701ae247 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -2,8 +2,15 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe ServicesController, "when using web services" do + integrate_views - + + # store and restore the locale in the context of the test suite to isolate + # changes made in these tests + before do + @old_locale = FastGettext.locale() + end + it "should show no alaveteli message when in the deployed country" do config = MySociety::Config.load_default() config['ISO_COUNTRY_CODE'] = "DE" @@ -29,5 +36,8 @@ describe ServicesController, "when using web services" do response.body.should match(/Puede hacer solicitudes de información en España/) end + after do + FastGettext.set_locale(@old_locale) + end -end +end
\ No newline at end of file |