From 084cc18aa872b3cd1cbc8c38d34dc17341472391 Mon Sep 17 00:00:00 2001 From: Seb Bacon Date: Fri, 25 May 2012 14:24:16 +0100 Subject: Support easy hiding of requests for admins. Currently not exposed in core admin interface (requires adminbootstraptheme). --- app/controllers/admin_request_controller.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'app/controllers/admin_request_controller.rb') diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index 3c700c567..2f1a92a50 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -6,6 +6,8 @@ # # $Id: admin_request_controller.rb,v 1.42 2009-10-03 01:28:33 francis Exp $ +require 'ostruct' + class AdminRequestController < AdminController def index list @@ -24,6 +26,15 @@ class AdminRequestController < AdminController def show @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'), + :info_request => @info_request, :reason => params[:reason], + :info_request_url => 'http://' + MySociety::Config.get('DOMAIN') + request_url(@info_request), + :site_name => site_name) + template = File.read(File.join(File.dirname(__FILE__), "..", "views", "admin_request", "hidden_user_explanation.rhtml")) + @request_hidden_user_explanation = ERB.new(template).result(vars.instance_eval { binding }) end def resend @@ -323,6 +334,24 @@ class AdminRequestController < AdminController redirect_to request_admin_url(info_request_event.info_request) end + def hide_request + ActiveRecord::Base.transaction do + explanation = params[:explanation] + info_request = InfoRequest.find(params[:id]) + info_request.set_described_state(params[:reason]) + info_request.prominence = "requester_only" + info_request.save! + + ContactMailer.deliver_from_admin_message( + info_request.user, + "hello", + params[:explanation] + ) + 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 + end + private end -- cgit v1.2.3