aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/outgoing_message.rb
diff options
context:
space:
mode:
authorLouise Crow <louise.crow@gmail.com>2013-10-28 13:33:08 +0000
committerLouise Crow <louise.crow@gmail.com>2013-12-04 09:32:43 +0000
commit90fd2c06e48c17909b9a7d2aae6d01c41047b4de (patch)
tree3e30ab49e09f8d33fd61ceec2bfeb166808c354d /app/models/outgoing_message.rb
parent97b7bc835eaa59da76c50db2c3105e4adcf89a8d (diff)
Add the specific salutations to each request.
Also, wrap model creation in a transaction and do the message sending separately - we may ultimately want to do this outside the request cycle.
Diffstat (limited to 'app/models/outgoing_message.rb')
-rw-r--r--app/models/outgoing_message.rb21
1 files changed, 16 insertions, 5 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index 7132ee223..a435511d3 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -68,19 +68,30 @@ class OutgoingMessage < ActiveRecord::Base
# How the default letter starts and ends
def get_salutation
+ if self.info_request.is_batch_request_template?
+ return OutgoingMessage.placeholder_salutation
+ end
ret = ""
if self.message_type == 'followup' && !self.incoming_message_followup.nil? && !self.incoming_message_followup.safe_mail_from.nil? && self.incoming_message_followup.valid_to_reply_to?
ret = ret + OutgoingMailer.name_for_followup(self.info_request, self.incoming_message_followup)
else
- if self.info_request.is_batch_request_template?
- ret = ret + _("[Authority name]")
- else
- ret = ret + self.info_request.public_body.name
- end
+ return OutgoingMessage.default_salutation(self.info_request.public_body)
end
salutation = _("Dear {{public_body_name}},", :public_body_name => ret)
end
+ def OutgoingMessage.default_salutation(public_body)
+ _("Dear {{public_body_name}},", :public_body_name => public_body.name)
+ end
+
+ def OutgoingMessage.placeholder_salutation
+ _("Dear [Authority name],")
+ end
+
+ def OutgoingMessage.fill_in_salutation(body, public_body)
+ body.gsub(placeholder_salutation, default_salutation(public_body))
+ end
+
def get_signoff
if self.message_type == 'followup' && !self.incoming_message_followup.nil? && !self.incoming_message_followup.safe_mail_from.nil? && self.incoming_message_followup.valid_to_reply_to?
return _("Yours sincerely,")