aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb40
-rw-r--r--app/models/incoming_message.rb4
-rw-r--r--app/models/info_request.rb52
-rw-r--r--app/models/info_request_event.rb5
-rw-r--r--app/models/outgoing_message.rb4
-rw-r--r--app/models/post_redirect.rb4
-rw-r--r--app/models/public_body.rb4
-rw-r--r--app/models/user.rb4
-rw-r--r--app/views/admin_request/show.rhtml1
-rw-r--r--app/views/request/_describe_state.rhtml1
-rw-r--r--app/views/request/describe_state.rhtml8
-rw-r--r--app/views/request/show.rhtml6
-rw-r--r--db/migrate/029_add_describe_status_history.rb11
-rw-r--r--db/schema.rb18
-rw-r--r--spec/controllers/request_controller_spec.rb6
-rw-r--r--spec/fixtures/info_request_events.yml3
-rw-r--r--spec/fixtures/info_requests.yml6
-rw-r--r--todo.txt7
18 files changed, 117 insertions, 67 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index f732cf687..cdb84434b 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.43 2008-02-01 15:27:48 francis Exp $
+# $Id: request_controller.rb,v 1.44 2008-02-06 09:41:43 francis Exp $
class RequestController < ApplicationController
@@ -16,7 +16,9 @@ class RequestController < ApplicationController
@date_response_required_by = @info_request.date_response_required_by
@collapse_quotes = params[:unfold] ? false : true
@is_owning_user = !authenticated_user.nil? && authenticated_user.id == @info_request.user_id
- @needing_description = @info_request.incoming_messages_needing_description
+ @events_needing_description = @info_request.events_needing_description
+ last_event = @events_needing_description[-1]
+ @last_info_request_event_id = last_event.nil? ? nil : last_event.id
end
def list
@@ -79,8 +81,6 @@ class RequestController < ApplicationController
# Page describing state of message posts to
def describe_state
@info_request = InfoRequest.find(params[:id])
- @needing_description = @info_request.incoming_messages_needing_description
- @is_owning_user = !authenticated_user.nil? && authenticated_user.id == @info_request.user_id
if not @info_request.awaiting_description
flash[:notice] = "The status of this request is up to date."
@@ -91,6 +91,18 @@ class RequestController < ApplicationController
return
end
+ @events_needing_description = @info_request.events_needing_description
+ last_event = @events_needing_description[-1]
+ @last_info_request_event_id = last_event.nil? ? nil : last_event.id
+ @is_owning_user = !authenticated_user.nil? && authenticated_user.id == @info_request.user_id
+
+ if @last_info_request_event_id.nil?
+ raise "mnoo " + @events_needing_description.size.to_s
+ flash[:notice] = "Internal error - awaiting description, but no event to describe"
+ redirect_to show_request_url(:id => @info_request)
+ return
+ end
+
if !params[:submitted_describe_state].nil?
if not authenticated_as_user?(@info_request.user,
:web => "To classify the response to this FOI request",
@@ -105,11 +117,21 @@ class RequestController < ApplicationController
flash[:error] = "Please choose whether or not you got some of the information that you wanted."
return
end
+
+ if params[:last_info_request_event_id].to_i != @last_info_request_event_id
+ flash[:error] = "The request has been updated since you originally loaded this page. Please check for any new incoming messages below, and try again."
+ return
+ end
+
+ ActiveRecord::Base.transaction do
+ @info_request.awaiting_description = false
+ last_event = InfoRequestEvent.find(@last_info_request_event_id)
+ last_event.described_state = params[:incoming_message][:described_state]
+ @info_request.described_state = params[:incoming_message][:described_state]
+ last_event.save!
+ @info_request.save!
+ end
- @info_request.awaiting_description = false
- @info_request.described_last_incoming_message_id = @needing_description[-1].id # XXX lock this with InfoRequest.receive
- @info_request.described_state = params[:incoming_message][:described_state]
- @info_request.save!
if @info_request.described_state == 'waiting_response'
flash[:notice] = "<p>Thank you! Hopefully your wait isn't too long.</p> <p>By law, you should get a response before the end of <strong>" + simple_date(@info_request.date_response_required_by) + "</strong>.</p>"
redirect_to show_request_url(:id => @info_request)
@@ -127,7 +149,7 @@ class RequestController < ApplicationController
redirect_to show_request_url(:id => @info_request)
elsif @info_request.described_state == 'waiting_clarification'
flash[:notice] = "Please write your follow up message containing the necessary clarifications below."
- redirect_to show_response_url(:id => @info_request.id, :incoming_message_id => @needing_description[-1].id)
+ redirect_to show_response_url(:id => @info_request.id, :incoming_message_id => @events_needing_description[-1].id)
else
raise "unknown described_state " + @info_request.described_state
end
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index fcd73508e..9c8d2fca9 100644
--- a/app/models/incoming_message.rb
+++ b/app/models/incoming_message.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# Table name: incoming_messages
#
@@ -18,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.37 2008-01-29 01:26:21 francis Exp $
+# $Id: incoming_message.rb,v 1.38 2008-02-06 09:41:44 francis Exp $
# TODO
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 8743a8572..68ace338a 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -1,17 +1,16 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# 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
-# described_state :string(255) not null
-# awaiting_description :boolean default(false), not null
-# described_last_incoming_message_id :integer
+# 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
#
# models/info_request.rb:
@@ -20,7 +19,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.33 2008-02-01 15:27:49 francis Exp $
+# $Id: info_request.rb,v 1.34 2008-02-06 09:41:44 francis Exp $
require 'digest/sha1'
@@ -49,7 +48,9 @@ class InfoRequest < ActiveRecord::Base
]
def after_initialize
- self.described_state = 'waiting_response'
+ if self.described_state.nil?
+ self.described_state = 'waiting_response'
+ end
end
public
@@ -225,15 +226,28 @@ public
return excerpt
end
- # Returns all the messages which the user hasn't described yet
- def incoming_messages_needing_description
- if self.described_last_incoming_message_id.nil?
- incoming_messages = self.incoming_messages.find(:all)
+ # Returns index of last event which is described or nil if none described.
+ def index_of_last_described_event
+ events = self.info_request_events.find(:all, :order => "created_at")
+ events.each_index do |i|
+ revi = events.size - 1 - i
+ m = events[revi]
+ if not m.described_state.nil?
+ return revi
+ end
+ end
+ return nil
+ end
+
+ # Returns all the events which the user hasn't described yet - an empty array if all described.
+ def events_needing_description
+ events = self.info_request_events.find(:all, :order => "created_at")
+ i = self.index_of_last_described_event
+ if i.nil?
+ return events
else
- incoming_messages = self.incoming_messages.find(:all, :conditions => "id > " + self.described_last_incoming_message_id.to_s)
+ return events[i + 1, events.size]
end
- incoming_messages.sort! { |a,b| a.sent_at <=> b.sent_at }
- return incoming_messages
end
protected
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index f291daca5..800acdf45 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# Table name: info_request_events
#
@@ -8,6 +8,7 @@
# event_type :text not null
# params_yaml :text not null
# created_at :datetime not null
+# described_state :string(255)
#
# models/info_request_event.rb:
@@ -15,7 +16,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.9 2008-02-01 15:27:49 francis Exp $
+# $Id: info_request_event.rb,v 1.10 2008-02-06 09:41:44 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 391308bd4..544ca87bc 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# 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.24 2008-01-29 01:26:21 francis Exp $
+# $Id: outgoing_message.rb,v 1.25 2008-02-06 09:41:44 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 864f2880f..f98591c44 100644
--- a/app/models/post_redirect.rb
+++ b/app/models/post_redirect.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# 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.14 2008-01-29 01:26:21 francis Exp $
+# $Id: post_redirect.rb,v 1.15 2008-02-06 09:41:44 francis Exp $
require 'openssl' # for random bytes function
diff --git a/app/models/public_body.rb b/app/models/public_body.rb
index 5e90ca9ec..2b367a84d 100644
--- a/app/models/public_body.rb
+++ b/app/models/public_body.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# 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.15 2008-01-29 01:26:21 francis Exp $
+# $Id: public_body.rb,v 1.16 2008-02-06 09:41:44 francis Exp $
class PublicBody < ActiveRecord::Base
validates_presence_of :name
diff --git a/app/models/user.rb b/app/models/user.rb
index 13a57ec92..7b23a1155 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 27
+# Schema version: 29
#
# 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.23 2008-01-29 01:26:21 francis Exp $
+# $Id: user.rb,v 1.24 2008-02-06 09:41:44 francis Exp $
require 'digest/sha1'
diff --git a/app/views/admin_request/show.rhtml b/app/views/admin_request/show.rhtml
index 6e4c432d6..769235fb4 100644
--- a/app/views/admin_request/show.rhtml
+++ b/app/views/admin_request/show.rhtml
@@ -10,7 +10,6 @@
<strong>Public body:</strong> <%=h @info_request.public_body.name %> <br>
<strong>Incoming email address:</strong> <%=h @info_request.incoming_email %> <br>
<strong>Envelope email address:</strong> <%=h @info_request.envelope_email %> <br>
-<strong>Described last incoming message id:</strong> <%=h @info_request.described_last_incoming_message_id.nil? ? "nil" : @info_request.described_last_incoming_message_id %>
</p>
<%= link_to 'Public page', main_url(request_url(@info_request)) %>
diff --git a/app/views/request/_describe_state.rhtml b/app/views/request/_describe_state.rhtml
index 068a9fdd5..d1bfb1d95 100644
--- a/app/views/request/_describe_state.rhtml
+++ b/app/views/request/_describe_state.rhtml
@@ -20,6 +20,7 @@
<p>Filling this in each time you get a new response helps us track the progress of your request.
</p>
+ <%= hidden_field_tag 'last_info_request_event_id', @last_info_request_event_id %>
<%= hidden_field_tag 'submitted_describe_state', 1 %>
<%= submit_tag "Next >>" %>
<% end %>
diff --git a/app/views/request/describe_state.rhtml b/app/views/request/describe_state.rhtml
index 9f8b4afe8..47ab3c232 100644
--- a/app/views/request/describe_state.rhtml
+++ b/app/views/request/describe_state.rhtml
@@ -1,4 +1,4 @@
-<% @title = MySociety::Format.fancy_pluralize(@needing_description.size, 'New response', 'new responses') +
+<% @title = MySociety::Format.fancy_pluralize(@events_needing_description.size, 'New response', 'new responses') +
" to '" + h(@info_request.title) + "'" %>
<%= foi_error_messages_for :incoming_message, :outgoing_message %>
@@ -8,11 +8,11 @@
</div>
<div id="show_response_view">
- <h2><%=MySociety::Format.fancy_pluralize(@needing_description.size, 'New response', 'new responses') %>
+ <h2><%=MySociety::Format.fancy_pluralize(@events_needing_description.size, 'New response', 'new responses') %>
to your request '<%= request_link @info_request %>'</h2>
- <% for incoming_message in @needing_description %>
- <%= render :partial => 'correspondence', :locals => { :info_request_event => nil, :incoming_message => incoming_message } %>
+ <% for info_request_event in @events_needing_description %>
+ <%= render :partial => 'correspondence', :locals => { :info_request_event => info_request_event } %>
<% end %>
</div>
diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml
index 681e64f4a..c438d7583 100644
--- a/app/views/request/show.rhtml
+++ b/app/views/request/show.rhtml
@@ -19,11 +19,11 @@
<% if @info_request.awaiting_description %>
<% if @is_owning_user %>
Please <strong>answer the question above</strong> so we know whether the
- <%= MySociety::Format.fancy_pluralize(@needing_description.size, 'recent response contains', 'recent responses contain') %> useful information.
+ <%= MySociety::Format.fancy_pluralize(@events_needing_description.size, 'recent response contains', 'recent responses contain') %> useful information.
<% else %>
This request has an <strong>unknown status</strong>. We're waiting for
<%= user_link(@info_request.user) %> to read
- <%= MySociety::Format.fancy_pluralize(@needing_description.size, 'a recent response', 'recent responses') %>
+ <%= MySociety::Format.fancy_pluralize(@events_needing_description.size, 'a recent response', 'recent responses') %>
and update the status.
<% end %>
<% elsif @status == 'waiting_response' %>
@@ -49,7 +49,7 @@
</p>
<% for info_request_event in @info_request_events %>
- <%= render :partial => 'correspondence', :locals => { :info_request_event => info_request_event, :incoming_message => nil } %>
+ <%= render :partial => 'correspondence', :locals => { :info_request_event => info_request_event } %>
<% end %>
</div>
diff --git a/db/migrate/029_add_describe_status_history.rb b/db/migrate/029_add_describe_status_history.rb
new file mode 100644
index 000000000..0c6095d69
--- /dev/null
+++ b/db/migrate/029_add_describe_status_history.rb
@@ -0,0 +1,11 @@
+class AddDescribeStatusHistory < ActiveRecord::Migration
+ def self.up
+ add_column :info_request_events, :described_state, :string
+ remove_column :info_requests, :described_last_incoming_message_id
+ end
+
+ def self.down
+ remove_column :info_request_events, :described_state
+ add_column :info_requests, :described_last_incoming_message_id, :integer
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 79fdc7e86..6632f5de9 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 28) do
+ActiveRecord::Schema.define(:version => 29) do
create_table "incoming_messages", :force => true do |t|
t.integer "info_request_id", :null => false
@@ -24,17 +24,17 @@ ActiveRecord::Schema.define(:version => 28) do
t.text "event_type", :null => false
t.text "params_yaml", :null => false
t.datetime "created_at", :null => false
+ t.string "described_state"
end
create_table "info_requests", :force => true do |t|
- t.text "title", :null => false
- t.integer "user_id", :null => false
- t.integer "public_body_id", :null => false
- t.datetime "created_at", :null => false
- t.datetime "updated_at", :null => false
- t.string "described_state", :null => false
- t.boolean "awaiting_description", :default => false, :null => false
- t.integer "described_last_incoming_message_id"
+ t.text "title", :null => false
+ t.integer "user_id", :null => false
+ t.integer "public_body_id", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ t.string "described_state", :null => false
+ t.boolean "awaiting_description", :default => false, :null => false
end
create_table "outgoing_messages", :force => true do |t|
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 0aa873d08..07a856585 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -166,21 +166,21 @@ describe RequestController, "when classifying an individual response" do
fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :outgoing_messages # all needed as integrating views
it "should require login" do
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_describe_state => 1
+ post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1
post_redirect = PostRedirect.get_last_post_redirect
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
it "should not classify response if logged in as wrong user" do
session[:user_id] = users(:silly_name_user).id
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_describe_state => 1
+ post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1
response.should render_template('user/wrong_user')
end
it "should successfully classify response if logged in as user controlling request" do
info_requests(:fancy_dog_request).awaiting_description.should == true
session[:user_id] = users(:bob_smith_user).id
- post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :submitted_describe_state => 1
+ post :describe_state, :incoming_message => { :described_state => "rejected" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:useless_incoming_message_event).id, :submitted_describe_state => 1
response.should redirect_to(:controller => 'help', :action => 'unhappy')
info_requests(:fancy_dog_request).reload
info_requests(:fancy_dog_request).awaiting_description.should == false
diff --git a/spec/fixtures/info_request_events.yml b/spec/fixtures/info_request_events.yml
index 260688999..af8869511 100644
--- a/spec/fixtures/info_request_events.yml
+++ b/spec/fixtures/info_request_events.yml
@@ -5,6 +5,7 @@ useless_outgoing_message_event:
info_request_id: 101
event_type: sent
created_at: 2007-10-25 10:41:12.686264
+ described_state:
silly_outgoing_message_event:
params_yaml: "--- \n\
:outgoing_message_id: 2\n"
@@ -12,6 +13,7 @@ silly_outgoing_message_event:
info_request_id: 103
event_type: sent
created_at: 2007-10-14 10:41:12.686264
+ described_state:
useless_incoming_message_event:
params_yaml: "--- \n\
:incoming_message_id: 1\n"
@@ -19,3 +21,4 @@ useless_incoming_message_event:
info_request_id: 101
event_type: response
created_at: 2007-11-13 18:09:20.042061
+ described_state:
diff --git a/spec/fixtures/info_requests.yml b/spec/fixtures/info_requests.yml
index 3fc3ea7f4..d9aa0d627 100644
--- a/spec/fixtures/info_requests.yml
+++ b/spec/fixtures/info_requests.yml
@@ -5,9 +5,8 @@ fancy_dog_request:
updated_at: 2007-10-11 18:15:57
public_body_id: 2
user_id: 1
- described_state: awaiting_response
+ described_state: waiting_response
awaiting_description: true
- described_last_incoming_message_id: nil
naughty_chicken_request:
id: 103
title: How much public money is wasted on breeding naughty chickens?
@@ -15,8 +14,7 @@ naughty_chicken_request:
updated_at: 2007-10-13 18:15:57
public_body_id: 2
user_id: 1
- described_state: awaiting_response
+ described_state: waiting_response
awaiting_description: false
- described_last_incoming_message_id: nil
diff --git a/todo.txt b/todo.txt
index 318e7c663..db16f67a4 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,7 +1,7 @@
-hack storing better info so know when state changed for stats purpose, and for RSS ordering
-
-how do we change the state when a follow up is sent?
+we change the state when a follow up is sent
+events_needing_description.size in views wrong
+check goes to describe URL from email
FOI requests to use to test it
==============================
@@ -26,6 +26,7 @@ Status of messages stuff
========================
Add - response was made in private state
+or maybe 'response refusing to publish for spurious reasons
Sort out state vs. status vs. describe vs. classify