aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--app/models/info_request.rb56
-rw-r--r--app/models/rejection_reason.rb20
3 files changed, 78 insertions, 2 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index 0d051d379..30cd1f74e 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -5,7 +5,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.4 2007-11-13 10:22:14 francis Exp $
+# $Id: incoming_message.rb,v 1.5 2007-11-14 01:01:39 francis Exp $
class IncomingMessage < ActiveRecord::Base
belongs_to :info_request
@@ -13,6 +13,8 @@ class IncomingMessage < ActiveRecord::Base
validates_presence_of :raw_data
+ has_many :rejection_reasons
+
# Return the structured TMail::Mail object
# Documentation at http://i.loveruby.net/en/projects/tmail/doc/
def mail
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index e6b8c2b0a..eb02587a8 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.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: info_request.rb,v 1.12 2007-11-13 10:22:14 francis Exp $
+# $Id: info_request.rb,v 1.13 2007-11-14 01:01:39 francis Exp $
require 'digest/sha1'
@@ -57,6 +57,60 @@ class InfoRequest < ActiveRecord::Base
incoming_message.save
end
+ # Work out what the situation of the request is
+ def calculate_status
+ # Extract aggregate information for any incoming messages all together
+ contains_information = false
+ rejection_reasons = []
+ self.incoming_messages.each do |msg|
+ if msg.user_classified
+ if msg.contains_information
+ contains_information = true
+ end
+ rejection_reasons += msg.rejection_reasons
+ end
+ end
+
+ # See if response would be overdue
+ overdue = false
+ # XXX if a second outgoing message is really a new request, then this
+ # is no good
+ earliest_sent = self.outgoing_messages.map { |om| om.sent_at }.min
+ time_left = Time.now - earliest_sent
+ # XXX use working days
+ if time_left > 20.days
+ overdue = true
+ end
+
+ # Return appropriate status string
+ if self.incoming_messages.size == 0
+ if overdue
+ return "overdue"
+ else
+ return "awaiting"
+ end
+ end
+ if contains_information and rejection_reasons.size > 0
+ return "information_and_rejection"
+ end
+ if contains_information and rejection_reasons.size == 0
+ return "information"
+ end
+ if rejection_reasons.size > 0
+ return "rejection"
+ end
+ return "unknown"
+ end
+ # - Awaiting response (in 20 working day limit)
+ # - Overdue a response (over 20 working day limit)
+ #
+ # - Has a response but not sure what to think of it
+ # - Received a positive response
+ # - Received a partly positive response w/ rejection reasons
+ # - Received an entirely negative response w/ rejection reasons
+ #
+ # - Have sent a follow up
+
end
diff --git a/app/models/rejection_reason.rb b/app/models/rejection_reason.rb
new file mode 100644
index 000000000..c3cc55d7d
--- /dev/null
+++ b/app/models/rejection_reason.rb
@@ -0,0 +1,20 @@
+# app/models/rejection_reasons.rb
+# Give one reason under the Freedom of Information Act 2000 as to why
+# a particular incoming message was rejected. An incoming message can
+# have multiple such reasons.
+#
+# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
+# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: rejection_reason.rb,v 1.1 2007-11-14 01:01:39 francis Exp $
+
+class RejectionReason < ActiveRecord::Base
+ belongs_to :incoming_message
+ validates_presence_of :incoming_message_id
+
+ def self.all_reasons
+ ['commerciallyconfidential']
+ end
+
+ validates_inclusion_of :reason, :in => RejectionReason.all_reasons
+end