diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 15 | ||||
-rw-r--r-- | app/models/info_request.rb | 4 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 6 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 47 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 4 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 13 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
8 files changed, 64 insertions, 33 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 427059b15..a6a869769 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: incoming_messages # @@ -20,7 +20,7 @@ # 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.25 2008-01-07 15:08:59 francis Exp $ +# $Id: incoming_message.rb,v 1.26 2008-01-10 01:13:28 francis Exp $ class IncomingMessage < ActiveRecord::Base belongs_to :info_request @@ -30,6 +30,8 @@ class IncomingMessage < ActiveRecord::Base has_many :rejection_reasons + has_many :outgoing_message_followups, :class_name => OutgoingMessage + # Return the structured TMail::Mail object # Documentation at http://i.loveruby.net/en/projects/tmail/doc/ def mail @@ -155,6 +157,15 @@ class IncomingMessage < ActiveRecord::Base return text end + # Returns the name of the person the incoming message is from, or nil if there isn't one + # or if there is only an email address. + def safe_mail_from + if self.mail.from and (not self.mail.friendly_from.include?('@')) + return self.mail.friendly_from + else + return nil + end + end end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index d86614f1d..198c6a30f 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: info_requests # @@ -17,7 +17,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.25 2008-01-09 15:35:40 francis Exp $ +# $Id: info_request.rb,v 1.26 2008-01-10 01:13:28 francis Exp $ require 'digest/sha1' diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 6c0ccc585..706db9d20 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: info_request_events # @@ -15,14 +15,14 @@ # 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.4 2008-01-07 13:26:46 francis Exp $ +# $Id: info_request_event.rb,v 1.5 2008-01-10 01:13:28 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request validates_presence_of :info_request validates_presence_of :event_type - validates_inclusion_of :event_type, :in => ['sent', 'resent', 'edit_outgoing'] + validates_inclusion_of :event_type, :in => ['sent', 'resent', 'followup_sent', 'followup_resent', 'edit_outgoing'] # We store YAML version of parameters in the database def params=(params) diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index cd28d7ae0..a8d9425c5 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,16 +1,17 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: outgoing_messages # -# id :integer not null, primary key -# info_request_id :integer -# body :text -# status :string(255) -# message_type :string(255) -# created_at :datetime -# updated_at :datetime -# last_sent_at :datetime +# id :integer not null, primary key +# info_request_id :integer +# body :text +# status :string(255) +# message_type :string(255) +# created_at :datetime +# updated_at :datetime +# last_sent_at :datetime +# incoming_message_followup_id :integer # # models/outgoing_message.rb: @@ -20,16 +21,18 @@ # 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.18 2008-01-04 11:19:18 francis Exp $ +# $Id: outgoing_message.rb,v 1.19 2008-01-10 01:13:28 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request validates_presence_of :info_request - validates_presence_of :body, :message => "^Please enter your letter requesting information." + validates_presence_of :body, :message => "^Please enter your letter requesting information" + validates_inclusion_of :status, :in => ['ready', 'sent', 'failed'] + validates_inclusion_of :message_type, :in => ['initial_request', 'followup' ] #, 'complaint'] - validates_inclusion_of :message_type, :in => ['initial_request'] #, 'complaint'] + belongs_to :incoming_message_followup, :foreign_key => 'incoming_message_followup_id', :class_name => 'IncomingMessage' # Set default letter def after_initialize @@ -52,20 +55,26 @@ class OutgoingMessage < ActiveRecord::Base # Note: You can test this from script/console with, say: # InfoRequest.find(1).outgoing_messages[0].send_message def send_message(log_event_type = 'sent') - if self.message_type == 'initial_request' - if self.status == 'ready' + if self.status == 'ready' + if self.message_type == 'initial_request' RequestMailer.deliver_initial_request(self.info_request, self) self.last_sent_at = Time.now self.status = 'sent' self.save! self.info_request.log_event(log_event_type, { :email => self.info_request.recipient_email, :outgoing_message_id => self.id }) - elsif self.status == 'sent' - raise "Message id #{self.id} has already been sent" + elsif self.message_type == 'followup' + RequestMailer.deliver_followup(self.info_request, self, self.incoming_message_followup) + self.last_sent_at = Time.now + self.status = 'sent' + self.save! + self.info_request.log_event('followup_' + log_event_type, { :email => self.info_request.recipient_email, :outgoing_message_id => self.id }) else - raise "Message id #{self.id} not in state for send_message" + raise "Message id #{self.id} has type '#{self.message_type}' which send_message can't handle" end + elsif self.status == 'sent' + raise "Message id #{self.id} has already been sent" else - raise "Message id #{self.id} has type '#{self.message_type}' which send_message can't handle" + raise "Message id #{self.id} not in state for send_message" end end @@ -75,7 +84,7 @@ class OutgoingMessage < ActiveRecord::Base self.status = 'ready' send_message('resent') else - raise "Message id #{self.id} has type '#{self.message_type}' status '#{self.status}' " + raise "Message id #{self.id} has type '#{self.message_type}' status '#{self.status}' which resend_message can't handle" end end diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index ba9d0946f..c190562b5 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: post_redirects # @@ -21,7 +21,7 @@ # 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.10 2008-01-09 17:47:31 francis Exp $ +# $Id: post_redirect.rb,v 1.11 2008-01-10 01:13:28 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 53d5dd0b3..99b829b0f 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: public_bodies # @@ -21,7 +21,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: public_body.rb,v 1.12 2008-01-04 11:19:18 francis Exp $ +# $Id: public_body.rb,v 1.13 2008-01-10 01:13:28 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index f6b34c120..6d5e6b0cd 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -4,7 +4,7 @@ # 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.15 2008-01-09 19:34:07 francis Exp $ +# $Id: request_mailer.rb,v 1.16 2008-01-10 01:13:28 francis Exp $ class RequestMailer < ActionMailer::Base @@ -17,6 +17,17 @@ class RequestMailer < ActionMailer::Base :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } end + def followup(info_request, outgoing_message, incoming_message_followup) + @from = info_request.incoming_email + headers 'Sender' => info_request.envelope_email + @recipients = incoming_message_followup.mail.from + @subject = 'Re: Freedom of Information Request - ' + info_request.title + @body = {:info_request => info_request, :outgoing_message => outgoing_message, + :incoming_message_followup => incoming_message_followup, + :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } + + end + def bounced_message(email) @from = MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') @recipients = @from diff --git a/app/models/user.rb b/app/models/user.rb index dc07afe47..a6e3bc434 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 24 +# Schema version: 25 # # Table name: users # @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: user.rb,v 1.16 2008-01-04 11:19:18 francis Exp $ +# $Id: user.rb,v 1.17 2008-01-10 01:13:28 francis Exp $ require 'digest/sha1' |