diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/admin_controller.rb | 1 | ||||
-rw-r--r-- | app/controllers/public_body_controller.rb | 12 | ||||
-rw-r--r-- | app/controllers/request_controller.rb | 2 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 34 | ||||
-rw-r--r-- | app/models/info_request.rb | 20 | ||||
-rw-r--r-- | app/models/public_body.rb | 48 | ||||
-rw-r--r-- | app/views/layouts/default.rhtml | 6 | ||||
-rw-r--r-- | app/views/user/bad_token.rhtml | 2 |
8 files changed, 63 insertions, 62 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 0bfbcd3d1..adb506b91 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -53,6 +53,7 @@ class AdminController < ApplicationController authenticate_or_request_with_http_basic do |user_name, password| if user_name == config_username && password == config_password session[:using_admin] = 1 + request.env['REMOTE_USER'] = user_name else request_http_basic_authentication end diff --git a/app/controllers/public_body_controller.rb b/app/controllers/public_body_controller.rb index 251ab5efe..ff9fbadb3 100644 --- a/app/controllers/public_body_controller.rb +++ b/app/controllers/public_body_controller.rb @@ -91,31 +91,31 @@ class PublicBodyController < ApplicationController @query = "%#{params[:public_body_query].nil? ? "" : params[:public_body_query]}%" @tag = params[:tag] @locale = self.locale_from_params() - + default_locale = I18n.default_locale.to_s locale_condition = "(upper(public_body_translations.name) LIKE upper(?) OR upper(public_body_translations.notes) LIKE upper (?)) AND public_body_translations.locale = ? AND public_bodies.id <> #{PublicBody.internal_admin_body.id}" if @tag.nil? or @tag == "all" @tag = "all" - conditions = [locale_condition, @query, @query, @locale] + conditions = [locale_condition, @query, @query, default_locale] elsif @tag == 'other' category_list = PublicBodyCategories::get().tags().map{|c| "'"+c+"'"}.join(",") conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, @locale] + and has_tag_string_tags.name in (' + category_list + ')) = 0', @query, @query, default_locale] elsif @tag.size == 1 @tag.upcase! - conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, @locale, @tag] + conditions = [locale_condition + ' AND public_body_translations.first_letter = ?', @query, @query, default_locale, @tag] elsif @tag.include?(":") name, value = HasTagString::HasTagStringTag.split_tag_into_name_value(@tag) conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, @locale, name, value] + and has_tag_string_tags.name = ? and has_tag_string_tags.value = ?) > 0', @query, @query, default_locale, name, value] else conditions = [locale_condition + ' AND (select count(*) from has_tag_string_tags where has_tag_string_tags.model_id = public_bodies.id and has_tag_string_tags.model = \'PublicBody\' - and has_tag_string_tags.name = ?) > 0', @query, @query, @locale, @tag] + and has_tag_string_tags.name = ?) > 0', @query, @query, default_locale, @tag] end if @tag == "all" @description = "" diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 4b7884065..1801648ca 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -774,7 +774,7 @@ class RequestController < ApplicationController :email => _("Then you can download a zip file of {{info_request_title}}.",:info_request_title=>info_request.title), :email_subject => _("Log in to download a zip file of {{info_request_title}}",:info_request_title=>info_request.title) ) - updated = Digest::SHA1.hexdigest(info_request.get_last_event.created_at.to_s + info_request.updated_at.to_s) + updated = Digest::SHA1.hexdigest(info_request.get_last_event.created_at.to_i.to_s + info_request.updated_at.to_i.to_s) @url_path = "/download/#{updated[0..1]}/#{updated}/#{params[:url_title]}.zip" file_path = File.join(File.dirname(__FILE__), '../../cache/zips', @url_path) if !File.exists?(file_path) diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 2b795ddf5..0608d46d7 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -267,7 +267,7 @@ class FOIAttachment tempfile.flush if self.content_type == 'application/pdf' - IO.popen("/usr/bin/pdftohtml -nodrm -zoom 1.0 -stdout -enc UTF-8 -noframes " + tempfile.path + "", "r") do |child| + IO.popen("#{`which pdftohtml`.chomp} -nodrm -zoom 1.0 -stdout -enc UTF-8 -noframes " + tempfile.path + "", "r") do |child| html = child.read() end elsif self.content_type == 'application/rtf' @@ -447,7 +447,7 @@ class IncomingMessage < ActiveRecord::Base # Special cases for some content types if content_type == 'application/pdf' uncompressed_text = nil - IO.popen("/usr/bin/pdftk - output - uncompress", "r+") do |child| + IO.popen("#{`which pdftk`.chomp} - output - uncompress", "r+") do |child| child.write(text) child.close_write() uncompressed_text = child.read() @@ -464,7 +464,7 @@ class IncomingMessage < ActiveRecord::Base if MySociety::Config.get('USE_GHOSTSCRIPT_COMPRESSION') == true command = "gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=- -" else - command = "/usr/bin/pdftk - output - compress" + command = "#{`which pdftk`.chomp} - output - compress" end IO.popen(command, "r+") do |child| child.write(censored_uncompressed_text) @@ -606,21 +606,13 @@ class IncomingMessage < ActiveRecord::Base text.gsub!(/^(>.*\n)/, replacement) text.gsub!(/^(On .+ (wrote|said):\n)/, replacement) - # Multiple line sections - # http://www.whatdotheyknow.com/request/identity_card_scheme_expenditure - # http://www.whatdotheyknow.com/request/parliament_protest_actions - # http://www.whatdotheyknow.com/request/64/response/102 - # http://www.whatdotheyknow.com/request/47/response/283 - # http://www.whatdotheyknow.com/request/30/response/166 - # http://www.whatdotheyknow.com/request/52/response/238 - # http://www.whatdotheyknow.com/request/224/response/328 # example with * * * * * - # http://www.whatdotheyknow.com/request/297/response/506 - ['-', '_', '*', '#'].each do |score| + ['-', '_', '*', '#'].each do |scorechar| + score = /(?:[#{scorechar}]\s*){8,}/ text.sub!(/(Disclaimer\s+)? # appears just before ( - \s*(?:[#{score}]\s*){8,}\s*\n.*? # top line + \s*#{score}\n(?:(?!#{score}\n).)*? # top line (disclaimer:\n|confidential|received\sthis\semail\sin\serror|virus|intended\s+recipient|monitored\s+centrally|intended\s+(for\s+|only\s+for\s+use\s+by\s+)the\s+addressee|routinely\s+monitored|MessageLabs|unauthorised\s+use) - .*?((?:[#{score}]\s*){8,}\s*\n|\z) # bottom line OR end of whole string (for ones with no terminator XXX risky) + .*?(?:#{score}|\z) # bottom line OR end of whole string (for ones with no terminator XXX risky) ) /imx, replacement) end @@ -1120,21 +1112,21 @@ class IncomingMessage < ActiveRecord::Base tempfile.print body tempfile.flush if content_type == 'application/vnd.ms-word' - AlaveteliExternalCommand.run("/usr/bin/wvText", tempfile.path, tempfile.path + ".txt") + AlaveteliExternalCommand.run(`which wvText`.chomp, tempfile.path, tempfile.path + ".txt") # Try catdoc if we get into trouble (e.g. for InfoRequestEvent 2701) if not File.exists?(tempfile.path + ".txt") - AlaveteliExternalCommand.run("/usr/bin/catdoc", tempfile.path, :append_to => text) + AlaveteliExternalCommand.run(`which catdoc`.chomp, tempfile.path, :append_to => text) else text += File.read(tempfile.path + ".txt") + "\n\n" File.unlink(tempfile.path + ".txt") end elsif content_type == 'application/rtf' # catdoc on RTF prodcues less comments and extra bumf than --text option to unrtf - AlaveteliExternalCommand.run("/usr/bin/catdoc", tempfile.path, :append_to => text) + AlaveteliExternalCommand.run(`which catdoc`.chomp, tempfile.path, :append_to => text) elsif content_type == 'text/html' # lynx wordwraps links in its output, which then don't get formatted properly # by Alaveteli. We use elinks instead, which doesn't do that. - AlaveteliExternalCommand.run("/usr/bin/elinks", "-eval", "'set document.codepage.assume = \"utf-8\"'", "-dump-charset", "utf-8", "-force-html", "-dump", + AlaveteliExternalCommand.run(`which elinks`.chomp, "-eval", "'set document.codepage.assume = \"utf-8\"'", "-dump-charset", "utf-8", "-force-html", "-dump", tempfile.path, :append_to => text) elsif content_type == 'application/vnd.ms-excel' # Bit crazy using /usr/bin/strings - but xls2csv, xlhtml and @@ -1145,9 +1137,9 @@ class IncomingMessage < ActiveRecord::Base elsif content_type == 'application/vnd.ms-powerpoint' # ppthtml seems to catch more text, but only outputs HTML when # we want text, so just use catppt for now - AlaveteliExternalCommand.run("/usr/bin/catppt", tempfile.path, :append_to => text) + AlaveteliExternalCommand.run(`which catppt`.chomp, tempfile.path, :append_to => text) elsif content_type == 'application/pdf' - AlaveteliExternalCommand.run("/usr/bin/pdftotext", tempfile.path, "-", :append_to => text) + AlaveteliExternalCommand.run(`which pdftotext`.chomp, tempfile.path, "-", :append_to => text) elsif content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' # This is Microsoft's XML office document format. # Just pull out the main XML file, and strip it of text. diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 92322f74f..f482ca700 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -240,9 +240,9 @@ public # into some sort of separate jurisdiction dependent file if self.public_body.url_name == 'general_register_office' # without GQ in the subject, you just get an auto response - self.law_used_full + ' request GQ - ' + self.title + _('{{law_used_full}} request GQ - {{title}}',:law_used_full=>self.law_used_full,:title=>self.title) else - self.law_used_full + ' request - ' + self.title + _('{{law_used_full}} request - {{title}}',:law_used_full=>self.law_used_full,:title=>self.title) end end def email_subject_followup(incoming_message = nil) @@ -260,36 +260,36 @@ public # Two sorts of laws for requests, FOI or EIR def law_used_full if self.law_used == 'foi' - return "Freedom of Information" + return _("Freedom of Information") elsif self.law_used == 'eir' - return "Environmental Information Regulations" + return _("Environmental Information Regulations") else raise "Unknown law used '" + self.law_used + "'" end end def law_used_short if self.law_used == 'foi' - return "FOI" + return _("FOI") elsif self.law_used == 'eir' - return "EIR" + return _("EIR") else raise "Unknown law used '" + self.law_used + "'" end end def law_used_act if self.law_used == 'foi' - return "Freedom of Information Act" + return _("Freedom of Information Act") elsif self.law_used == 'eir' - return "Environmental Information Regulations" + return _("Environmental Information Regulations") else raise "Unknown law used '" + self.law_used + "'" end end def law_used_with_a if self.law_used == 'foi' - return "A Freedom of Information request" + return _("A Freedom of Information request") elsif self.law_used == 'eir' - return "An Environmental Information Regulations request" + return _("An Environmental Information Regulations request") else raise "Unknown law used '" + self.law_used + "'" end diff --git a/app/models/public_body.rb b/app/models/public_body.rb index ab836657b..453e3a6cf 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -64,8 +64,14 @@ class PublicBody < ActiveRecord::Base end def translated_versions=(translation_attrs) + def skip?(attrs) + valueless = attrs.inject({}) { |h, (k, v)| h[k] = v if v != '' and k != 'locale'; h } # because we want to fall back to alternative translations where there are empty values + return valueless.length == 0 + end + if translation_attrs.respond_to? :each_value # Hash => updating translation_attrs.each_value do |attrs| + next if skip?(attrs) t = translation(attrs[:locale]) || PublicBody::Translation.new t.attributes = attrs calculate_cached_fields(t) @@ -73,6 +79,7 @@ class PublicBody < ActiveRecord::Base end else # Array => creating translation_attrs.each do |attrs| + next if skip?(attrs) new_translation = PublicBody::Translation.new(attrs) calculate_cached_fields(new_translation) translations << new_translation @@ -309,22 +316,23 @@ class PublicBody < ActiveRecord::Base # The "internal admin" is a special body for internal use. def PublicBody.internal_admin_body - pb = PublicBody.find_by_url_name("internal_admin_authority") - if pb.nil? - pb = PublicBody.new( - :name => 'Internal admin authority', - :short_name => "", - :request_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), - :home_page => "", - :notes => "", - :publication_scheme => "", - :last_edit_editor => "internal_admin", - :last_edit_comment => "Made by PublicBody.internal_admin_body" - ) - pb.save! + PublicBody.with_locale(I18n.default_locale) do + pb = PublicBody.find_by_url_name("internal_admin_authority") + if pb.nil? + pb = PublicBody.new( + :name => 'Internal admin authority', + :short_name => "", + :request_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), + :home_page => "", + :notes => "", + :publication_scheme => "", + :last_edit_editor => "internal_admin", + :last_edit_comment => "Made by PublicBody.internal_admin_body" + ) + pb.save! + end + return pb end - - return pb end @@ -360,11 +368,11 @@ class PublicBody < ActiveRecord::Base set_of_importing = Set.new() field_names = { 'name'=>1, 'request_email'=>2 } # Default values in case no field list is given line = 0 - CSV::Reader.parse(csv) do |row| + CSV.parse(csv) do |row| line = line + 1 # Parse the first line as a field list if it starts with '#' - if line==1 and row.to_s =~ /^#(.*)$/ + if line==1 and row.first.to_s =~ /^#(.*)$/ row[0] = row[0][1..-1] # Remove the # sign on first field row.each_with_index {|field, i| field_names[field] = i} next @@ -390,7 +398,7 @@ class PublicBody < ActiveRecord::Base if public_body = bodies_by_name[name] # Existing public body available_locales.each do |locale| PublicBody.with_locale(locale) do - changed = {} + changed = ActiveSupport::OrderedHash.new field_list.each do |field_name| localized_field_name = (locale.to_s == I18n.default_locale.to_s) ? field_name : "#{field_name}.#{locale}" localized_value = field_names[localized_field_name] && row[field_names[localized_field_name]] @@ -425,7 +433,7 @@ class PublicBody < ActiveRecord::Base public_body = PublicBody.new(:name=>"", :short_name=>"", :request_email=>"") available_locales.each do |locale| PublicBody.with_locale(locale) do - changed = {} + changed = ActiveSupport::OrderedHash.new field_list.each do |field_name| localized_field_name = (locale.to_s == I18n.default_locale.to_s) ? field_name : "#{field_name}.#{locale}" localized_value = field_names[localized_field_name] && row[field_names[localized_field_name]] @@ -457,7 +465,7 @@ class PublicBody < ActiveRecord::Base # Give an error listing ones that are to be deleted deleted_ones = set_of_existing - set_of_importing if deleted_ones.size > 0 - notes.push "Notes: Some " + tag + " bodies are in database, but not in CSV file:\n " + Array(deleted_ones).join("\n ") + "\nYou may want to delete them manually.\n" + notes.push "Notes: Some " + tag + " bodies are in database, but not in CSV file:\n " + Array(deleted_ones).sort.join("\n ") + "\nYou may want to delete them manually.\n" end # Rollback if a dry run, or we had errors diff --git a/app/views/layouts/default.rhtml b/app/views/layouts/default.rhtml index 2af13f342..675bb38de 100644 --- a/app/views/layouts/default.rhtml +++ b/app/views/layouts/default.rhtml @@ -12,7 +12,6 @@ <link rel="shortcut icon" href="/favicon.ico"> <%= stylesheet_link_tag 'main', :title => "Main", :rel => "stylesheet", :media => "all" %> <%= stylesheet_link_tag 'fonts', :rel => "stylesheet", :media => "all" %> - <%= stylesheet_link_tag 'theme', :rel => "stylesheet", :media => "all" %> <%= stylesheet_link_tag 'print', :rel => "stylesheet", :media => "print" %> <% if !params[:print_stylesheet].nil? %> <%= stylesheet_link_tag 'print', :rel => "stylesheet", :media => "all" %> @@ -35,11 +34,12 @@ <!--[if LT IE 8]> <style type="text/css">@import url("/stylesheets/ie7.css");</style> <![endif]--> - <%= stylesheet_link_tag 'custom', :title => "Main", :rel => "stylesheet" %> + <!-- the following method for customising CSS is deprecated; see `doc/THEMES.md` for detail --> + <%= stylesheet_link_tag 'custom', :title => "Main", :rel => "stylesheet" %> <% if force_registration_on_new_request %> <%= stylesheet_link_tag 'jquery.fancybox-1.3.4', :rel => "stylesheet" %> <% end %> - + <% if @feed_autodetect %> <% for feed in @feed_autodetect %> <link rel="alternate" type="application/atom+xml" title="<%=h feed[:title] %>" href="<%=h feed[:url]%>"> diff --git a/app/views/user/bad_token.rhtml b/app/views/user/bad_token.rhtml index 443835382..538bc5606 100644 --- a/app/views/user/bad_token.rhtml +++ b/app/views/user/bad_token.rhtml @@ -1,6 +1,6 @@ <h1> <%= _('Please check the URL (i.e. the long code of letters and numbers) is copied -correctly from your email.'%> +correctly from your email.')%> </h1> <p> |