diff options
-rw-r--r-- | app/controllers/admin_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/admin_request_controller.rb | 23 | ||||
-rw-r--r-- | spec/controllers/admin_request_controller_spec.rb | 105 |
3 files changed, 104 insertions, 26 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index d8fda9c01..08528f8a8 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -36,7 +36,7 @@ class AdminController < ApplicationController # also force a search reindexing (so changed text reflected in search) info_request.reindex_request_events - # and remove from varnsi + # and remove from varnish info_request.purge_in_cache end diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index fd1405319..dba4955dc 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -28,8 +28,8 @@ class AdminRequestController < AdminController @info_request = InfoRequest.find(params[:id]) # XXX is this *really* the only way to render a template to a # variable, rather than to the response? - vars = OpenStruct.new(:name_to => @info_request.user.name, - :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'), + vars = OpenStruct.new(:name_to => @info_request.user.name, + :name_from => MySociety::Config.get("CONTACT_NAME", 'Alaveteli'), :info_request => @info_request, :reason => params[:reason], :info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(@info_request), :site_name => site_name) @@ -81,6 +81,8 @@ class AdminRequestController < AdminController :old_handle_rejected_responses => old_handle_rejected_responses, :handle_rejected_responses => @info_request.handle_rejected_responses, :old_tag_string => old_tag_string, :tag_string => @info_request.tag_string }) + # expire cached files + expire_for_request(@info_request) flash[:notice] = 'Request successfully updated.' redirect_to request_admin_url(@info_request) else @@ -95,7 +97,8 @@ class AdminRequestController < AdminController url_title = @info_request.url_title @info_request.fully_destroy - + # expire cached files + expire_for_request(@info_request) flash[:notice] = "Request #{url_title} has been completely destroyed. Email of user who made request: " + user.email redirect_to admin_url('request/list') end @@ -166,7 +169,8 @@ class AdminRequestController < AdminController @incoming_message.fully_destroy @incoming_message.info_request.log_event("destroy_incoming", { :editor => admin_http_auth_user(), :deleted_incoming_message_id => incoming_message_id }) - + # expire cached files + expire_for_request(@info_request) flash[:notice] = 'Incoming message successfully destroyed.' redirect_to request_admin_url(@info_request) end @@ -174,6 +178,7 @@ class AdminRequestController < AdminController def redeliver_incoming incoming_message = IncomingMessage.find(params[:redeliver_incoming_message_id]) message_ids = params[:url_title].split(",").each {|x| x.strip} + previous_request = incoming_message.info_request destination_request = nil ActiveRecord::Base.transaction do for m in message_ids @@ -184,7 +189,7 @@ class AdminRequestController < AdminController end if destination_request.nil? flash[:error] = "Failed to find destination request '" + m + "'" - return redirect_to request_admin_url(incoming_message.info_request) + return redirect_to request_admin_url(previous_request) end raw_email_data = incoming_message.raw_email.data @@ -201,6 +206,8 @@ class AdminRequestController < AdminController flash[:notice] = "Message has been moved to request(s). Showing the last one:" end + # expire cached files + expire_for_request(previous_request) incoming_message.fully_destroy end redirect_to request_admin_url(destination_request) @@ -344,14 +351,14 @@ class AdminRequestController < AdminController explanation = params[:explanation] info_request = InfoRequest.find(params[:id]) info_request.prominence = "requester_only" - + info_request.log_event("hide", { :editor => admin_http_auth_user(), :reason => params[:reason], :subject => subject, :explanation => explanation }) - + info_request.set_described_state(params[:reason]) info_request.save! @@ -360,6 +367,8 @@ class AdminRequestController < AdminController subject, params[:explanation] ) + # expire cached files + expire_for_request(info_request) flash[:notice] = _("Your message to {{recipient_user_name}} has been sent",:recipient_user_name=>CGI.escapeHTML(info_request.user.name)) redirect_to request_admin_url(info_request) end diff --git a/spec/controllers/admin_request_controller_spec.rb b/spec/controllers/admin_request_controller_spec.rb index b0468822a..eb6f7aebc 100644 --- a/spec/controllers/admin_request_controller_spec.rb +++ b/spec/controllers/admin_request_controller_spec.rb @@ -27,12 +27,31 @@ describe AdminRequestController, "when administering requests" do it "saves edits to a request" do info_requests(:fancy_dog_request).title.should == "Why do you have & such a fancy dog?" - post :update, { :id => info_requests(:fancy_dog_request), :info_request => { :title => "Renamed", :prominence => "normal", :described_state => "waiting_response", :awaiting_description => false, :allow_new_responses_from => 'anybody', :handle_rejected_responses => 'bounce' } } + post :update, { :id => info_requests(:fancy_dog_request), + :info_request => { :title => "Renamed", + :prominence => "normal", + :described_state => "waiting_response", + :awaiting_description => false, + :allow_new_responses_from => 'anybody', + :handle_rejected_responses => 'bounce' } } response.flash[:notice].should include('successful') ir = InfoRequest.find(info_requests(:fancy_dog_request).id) ir.title.should == "Renamed" end + it 'expires the request cache when saving edits to it' do + info_request = info_requests(:fancy_dog_request) + @controller.should_receive(:expire_for_request).with(info_request) + post :update, { :id => info_request, + :info_request => { :title => "Renamed", + :prominence => "normal", + :described_state => "waiting_response", + :awaiting_description => false, + :allow_new_responses_from => 'anybody', + :handle_rejected_responses => 'bounce' } } + + end + it "edits an outgoing message" do get :edit_outgoing, :id => outgoing_messages(:useless_outgoing_message) end @@ -45,6 +64,16 @@ describe AdminRequestController, "when administering requests" do ir.body.should include("delicious cat") end + describe 'when fully destroying a request' do + + it 'expires the file cache for that request' do + info_request = info_requests(:badger_request) + @controller.should_receive(:expire_for_request).with(info_request) + get :fully_destroy, { :id => info_request } + end + + end + end describe AdminRequestController, "when administering the holding pen" do @@ -80,12 +109,13 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 1 new_im = InfoRequest.holding_pen_request.incoming_messages[0] ir.incoming_messages.length.should == 1 - post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title + post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => ir.url_title ir = InfoRequest.find_by_url_title(ir.url_title) ir.incoming_messages.length.should == 2 response.should redirect_to(:controller=>'admin_request', :action=>'show', :id=>101) InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end + it "allows redelivery to more than one request" do ir1 = info_requests(:fancy_dog_request) ir1.allow_new_responses_from = 'nobody' @@ -99,7 +129,7 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 1 new_im = InfoRequest.holding_pen_request.incoming_messages[0] - post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}" + post :redeliver_incoming, :redeliver_incoming_message_id => new_im.id, :url_title => "#{ir1.url_title},#{ir2.url_title}" ir1.reload ir1.incoming_messages.length.should == 2 ir2.reload @@ -108,6 +138,15 @@ describe AdminRequestController, "when administering the holding pen" do InfoRequest.holding_pen_request.incoming_messages.length.should == 0 end + it 'expires the file cache for the previous request' do + current_info_request = info_requests(:fancy_dog_request) + destination_info_request = info_requests(:naughty_chicken_request) + incoming_message = incoming_messages(:useless_incoming_message) + @controller.should_receive(:expire_for_request).with(current_info_request) + post :redeliver_incoming, :redeliver_incoming_message_id => incoming_message.id, + :url_title => destination_info_request.url_title + end + it "guesses a misdirected request" do ir = info_requests(:fancy_dog_request) ir.handle_rejected_responses = 'holding_pen' @@ -124,11 +163,31 @@ describe AdminRequestController, "when administering the holding pen" do assigns[:info_requests][0].should == ir end - it "destroys an incoming message" do - im = incoming_messages(:useless_incoming_message) - raw_email = im.raw_email.filepath - post :destroy_incoming, :incoming_message_id => im.id - assert_equal File.exists?(raw_email), false + describe 'when destroying an incoming message' do + + before do + @im = incoming_messages(:useless_incoming_message) + @controller.stub!(:expire_for_request) + end + + it "destroys the raw email file" do + raw_email = @im.raw_email.filepath + assert_equal File.exists?(raw_email), true + post :destroy_incoming, :incoming_message_id => @im.id + assert_equal File.exists?(raw_email), false + end + + it 'asks the incoming message to fully destroy itself' do + IncomingMessage.stub!(:find).and_return(@im) + @im.should_receive(:fully_destroy) + post :destroy_incoming, :incoming_message_id => @im.id + end + + it 'expires the file cache for the associated info_request' do + @controller.should_receive(:expire_for_request).with(@im.info_request) + post :destroy_incoming, :incoming_message_id => @im.id + end + end it "shows a suitable default 'your email has been hidden' message" do @@ -141,16 +200,26 @@ describe AdminRequestController, "when administering the holding pen" do assigns[:request_hidden_user_explanation].should include("not a valid FOI") end - it "hides requests and sends a notification email that it has done so" do - ir = info_requests(:fancy_dog_request) - post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" - ir.reload - ir.prominence.should == "requester_only" - ir.described_state.should == "vexatious" - deliveries = ActionMailer::Base.deliveries - deliveries.size.should == 1 - mail = deliveries[0] - mail.body.should =~ /Foo/ + describe 'when hiding requests' do + + it "hides requests and sends a notification email that it has done so" do + ir = info_requests(:fancy_dog_request) + post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + ir.reload + ir.prominence.should == "requester_only" + ir.described_state.should == "vexatious" + deliveries = ActionMailer::Base.deliveries + deliveries.size.should == 1 + mail = deliveries[0] + mail.body.should =~ /Foo/ + end + + it 'expires the file cache for the request' do + ir = info_requests(:fancy_dog_request) + @controller.should_receive(:expire_for_request).with(ir) + post :hide_request, :id => ir.id, :explanation => "Foo", :reason => "vexatious" + end + end end |