diff options
-rw-r--r-- | app/controllers/request_controller.rb | 4 | ||||
-rw-r--r-- | app/models/info_request.rb | 20 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 30 | ||||
-rw-r--r-- | app/models/outgoing_message.rb | 7 | ||||
-rw-r--r-- | app/models/post_redirect.rb | 4 | ||||
-rw-r--r-- | app/models/request_mailer.rb | 8 | ||||
-rw-r--r-- | app/views/admin_request/show.rhtml | 19 | ||||
-rw-r--r-- | app/views/request/_correspondence.rhtml | 60 | ||||
-rw-r--r-- | db/migrate/022_create_info_request_events.rb | 24 | ||||
-rw-r--r-- | db/schema.rb | 9 | ||||
-rw-r--r-- | public/stylesheets/main.css | 9 | ||||
-rw-r--r-- | todo.txt | 4 |
12 files changed, 159 insertions, 39 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 1c5cef751..ff09e43ff 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -4,13 +4,13 @@ # 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.23 2007-12-24 16:49:36 francis Exp $ +# $Id: request_controller.rb,v 1.24 2008-01-02 15:45:00 francis Exp $ class RequestController < ApplicationController def show @info_request = InfoRequest.find(params[:id]) - @correspondences = @info_request.outgoing_messages + @info_request.incoming_messages + @correspondences = @info_request.incoming_messages + @info_request.info_request_events @correspondences.sort! { |a,b| a.sent_at <=> b.sent_at } @status = @info_request.calculate_status @collapse_quotes = params[:unfold] ? false : true diff --git a/app/models/info_request.rb b/app/models/info_request.rb index d1db6f1a4..17eea71e4 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -17,7 +17,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.17 2007-12-24 16:49:36 francis Exp $ +# $Id: info_request.rb,v 1.18 2008-01-02 15:45:00 francis Exp $ require 'digest/sha1' @@ -32,6 +32,7 @@ class InfoRequest < ActiveRecord::Base has_many :outgoing_messages has_many :incoming_messages + has_many :info_request_events # 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 @@ -123,6 +124,23 @@ class InfoRequest < ActiveRecord::Base end end + # Where the initial request is sent to + def recipient_email + if MySociety::Config.getbool("STAGING_SITE", 1) + return self.user.email + else + return self.public_body.request_email + end + end + + # History of some things that have happened + def log_event(type, params) + info_request_event = InfoRequestEvent.new + info_request_event.event_type = type + info_request_event.params = params + info_request_event.info_request = self + info_request_event.save! + end end diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb new file mode 100644 index 000000000..1d9429035 --- /dev/null +++ b/app/models/info_request_event.rb @@ -0,0 +1,30 @@ +# models/info_request_event.rb: +# +# 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.1 2008-01-02 15:45:00 francis Exp $ + +class InfoRequestEvent < ActiveRecord::Base + belongs_to :info_request + validates_presence_of :info_request + + validates_presence_of :event_type + validates_inclusion_of :event_type, :in => ['sent', 'resent'] + + # We store YAML version of parameters in the database + def params=(params) + self.params_yaml = params.to_yaml + end + def params + YAML.load(self.params_yaml) + end + + # Used for sorting with the incoming/outgoing messages + def sent_at + created_at + end + +end + + diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb index e24e8ae97..a717cff0e 100644 --- a/app/models/outgoing_message.rb +++ b/app/models/outgoing_message.rb @@ -20,7 +20,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.14 2007-12-23 13:44:18 francis Exp $ +# $Id: outgoing_message.rb,v 1.15 2008-01-02 15:45:00 francis Exp $ class OutgoingMessage < ActiveRecord::Base belongs_to :info_request @@ -51,13 +51,14 @@ class OutgoingMessage < ActiveRecord::Base # Deliver outgoing message # Note: You can test this from script/console with, say: # InfoRequest.find(1).outgoing_messages[0].send_message - def send_message + def send_message(log_event_type = 'sent') if self.message_type == 'initial_request' if self.status == 'ready' RequestMailer.deliver_initial_request(self.info_request, self) self.sent_at = Time.now self.status = 'sent' self.save! + self.info_request.log_event(log_event_type, { :email => self.info_request.recipient_email, :outgoing_message_id => self.id }) elsif self.status == 'sent' raise "Message id #{self.id} has already been sent" else @@ -72,7 +73,7 @@ class OutgoingMessage < ActiveRecord::Base def resend_message if self.message_type == 'initial_request' and self.status == 'sent' self.status = 'ready' - send_message + send_message('resent') else raise "Message id #{self.id} has type '#{self.message_type}' status '#{self.status}' " end diff --git a/app/models/post_redirect.rb b/app/models/post_redirect.rb index 06d6d108d..5c918e774 100644 --- a/app/models/post_redirect.rb +++ b/app/models/post_redirect.rb @@ -14,14 +14,14 @@ # user_id :integer # -# models/postredirect.rb: +# models/post_redirect.rb: # Saves an HTTP POST request, so it can be redirected to later. # For example, after registering / logging in. # # 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.6 2007-12-11 12:16:29 francis Exp $ +# $Id: post_redirect.rb,v 1.7 2008-01-02 15:45:00 francis Exp $ require 'openssl' # for random bytes function diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb index 38c67befe..5c5e33065 100644 --- a/app/models/request_mailer.rb +++ b/app/models/request_mailer.rb @@ -4,17 +4,13 @@ # 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.12 2007-12-14 14:55:56 francis Exp $ +# $Id: request_mailer.rb,v 1.13 2008-01-02 15:45:00 francis Exp $ class RequestMailer < ActionMailer::Base def initial_request(info_request, outgoing_message) @from = info_request.incoming_email - if MySociety::Config.getbool("STAGING_SITE", 1) - @recipients = info_request.user.email - else - @recipients = info_request.public_body.request_email - end + @recipients = info_request.recipient_email @subject = 'Freedom of Information Request - ' + info_request.title @body = {:info_request => info_request, :outgoing_message => outgoing_message, :contact_email => MySociety::Config.get("CONTACT_EMAIL", 'contact@localhost') } diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml index a41335ae4..217b6208e 100644 --- a/app/views/admin_request/show.rhtml +++ b/app/views/admin_request/show.rhtml @@ -56,3 +56,22 @@ </table> +<h2>Events</h2> + +<table> + <tr> + <% for column in InfoRequestEvent.content_columns %> + <th><%= column.human_name %></th> + <% end %> + </tr> + +<% for info_request_event in @info_request.info_request_events %> + <tr class="<%= cycle('odd', 'even') %>"> + <% for column in InfoRequestEvent.content_columns.map { |c| c.name } %> + <td><%=h info_request_event.send(column) %></td> + <% end %> + </tr> +<% end %> +</table> + + diff --git a/app/views/request/_correspondence.rhtml b/app/views/request/_correspondence.rhtml index ff5e830d6..8c2fa5394 100644 --- a/app/views/request/_correspondence.rhtml +++ b/app/views/request/_correspondence.rhtml @@ -1,29 +1,12 @@ <div id="correspondence"> -<% if (correspondence.class.to_s == 'OutgoingMessage') - outgoing_message = correspondence %> - <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_display() } %> +<% @last_email = nil - <p class="xspeaker"> - <%= user_link(@info_request.user) %> - - <% if outgoing_message.message_type == 'initial_request' %> - sent the initial request - <% if outgoing_message.status == 'sent' %> - to <%= public_body_link(@info_request.public_body) %> - on <strong><%= simple_date(outgoing_message.sent_at) %></strong> - <% elsif outgoing_message.status == 'ready' %> - it has <strong>not yet been sent</strong> - <% else raise "unknown outgoing_message.status" %> - <% end %> - <% else raise "unknown outgoing_message.message_type" %> - <% end %> - </p> -<% elsif (correspondence.class.to_s == 'IncomingMessage') + if (correspondence.class.to_s == 'IncomingMessage') incoming_message = correspondence%> <%= render :partial => 'bubble', :locals => { :body => incoming_message.get_body_for_display(@collapse_quotes) } %> - <p class="xspeaker"> + <p class="event_bubble"> <% if incoming_message.mail.from and (not incoming_message.mail.friendly_from.include?('@')) %> <%= incoming_message.mail.friendly_from %> of <% end %> @@ -33,12 +16,45 @@ <% else %> replied <% end %> - on <strong><%= simple_date(incoming_message.sent_at) - %></strong> + on <strong><%= simple_date(incoming_message.sent_at) %></strong> <% if not incoming_message.user_classified %> — please <%= link_to "classify this response", classify_request_url(:incoming_message_id => incoming_message.id) %> <% end %> </p> +<% elsif (correspondence.class.to_s == 'InfoRequestEvent') + info_request_event = correspondence + if info_request_event.event_type == 'sent' + outgoing_message = OutgoingMessage.find(info_request_event.params[:outgoing_message_id]) + %> + <%= render :partial => 'bubble', :locals => { :body => outgoing_message.get_body_for_display() } %> + + <p class="event_bubble"> + <%= user_link(@info_request.user) %> + + <% if outgoing_message.message_type == 'initial_request' %> + sent the initial request + <% if outgoing_message.status == 'sent' %> + to <%= public_body_link(@info_request.public_body) %> + on <strong><%= simple_date(outgoing_message.sent_at) %></strong> + <% elsif outgoing_message.status == 'ready' %> + it has <strong>not yet been sent</strong> + <% else raise "unknown outgoing_message.status" %> + <% end %> + <% else raise "unknown outgoing_message.message_type" %> + <% end %> + </p> + <% elsif info_request_event.event_type == 'resent' %> + <p class="event_plain"> + Sent to <%= public_body_link(@info_request.public_body) %> + again (perhaps to a new contact address) <!-- XXX actually say if it is a new one or not --> + on <strong><%= simple_date(info_request_event.sent_at) %></strong> + </p> + <% + end + if ['sent', 'resent'].include?(info_request_event.event_type) + @last_email = info_request_event.params[:email] + end + %> <% else %> <% raise "Unknown correspondence type " + correspondence.class.to_s %> <% end %> diff --git a/db/migrate/022_create_info_request_events.rb b/db/migrate/022_create_info_request_events.rb new file mode 100644 index 000000000..fe7450773 --- /dev/null +++ b/db/migrate/022_create_info_request_events.rb @@ -0,0 +1,24 @@ +class CreateInfoRequestEvents < ActiveRecord::Migration + def self.up + create_table :info_request_events do |t| + t.column "info_request_id", :integer + t.column :event_type, :text + t.column :params_yaml, :text + t.column :created_at, :datetime + end + + # Create the missing events for requests already sent + InfoRequest.find(:all).each do |info_request| + info_request_event = InfoRequestEvent.new + info_request_event.event_type = 'sent' + info_request_event.params = { :email => info_request.recipient_email, :outgoing_message_id => info_request.outgoing_messages[0].id } + info_request_event.info_request = info_request + info_request_event.created_at = info_request.outgoing_messages[0].sent_at + info_request_event.save! + end + end + + def self.down + drop_table :info_request_events + end +end diff --git a/db/schema.rb b/db/schema.rb index b8fbac966..f2032fdc5 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -2,7 +2,7 @@ # migrations feature of ActiveRecord to incrementally modify your database, and # then regenerate this schema definition. -ActiveRecord::Schema.define(:version => 21) do +ActiveRecord::Schema.define(:version => 22) do create_table "incoming_messages", :force => true do |t| t.column "info_request_id", :integer @@ -13,6 +13,13 @@ ActiveRecord::Schema.define(:version => 21) do t.column "contains_information", :boolean end + create_table "info_request_events", :force => true do |t| + t.column "info_request_id", :integer + t.column "event_type", :text + t.column "params_yaml", :text + t.column "created_at", :datetime + end + create_table "info_requests", :force => true do |t| t.column "title", :text t.column "user_id", :integer diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css index b4615b648..aa54ada4d 100644 --- a/public/stylesheets/main.css +++ b/public/stylesheets/main.css @@ -356,5 +356,12 @@ table#list_requests .odd { color: #999999; } -.xspeaker { margin: -0.5em 1.5em; } +.event_bubble { + margin: -0.5em 1.5em; +} + +.event_plain { + margin-left: 1.5em; +} + @@ -21,7 +21,9 @@ DTI CAM one Next ==== -sent_at - record when resent +Make response messages go to a mailbox as backup + +Add fixtures for info_request_event Track bounce messages via a separate address - just record if they are bounce, and any DSN, for now |