aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/request_controller.rb16
-rw-r--r--app/views/request/_describe_state.rhtml19
-rw-r--r--app/views/request/_other_describe_state.rhtml72
-rw-r--r--public/stylesheets/main.css2
-rw-r--r--spec/controllers/request_controller_spec.rb165
-rw-r--r--spec/views/request/_describe_state.rhtml_spec.rb42
6 files changed, 245 insertions, 71 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index ae4f3a229..0c3ee596f 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.155 2009-04-07 10:32:54 louise Exp $
+# $Id: request_controller.rb,v 1.156 2009-04-14 13:36:32 louise Exp $
class RequestController < ApplicationController
@@ -26,6 +26,7 @@ class RequestController < ApplicationController
@collapse_quotes = params[:unfold] ? false : true
@update_status = params[:update_status] ? true : false
@is_owning_user = @info_request.is_owning_user?(authenticated_user)
+ @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil?
if @update_status
return if !@is_owning_user && !authenticated_as_user?(@info_request.user,
@@ -248,11 +249,11 @@ class RequestController < ApplicationController
@is_owning_user = @info_request.is_owning_user?(authenticated_user)
@events_needing_description = @info_request.events_needing_description
@last_info_request_event_id = @info_request.last_event_id_needing_description
- @new_responses_count = @events_needing_description.select {|i| i.event_type == 'response'}.size
-
+ @old_unclassified = @info_request.is_old_unclassified? && !authenticated_user.nil?
+
# Check authenticated, and parameters set. We check is_owning_user
# to get admin overrides (see owns_every_request? above)
- if !@is_owning_user && !authenticated_as_user?(@info_request.user,
+ if !@old_unclassified && !@is_owning_user && !authenticated_as_user?(@info_request.user,
:web => "To classify the response to this FOI request",
:email => "Then you can classify the FOI response you have got from " + @info_request.public_body.name + ".",
:email_subject => "Classify an FOI response from " + @info_request.public_body.name
@@ -281,6 +282,13 @@ class RequestController < ApplicationController
redirect_to request_url(@info_request)
return
end
+
+ if @old_unclassified && !@is_owning_user
+ flash[:notice] = '<p>Thank you for updating this request!</p>'
+ RequestMailer.deliver_old_unclassified_updated(@info_request)
+ redirect_to request_url(@info_request)
+ return
+ end
# Display appropriate next page (e.g. help for complaint etc.)
if @info_request.calculate_status == 'waiting_response'
diff --git a/app/views/request/_describe_state.rhtml b/app/views/request/_describe_state.rhtml
index 8b3ac2cf3..f75a76c4d 100644
--- a/app/views/request/_describe_state.rhtml
+++ b/app/views/request/_describe_state.rhtml
@@ -93,14 +93,17 @@
<%= submit_tag "Submit status" %> (and we'll suggest <strong>what to do next</strong>)
</p>
<% end %>
+<% elsif @old_unclassified %>
+ <%= render :partial => 'other_describe_state', :locals => {:id_suffix => id_suffix } %>
<% else %>
- We don't know whether the most recent response to this request contains
- information or not
- &ndash;
- if you are
- <%= user_link(@info_request.user) %>,
- please
- <%= link_to "sign in", signin_url(:r => request.request_uri) %>
- and let everyone know.
+ We don't know whether the most recent response to this request contains
+ information or not
+ &ndash;
+ if you are
+ <%= user_link(@info_request.user) %>,
+ please
+ <%= link_to "sign in", signin_url(:r => request.request_uri) %>
+ and let everyone know.
+
<% end %>
diff --git a/app/views/request/_other_describe_state.rhtml b/app/views/request/_other_describe_state.rhtml
new file mode 100644
index 000000000..6bfff9b2a
--- /dev/null
+++ b/app/views/request/_other_describe_state.rhtml
@@ -0,0 +1,72 @@
+
+
+<% form_for(:incoming_message, @info_request, :url => describe_state_url(:id => @info_request.id)) do |f| %>
+ <h2>Can you help us by describing the status of this request now?</h2>
+
+ <hr> <!------------------------------------------------>
+
+ <% if @info_request.described_state != 'internal_review' %>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "waiting_response", :id => 'waiting_response' + id_suffix %>
+ <label for="waiting_response<%=id_suffix%>"> <strong>No response</strong> has been received</label>
+ </div>
+ <% end %>
+ <% if @info_request.described_state == 'internal_review' %>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "internal_review", :id => 'internal_review' + id_suffix %>
+ <label for="internal_review<%=id_suffix%>">Still awaiting an <strong>internal review</strong></label>
+ </div>
+ <% end %>
+
+ <% if @info_request.described_state != 'internal_review' %>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "waiting_clarification", :id => 'waiting_clarification' + id_suffix %>
+ <label for="waiting_clarification<%=id_suffix%>"><strong>Clarification</strong> has been requested</label>
+ </div>
+ <% end %>
+
+ <div>
+ <%= radio_button "incoming_message", "described_state", "gone_postal", :id => 'gone_postal' + id_suffix %>
+ <label for="gone_postal<%=id_suffix%>">A response will be sent <strong>by post</strong></label>
+ </div>
+
+ <hr> <!------------------------------------------------>
+
+ <% if @info_request.described_state == 'internal_review' %>
+ <p>The <strong>review has finished</strong> and overall:</p>
+ <% end %>
+
+ <div>
+ <%= radio_button "incoming_message", "described_state", "not_held", :id => 'not_held' + id_suffix %>
+ <label for="not_held<%=id_suffix%>">The authority do <strong>not have</strong> the information <small>(maybe they say who does)</small></label>
+ </div>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "partially_successful", :id => 'partially_successful' + id_suffix %>
+ <label for="partially_successful<%=id_suffix%>"><strong>Some of the information</strong> has been sent </label>
+ </div>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "successful", :id => 'successful' + id_suffix %>
+ <label for="successful<%=id_suffix%>"><strong>All the information</strong> has been sent</label>
+ </div>
+ <div>
+ <%= radio_button "incoming_message", "described_state", "rejected", :id => 'rejected' + id_suffix %>
+ <label for="rejected<%=id_suffix%>">The request has been <strong>rejected</strong></label>
+ </div>
+
+ <hr> <!------------------------------------------------>
+
+ <div>
+ <%= radio_button "incoming_message", "described_state", "error_message", :id => 'error_message' + id_suffix %>
+ <label for="error_message<%=id_suffix%>">
+ An <strong>error message</strong> has been received
+ </label>
+ </div>
+
+ <hr>
+
+ <p>
+ <%= hidden_field_tag 'last_info_request_event_id', @last_info_request_event_id, :id => 'last_info_request_event_id' + id_suffix %>
+ <%= hidden_field_tag 'submitted_describe_state', 1, :id => 'submitted_describe_state' + id_suffix %>
+ <%= submit_tag "Submit status" %>
+ </p>
+<% end %>
diff --git a/public/stylesheets/main.css b/public/stylesheets/main.css
index d9ccd7224..809de9862 100644
--- a/public/stylesheets/main.css
+++ b/public/stylesheets/main.css
@@ -631,7 +631,7 @@ div.pagination { text-align: center; padding-top: 0.3em;}
}
/*-------------------- Content : action notice */
-#notice, .describe_state_form, .undescribed_requests, .gone_postal_help
+#notice, .describe_state_form, .undescribed_requests, .other_describe_state_form, .gone_postal_help
{
color: #16C132;
font-size: 1.4em;
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index 950682ca7..e3b1ebc5a 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -304,25 +304,85 @@ describe RequestController, "when classifying an information request" do
fixtures :info_requests, :info_request_events, :public_bodies, :users, :incoming_messages, :raw_emails, :outgoing_messages, :comments # all needed as integrating views
- def post_rejected_status
- post :describe_state, :incoming_message => { :described_state => "rejected" },
- :id => info_requests(:fancy_dog_request).id,
- :last_info_request_event_id => info_request_events(:silly_comment_event).id,
+ before do
+ @dog_request = info_requests(:fancy_dog_request)
+ @dog_request.stub!(:is_old_unclassified?).and_return(false)
+ InfoRequest.stub!(:find).and_return(@dog_request)
+ end
+
+ def post_status(status)
+ post :describe_state, :incoming_message => { :described_state => status },
+ :id => @dog_request.id,
+ :last_info_request_event_id => @dog_request.last_event_id_needing_description,
:submitted_describe_state => 1
end
-
+
it "should require login" do
- post_rejected_status
+ post_status('rejected')
post_redirect = PostRedirect.get_last_post_redirect
response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
end
- it "should not classify the reqest if logged in as the wrong user" do
+ it 'should ask whether the request is old and unclassified' do
+ @dog_request.should_receive(:is_old_unclassified?)
+ post_status('rejected')
+ end
+
+ it "should not classify the request if logged in as the wrong user" do
session[:user_id] = users(:silly_name_user).id
- post_rejected_status
+ post_status('rejected')
response.should render_template('user/wrong_user')
end
+ describe 'when the request is old and unclassified' do
+
+ before do
+ @dog_request.stub!(:is_old_unclassified?).and_return(true)
+ RequestMailer.stub!(:deliver_old_unclassified_updated)
+ end
+
+ describe 'when the user is not logged in' do
+
+ it 'should require login' do
+ session[:user_id] = nil
+ post_status('rejected')
+ post_redirect = PostRedirect.get_last_post_redirect
+ response.should redirect_to(:controller => 'user', :action => 'signin', :token => post_redirect.token)
+ end
+
+ end
+
+ describe 'when the user is logged in as a different user' do
+
+ before do
+ @other_user = mock_model(User)
+ session[:user_id] = users(:silly_name_user).id
+ end
+
+ it 'should classify the request' do
+ @dog_request.stub!(:calculate_status).and_return('rejected')
+ @dog_request.should_receive(:set_described_state).with('rejected')
+ post_status('rejected')
+ end
+
+ it 'should send an email to the requester letting them know someone has updated the status of their request' do
+ RequestMailer.should_receive(:deliver_old_unclassified_updated)
+ post_status('rejected')
+ end
+
+ it 'should redirect to the request page' do
+ post_status('rejected')
+ response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
+ end
+
+ it 'should show a message thanking the user for a good deed' do
+ post_status('rejected')
+ flash[:notice].should == '<p>Thank you for updating this request!</p>'
+ end
+
+ end
+ end
+
describe 'when logged in as an admin user' do
before do
@@ -332,55 +392,63 @@ describe RequestController, "when classifying an information request" do
InfoRequest.stub!(:find).and_return(@dog_request)
end
- it 'should update the status of the request if the request requires admin' do
+ it 'should update the status of the request' do
@dog_request.stub!(:calculate_status).and_return('rejected')
@dog_request.should_receive(:set_described_state).with('rejected')
- post_rejected_status
+ post_status('rejected')
end
it 'should show the message "The request status has been updated"' do
- post_rejected_status
+ post_status('rejected')
flash[:notice].should == '<p>The request status has been updated</p>'
end
it 'should redirect to the page that shows the request' do
- post_rejected_status
+ post_status('rejected')
response.should redirect_to(:action => 'show', :controller => 'request', :url_title => @dog_request.url_title)
end
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,
- :last_info_request_event_id => info_request_events(:silly_comment_event).id,
- :submitted_describe_state => 1
- response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => info_requests(:fancy_dog_request).url_title)
- info_requests(:fancy_dog_request).reload
- info_requests(:fancy_dog_request).awaiting_description.should == false
- info_requests(:fancy_dog_request).described_state.should == 'rejected'
- info_requests(:fancy_dog_request).get_last_response_event.should == info_request_events(:useless_incoming_message_event)
- info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'rejected'
- end
+ describe 'when logged in as the requestor' do
+
+ before do
+ @request_owner = users(:bob_smith_user)
+ session[:user_id] = @request_owner.id
+ @dog_request.awaiting_description.should == true
+ end
+
+ it "should successfully classify response if logged in as user controlling request" do
+ post_status('rejected')
+ response.should redirect_to(:controller => 'help', :action => 'unhappy', :url_title => @dog_request.url_title)
+ @dog_request.reload
+ @dog_request.awaiting_description.should == false
+ @dog_request.described_state.should == 'rejected'
+ @dog_request.get_last_response_event.should == info_request_events(:useless_incoming_message_event)
+ @dog_request.get_last_response_event.calculated_state.should == 'rejected'
+ end
- it "should send email when classified as requires_admin" 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 => "requires_admin" }, :id => info_requests(:fancy_dog_request).id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => info_request_events(:silly_comment_event).id, :submitted_describe_state => 1
- response.should redirect_to(:controller => 'help', :action => 'contact')
+ it 'should not send an email to the requester letting them know someone has updated the status of their request' do
+ RequestMailer.should_not_receive(:deliver_old_unclassified_updated)
+ post_status('rejected')
+ end
+
+ it "should send email when classified as requires_admin" do
+ post :describe_state, :incoming_message => { :described_state => "requires_admin" }, :id => @dog_request.id, :incoming_message_id => incoming_messages(:useless_incoming_message), :last_info_request_event_id => @dog_request.last_event_id_needing_description, :submitted_describe_state => 1
+ response.should redirect_to(:controller => 'help', :action => 'contact')
- info_requests(:fancy_dog_request).reload
- info_requests(:fancy_dog_request).awaiting_description.should == false
- info_requests(:fancy_dog_request).described_state.should == 'requires_admin'
- info_requests(:fancy_dog_request).get_last_response_event.calculated_state.should == 'requires_admin'
+ @dog_request.reload
+ @dog_request.awaiting_description.should == false
+ @dog_request.described_state.should == 'requires_admin'
+ @dog_request.get_last_response_event.calculated_state.should == 'requires_admin'
- deliveries = ActionMailer::Base.deliveries
- deliveries.size.should == 1
- mail = deliveries[0]
- mail.body.should =~ /as needing admin/
- mail.from_addrs.to_s.should == users(:bob_smith_user).name_and_email
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.body.should =~ /as needing admin/
+ mail.from_addrs.to_s.should == @request_owner.name_and_email
+ end
+
end
describe 'when redirecting after a successful status update by the request owner' do
@@ -392,11 +460,8 @@ describe RequestController, "when classifying an information request" do
InfoRequest.stub!(:find).and_return(@dog_request)
end
- def post_status(status)
- post :describe_state, :incoming_message => { :described_state => status },
- :id => @dog_request.id,
- :last_info_request_event_id => @dog_request.last_event_id_needing_description,
- :submitted_describe_state => 1
+ def request_url
+ "request/#{@dog_request.url_title}"
end
def expect_redirect(status, redirect_path)
@@ -412,16 +477,16 @@ describe RequestController, "when classifying an information request" do
it 'should redirect to the "request url" with a message in the right tense when status is updated to "waiting response" and the response is overdue' do
@dog_request.stub!(:date_response_required_by).and_return(Time.now.to_date-1)
- expect_redirect('waiting_response', "request/#{@dog_request.url_title}")
+ expect_redirect('waiting_response', request_url)
flash[:notice].should match(/should have got a response/)
end
it 'should redirect to the "request url" when status is updated to "not held"' do
- expect_redirect('not_held', "request/#{@dog_request.url_title}")
+ expect_redirect('not_held', request_url)
end
it 'should redirect to the "request url" when status is updated to "successful"' do
- expect_redirect('successful', "request/#{@dog_request.url_title}")
+ expect_redirect('successful', request_url)
end
it 'should redirect to the "unhappy url" when status is updated to "rejected"' do
@@ -448,7 +513,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should redirect to the "request url" when status is updated to "internal review"' do
- expect_redirect('internal_review', "request/#{@dog_request.url_title}")
+ expect_redirect('internal_review', request_url)
end
it 'should redirect to the "help general url" when status is updated to "requires admin"' do
@@ -460,7 +525,7 @@ describe RequestController, "when classifying an information request" do
end
it 'should redirect to the "request url" when status is updated to "user_withdrawn"' do
- expect_redirect('user_withdrawn', "request/#{@dog_request.url_title}")
+ expect_redirect('user_withdrawn', request_url)
end
end
diff --git a/spec/views/request/_describe_state.rhtml_spec.rb b/spec/views/request/_describe_state.rhtml_spec.rb
index ebb1d5a91..8460013d3 100644
--- a/spec/views/request/_describe_state.rhtml_spec.rb
+++ b/spec/views/request/_describe_state.rhtml_spec.rb
@@ -22,20 +22,46 @@ describe 'when showing the form for describing the state of a request' do
assigns[:info_request] = @mock_request
end
- describe 'if the user is a regular user' do
+ describe 'if the user is a regular user (not the request owner)' do
before do
assigns[:is_owning_user] = false
end
- it 'should not show the form' do
- do_render
- response.should_not have_tag('form')
- end
+ describe 'if the request is not old and unclassified' do
+
+ it 'should not show the form' do
+ do_render
+ response.should_not have_tag('h2', :text => 'What best describes the status of this request now?')
+ end
- it 'should give a link to login' do
- do_render
- response.should have_tag('a', :text => 'sign in')
+ it 'should give a link to login' do
+ do_render
+ response.should have_tag('a', :text => 'sign in')
+ end
+
+ end
+
+ describe 'if the request is old and unclassified' do
+
+ before do
+ assigns[:old_unclassified] = true
+ end
+
+ it 'should not show the form' do
+ do_render
+ response.should_not have_tag('h2', :text => 'What best describes the status of this request now?')
+ end
+
+ it 'should show the form for someone else to classify the request' do
+ do_render
+ response.should have_tag('h2', :text => 'Can you help us by describing the status of this request now?')
+ end
+
+ it 'should not give a link to login' do
+ do_render
+ response.should_not have_tag('a', :text => 'sign in')
+ end
end
end