aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/info_request.rb14
-rw-r--r--app/models/request_mailer.rb57
-rw-r--r--app/models/user.rb3
-rw-r--r--app/models/user_info_request_sent_alert.rb19
4 files changed, 89 insertions, 4 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index bad751efe..48ccedcc1 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.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.rb,v 1.44 2008-02-21 20:45:51 francis Exp $
+# $Id: info_request.rb,v 1.45 2008-02-22 01:58:36 francis Exp $
require 'digest/sha1'
@@ -36,6 +36,7 @@ class InfoRequest < ActiveRecord::Base
has_many :outgoing_messages
has_many :incoming_messages
has_many :info_request_events
+ has_many :user_info_request_sent_alerts
belongs_to :dsecribed_last_incoming_message_id
@@ -280,6 +281,17 @@ public
return nil
end
+ # The last outgoing message
+ def get_last_outgoing_event
+ events = self.info_request_events.find(:all, :order => "created_at")
+ events.reverse.each do |e|
+ if e.event_type == 'sent' || e.event_type == 'resent' || e.event_type == 'followup_sent'
+ return e
+ end
+ end
+ return nil
+ end
+
# Text from the the initial request, for use in summary display
def initial_request_text
if outgoing_messages.empty? # mainly for use with incomplete fixtures
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 515008209..20ac78b70 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.22 2008-02-21 20:10:21 francis Exp $
+# $Id: request_mailer.rb,v 1.23 2008-02-22 01:58:36 francis Exp $
class RequestMailer < ApplicationMailer
@@ -30,7 +30,11 @@ class RequestMailer < ApplicationMailer
@from = info_request.incoming_name_and_email
headers 'Sender' => info_request.envelope_name_and_email,
'Reply-To' => @from
- @recipients = incoming_message_followup.mail.from_addrs.to_s
+ if incoming_message_followup.nil?
+ @recipients = info_request.recipient_name_and_email
+ else
+ @recipients = incoming_message_followup.mail.from_addrs.to_s
+ end
@subject = 'Re: Freedom of Information Request - ' + info_request.title
@body = {:info_request => info_request, :outgoing_message => outgoing_message,
:incoming_message_followup => incoming_message_followup,
@@ -70,6 +74,29 @@ class RequestMailer < ApplicationMailer
@body = { :incoming_message => incoming_message, :info_request => info_request, :url => url }
end
+ # Tell the requester that a new response has arrived
+ def overdue_alert(info_request, user)
+ last_response = info_request.get_last_response
+ if last_response.nil?
+ respond_url = show_response_no_followup_url(:id => info_request.id)
+ else
+ respond_url = show_response_url(:id => info_request.id, :incoming_message_id => last_response.id)
+ end
+ respond_url = respond_url + "#show_response_followup"
+
+ post_redirect = PostRedirect.new(
+ :uri => respond_url,
+ :user_id => user.id)
+ post_redirect.save!
+ url = confirm_url(:email_token => post_redirect.email_token)
+
+ @from = contact_from_name_and_email
+ @recipients = user.name_and_email
+ @subject = "You're overdue a response to your FOI request - " + info_request.title
+ @body = { :info_request => info_request, :url => url }
+ end
+
+
# Class function, called by script/mailin with all incoming responses.
# [ This is a copy (Monkeypatch!) of function from action_mailer/base.rb,
# but which additionally passes the raw_email to the member function, as we
@@ -107,4 +134,30 @@ class RequestMailer < ApplicationMailer
end
end
+ # Send email alerts for overdue requests
+ def self.alert_overdue_requests()
+ #puts "alert_overdue_requests"
+ info_requests = InfoRequest.find(:all, :conditions => [ "described_state = 'waiting_response' and not awaiting_description" ], :include => [ :user ] )
+ for info_request in info_requests
+ # Only overdue requests
+ if info_request.calculate_status == 'waiting_response_overdue'
+ # For now, just to the user who created the request
+ sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = 'overdue_1' and user_id = ? and info_request_id = ?", info_request.user_id, info_request.id])
+ if sent_already.nil?
+ # Alert not yet sent for this user
+ puts "sending overdue alert to info_request " + info_request.id.to_s + " user " + info_request.user_id.to_s
+ store_sent = UserInfoRequestSentAlert.new
+ store_sent.info_request = info_request
+ store_sent.user = info_request.user
+ store_sent.alert_type = 'overdue_1'
+ RequestMailer.deliver_overdue_alert(info_request, info_request.user)
+ store_sent.save!
+ #puts "sent " + info_request.user.email
+ end
+ end
+ end
+
+ end
end
+
+
diff --git a/app/models/user.rb b/app/models/user.rb
index b7897bcba..1fa71dffb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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.27 2008-02-21 20:45:51 francis Exp $
+# $Id: user.rb,v 1.28 2008-02-22 01:58:36 francis Exp $
require 'digest/sha1'
@@ -31,6 +31,7 @@ class User < ActiveRecord::Base
validates_presence_of :hashed_password, :message => "^Please enter a password"
has_many :info_requests
+ has_many :user_info_request_sent_alerts
attr_accessor :password_confirmation
validates_confirmation_of :password, :message =>"^Please enter the same password twice"
diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb
new file mode 100644
index 000000000..8a272d274
--- /dev/null
+++ b/app/models/user_info_request_sent_alert.rb
@@ -0,0 +1,19 @@
+# models/user_info_request_sent_alert.rb:
+# Whether an alert has been sent to this user for this info_request, for a
+# given type of alert.
+#
+# 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.1 2008-02-22 01:58:36 francis Exp $
+
+class UserInfoRequestSentAlert < ActiveRecord::Base
+ belongs_to :user
+ belongs_to :info_request
+
+ validates_inclusion_of :alert_type, :in => [
+ 'overdue_1' # tell user that info request has become overdue
+ ]
+end
+
+