aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/request_controller.rb3
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--app/models/info_request.rb56
-rw-r--r--app/models/rejection_reason.rb20
-rw-r--r--app/views/request/show.rhtml26
5 files changed, 104 insertions, 5 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 05affaf67..1a1b2be90 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.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_controller.rb,v 1.15 2007-11-13 12:47:05 francis Exp $
+# $Id: request_controller.rb,v 1.16 2007-11-14 01:01:38 francis Exp $
class RequestController < ApplicationController
@@ -12,6 +12,7 @@ class RequestController < ApplicationController
@info_request = InfoRequest.find(params[:id])
@correspondences = @info_request.outgoing_messages + @info_request.incoming_messages
@correspondences.sort! { |a,b| a.sent_at <=> b.sent_at }
+ @status = @info_request.calculate_status
end
def list
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
diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml
index c880261dc..8b29c3009 100644
--- a/app/views/request/show.rhtml
+++ b/app/views/request/show.rhtml
@@ -8,6 +8,27 @@ by
<%= user_link(@info_request.user) %>
</p>
+<p class="xspeaker">
+<% if @status == 'awaiting' %>
+Currently <strong>waiting for a response</strong> from <%= public_body_link(@info_request.public_body) %>
+<% elsif @status == 'overdue' %>
+Currently <strong>overdue a response</strong> from <%=
+public_body_link(@info_request.public_body) %>. Under section blah of the
+Freedom of Information Act 2000 responses must be made within 20 working days.
+<% elsif @status == 'information_and_rejection' %>
+The request was <strong>partly successful, partly rejected</strong>
+<% elsif @status == 'information' %>
+The request was <strong>successful</strong>
+<% elsif @status == 'rejection' %>
+The request was <strong>rejected</strong>
+<% elsif @status == 'unknown' %>
+<strong>Response received</strong>, but <%= user_link(@info_request.user) %> has not yet reported if it was
+successful or a rejection.
+<% else %>
+<% raise "unknown status " + $status %>
+<% end %>
+</p>
+
<% for correspondence in @correspondences %>
<div id="correspondence">
@@ -36,8 +57,9 @@ by
<p class="xspeaker">
<%= incoming_message.mail.friendly_from %>
- wrote a reply
- on <strong><%= simple_date(incoming_message.sent_at) %></strong>
+ of <%= public_body_link(@info_request.public_body) %>
+ wrote a reply on <strong><%= simple_date(incoming_message.sent_at)
+ %></strong>
</p>
<% else %>
<% raise "Unknown correspondence type" + correspondence.class.to_s %>