diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/info_request.rb | 23 | ||||
-rw-r--r-- | app/models/public_body.rb | 8 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 53 | ||||
-rw-r--r-- | app/models/user_info_request_sent_alert.rb | 5 |
4 files changed, 69 insertions, 20 deletions
diff --git a/app/models/info_request.rb b/app/models/info_request.rb index ece806009..14cd503ba 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -22,7 +22,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.113 2008-05-21 10:51:24 francis Exp $ +# $Id: info_request.rb,v 1.114 2008-05-21 22:37:33 francis Exp $ require 'digest/sha1' require File.join(File.dirname(__FILE__),'../../vendor/plugins/acts_as_xapian/lib/acts_as_xapian') @@ -262,7 +262,7 @@ public # -- sent at all # -- OR the same message was resent # -- OR the public body requested clarification, and a follow up was sent - def last_outgoing_message_forming_initial_request + def last_event_forming_initial_request last_sent = nil expecting_clarification = false for event in self.info_request_events @@ -271,14 +271,12 @@ public end if [ 'sent', 'resent', 'followup_sent' ].include?(event.event_type) - outgoing_message = event.outgoing_message - if last_sent.nil? - last_sent = outgoing_message + last_sent = event elsif event.event_type == 'resent' - last_sent = outgoing_message + last_sent = event elsif expecting_clarification and event.event_type == 'followup_sent' - last_sent = outgoing_message + last_sent = event expecting_clarification = false end end @@ -297,12 +295,15 @@ public # # Freedom of Information Act 2000 section 10 # - # XXX how do we cope with case where extra info was required from the requester - # by the public body in order to fulfill the request, as per sections 1(3) and 10(6b) ? + # How do we cope with case where extra info was required from the requester + # by the public body in order to fulfill the request, as per sections 1(3) + # and 10(6b) ? For clarifications this is covered by + # last_event_forming_initial_request. There may be more obscure + # things, e.g. fees, not properly covered. def date_response_required_by # Find the ear - last_sent = self.last_outgoing_message_forming_initial_request - last_sent_at = last_sent.last_sent_at + last_sent = self.last_event_forming_initial_request + last_sent_at = last_sent.outgoing_message.last_sent_at # Count forward 20 working days days_passed = 0 diff --git a/app/models/public_body.rb b/app/models/public_body.rb index 03e74f2b7..9b7c97c4c 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.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: public_body.rb,v 1.71 2008-05-21 10:51:24 francis Exp $ +# $Id: public_body.rb,v 1.72 2008-05-21 22:37:33 francis Exp $ require 'csv' require 'set' @@ -154,7 +154,7 @@ class PublicBody < ActiveRecord::Base # Import from CSV. Just tests things and returns messages if dry_run is true. # Returns an array of [array of errors, array of notes]. If there are errors, # always rolls back (as with dry_run). - def self.import_csv(csv, tag, dry_run = false) + def self.import_csv(csv, tag, dry_run, editor) errors = [] notes = [] @@ -195,14 +195,14 @@ class PublicBody < ActiveRecord::Base if public_body.request_email != email notes.push "line " + line.to_s + ": updating email for '" + name + "' from " + public_body.request_email + " to " + email public_body.request_email = email - public_body.last_edit_editor = 'import_csv' + public_body.last_edit_editor = editor public_body.last_edit_comment = 'Updated from spreadsheet' public_body.save! end else # New public body notes.push "line " + line.to_s + ": new authority '" + name + "' with email " + email - public_body = PublicBody.new(:name => name, :request_email => email, :short_name => "", :last_edit_editor => "import_csv", :last_edit_comment => 'Created from spreadsheet') + public_body = PublicBody.new(:name => name, :request_email => email, :short_name => "", :last_edit_editor => editor, :last_edit_comment => 'Created from spreadsheet') public_body.tag_string = tag public_body.save! end diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index cb43b59f8..cfe837b3b 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.32 2008-05-19 12:01:22 francis Exp $ +# $Id: request_mailer.rb,v 1.33 2008-05-21 22:37:33 francis Exp $ class RequestMailer < ApplicationMailer @@ -113,6 +113,23 @@ class RequestMailer < ApplicationMailer @body = { :incoming_message => incoming_message, :info_request => info_request, :url => url } end + # Tell the requester that they need to clarify their request + def not_clarified_alert(info_request, incoming_message) + respond_url = show_response_url(:id => info_request.id, :incoming_message_id => incoming_message.id) + respond_url = respond_url + "#show_response_followup" + + post_redirect = PostRedirect.new( + :uri => respond_url, + :user_id => info_request.user.id) + post_redirect.save! + url = confirm_url(:email_token => post_redirect.email_token) + + @from = contact_from_name_and_email + @recipients = info_request.user.name_and_email + @subject = "Clarify your FOI request - " + info_request.title + @body = { :incoming_message => incoming_message, :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, @@ -150,17 +167,19 @@ class RequestMailer < ApplicationMailer #STDERR.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 + alert_event_id = info_request.last_event_forming_initial_request.id # 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]) + 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]) if sent_already.nil? # Alert not yet sent for this user - #STDERR.puts "sending overdue alert to info_request " + info_request.id.to_s + " user " + info_request.user_id.to_s + #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.info_request_event_id = alert_event_id RequestMailer.deliver_overdue_alert(info_request, info_request.user) store_sent.save! #STDERR.puts "sent " + info_request.user.email @@ -197,6 +216,34 @@ class RequestMailer < ApplicationMailer end end + # Send email alerts for requests which need clarification. Goes out 3 days + # after last update of event. + def self.alert_not_clarified_request() + #STDERR.puts "alert_not_clarified_request" + info_requests = InfoRequest.find(:all, :conditions => [ "not awaiting_description and described_state = 'waiting_clarification' and info_requests.updated_at < ?", Time.now() - 3.days ], :include => [ :user ], :order => "info_requests.id" ) + for info_request in info_requests + alert_event_id = info_request.get_last_response_event_id + last_response_message = info_request.get_last_response + if alert_event_id.nil? + raise "internal error, no last response while making alert not clarified reminder, request id " + info_request.id.to_s + end + # To the user who created the request + sent_already = UserInfoRequestSentAlert.find(:first, :conditions => [ "alert_type = 'not_clarified_1' and user_id = ? and info_request_id = ? and info_request_event_id = ?", info_request.user_id, info_request.id, alert_event_id]) + if sent_already.nil? + # Alert not yet sent for this user + STDERR.puts "sending clarification reminder alert to info_request " + info_request.id.to_s + " user " + info_request.user_id.to_s + " event " + alert_event_id.to_s + store_sent = UserInfoRequestSentAlert.new + store_sent.info_request = info_request + store_sent.user = info_request.user + store_sent.alert_type = 'not_clarified_1' + store_sent.info_request_event_id = alert_event_id + RequestMailer.deliver_not_clarified_alert(info_request, last_response_message) + store_sent.save! + #STDERR.puts "sent " + info_request.user.email + end + end + end + end diff --git a/app/models/user_info_request_sent_alert.rb b/app/models/user_info_request_sent_alert.rb index 872286c88..2b6cfed1d 100644 --- a/app/models/user_info_request_sent_alert.rb +++ b/app/models/user_info_request_sent_alert.rb @@ -17,7 +17,7 @@ # 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.15 2008-05-21 10:51:24 francis Exp $ +# $Id: user_info_request_sent_alert.rb,v 1.16 2008-05-21 22:37:33 francis Exp $ class UserInfoRequestSentAlert < ActiveRecord::Base belongs_to :user @@ -25,7 +25,8 @@ class UserInfoRequestSentAlert < ActiveRecord::Base validates_inclusion_of :alert_type, :in => [ 'overdue_1', # tell user that info request has become overdue - 'new_response_reminder_1' # reminder user to classify the recent response + 'new_response_reminder_1', # reminder user to classify the recent response + 'not_clarified_1', # reminder that user has to explain part of the request ] end |