diff options
Diffstat (limited to 'app/models')
26 files changed, 221 insertions, 112 deletions
diff --git a/app/models/about_me_validator.rb b/app/models/about_me_validator.rb index 67b81bc9c..5e04c2761 100644 --- a/app/models/about_me_validator.rb +++ b/app/models/about_me_validator.rb @@ -11,8 +11,6 @@ # # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $ class AboutMeValidator < ActiveRecord::BaseWithoutTable strip_attributes! diff --git a/app/models/application_mailer.rb b/app/models/application_mailer.rb index 044006f7c..cdb279c3c 100644 --- a/app/models/application_mailer.rb +++ b/app/models/application_mailer.rb @@ -3,9 +3,8 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: application_mailer.rb,v 1.8 2009-02-09 10:37:12 francis Exp $ +require 'action_mailer/version' class ApplicationMailer < ActionMailer::Base # Include all the functions views get, as emails call similar things. helper :application @@ -16,7 +15,7 @@ class ApplicationMailer < ActionMailer::Base self.raise_delivery_errors = true def blackhole_email - MySociety::Config.get("BLACKHOLE_PREFIX", 'do-not-reply-to-this-address')+"@"+MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") + Configuration::blackhole_prefix+"@"+Configuration::incoming_email_domain end # URL generating functions are needed by all controllers (for redirects), @@ -26,5 +25,126 @@ class ApplicationMailer < ActionMailer::Base # Site-wide access to configuration settings include ConfigHelper + + # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer + # will be initialized according to the named method. If not, the mailer will + # remain uninitialized (useful when you only need to invoke the "receive" + # method, for instance). + def initialize(method_name=nil, *parameters) #:nodoc: + create!(method_name, *parameters) if method_name + end + + # For each multipart template (e.g. "the_template_file.text.html.erb") available, + # add the one from the view path with the highest priority as a part to the mail + def render_multipart_templates + added_content_types = {} + self.view_paths.each do |view_path| + Dir.glob("#{view_path}/#{mailer_name}/#{@template}.*").each do |path| + template = view_path["#{mailer_name}/#{File.basename(path)}"] + + # Skip unless template has a multipart format + next unless template && template.multipart? + next if added_content_types[template.content_type] == true + @parts << Part.new( + :content_type => template.content_type, + :disposition => "inline", + :charset => charset, + :body => render_message(template, @body) + ) + added_content_types[template.content_type] = true + end + end + end + + # Look for the current template in each element of view_paths in order, + # return the first + def find_template + self.view_paths.each do |view_path| + if template = view_path["#{mailer_name}/#{@template}"] + return template + end + end + return nil + end + + if ActionMailer::VERSION::MAJOR == 2 + + # This method is a customised version of ActionMailer::Base.create! + # modified to allow templates to be selected correctly for multipart + # mails when themes have added to the view_paths. The problem from our + # point of view with ActionMailer::Base is that it sets template_root to + # the first element of the view_paths array and then uses only that (directly + # and via template_path, which is created from it) in the create! method when + # looking for templates. Our modified version looks for templates in the view_paths + # in order. + # Changed lines marked with *** + + # Initialize the mailer via the given +method_name+. The body will be + # rendered and a new TMail::Mail object created. + def create!(method_name, *parameters) #:nodoc: + initialize_defaults(method_name) + __send__(method_name, *parameters) + + # If an explicit, textual body has not been set, we check assumptions. + unless String === @body + # First, we look to see if there are any likely templates that match, + # which include the content-type in their file name (i.e., + # "the_template_file.text.html.erb", etc.). Only do this if parts + # have not already been specified manually. + if @parts.empty? + # *** render_multipart_templates replaces the following code + # Dir.glob("#{template_path}/#{@template}.*").each do |path| + # template = template_root["#{mailer_name}/#{File.basename(path)}"] + # + # # Skip unless template has a multipart format + # next unless template && template.multipart? + # + # @parts << Part.new( + # :content_type => template.content_type, + # :disposition => "inline", + # :charset => charset, + # :body => render_message(template, @body) + # ) + # end + render_multipart_templates + + unless @parts.empty? + @content_type = "multipart/alternative" if @content_type !~ /^multipart/ + @parts = sort_parts(@parts, @implicit_parts_order) + end + end + + # Then, if there were such templates, we check to see if we ought to + # also render a "normal" template (without the content type). If a + # normal template exists (or if there were no implicit parts) we render + # it. + template_exists = @parts.empty? + + # *** find_template replaces template_root call + # template_exists ||= template_root["#{mailer_name}/#{@template}"] + template_exists ||= find_template + + @body = render_message(@template, @body) if template_exists + + # Finally, if there are other message parts and a textual body exists, + # we shift it onto the front of the parts and set the body to nil (so + # that create_mail doesn't try to render it in addition to the parts). + if !@parts.empty? && String === @body + @parts.unshift ActionMailer::Part.new(:charset => charset, :body => @body) + @body = nil + end + end + + # If this is a multipart e-mail add the mime_version if it is not + # already set. + @mime_version ||= "1.0" if !@parts.empty? + + # build the mail object itself + @mail = create_mail + end + else + raise "ApplicationMailer.create! is obsolete - find another way to ensure that themes can override mail templates for multipart mails" + end + end diff --git a/app/models/censor_rule.rb b/app/models/censor_rule.rb index a74fdcb24..f40ab6fbb 100644 --- a/app/models/censor_rule.rb +++ b/app/models/censor_rule.rb @@ -21,8 +21,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: censor_rule.rb,v 1.14 2009-09-17 21:10:04 francis Exp $ class CensorRule < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/change_email_validator.rb b/app/models/change_email_validator.rb index 0395ab6d5..9ef25217d 100644 --- a/app/models/change_email_validator.rb +++ b/app/models/change_email_validator.rb @@ -14,8 +14,6 @@ # # Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $ class ChangeEmailValidator < ActiveRecord::BaseWithoutTable strip_attributes! diff --git a/app/models/comment.rb b/app/models/comment.rb index 6edfaa24f..5507910e2 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -19,8 +19,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: comment.rb,v 1.18 2009-09-17 21:10:05 francis Exp $ class Comment < ActiveRecord::Base strip_attributes! diff --git a/app/models/contact_mailer.rb b/app/models/contact_mailer.rb index 6e781d48c..16aae2f15 100644 --- a/app/models/contact_mailer.rb +++ b/app/models/contact_mailer.rb @@ -3,8 +3,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: contact_mailer.rb,v 1.10 2009-02-09 10:37:12 francis Exp $ class ContactMailer < ApplicationMailer @@ -52,7 +50,7 @@ class ContactMailer < ApplicationMailer :from_user => @from, :recipient_user => recipient_user, } - bcc MySociety::Config::get("CONTACT_EMAIL") + bcc Configuration::contact_email end end diff --git a/app/models/contact_validator.rb b/app/models/contact_validator.rb index a9748a739..d277161f9 100644 --- a/app/models/contact_validator.rb +++ b/app/models/contact_validator.rb @@ -14,8 +14,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: contact_validator.rb,v 1.32 2009-09-17 21:10:05 francis Exp $ class ContactValidator < ActiveRecord::BaseWithoutTable strip_attributes! diff --git a/app/models/exim_log.rb b/app/models/exim_log.rb index 82000efa1..abe198493 100644 --- a/app/models/exim_log.rb +++ b/app/models/exim_log.rb @@ -17,8 +17,6 @@ # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: exim_log.rb,v 1.14 2009-09-17 21:10:05 francis Exp $ class EximLog < ActiveRecord::Base belongs_to :info_request @@ -63,7 +61,7 @@ class EximLog < ActiveRecord::Base order = 0 for line in f order = order + 1 - email_domain = MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") + email_domain = Configuration::incoming_email_domain emails = line.scan(/request-[^\s]+@#{email_domain}/).sort.uniq for email in emails info_request = InfoRequest.find_by_incoming_email(email) diff --git a/app/models/exim_log_done.rb b/app/models/exim_log_done.rb index 3cedc1379..86574a4cd 100644 --- a/app/models/exim_log_done.rb +++ b/app/models/exim_log_done.rb @@ -15,8 +15,6 @@ # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: exim_log_done.rb,v 1.8 2009-09-17 21:10:05 francis Exp $ class EximLogDone < ActiveRecord::Base has_many :exim_logs diff --git a/app/models/holiday.rb b/app/models/holiday.rb index debd88dec..d2437f438 100644 --- a/app/models/holiday.rb +++ b/app/models/holiday.rb @@ -20,23 +20,37 @@ # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: holiday.rb,v 1.10 2009-10-26 17:52:39 francis Exp $ class Holiday < ActiveRecord::Base - # Calculate the date on which a request made on a given date falls due. + def Holiday.weekend_or_holiday?(date) + # TODO only fetch holidays after the start_date + holidays = self.all.collect { |h| h.day }.to_set + + date.wday == 0 || date.wday == 6 || holidays.include?(date) + end + + def Holiday.due_date_from(start_date, days, type_of_days) + case type_of_days + when "working" + Holiday.due_date_from_working_days(start_date, days) + when "calendar" + Holiday.due_date_from_calendar_days(start_date, days) + else + raise "Unexpected value for type_of_days: #{type_of_days}" + end + end + + # Calculate the date on which a request made on a given date falls due when + # days are given in working days # i.e. it is due by the end of that day. - def Holiday.due_date_from(start_date, working_days) + def Holiday.due_date_from_working_days(start_date, working_days) # convert date/times into dates start_date = start_date.to_date - # TODO only fetch holidays after the start_date - holidays = self.all.collect { |h| h.day }.to_set - - # Count forward (20) working days. We start with today as "day zero". The - # first of the twenty full working days is the next day. We return the - # date of the last of the twenty. + # Count forward the number of working days. We start with today as "day zero". The + # first of the full working days is the next day. We return the + # date of the last of the number of working days. # This response for example of a public authority complains that we had # it wrong. We didn't (even thought I changed the code for a while, @@ -46,15 +60,27 @@ class Holiday < ActiveRecord::Base days_passed = 0 response_required_by = start_date - # Now step forward into each of the 20 days. + # Now step forward into each of the working days. while days_passed < working_days - response_required_by += 1.day - next if response_required_by.wday == 0 || response_required_by.wday == 6 # weekend - next if holidays.include?(response_required_by) - days_passed += 1 + response_required_by += 1 + days_passed += 1 unless weekend_or_holiday?(response_required_by) end - return response_required_by + response_required_by end + # Calculate the date on which a request made on a given date falls due when + # the days are given in calendar days (rather than working days) + # If the due date falls on a weekend or a holiday then the due date is the next + # weekday that isn't a holiday. + def Holiday.due_date_from_calendar_days(start_date, days) + # convert date/times into dates + start_date = start_date.to_date + + response_required_by = start_date + days + while weekend_or_holiday?(response_required_by) + response_required_by += 1 + end + response_required_by + end end diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 13fc316cd..fcb4671c5 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -27,8 +27,6 @@ # # 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.228 2009-10-21 11:24:14 francis Exp $ # TODO # Move some of the (e.g. quoting) functions here into rblib, as they feel @@ -253,7 +251,7 @@ class IncomingMessage < ActiveRecord::Base text.gsub!(self.info_request.public_body.request_email, _("[{{public_body}} request email]", :public_body => self.info_request.public_body.short_or_long_name)) end text.gsub!(self.info_request.incoming_email, _('[FOI #{{request}} email]', :request => self.info_request.id.to_s) ) - text.gsub!(MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), _("[{{site_name}} contact email]", :site_name => MySociety::Config.get('SITE_NAME', 'Alaveteli')) ) + text.gsub!(Configuration::contact_email, _("[{{site_name}} contact email]", :site_name => Configuration::site_name) ) end # Replaces all email addresses in (possibly binary data) with equal length alternative ones. @@ -279,7 +277,7 @@ class IncomingMessage < ActiveRecord::Base if censored_uncompressed_text != uncompressed_text # then use the altered file (recompressed) recompressed_text = nil - if MySociety::Config.get('USE_GHOSTSCRIPT_COMPRESSION') == true + if Configuration::use_ghostscript_compression == true command = ["gs", "-sDEVICE=pdfwrite", "-dCompatibilityLevel=1.4", "-dPDFSETTINGS=/screen", "-dNOPAUSE", "-dQUIET", "-dBATCH", "-sOutputFile=-", "-"] else command = ["pdftk", "-", "output", "-", "compress"] @@ -376,8 +374,7 @@ class IncomingMessage < ActiveRecord::Base text.gsub!(/(Mobile|Mob)([\s\/]*(Fax|Tel))*\s*:?[\s\d]*\d/, "[mobile number]") # Remove WhatDoTheyKnow signup links - domain = MySociety::Config.get('DOMAIN') - text.gsub!(/http:\/\/#{domain}\/c\/[^\s]+/, "[WDTK login link]") + text.gsub!(/http:\/\/#{Configuration::domain}\/c\/[^\s]+/, "[WDTK login link]") # Remove things from censor rules self.info_request.apply_censor_rules_to_text!(text) @@ -647,9 +644,10 @@ class IncomingMessage < ActiveRecord::Base # Text looks like unlabelled nonsense, # strip out anything that isn't UTF-8 begin + source_charset = 'utf-8' if source_charset.nil? text = Iconv.conv('utf-8//IGNORE', source_charset, text) + _("\n\n[ {{site_name}} note: The above text was badly encoded, and has had strange characters removed. ]", - :site_name => MySociety::Config.get('SITE_NAME', 'Alaveteli')) + :site_name => Configuration::site_name) rescue Iconv::InvalidEncoding, Iconv::IllegalSequence if source_charset != "utf-8" source_charset = "utf-8" diff --git a/app/models/info_request.rb b/app/models/info_request.rb index b62f67ee1..85168e6d4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -689,21 +689,18 @@ public # last_event_forming_initial_request. There may be more obscure # things, e.g. fees, not properly covered. def date_response_required_by - days_later = MySociety::Config.get('REPLY_LATE_AFTER_DAYS', 20) - return Holiday.due_date_from(self.date_initial_request_last_sent_at, days_later) + Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_late_after_days, Configuration::working_or_calendar_days) end # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. def date_very_overdue_after last_sent = last_event_forming_initial_request - very_late_days_later = MySociety::Config.get('REPLY_VERY_LATE_AFTER_DAYS', 40) - school_very_late_days_later = MySociety::Config.get('SPECIAL_REPLY_VERY_LATE_AFTER_DAYS', 60) if self.public_body.is_school? # schools have 60 working days maximum (even over a long holiday) - return Holiday.due_date_from(self.date_initial_request_last_sent_at, 60) + Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::special_reply_very_late_after_days, Configuration::working_or_calendar_days) else # public interest test ICO guidance gives 40 working maximum - return Holiday.due_date_from(self.date_initial_request_last_sent_at, 40) + Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_very_late_after_days, Configuration::working_or_calendar_days) end end @@ -903,10 +900,10 @@ public end def InfoRequest.magic_email_for_id(prefix_part, id) - magic_email = MySociety::Config.get("INCOMING_EMAIL_PREFIX", "") + magic_email = Configuration::incoming_email_prefix magic_email += prefix_part + id.to_s magic_email += "-" + InfoRequest.hash_from_id(id) - magic_email += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") + magic_email += "@" + Configuration::incoming_email_domain return magic_email end @@ -917,7 +914,7 @@ public end def InfoRequest.hash_from_id(id) - return Digest::SHA1.hexdigest(id.to_s + MySociety::Config.get("INCOMING_EMAIL_SECRET", 'dummysecret'))[0,8] + return Digest::SHA1.hexdigest(id.to_s + Configuration::incoming_email_secret)[0,8] end # Called by find_by_incoming_email - and used to be called by separate @@ -1141,7 +1138,7 @@ public before_save :purge_in_cache def purge_in_cache - if !MySociety::Config.get('VARNISH_HOST').nil? && !self.id.nil? + if !Configuration::varnish_host.nil? && !self.id.nil? # we only do this for existing info_requests (new ones have a nil id) path = url_for(:controller => 'request', :action => 'show', :url_title => self.url_title, :only_path => true, :locale => :none) req = PurgeRequest.find_by_url(path) diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 54d2f5ef7..5a8e3416f 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -21,8 +21,6 @@ # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: info_request_event.rb,v 1.96 2009-10-19 22:06:55 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/outgoing_mailer.rb b/app/models/outgoing_mailer.rb index 8562c5b68..a307bb778 100644 --- a/app/models/outgoing_mailer.rb +++ b/app/models/outgoing_mailer.rb @@ -3,8 +3,6 @@ # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: outgoing_mailer.rb,v 1.1 2009-10-04 21:53:54 francis Exp $ # Note: The layout for this wraps messages by lines rather than (blank line # separated) paragraphs, as is the convention for all the other mailers. This @@ -24,7 +22,7 @@ class OutgoingMailer < ApplicationMailer @subject = info_request.email_subject_request @headers["message-id"] = OutgoingMailer.id_for_message(outgoing_message) @body = {:info_request => info_request, :outgoing_message => outgoing_message, - :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } + :contact_email => Configuration::contact_email } end # Later message to public body regarding existing request @@ -36,7 +34,7 @@ class OutgoingMailer < ApplicationMailer @headers["message-id"] = OutgoingMailer.id_for_message(outgoing_message) @body = {:info_request => info_request, :outgoing_message => outgoing_message, :incoming_message_followup => incoming_message_followup, - :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } + :contact_email => Configuration::contact_email } end # XXX the condition checking valid_to_reply_to? also appears in views/request/_followup.rhtml, @@ -91,7 +89,7 @@ class OutgoingMailer < ApplicationMailer message_id = "ogm-" + outgoing_message.id.to_s t = Time.now message_id += "+" + '%08x%05x-%04x' % [t.to_i, t.tv_usec, rand(0xffff)] - message_id += "@" + MySociety::Config.get("INCOMING_EMAIL_DOMAIN", "localhost") + message_id += "@" + Configuration::incoming_email_domain return "<" + message_id + ">" end diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 0ce1ee11c..0e547d493 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -21,8 +21,6 @@ # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: outgoing_message.rb,v 1.95 2009-10-04 21:53:54 francis Exp $ class OutgoingMessage < ActiveRecord::Base strip_attributes! @@ -87,7 +85,7 @@ class OutgoingMessage < ActiveRecord::Base "'" + self.info_request.title + "'." + "\n\n\n\n [ " + self.get_internal_review_insert_here_note + " ] \n\n\n\n" + "A full history of my FOI request and all correspondence is available on the Internet at this address:\n" + - "http://" + MySociety::Config.get("DOMAIN", '127.0.0.1:3000') + "/request/" + self.info_request.url_title + "http://" + Configuration::domain + "/request/" + self.info_request.url_title else "" end diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index f613fc58d..31f08c21a 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -25,8 +25,6 @@ # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: post_redirect.rb,v 1.51 2009-09-17 21:10:05 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/profile_photo.rb b/app/models/profile_photo.rb index 72bfe954f..6e605651d 100644 --- a/app/models/profile_photo.rb +++ b/app/models/profile_photo.rb @@ -14,9 +14,6 @@ # # Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: profile_photo.rb,v 1.2 2009-09-17 21:10:05 francis Exp $ -# class ProfilePhoto < ActiveRecord::Base WIDTH = 96 diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 2cf1ce8a2..34bcd332c 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -336,7 +336,7 @@ class PublicBody < ActiveRecord::Base pb = PublicBody.new( :name => 'Internal admin authority', :short_name => "", - :request_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost'), + :request_email => Configuration::contact_email, :home_page => "", :notes => "", :publication_scheme => "", @@ -509,6 +509,20 @@ class PublicBody < ActiveRecord::Base return self.request_email_domain end + # Returns nil if configuration variable not set + def override_request_email + e = Configuration::override_all_public_body_request_emails + e if e != "" + end + + def request_email + if override_request_email + override_request_email + else + read_attribute(:request_email) + end + end + # Domain name of the request email def request_email_domain return PublicBody.extract_domain_from_email(self.request_email) diff --git a/app/models/raw_email.rb b/app/models/raw_email.rb index 3bb794684..bae144931 100644 --- a/app/models/raw_email.rb +++ b/app/models/raw_email.rb @@ -11,8 +11,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: raw_email.rb,v 1.12 2009-09-17 21:10:05 francis Exp $ class RawEmail < ActiveRecord::Base # deliberately don't strip_attributes, so keeps raw email properly @@ -28,8 +26,7 @@ class RawEmail < ActiveRecord::Base if ENV["RAILS_ENV"] == "test" return File.join(Rails.root, 'files/raw_email_test') else - return File.join(MySociety::Config.get('RAW_EMAILS_LOCATION', - 'files/raw_emails'), + return File.join(Configuration::raw_emails_location, request_id[0..2], request_id) end end diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index ba9285fc6..413e93e25 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -3,8 +3,6 @@ # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: request_mailer.rb,v 1.89 2009-10-04 21:53:54 francis Exp $ require 'alaveteli_file_types' @@ -50,12 +48,12 @@ class RequestMailer < ApplicationMailer headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # we don't care about bounces, likely from spammers 'Auto-Submitted' => 'auto-replied' # http://tools.ietf.org/html/rfc3834 @recipients = email.from_addrs[0].to_s - @subject = "Your response to an FOI request was not delivered" + @subject = _("Your response to an FOI request was not delivered") attachment :content_type => 'message/rfc822', :body => raw_email_data, :filename => "original.eml", :transfer_encoding => '7bit', :content_disposition => 'inline' @body = { :info_request => info_request, - :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') + :contact_email => Configuration::contact_email } end @@ -154,7 +152,7 @@ class RequestMailer < ApplicationMailer 'Auto-Submitted' => 'auto-generated', # http://tools.ietf.org/html/rfc3834 'X-Auto-Response-Suppress' => 'OOF' @recipients = info_request.user.name_and_email - @subject = "Someone has updated the status of your request" + @subject = _("Someone has updated the status of your request") url = main_url(request_url(info_request)) @body = {:info_request => info_request, :url => url} end @@ -303,7 +301,7 @@ class RequestMailer < ApplicationMailer # Send email alerts for new responses which haven't been classified. By default, # it goes out 3 days after last update of event, then after 10, then after 24. def self.alert_new_response_reminders - MySociety::Config.get("NEW_RESPONSE_REMINDER_AFTER_DAYS", [3, 10, 24]).each_with_index do |days, i| + Configuration::new_response_reminder_after_days.each_with_index do |days, i| self.alert_new_response_reminders_internal(days, "new_response_reminder_#{i+1}") end end diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb index 92da7c376..7dfa87f52 100644 --- a/app/models/track_mailer.rb +++ b/app/models/track_mailer.rb @@ -3,8 +3,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: track_mailer.rb,v 1.23 2009-10-03 02:50:11 francis Exp $ class TrackMailer < ApplicationMailer def event_digest(user, email_about_things) @@ -27,9 +25,7 @@ class TrackMailer < ApplicationMailer end def contact_from_name_and_email - contact_name = MySociety::Config.get("TRACK_SENDER_NAME", 'Alaveteli') - contact_email = MySociety::Config.get("TRACK_SENDER_EMAIL", 'contact@localhost') - return "#{contact_name} <#{contact_email}>" + "#{Configuration::track_sender_name} <#{Configuration::track_sender_email}>" end # Send email alerts for tracked things. Never more than one email diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index d0fc62e12..d1cef4d4d 100644 --- a/app/models/track_thing.rb +++ b/app/models/track_thing.rb @@ -20,8 +20,7 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: track_thing.rb,v 1.53 2009-09-17 21:10:05 francis Exp $ + require 'set' class TrackThing < ActiveRecord::Base @@ -51,15 +50,15 @@ class TrackThing < ActiveRecord::Base def TrackThing.track_type_description(track_type) if track_type == 'request_updates' - "Individual requests" + _("Individual requests") elsif track_type == 'all_new_requests' || track_type == "all_successful_requests" - "Many requests" + _("Many requests") elsif track_type == 'public_body_updates' - "Public authorities" + _("Public authorities") elsif track_type == 'user_updates' - "People" + _("People") elsif track_type == 'search_query' - "Search queries" + _("Search queries") else raise "internal error " + track_type end @@ -195,7 +194,7 @@ class TrackThing < ActiveRecord::Base if self.track_type == 'request_updates' @params = { # Website - :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Follow this request"), :verb_on_page_already => _("You are already following this request"), # Email @@ -246,14 +245,14 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'public_body_updates' @params = { # Website - :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Follow requests to {{public_body_name}}",:public_body_name=>CGI.escapeHTML(self.public_body.name)), :verb_on_page_already => _("You are already following requests to {{public_body_name}}", :public_body_name=>CGI.escapeHTML(self.public_body.name)), # Email :title_in_email => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'", :title_in_rss => self.public_body.law_only_short + " requests to '" + self.public_body.name + "'", # Authentication - :web => _("To follow requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>MySociety::Config.get('SITE_NAME', 'Alaveteli'), :public_body_name=>CGI.escapeHTML(self.public_body.name)), + :web => _("To follow requests made using {{site_name}} to the public authority '{{public_body_name}}'", :site_name=>Configuration::site_name, :public_body_name=>CGI.escapeHTML(self.public_body.name)), :email => _("Then you will be notified whenever someone requests something or gets a response from '{{public_body_name}}'.", :public_body_name=>CGI.escapeHTML(self.public_body.name)), :email_subject => _("Confirm you want to follow requests to '{{public_body_name}}'", :public_body_name=>self.public_body.name), # RSS sorting @@ -262,7 +261,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'user_updates' @params = { # Website - :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Follow this person"), :verb_on_page_already => _("You are already following this person"), # Email @@ -278,7 +277,7 @@ class TrackThing < ActiveRecord::Base elsif self.track_type == 'search_query' @params = { # Website - :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how + :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how :verb_on_page => _("Follow things matching this search"), :verb_on_page_already => _("You are already following things matching this search"), # Email diff --git a/app/models/track_things_sent_email.rb b/app/models/track_things_sent_email.rb index 24297f57b..a0a4c0f0c 100644 --- a/app/models/track_things_sent_email.rb +++ b/app/models/track_things_sent_email.rb @@ -17,8 +17,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: track_things_sent_email.rb,v 1.22 2009-09-17 21:10:05 francis Exp $ class TrackThingsSentEmail < ActiveRecord::Base belongs_to :info_request_event diff --git a/app/models/user.rb b/app/models/user.rb index bb1b54d70..59f6c971c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -208,13 +208,12 @@ class User < ActiveRecord::Base # The "internal admin" is a special user for internal use. def User.internal_admin_user - contact_email = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') - u = User.find_by_email(contact_email) + u = User.find_by_email(Configuration::contact_email) if u.nil? password = PostRedirect.generate_random_token u = User.new( :name => 'Internal admin user', - :email => contact_email, + :email => Configuration::contact_email, :password => password, :password_confirmation => password ) @@ -282,18 +281,16 @@ class User < ActiveRecord::Base return false if self.no_limit # Has the user issued as many as MAX_REQUESTS_PER_USER_PER_DAY requests in the past 24 hours? - daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY") - return false if daily_limit.nil? + return false if Configuration::max_requests_per_user_per_day.nil? recent_requests = InfoRequest.count(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id]) - return (recent_requests >= daily_limit) + return (recent_requests >= Configuration::max_requests_per_user_per_day) end def next_request_permitted_at return nil if self.no_limit - daily_limit = MySociety::Config.get("MAX_REQUESTS_PER_USER_PER_DAY") - n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => daily_limit) - return nil if n_most_recent_requests.size < daily_limit + n_most_recent_requests = InfoRequest.all(:conditions => ["user_id = ? and created_at > now() - '1 day'::interval", self.id], :order => "created_at DESC", :limit => Configuration::max_requests_per_user_per_day) + return nil if n_most_recent_requests.size < Configuration::max_requests_per_user_per_day nth_most_recent_request = n_most_recent_requests[-1] return nth_most_recent_request.created_at + 1.day diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index a97fd5d44..cf20bcbf5 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -16,8 +16,6 @@ # # Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: user_info_request_sent_alert.rb,v 1.34 2009-10-03 02:22:18 francis Exp $ class UserInfoRequestSentAlert < ActiveRecord::Base belongs_to :user diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb index 7adf5b63c..1be4f8aa3 100644 --- a/app/models/user_mailer.rb +++ b/app/models/user_mailer.rb @@ -3,8 +3,6 @@ # # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ -# -# $Id: user_mailer.rb,v 1.8 2009-02-09 10:37:12 francis Exp $ class UserMailer < ApplicationMailer def confirm_login(user, reasons, url) |