aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/admin_request_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/admin_request_controller.rb')
-rw-r--r--app/controllers/admin_request_controller.rb139
1 files changed, 86 insertions, 53 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb
index e5de4f8b7..522e1cd39 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
@@ -60,10 +71,10 @@ class AdminRequestController < AdminController
if @info_request.valid?
@info_request.save!
- @info_request.log_event("edit",
- { :editor => admin_http_auth_user(),
- :old_title => old_title, :title => @info_request.title,
- :old_prominence => old_prominence, :prominence => @info_request.prominence,
+ @info_request.log_event("edit",
+ { :editor => admin_http_auth_user(),
+ :old_title => old_title, :title => @info_request.title,
+ :old_prominence => old_prominence, :prominence => @info_request.prominence,
:old_described_state => old_described_state, :described_state => @info_request.described_state,
:old_awaiting_description => old_awaiting_description, :awaiting_description => @info_request.awaiting_description,
:old_allow_new_responses_from => old_allow_new_responses_from, :allow_new_responses_from => @info_request.allow_new_responses_from,
@@ -75,7 +86,7 @@ class AdminRequestController < AdminController
else
render :action => 'edit'
end
- end
+ end
def fully_destroy
@info_request = InfoRequest.find(params[:id])
@@ -99,28 +110,28 @@ class AdminRequestController < AdminController
outgoing_message_id = @outgoing_message.id
@outgoing_message.fully_destroy
- @outgoing_message.info_request.log_event("destroy_outgoing",
+ @outgoing_message.info_request.log_event("destroy_outgoing",
{ :editor => admin_http_auth_user(), :deleted_outgoing_message_id => outgoing_message_id })
flash[:notice] = 'Outgoing message successfully destroyed.'
redirect_to request_admin_url(@info_request)
- end
+ end
def update_outgoing
@outgoing_message = OutgoingMessage.find(params[:id])
old_body = @outgoing_message.body
- if @outgoing_message.update_attributes(params[:outgoing_message])
- @outgoing_message.info_request.log_event("edit_outgoing",
- { :outgoing_message_id => @outgoing_message.id, :editor => admin_http_auth_user(),
+ if @outgoing_message.update_attributes(params[:outgoing_message])
+ @outgoing_message.info_request.log_event("edit_outgoing",
+ { :outgoing_message_id => @outgoing_message.id, :editor => admin_http_auth_user(),
:old_body => old_body, :body => @outgoing_message.body })
flash[:notice] = 'Outgoing message successfully updated.'
redirect_to request_admin_url(@outgoing_message.info_request)
else
render :action => 'edit_outgoing'
end
- end
+ end
def edit_comment
@comment = Comment.find(params[:id])
@@ -133,9 +144,9 @@ class AdminRequestController < AdminController
old_visible = @comment.visible
@comment.visible = params[:comment][:visible] == "true" ? true : false
- if @comment.update_attributes(params[:comment])
- @comment.info_request.log_event("edit_comment",
- { :comment_id => @comment.id, :editor => admin_http_auth_user(),
+ if @comment.update_attributes(params[:comment])
+ @comment.info_request.log_event("edit_comment",
+ { :comment_id => @comment.id, :editor => admin_http_auth_user(),
:old_body => old_body, :body => @comment.body,
:old_visible => old_visible, :visible => @comment.visible,
})
@@ -144,7 +155,7 @@ class AdminRequestController < AdminController
else
render :action => 'edit_comment'
end
- end
+ end
def destroy_incoming
@@ -153,41 +164,45 @@ class AdminRequestController < AdminController
incoming_message_id = @incoming_message.id
@incoming_message.fully_destroy
- @incoming_message.info_request.log_event("destroy_incoming",
+ @incoming_message.info_request.log_event("destroy_incoming",
{ :editor => admin_http_auth_user(), :deleted_incoming_message_id => incoming_message_id })
flash[:notice] = 'Incoming message successfully destroyed.'
redirect_to request_admin_url(@info_request)
- end
+ end
def redeliver_incoming
incoming_message = IncomingMessage.find(params[:redeliver_incoming_message_id])
-
- if params[:url_title].match(/^[0-9]+$/)
- destination_request = InfoRequest.find(params[:url_title].to_i)
- else
- destination_request = InfoRequest.find_by_url_title(params[:url_title])
- end
-
- if destination_request.nil?
- flash[:error] = "Failed to find destination request '" + params[:url_title] + "'"
- redirect_to request_admin_url(incoming_message.info_request)
+ message_ids = params[:url_title].split(",").each {|x| x.strip}
+ destination_request = nil
+ ActiveRecord::Base.transaction do
+ for m in message_ids
+ if m.match(/^[0-9]+$/)
+ destination_request = InfoRequest.find_by_id(m.to_i)
+ else
+ destination_request = InfoRequest.find_by_url_title(m)
+ end
+ if destination_request.nil?
+ flash[:error] = "Failed to find destination request '" + m + "'"
+ return redirect_to request_admin_url(incoming_message.info_request)
+ end
+
+ raw_email_data = incoming_message.raw_email.data
+ mail = TMail::Mail.parse(raw_email_data)
+ mail.base64_decode
+ destination_request.receive(mail, raw_email_data, true)
+
+ incoming_message_id = incoming_message.id
+ incoming_message.info_request.log_event("redeliver_incoming", {
+ :editor => admin_http_auth_user(),
+ :destination_request => destination_request.id,
+ :deleted_incoming_message_id => incoming_message_id
+ })
+
+ flash[:notice] = "Message has been moved to request(s). Showing the last one:"
+ end
+ incoming_message.fully_destroy
end
-
- raw_email_data = incoming_message.raw_email.data
- mail = TMail::Mail.parse(raw_email_data)
- mail.base64_decode
- destination_request.receive(mail, raw_email_data, true)
-
- incoming_message_id = incoming_message.id
- incoming_message.fully_destroy
- incoming_message.info_request.log_event("redeliver_incoming", {
- :editor => admin_http_auth_user(),
- :destination_request => destination_request.id,
- :deleted_incoming_message_id => incoming_message_id
- })
-
- flash[:notice] = "Message has been moved to this request"
redirect_to request_admin_url(destination_request)
end
@@ -202,10 +217,10 @@ class AdminRequestController < AdminController
else
info_request.user = destination_user
info_request.save!
- info_request.log_event("move_request", {
- :editor => admin_http_auth_user(),
- :old_user_url_name => old_user.url_name,
- :user_url_name => destination_user.url_name
+ info_request.log_event("move_request", {
+ :editor => admin_http_auth_user(),
+ :old_user_url_name => old_user.url_name,
+ :user_url_name => destination_user.url_name
})
info_request.reindex_request_events
@@ -220,10 +235,10 @@ class AdminRequestController < AdminController
else
info_request.public_body = destination_public_body
info_request.save!
- info_request.log_event("move_request", {
- :editor => admin_http_auth_user(),
- :old_public_body_url_name => old_public_body.url_name,
- :public_body_url_name => destination_public_body.url_name
+ info_request.log_event("move_request", {
+ :editor => admin_http_auth_user(),
+ :old_public_body_url_name => old_public_body.url_name,
+ :public_body_url_name => destination_public_body.url_name
})
info_request.reindex_request_events
@@ -288,16 +303,16 @@ class AdminRequestController < AdminController
if domain.nil?
@public_bodies = []
else
- @public_bodies = PublicBody.find(:all, :order => "name",
+ @public_bodies = PublicBody.find(:all, :order => "name",
:conditions => [ "lower(request_email) like lower('%'||?||'%')", domain ])
end
-
+
# 2. Match the email address in the message without matching the hash
@info_requests = InfoRequest.guess_by_incoming_email(@raw_email.incoming_message)
# 3. Give a reason why it's in the holding pen
last_event = InfoRequestEvent.find_by_incoming_message_id(@raw_email.incoming_message.id)
- @rejected_reason = last_event.params[:rejected_reason]
+ @rejected_reason = last_event.params[:rejected_reason] || "unknown reason"
end
end
@@ -323,6 +338,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