From 00390ee73921e99a0856bf8a48d4099e73fbff83 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 12 May 2014 16:51:53 -0400 Subject: [PATCH] Add a way to show a custom message at the top of all notification emails. Customize it at /admin/site_contents/notification_email_top --- app/mailers/user_notifications.rb | 4 +++- app/models/site_content.rb | 1 + app/views/email/notification.html.erb | 6 ++++++ config/locales/server.en.yml | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb index ab71e381f23..5981e879699 100644 --- a/app/mailers/user_notifications.rb +++ b/app/mailers/user_notifications.rb @@ -192,10 +192,12 @@ class UserNotifications < ActionMailer::Base end end + top = SiteContent.content_for(:notification_email_top) + html = UserNotificationRenderer.new(Rails.configuration.paths["app/views"]).render( template: 'email/notification', format: :html, - locals: { context_posts: context_posts, post: post } + locals: { context_posts: context_posts, post: post, top: top ? PrettyText.cook(top).html_safe : nil } ) template = "user_notifications.user_#{notification_type}" diff --git a/app/models/site_content.rb b/app/models/site_content.rb index 000495f662f..c346be4153c 100644 --- a/app/models/site_content.rb +++ b/app/models/site_content.rb @@ -24,6 +24,7 @@ class SiteContent < ActiveRecord::Base add_content_type :top, allow_blank: true, format: :html add_content_type :bottom, allow_blank: true, format: :html add_content_type :head, allow_blank: true, format: :html + add_content_type :notification_email_top, allow_blank: true, format: :markdown def site_content_type @site_content_type ||= SiteContent.content_types.find {|t| t.content_type == content_type.to_sym} diff --git a/app/views/email/notification.html.erb b/app/views/email/notification.html.erb index ef1e3afbc0e..8108cc693f6 100644 --- a/app/views/email/notification.html.erb +++ b/app/views/email/notification.html.erb @@ -1,4 +1,10 @@
+ +<% if top.present? %> +
<%= top %>
+
+<% end %> + <%= render :partial => 'email/post', :locals => {:post => post} %> <% if context_posts.present? %> diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 54ecbd5f726..1876b64f643 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -578,6 +578,9 @@ en: tos_signup_form_message: title: "Signup Form: Terms of Service Message" description: "The message that will appear beside a checkbox on the signup form if the tos_accept_required site setting is enabled." + notification_email_top: + title: "Notification Email Top" + description: "A message that will be displayed at the top of all notification emails." site_settings: default_locale: "The default language of this Discourse instance (ISO 639-1 Code)"