aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/request_mailer.rb42
-rw-r--r--app/models/user_info_request_sent_alert.rb1
-rw-r--r--app/views/request_mailer/overdue_alert.rhtml5
-rw-r--r--app/views/request_mailer/very_overdue_alert.rhtml14
-rw-r--r--spec/controllers/request_controller_spec.rb25
5 files changed, 80 insertions, 7 deletions
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 1bebb5181..7e2041b4f 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -85,7 +85,25 @@ class RequestMailer < ApplicationMailer
headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken
'Auto-Submitted' => 'auto-generated' # http://tools.ietf.org/html/rfc3834
@recipients = user.name_and_email
- @subject = "You're overdue a response to your FOI request - " + info_request.title
+ @subject = "Delayed response to your FOI request - " + info_request.title
+ @body = { :info_request => info_request, :url => url }
+ end
+
+ # Tell the requester that the public body is very late in replying
+ def very_overdue_alert(info_request, user)
+ respond_url = respond_to_last_url(info_request) + "#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
+ headers 'Return-Path' => blackhole_email, 'Reply-To' => @from, # not much we can do if the user's email is broken
+ 'Auto-Submitted' => 'auto-generated' # http://tools.ietf.org/html/rfc3834
+ @recipients = user.name_and_email
+ @subject = "You're long overdue a response to your FOI request - " + info_request.title
@body = { :info_request => info_request, :url => url }
end
@@ -209,21 +227,35 @@ class RequestMailer < ApplicationMailer
for info_request in info_requests
alert_event_id = info_request.last_event_forming_initial_request.id
# Only overdue requests
- if info_request.calculate_status == 'waiting_response_overdue'
+ if ['waiting_response_overdue', 'waiting_response_very_overdue'].include?(info_request.calculate_status)
+ if info_request.calculate_status == 'waiting_response_overdue'
+ alert_type = 'overdue_1'
+ elsif info_request.calculate_status == 'waiting_response_very_overdue'
+ alert_type = 'very_overdue_1'
+ else
+ raise "unknown request status"
+ end
+
# 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 = ? and info_request_event_id = ?", info_request.user_id, info_request.id, alert_event_id])
+ sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = ? and user_id = ? and info_request_id = ? and info_request_event_id = ?", alert_type, info_request.user_id, info_request.id, alert_event_id])
if sent_already.nil?
# Alert not yet sent for this user, so send it
#STDERR.puts "sending overdue alert to info_request " + info_request.id.to_s + " user " + info_request.user_id.to_s + " event " + alert_event_id
store_sent = UserInfoRequestSentAlert.new
store_sent.info_request = info_request
store_sent.user = info_request.user
- store_sent.alert_type = 'overdue_1'
+ store_sent.alert_type = alert_type
store_sent.info_request_event_id = alert_event_id
# Only send the alert if the user can act on it by making a followup
# (otherwise they are banned, and there is no point sending it)
if info_request.user.can_make_followup?
- RequestMailer.deliver_overdue_alert(info_request, info_request.user)
+ if info_request.calculate_status == 'waiting_response_overdue'
+ RequestMailer.deliver_overdue_alert(info_request, info_request.user)
+ elsif info_request.calculate_status == 'waiting_response_very_overdue'
+ RequestMailer.deliver_very_overdue_alert(info_request, info_request.user)
+ else
+ raise "unknown request status"
+ end
end
store_sent.save!
#STDERR.puts "sent " + info_request.user.email
diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb
index 309466792..dde6fd339 100644
--- a/app/models/user_info_request_sent_alert.rb
+++ b/app/models/user_info_request_sent_alert.rb
@@ -25,6 +25,7 @@ class UserInfoRequestSentAlert < ActiveRecord::Base
validates_inclusion_of :alert_type, :in => [
'overdue_1', # tell user that info request has become overdue
+ 'very_overdue_1', # tell user that info request has become very overdue
'new_response_reminder_1', # reminder user to classify the recent response
'new_response_reminder_2', # repeat reminder user to classify the recent response
'new_response_reminder_3', # repeat reminder user to classify the recent response
diff --git a/app/views/request_mailer/overdue_alert.rhtml b/app/views/request_mailer/overdue_alert.rhtml
index d14abc419..29a1a1d68 100644
--- a/app/views/request_mailer/overdue_alert.rhtml
+++ b/app/views/request_mailer/overdue_alert.rhtml
@@ -1,10 +1,11 @@
-<%= @info_request.public_body.name %> are late.
+<%= @info_request.public_body.name %> have delayed.
They have not replied to your <%=@info_request.law_used_short%> request '<%= @info_request.title %>'
-promptly, as normally required by law <% if @info_request.public_body.is_school? %>during term time<% end %>.
+promptly, as normally required by law<% if @info_request.public_body.is_school? %> during term time<% end %>.
Click on the link below to send a message to <%= @info_request.public_body.name
%> reminding them to reply to your request.
+
<%=@url%>
-- the WhatDoTheyKnow team
diff --git a/app/views/request_mailer/very_overdue_alert.rhtml b/app/views/request_mailer/very_overdue_alert.rhtml
new file mode 100644
index 000000000..2393d29e5
--- /dev/null
+++ b/app/views/request_mailer/very_overdue_alert.rhtml
@@ -0,0 +1,14 @@
+<%= @info_request.public_body.name %> are long overdue.
+
+They have not replied to your <%=@info_request.law_used_short%> request '<%= @info_request.title %>',
+as required by law<% if @info_request.public_body.is_school? %> even during holidays<% end %>.
+
+Click on the link below to send a message to <%= @info_request.public_body.name
+%> telling them to reply to your request. You might like to ask for an internal
+review, asking them to find out why response to the request has been so slow.
+
+<%=@url%>
+
+-- the WhatDoTheyKnow team
+
+
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 1ab68cd03..6a8f3538a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -891,6 +891,31 @@ describe RequestController, "sending overdue request alerts" do
deliveries.size.should == 0
end
+ it "should send a very overdue alert mail to creators of very overdue requests" do
+ chicken_request = info_requests(:naughty_chicken_request)
+ chicken_request.outgoing_messages[0].last_sent_at = Time.now() - 60.days
+ chicken_request.outgoing_messages[0].save!
+
+ RequestMailer.alert_overdue_requests
+
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /as required by law/
+ mail.to_addrs.to_s.should == info_requests(:naughty_chicken_request).user.name_and_email
+
+ mail.body =~ /(http:\/\/.*\/c\/(.*))/
+ mail_url = $1
+ mail_token = $2
+
+ session[:user_id].should be_nil
+ controller.test_code_redirect_by_email_token(mail_token, self) # XXX hack to avoid having to call User controller for email link
+ session[:user_id].should == info_requests(:naughty_chicken_request).user.id
+
+ response.should render_template('show_response')
+ assigns[:info_request].should == info_requests(:naughty_chicken_request)
+ end
+
end
describe RequestController, "sending unclassified new response reminder alerts" do