aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/outgoing_message.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/outgoing_message.rb')
-rw-r--r--app/models/outgoing_message.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/app/models/outgoing_message.rb b/app/models/outgoing_message.rb
index aedfb9cad..e2ee696c5 100644
--- a/app/models/outgoing_message.rb
+++ b/app/models/outgoing_message.rb
@@ -1,18 +1,17 @@
# == Schema Information
-# Schema version: 114
#
# Table name: outgoing_messages
#
-# id :integer not null, primary key
-# info_request_id :integer not null
-# body :text not null
-# status :string(255) not null
-# message_type :string(255) not null
-# created_at :datetime not null
-# updated_at :datetime not null
+# id :integer not null, primary key
+# info_request_id :integer not null
+# body :text not null
+# status :string(255) not null
+# message_type :string(255) not null
+# created_at :datetime not null
+# updated_at :datetime not null
# last_sent_at :datetime
# incoming_message_followup_id :integer
-# what_doing :string(255) not null
+# what_doing :string(255) not null
#
# models/outgoing_message.rb:
@@ -23,6 +22,7 @@
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/
class OutgoingMessage < ActiveRecord::Base
+ extend MessageProminence
include Rails.application.routes.url_helpers
include LinkToHelper
self.default_url_options[:host] = AlaveteliConfiguration::domain
@@ -33,6 +33,8 @@ class OutgoingMessage < ActiveRecord::Base
strip_attributes!
+ has_prominence
+
belongs_to :info_request
validates_presence_of :info_request
@@ -209,11 +211,11 @@ class OutgoingMessage < ActiveRecord::Base
end
# Returns text for indexing / text display
- def get_text_for_indexing
+ def get_text_for_indexing(strip_salutation=true)
text = self.body.strip
# Remove salutation
- text.sub!(/Dear .+,/, "")
+ text.sub!(/Dear .+,/, "") if strip_salutation
# Remove email addresses from display/index etc.
self.remove_privacy_sensitive_things!(text)
@@ -233,6 +235,12 @@ class OutgoingMessage < ActiveRecord::Base
return text.html_safe
end
+ # Return body for display as text
+ def get_body_for_text_display
+ get_text_for_indexing(strip_salutation=false)
+ end
+
+
def fully_destroy
ActiveRecord::Base.transaction do
info_request_event = InfoRequestEvent.find_by_outgoing_message_id(self.id)
@@ -263,7 +271,7 @@ class OutgoingMessage < ActiveRecord::Base
end
def format_of_body
- if self.body.empty? || self.body =~ /\A#{get_salutation}\s+#{get_signoff}/ || self.body =~ /#{get_internal_review_insert_here_note}/
+ if self.body.empty? || self.body =~ /\A#{Regexp.escape(get_salutation)}\s+#{Regexp.escape(get_signoff)}/ || self.body =~ /#{Regexp.escape(get_internal_review_insert_here_note)}/
if self.message_type == 'followup'
if self.what_doing == 'internal_review'
errors.add(:body, _("Please give details explaining why you want a review"))