diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 9 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 5 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 28 |
3 files changed, 33 insertions, 9 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 5a352026e..43b37a454 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.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: info_request.rb,v 1.41 2008-02-15 11:18:55 francis Exp $ +# $Id: info_request.rb,v 1.42 2008-02-21 20:10:21 francis Exp $ require 'digest/sha1' @@ -44,7 +44,8 @@ class InfoRequest < ActiveRecord::Base 'waiting_clarification', 'rejected', 'successful', - 'partially_successful' + 'partially_successful', + 'requires_admin' ] validates_inclusion_of :prominence, :in => [ @@ -135,6 +136,10 @@ public last_event.save! self.save! end + + if new_state == 'requires_admin' + RequestMailer.deliver_requires_admin(self) + end end # Work out what the situation of the request is diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index a8c2c7f50..c89f1c720 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -16,7 +16,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.15 2008-02-15 11:18:55 francis Exp $ +# $Id: info_request_event.rb,v 1.16 2008-02-21 20:10:21 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -40,7 +40,8 @@ class InfoRequestEvent < ActiveRecord::Base 'waiting_clarification', 'rejected', 'successful', - 'partially_successful' + 'partially_successful', + 'requires_admin' ] # We store YAML version of parameters in the database diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 7dfbfc315..515008209 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.21 2008-02-13 08:59:37 francis Exp $ +# $Id: request_mailer.rb,v 1.22 2008-02-21 20:10:21 francis Exp $ class RequestMailer < ApplicationMailer @@ -13,6 +13,8 @@ class RequestMailer < ApplicationMailer # they shouldn't, and this might help. (Have had mysterious cases of a # reply coming in duplicate from a public body to both From and envelope # from) + + # Email to public body requesting info def initial_request(info_request, outgoing_message) @from = info_request.incoming_name_and_email headers 'Sender' => info_request.envelope_name_and_email, @@ -23,6 +25,7 @@ class RequestMailer < ApplicationMailer :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } end + # Later message to public body regarding existing request def followup(info_request, outgoing_message, incoming_message_followup) @from = info_request.incoming_name_and_email headers 'Sender' => info_request.envelope_name_and_email, @@ -34,6 +37,7 @@ class RequestMailer < ApplicationMailer :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } end + # Incoming message arrived at FOI address, but hasn't got To:/CC: of valid request def bounced_message(email) @from = contact_from_name_and_email @recipients = @from @@ -41,6 +45,18 @@ class RequestMailer < ApplicationMailer email.setup_forward(self) end + # An FOI response is outside the scope of the system, and needs admin attention + def requires_admin(info_request) + @from = contact_from_name_and_email + @recipients = @from + @subject = "Unusual FOI response, requires admin attention" + # XXX these are repeats of things in helpers/link_to_helper.rb, and shouldn't be + url = show_request_url(:id => info_request) + admin_url = MySociety::Config.get("ADMIN_BASE_URL", "/admin/") + 'request/show/' + info_request.id.to_s + @body = {:info_request => info_request, :url => url, :admin_url => admin_url } + end + + # Tell the requester that a new response has arrived def new_response(info_request, incoming_message) post_redirect = PostRedirect.new( :uri => describe_state_url(:id => info_request.id), @@ -54,9 +70,10 @@ class RequestMailer < ApplicationMailer @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } end - # Copy of function from action_mailer/base.rb, which passes the - # raw_email to the member function, as we want to record it. - # script/mailin calls this function. + # 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 + # want to record it. ] def self.receive(raw_email) logger.info "Received mail:\n #{raw_email}" unless logger.nil? mail = TMail::Mail.parse(raw_email) @@ -64,6 +81,7 @@ class RequestMailer < ApplicationMailer new.receive(mail, raw_email) end + # Member function, called on the new class made in self.receive above def receive(email, raw_email) # Find which info requests the email is for reply_info_requests = [] @@ -80,7 +98,7 @@ class RequestMailer < ApplicationMailer RequestMailer.deliver_bounced_message(email) end - # Send the message to each request + # Send the message to each request, to be archived with it for reply_info_request in reply_info_requests reply_info_request.receive(email, raw_email, false) end |