diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/incoming_message.rb | 23 | ||||
-rw-r--r-- | app/models/info_request.rb | 93 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 4 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 4 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 4 | ||||
-rw-r--r-- | app/models/public_body.rb | 4 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
7 files changed, 66 insertions, 70 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 2d35e14f2..fcd73508e 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -1,16 +1,14 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # Table name: incoming_messages # -# id :integer not null, primary key -# info_request_id :integer not null -# raw_data :text not null -# created_at :datetime not null -# updated_at :datetime not null -# user_classified :boolean default(false), not null -# contains_information :boolean -# is_bounce :boolean default(false), not null +# id :integer not null, primary key +# info_request_id :integer not null +# raw_data :text not null +# created_at :datetime not null +# updated_at :datetime not null +# is_bounce :boolean default(false), not null # # models/incoming_message.rb: @@ -20,7 +18,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.36 2008-01-24 15:53:15 francis Exp $ +# $Id: incoming_message.rb,v 1.37 2008-01-29 01:26:21 francis Exp $ # TODO @@ -280,6 +278,11 @@ class IncomingMessage < ActiveRecord::Base return nil end end + + # Has message arrived "recently"? + def recently_arrived + (Time.now - self.created_at) <= 3.days + end end diff --git a/app/models/info_request.rb b/app/models/info_request.rb index 445682e1a..0207bca94 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -1,14 +1,17 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # Table name: info_requests # -# id :integer not null, primary key -# title :text not null -# user_id :integer not null -# public_body_id :integer not null -# created_at :datetime not null -# updated_at :datetime not null +# id :integer not null, primary key +# title :text not null +# user_id :integer not null +# public_body_id :integer not null +# created_at :datetime not null +# updated_at :datetime not null +# described_state :string(255) not null +# awaiting_description :boolean default(false), not null +# described_last_incoming_message_id :integer # # models/info_request.rb: @@ -17,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.29 2008-01-24 15:53:15 francis Exp $ +# $Id: info_request.rb,v 1.30 2008-01-29 01:26:21 francis Exp $ require 'digest/sha1' @@ -34,6 +37,17 @@ class InfoRequest < ActiveRecord::Base has_many :incoming_messages has_many :info_request_events + belongs_to :dsecribed_last_incoming_message_id + + # user described state + validates_inclusion_of :described_state, :in => [ + 'waiting_response', + 'waiting_clarification', + 'rejected', + 'successful', + 'partially_successful' + ] + public # Email which public body should use to respond to request. This is in # the format PREFIXrequest-ID-HASH@DOMAIN. Here ID is the id of the @@ -75,35 +89,28 @@ public # A new incoming email to this request def receive(email, raw_email, is_bounce) - incoming_message = IncomingMessage.new - incoming_message.raw_data = raw_email - incoming_message.is_bounce = is_bounce - incoming_message.info_request = self - incoming_message.save! + ActiveRecord::Base.transaction do + incoming_message = IncomingMessage.new + incoming_message.raw_data = raw_email + incoming_message.is_bounce = is_bounce + incoming_message.info_request = self + incoming_message.save! + + self.awaiting_description = true + self.save! + end RequestMailer.deliver_new_response(self, incoming_message) end # Work out what the situation of the request is - # awaiting - awaiting a response - # overdue - response is overdue - # information - has response containing information - # none - received a response, but no information XXX - # unknown - received a response that hasn't been classified + # waiting_response + # waiting_response_overdue # XXX calculated, should be cached for display? + # waiting_clarification + # rejected + # successful + # partially_successful def calculate_status - # Extract aggregate information for any incoming messages all together - contains_information = false - missing_classification = false - self.incoming_messages.each do |msg| - if msg.user_classified - if msg.contains_information - contains_information = true - end - else - missing_classification = true - end - end - # See if response would be overdue date_today = Time.now.strftime("%Y-%m-%d") date_response = date_response_required_by.strftime("%Y-%m-%d") @@ -113,22 +120,15 @@ public overdue = false end - # Return appropriate status string - if self.incoming_messages.size == 0 + if self.described_state == "waiting_response" if overdue - return "overdue" + return 'waiting_response_overdue' else - return "awaiting" + return 'waiting_response' end end - if missing_classification - return "unknown" - end - if contains_information - return "information" - else - return "none" - end + + return self.described_state end # Calculate date by which response is required by law. @@ -185,13 +185,6 @@ public return response_required_by end - # Return array of unclassified responses - def unclassified_responses - return self.incoming_messages.select do |msg| - not msg.user_classified - end - end - # Where the initial request is sent to def recipient_email if MySociety::Config.getbool("STAGING_SITE", 1) diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 320ebd7e8..0b5ac64f5 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # Table name: info_request_events # @@ -15,7 +15,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.7 2008-01-24 15:53:15 francis Exp $ +# $Id: info_request_event.rb,v 1.8 2008-01-29 01:26:21 francis Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index 5010a6c2b..391308bd4 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # Table name: outgoing_messages # @@ -21,7 +21,7 @@ # 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.23 2008-01-24 15:53:15 francis Exp $ +# $Id: outgoing_message.rb,v 1.24 2008-01-29 01:26:21 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index b468735de..864f2880f 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # Table name: post_redirects # @@ -25,7 +25,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.13 2008-01-24 15:53:15 francis Exp $ +# $Id: post_redirect.rb,v 1.14 2008-01-29 01:26:21 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/public_body.rb b/app/models/public_body.rb index cc3d1d928..5e90ca9ec 100644 --- a/app/models/public_body.rb +++ b/app/models/public_body.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # 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.14 2008-01-24 15:53:15 francis Exp $ +# $Id: public_body.rb,v 1.15 2008-01-29 01:26:21 francis Exp $ class PublicBody < ActiveRecord::Base validates_presence_of :name diff --git a/app/models/user.rb b/app/models/user.rb index 31d6b43a3..13a57ec92 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,5 @@ # == Schema Information -# Schema version: 26 +# Schema version: 27 # # 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.22 2008-01-24 15:53:15 francis Exp $ +# $Id: user.rb,v 1.23 2008-01-29 01:26:21 francis Exp $ require 'digest/sha1' |