From a28501f8295e7df5f0623ebedae86f569d04c0e9 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 00:55:21 +1100 Subject: named_scope has been renamed to scope --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 3355b9443..07fe11665 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -51,7 +51,7 @@ class InfoRequest < ActiveRecord::Base has_tag_string - named_scope :visible, :conditions => {:prominence => "normal"} + scope :visible, :conditions => {:prominence => "normal"} # user described state (also update in info_request_event, admin_request/edit.rhtml) validate :must_be_valid_state -- cgit v1.2.3 From 4705859e54ca7d8e255f4ccb090ce5f6d9e02ab8 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 00:56:16 +1100 Subject: include ActionController::UrlWriter is deprecated --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 07fe11665..9029ec0ef 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -27,7 +27,7 @@ require 'digest/sha1' class InfoRequest < ActiveRecord::Base include ActionView::Helpers::UrlHelper - include ActionController::UrlWriter + include Rails.application.routes.url_helpers strip_attributes! -- cgit v1.2.3 From 18d0600855b73066c87ea5f2fe33db01fb7a0730 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 10 Dec 2012 01:22:58 +1100 Subject: Method-style callbacks are deprecated for after_initialize --- app/models/info_request.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 9029ec0ef..df362b410 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -81,6 +81,8 @@ class InfoRequest < ActiveRecord::Base 'blackhole' # just dump them ] + after_initialize :set_defaults + def self.enumerate_states states = [ 'waiting_response', @@ -171,16 +173,6 @@ class InfoRequest < ActiveRecord::Base OLD_AGE_IN_DAYS = 21.days - def after_initialize - if self.described_state.nil? - self.described_state = 'waiting_response' - end - # FOI or EIR? - if !self.public_body.nil? && self.public_body.eir_only? - self.law_used = 'eir' - end - end - def visible_comments self.comments.find(:all, :conditions => 'visible') end @@ -1155,5 +1147,17 @@ public yield(column.human_name, self.send(column.name), column.type.to_s, column.name) end end + + private + + def set_defaults + if self.described_state.nil? + self.described_state = 'waiting_response' + end + # FOI or EIR? + if !self.public_body.nil? && self.public_body.eir_only? + self.law_used = 'eir' + end + end end -- cgit v1.2.3 From 4b6fb7bb4bb01fdc3fcc4ae9d80543c1789485b6 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 12 Dec 2012 15:34:56 +1100 Subject: Overwriting validate_on_create in your models has been deprecated --- app/models/info_request.rb | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index df362b410..08b331c26 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -81,6 +81,9 @@ class InfoRequest < ActiveRecord::Base 'blackhole' # just dump them ] + # only check on create, so existing models with mixed case are allowed + validate :title_formatting, :on => :create + after_initialize :set_defaults def self.enumerate_states @@ -158,19 +161,6 @@ class InfoRequest < ActiveRecord::Base rescue MissingSourceFile, NameError end - # only check on create, so existing models with mixed case are allowed - def validate_on_create - if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) - errors.add(:title, _('Please write the summary using a mixture of capital and lower case letters. This makes it easier for others to read.')) - end - if !self.title.nil? && title.size > 200 - errors.add(:title, _('Please keep the summary short, like in the subject of an email. You can use a phrase, rather than a full sentence.')) - end - if !self.title.nil? && self.title =~ /^(FOI|Freedom of Information)\s*requests?$/i - errors.add(:title, _('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) - end - end - OLD_AGE_IN_DAYS = 21.days def visible_comments @@ -1159,5 +1149,17 @@ public self.law_used = 'eir' end end + + def title_formatting + if !self.title.nil? && !MySociety::Validate.uses_mixed_capitals(self.title, 10) + errors.add(:title, _('Please write the summary using a mixture of capital and lower case letters. This makes it easier for others to read.')) + end + if !self.title.nil? && title.size > 200 + errors.add(:title, _('Please keep the summary short, like in the subject of an email. You can use a phrase, rather than a full sentence.')) + end + if !self.title.nil? && self.title =~ /^(FOI|Freedom of Information)\s*requests?$/i + errors.add(:title, _('Please describe more what the request is about in the subject. There is no need to say it is an FOI request, we add that on anyway.')) + end + end end -- cgit v1.2.3 From 0fdf66b752e041ee0a3ce52bded856524b7d5fe3 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 25 Jan 2013 16:45:25 +1100 Subject: Don't need both url_helpers --- app/models/info_request.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index c85a9701d..aed49bc21 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -26,7 +26,6 @@ require 'digest/sha1' class InfoRequest < ActiveRecord::Base - include ActionView::Helpers::UrlHelper include Rails.application.routes.url_helpers strip_attributes! -- cgit v1.2.3 From e5931a86d13211460d44a28e52dd4d851958027b Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Tue, 29 Jan 2013 13:07:00 +1100 Subject: Workaround for setting default value on attribute when exists? is called --- app/models/info_request.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index aed49bc21..3ee1c3c08 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1140,8 +1140,13 @@ public private def set_defaults - if self.described_state.nil? - self.described_state = 'waiting_response' + begin + if self.described_state.nil? + self.described_state = 'waiting_response' + end + rescue ActiveModel::MissingAttributeError + # this should only happen on Model.exists?() call. It can be safely ignored. + # See http://www.tatvartha.com/2011/03/activerecordmissingattributeerror-missing-attribute-a-bug-or-a-features/ end # FOI or EIR? if !self.public_body.nil? && self.public_body.eir_only? -- cgit v1.2.3 From e9a8afc0458f0c23e1fdcc26791745827f9ad7c2 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Thu, 31 Jan 2013 16:38:20 +1100 Subject: Added a bit of a safety net. It's an ugly temporary hack to make debugging easier --- app/models/info_request.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 3ee1c3c08..9fcac0622 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -405,6 +405,14 @@ public # A new incoming email to this request def receive(email, raw_email_data, override_stop_new_responses = false, rejected_reason = "") + # Just adding a bit of extra error checking just to save a lot of deep chasing of + # strangeness. + # TODO: Remove this when we don't use the TMail backend anymore for anything + if (MailHandler.backend == "TMail" && !email.kind_of?(TMail::Mail)) || + (MailHandler.backend == "Mail" && !email.kind_of?(Mail::Mail)) + raise "Wrong kind of mail object passed in receive" + end + if !override_stop_new_responses allow = nil reason = nil -- cgit v1.2.3 From 00fe0cfd7f6c6852722779e9df46ec13b8371cd8 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 10 Feb 2013 17:30:15 +1100 Subject: Looks like this is different in the older version of Mail too --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 9fcac0622..9d8fc29fd 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -409,7 +409,7 @@ public # strangeness. # TODO: Remove this when we don't use the TMail backend anymore for anything if (MailHandler.backend == "TMail" && !email.kind_of?(TMail::Mail)) || - (MailHandler.backend == "Mail" && !email.kind_of?(Mail::Mail)) + (MailHandler.backend == "Mail" && !email.kind_of?(Mail::Message)) raise "Wrong kind of mail object passed in receive" end -- cgit v1.2.3 From 7f93d7f1d486f55f6ebe9da37150d16b1a4fa634 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 20 Feb 2013 11:58:48 +1100 Subject: Remove deprecated constants - #589 --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 9d8fc29fd..375d972a3 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -152,7 +152,7 @@ class InfoRequest < ActiveRecord::Base @@custom_states_loaded = false begin - if ENV["RAILS_ENV"] != "test" + if !Rails.env.test? require 'customstates' include InfoRequestCustomStates @@custom_states_loaded = true -- cgit v1.2.3 From b3d3fecdfe3588d842174ff3921e748864a85114 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Thu, 21 Feb 2013 17:24:13 +1100 Subject: Under Ruby 1.9 this saved to the DB as a Ruby ActiveSupport::SafeBuffer object but we want it saved as a String --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 375d972a3..42efa4484 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -473,7 +473,7 @@ public self.awaiting_description = true params = { :incoming_message_id => incoming_message.id } if !rejected_reason.empty? - params[:rejected_reason] = rejected_reason + params[:rejected_reason] = rejected_reason.to_str end self.log_event("response", params) self.save! -- cgit v1.2.3 From e9b4f4df38181e92938f99c98509b5f36033072d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 15:56:50 +1100 Subject: New way of sending an email --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 42efa4484..e4b24b991 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -479,7 +479,7 @@ public self.save! end self.info_request_events.each { |event| event.xapian_mark_needs_index } # for the "waiting_classification" index - RequestMailer.deliver_new_response(self, incoming_message) if !is_external? + RequestMailer.new_response(self, incoming_message).deliver if !is_external? end -- cgit v1.2.3 From 532a21ba4941197a13524ac3f1ce9267a46bec1d Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Mon, 25 Feb 2013 17:25:59 +1100 Subject: Update to new mail sending API --- app/models/info_request.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index e4b24b991..b66c388c4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -445,7 +445,7 @@ public if !allow if self.handle_rejected_responses == 'bounce' - RequestMailer.deliver_stopped_responses(self, email, raw_email_data) if !is_external? + RequestMailer.stopped_responses(self, email, raw_email_data).deliver if !is_external? elsif self.handle_rejected_responses == 'holding_pen' InfoRequest.holding_pen_request.receive(email, raw_email_data, false, reason) elsif self.handle_rejected_responses == 'blackhole' @@ -557,7 +557,7 @@ public if self.requires_admin? # Check there is someone to send the message "from" if !set_by.nil? || !self.user.nil? - RequestMailer.deliver_requires_admin(self, set_by) + RequestMailer.requires_admin(self, set_by).deliver end end end -- cgit v1.2.3 From f07444d80961fcd3e7bb9555f5ed4a4e0b65b5db Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Wed, 27 Feb 2013 14:17:16 +1100 Subject: Remove Tmail and use the Mail gem under Ruby 1.8.7 as well --- app/models/info_request.rb | 8 -------- 1 file changed, 8 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index b66c388c4..913d053bf 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -405,14 +405,6 @@ public # A new incoming email to this request def receive(email, raw_email_data, override_stop_new_responses = false, rejected_reason = "") - # Just adding a bit of extra error checking just to save a lot of deep chasing of - # strangeness. - # TODO: Remove this when we don't use the TMail backend anymore for anything - if (MailHandler.backend == "TMail" && !email.kind_of?(TMail::Mail)) || - (MailHandler.backend == "Mail" && !email.kind_of?(Mail::Message)) - raise "Wrong kind of mail object passed in receive" - end - if !override_stop_new_responses allow = nil reason = nil -- cgit v1.2.3 From cbdff06aa95a7987b54c712dc6729e138f608eca Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Sun, 3 Mar 2013 14:52:30 +1100 Subject: Rename Configuration class to avoid conflict with ActiveSupport::Configurable --- app/models/info_request.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 913d053bf..5f5cc28c7 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -665,7 +665,7 @@ public # last_event_forming_initial_request. There may be more obscure # things, e.g. fees, not properly covered. def date_response_required_by - Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_late_after_days, Configuration::working_or_calendar_days) + Holiday.due_date_from(self.date_initial_request_last_sent_at, AlaveteliConfiguration::reply_late_after_days, AlaveteliConfiguration::working_or_calendar_days) end # This is a long stop - even with UK public interest test extensions, 40 # days is a very long time. @@ -673,10 +673,10 @@ public last_sent = last_event_forming_initial_request if self.public_body.is_school? # schools have 60 working days maximum (even over a long holiday) - Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::special_reply_very_late_after_days, Configuration::working_or_calendar_days) + Holiday.due_date_from(self.date_initial_request_last_sent_at, AlaveteliConfiguration::special_reply_very_late_after_days, AlaveteliConfiguration::working_or_calendar_days) else # public interest test ICO guidance gives 40 working maximum - Holiday.due_date_from(self.date_initial_request_last_sent_at, Configuration::reply_very_late_after_days, Configuration::working_or_calendar_days) + Holiday.due_date_from(self.date_initial_request_last_sent_at, AlaveteliConfiguration::reply_very_late_after_days, AlaveteliConfiguration::working_or_calendar_days) end end @@ -876,10 +876,10 @@ public end def InfoRequest.magic_email_for_id(prefix_part, id) - magic_email = Configuration::incoming_email_prefix + magic_email = AlaveteliConfiguration::incoming_email_prefix magic_email += prefix_part + id.to_s magic_email += "-" + InfoRequest.hash_from_id(id) - magic_email += "@" + Configuration::incoming_email_domain + magic_email += "@" + AlaveteliConfiguration::incoming_email_domain return magic_email end @@ -890,7 +890,7 @@ public end def InfoRequest.hash_from_id(id) - return Digest::SHA1.hexdigest(id.to_s + Configuration::incoming_email_secret)[0,8] + return Digest::SHA1.hexdigest(id.to_s + AlaveteliConfiguration::incoming_email_secret)[0,8] end # Called by find_by_incoming_email - and used to be called by separate @@ -1118,7 +1118,7 @@ public before_save :purge_in_cache def purge_in_cache - if !Configuration::varnish_host.blank? && !self.id.nil? + if !AlaveteliConfiguration::varnish_host.blank? && !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) -- cgit v1.2.3 From d348cbf1de3d10818e4994c04f842c15bb333b99 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Fri, 15 Mar 2013 15:18:09 +1100 Subject: Fix up some merge action from f60ada47d4e7aabe0dce152109cb0d91865929da --- app/models/info_request.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/info_request.rb') diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 130c5b02c..156399b99 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -587,7 +587,7 @@ public RequestClassification.create!(:user_id => set_by.id, :info_request_event_id => event.id) - RequestMailer.deliver_old_unclassified_updated(self) if !is_external? + RequestMailer.old_unclassified_updated(self).deliver if !is_external? end end -- cgit v1.2.3