docbrown/app/models/email_message.rb
rhymes 5ba8c44b05
[deploy] Add missing foreign keys to ahoy_messages and articles (#10321)
* Add FK between ahoy_messages and feedback_messages

* Add FKs between articles.second_user_id, articles.third_user_id and users

* Fix associations and specs

* Add more validations

* Remove FKs to articles.second_user_id and .third_user_id as they are about to be removed
2020-09-16 19:47:03 +02:00

17 lines
676 B
Ruby

class EmailMessage < Ahoy::Message
belongs_to :feedback_message, optional: true
# So far this is mostly used to be compatible with administrate gem,
# which doesn't seem to play nicely with namespaces. But there could be other
# reasons to define behavior here, similar to how we use the Tag model.
def body_html_content
doctype_index = content.index("<!DOCTYPE")
closing_html_index = content.index("</html>") + 6
content[doctype_index..closing_html_index]
end
def self.find_for_reports(feedback_message_ids)
select(:to, :subject, :content, :utm_campaign, :feedback_message_id)
.where(feedback_message_id: feedback_message_ids)
end
end