diff options
-rw-r--r-- | app/controllers/request_controller.rb | 12 | ||||
-rw-r--r-- | app/models/info_request_event.rb | 5 | ||||
-rw-r--r-- | app/views/admin_general/timeline.rhtml | 2 | ||||
-rw-r--r-- | spec/controllers/request_controller_spec.rb | 21 |
4 files changed, 37 insertions, 3 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 0c3ee596f..2605a7e05 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.156 2009-04-14 13:36:32 louise Exp $ +# $Id: request_controller.rb,v 1.157 2009-04-15 18:15:30 louise Exp $ class RequestController < ApplicationController @@ -275,8 +275,18 @@ class RequestController < ApplicationController end # Make the state change + old_described_state = @info_request.described_state @info_request.set_described_state(params[:incoming_message][:described_state]) + # Log it if not made by user + if authenticated_user != @info_request.user + @info_request.log_event("status_update", + { :user_id => authenticated_user.id, + :old_described_state => old_described_state, + :described_state => @info_request.described_state, + }) + end + if User.owns_every_request?(authenticated_user) flash[:notice] = '<p>The request status has been updated</p>' redirect_to request_url(@info_request) diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb index 05d2ce50a..1a96723a0 100644 --- a/app/models/info_request_event.rb +++ b/app/models/info_request_event.rb @@ -21,7 +21,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.79 2009-04-13 09:18:48 tony Exp $ +# $Id: info_request_event.rb,v 1.80 2009-04-15 18:15:30 louise Exp $ class InfoRequestEvent < ActiveRecord::Base belongs_to :info_request @@ -47,7 +47,8 @@ class InfoRequestEvent < ActiveRecord::Base 'redeliver_incoming', # redelivered an incoming message elsewhere 'manual', # you did something in the db by hand 'response', - 'comment' + 'comment', + 'status_update' ] # user described state (also update in info_request) diff --git a/app/views/admin_general/timeline.rhtml b/app/views/admin_general/timeline.rhtml index 25e871232..21e4a1637 100644 --- a/app/views/admin_general/timeline.rhtml +++ b/app/views/admin_general/timeline.rhtml @@ -79,6 +79,8 @@ had a follow up message sent to <%=h event.info_request.public_body.name %>. <% elsif event.event_type == 'comment' %> had an annotation posted by <%=h event.comment.user.name %>. + <% elsif event.event_type == 'status_update' %> + had its status updated by <%=h User.find(event.params[:user_id]).name %> from '<%= h event.params[:old_described_state] %>' to '<%= h event.params[:described_state] %>'. <% else %> had '<%=event.event_type%>' done to it, parameters <%=h event.params_yaml%>. <% end %> diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index e3b1ebc5a..57d092afb 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -365,6 +365,14 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end + it 'should log a status update event' do + expected_params = {:user_id => users(:silly_name_user).id, + :old_described_state => 'waiting_response', + :described_state => 'rejected'} + @dog_request.should_receive(:log_event).with("status_update", expected_params) + 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') @@ -398,6 +406,14 @@ describe RequestController, "when classifying an information request" do post_status('rejected') end + it 'should log a status update event' do + expected_params = {:user_id => @admin_user.id, + :old_described_state => 'waiting_response', + :described_state => 'rejected'} + @dog_request.should_receive(:log_event).with("status_update", expected_params) + post_status('rejected') + end + it 'should show the message "The request status has been updated"' do post_status('rejected') flash[:notice].should == '<p>The request status has been updated</p>' @@ -428,6 +444,11 @@ describe RequestController, "when classifying an information request" do @dog_request.get_last_response_event.calculated_state.should == 'rejected' end + it 'should not log a status update event' do + @dog_request.should_not_receive(:log_event) + post_status('rejected') + end + 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') |