aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/info_request.rb11
-rw-r--r--app/models/info_request_event.rb29
-rw-r--r--app/models/outgoing_message.rb4
3 files changed, 37 insertions, 7 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index e9a366d36..e6ac03d72 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -23,7 +23,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: info_request.rb,v 1.128 2008-08-13 09:51:45 francis Exp $
+# $Id: info_request.rb,v 1.129 2008-08-20 23:56:21 francis Exp $
require 'digest/sha1'
require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian')
@@ -396,12 +396,15 @@ public
expecting_clarification = true
end
- if [ 'sent', 'resent', 'followup_sent' ].include?(event.event_type)
+ if [ 'sent', 'resent', 'followup_sent', 'followup_resent' ].include?(event.event_type)
if last_sent.nil?
last_sent = event
elsif event.event_type == 'resent'
last_sent = event
elsif expecting_clarification and event.event_type == 'followup_sent'
+ # XXX this needs to cope with followup_resent, which it doesn't.
+ # Not really easy to do, and only affects cases where followups
+ # were resent after a clarification.
last_sent = event
expecting_clarification = false
end
@@ -524,7 +527,7 @@ public
# The last outgoing message
def get_last_outgoing_event
for e in self.info_request_events.reverse
- if e.event_type == 'sent' || e.event_type == 'resent' || e.event_type == 'followup_sent'
+ if [ 'sent', 'resent', 'followup_sent', 'followup_resent' ].include?(e.event_type)
return e
end
end
@@ -578,7 +581,7 @@ public
def get_previous_email_sent_to(info_request_event)
last_email = nil
for e in self.info_request_events
- if (e.event_type == 'sent' || e.event_type == 'resent') && e.outgoing_message_id == info_request_event.outgoing_message_id
+ if ((info_request_event.is_sent_sort? && e.is_sent_sort?) || (info_request_event.is_followup_sort? && e.is_followup_sort?)) && e.outgoing_message_id == info_request_event.outgoing_message_id
if e.id == info_request_event.id
break
end
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index eb1cb98d8..48015500a 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -20,7 +20,7 @@
# 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.51 2008-08-13 01:39:41 francis Exp $
+# $Id: info_request_event.rb,v 1.52 2008-08-20 23:56:21 francis Exp $
class InfoRequestEvent < ActiveRecord::Base
belongs_to :info_request
@@ -38,6 +38,7 @@ class InfoRequestEvent < ActiveRecord::Base
'sent',
'resent',
'followup_sent',
+ 'followup_resent',
'edit', # title etc. edited in admin interface
'edit_outgoing', # outgoing message edited in admin interface
'destroy_incoming', # deleted an incoming message
@@ -171,6 +172,32 @@ class InfoRequestEvent < ActiveRecord::Base
raise "unknown status " + status
end
end
+
+ def is_sent_sort?
+ if [ 'sent', 'resent'].include?(self.event_type)
+ return true
+ end
+ return false
+ end
+ def is_followup_sort?
+ if [ 'followup_sent', 'followup_resent'].include?(self.event_type)
+ return true
+ end
+ return false
+ end
+
+ def same_email_as_previous_send?
+ prev_addr = self.info_request.get_previous_email_sent_to(self)
+ curr_addr = self.params[:email]
+ if prev_addr.nil? && curr_addr.nil?
+ return true
+ end
+ if prev_addr.nil? || curr_addr.nil?
+ return false
+ end
+ return TMail::Address.parse(prev_addr).address == TMail::Address.parse(curr_addr).address
+ end
+
end
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index d02037374..f5bca3669 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -21,7 +21,7 @@
# 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.58 2008-08-09 15:19:01 francis Exp $
+# $Id: outgoing_message.rb,v 1.59 2008-08-20 23:56:21 francis Exp $
class OutgoingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -132,7 +132,7 @@ class OutgoingMessage < ActiveRecord::Base
# An admin function
def resend_message
- if self.message_type == 'initial_request' and self.status == 'sent'
+ if ['initial_request', 'followup'].include?(self.message_type) and self.status == 'sent'
self.status = 'ready'
send_message('resent')
else