aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-06-12 09:55:16 +0100
committerSeb Bacon <seb.bacon@gmail.com>2012-06-12 09:55:16 +0100
commitf560987ab0d3ea3471837a2b30d30c7101dc5616 (patch)
treec27a235cbafc540e887f3d98feadf8c8fe4a0026
parent4a4367ba4ec43aea7a0eb19c4a06bb004abd01eb (diff)
Make emails requesting admin attention appear to come from the user who requested the attention, not the user who made the original request.
-rw-r--r--app/controllers/request_controller.rb2
-rw-r--r--app/models/info_request.rb4
-rw-r--r--app/models/request_mailer.rb8
-rw-r--r--spec/controllers/request_controller_spec.rb10
4 files changed, 19 insertions, 5 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index bd2bfc974..f87efbcb0 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -663,7 +663,7 @@ class RequestController < ApplicationController
)
if !info_request.attention_requested
- info_request.set_described_state('attention_requested')
+ info_request.set_described_state('attention_requested', @user)
info_request.attention_requested = true # tells us if attention has ever been requested
info_request.save!
flash[:notice] = _("This request has been reported for administrator attention")
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index 095a1b1af..45819bfe7 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -519,7 +519,7 @@ public
end
# change status, including for last event for later historical purposes
- def set_described_state(new_state)
+ def set_described_state(new_state, set_by = nil)
ActiveRecord::Base.transaction do
self.awaiting_description = false
last_event = self.get_last_event
@@ -532,7 +532,7 @@ public
self.calculate_event_states
if self.requires_admin?
- RequestMailer.deliver_requires_admin(self)
+ RequestMailer.deliver_requires_admin(self, set_by)
end
end
diff --git a/app/models/request_mailer.rb b/app/models/request_mailer.rb
index 8e6e65a26..c208923f3 100644
--- a/app/models/request_mailer.rb
+++ b/app/models/request_mailer.rb
@@ -45,8 +45,12 @@ class RequestMailer < ApplicationMailer
end
# An FOI response is outside the scope of the system, and needs admin attention
- def requires_admin(info_request)
- @from = info_request.user.name_and_email
+ def requires_admin(info_request, set_by = nil)
+ if !set_by.nil?
+ @from = set_by.name_and_email
+ else
+ @from = info_request.user.name_and_email
+ end
@recipients = contact_from_name_and_email
@subject = _("FOI response requires admin ({{reason}}) - {{title}}", :reason => info_request.described_state, :title => info_request.title)
url = main_url(request_url(info_request))
diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb
index c70284748..daa26c71e 100644
--- a/spec/controllers/request_controller_spec.rb
+++ b/spec/controllers/request_controller_spec.rb
@@ -1883,6 +1883,16 @@ describe RequestController, "when reporting a request" do
response.body.should include("The site administrators have reviewed this request")
end
+ it "should send an email from the reporter to admins" do
+ ir = info_requests(:badger_request)
+ title = ir.url_title
+ post :report_request, :url_title => title
+ deliveries = ActionMailer::Base.deliveries
+ deliveries.size.should == 1
+ mail = deliveries[0]
+ mail.subject.should =~ /attention_requested/
+ mail.from.should include(@user.email)
+ end
end