From 63b9d1c64588bb2d7a3fe3c84741edf0cd836a5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= <regis@hanol.fr>
Date: Tue, 16 Feb 2016 18:29:23 +0100
Subject: [PATCH] FIX: sends an email notifcation when a user's post is linked

---
 app/controllers/admin/email_templates_controller.rb |  3 ++-
 app/mailers/user_notifications.rb                   |  7 +++++++
 app/models/user_email_observer.rb                   |  4 ++++
 config/locales/server.en.yml                        | 12 ++++++++++++
 spec/models/user_email_observer_spec.rb             |  8 ++++++++
 5 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/app/controllers/admin/email_templates_controller.rb b/app/controllers/admin/email_templates_controller.rb
index 9d872c998..ccbb3eaf6 100644
--- a/app/controllers/admin/email_templates_controller.rb
+++ b/app/controllers/admin/email_templates_controller.rb
@@ -26,7 +26,8 @@ class Admin::EmailTemplatesController < Admin::AdminController
                      "user_notifications.user_invited_to_private_message_pm",
                      "user_notifications.user_invited_to_topic", "user_notifications.user_mentioned",
                      "user_notifications.user_posted", "user_notifications.user_posted_pm",
-                     "user_notifications.user_quoted", "user_notifications.user_replied"]
+                     "user_notifications.user_quoted", "user_notifications.user_replied",
+                     "user_notifications.user_linked"]
   end
 
   def show
diff --git a/app/mailers/user_notifications.rb b/app/mailers/user_notifications.rb
index 517294278..2f4423cb1 100644
--- a/app/mailers/user_notifications.rb
+++ b/app/mailers/user_notifications.rb
@@ -110,6 +110,13 @@ class UserNotifications < ActionMailer::Base
     notification_email(user, opts)
   end
 
+  def user_linked(user, opts)
+    opts[:allow_reply_by_email] = true
+    opts[:use_site_subject] = true
+    opts[:show_category_in_subject] = true
+    notification_email(user, opts)
+  end
+
   def user_mentioned(user, opts)
     opts[:allow_reply_by_email] = true
     opts[:use_site_subject] = true
diff --git a/app/models/user_email_observer.rb b/app/models/user_email_observer.rb
index db9dbdc73..31128235e 100644
--- a/app/models/user_email_observer.rb
+++ b/app/models/user_email_observer.rb
@@ -28,6 +28,10 @@ class UserEmailObserver < ActiveRecord::Observer
       enqueue :user_replied
     end
 
+    def linked
+      enqueue :user_linked
+    end
+
     def private_message
       enqueue_private(:user_private_message)
     end
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 2e7ef4768..281d53654 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -2095,6 +2095,18 @@ en:
         ---
         %{respond_instructions}
 
+    user_linked:
+      subject_template: "[%{site_name}] %{topic_title}"
+      text_body_template: |
+        %{header_instructions}
+
+        %{message}
+
+        %{context}
+
+        ---
+        %{respond_instructions}
+
     user_mentioned:
       subject_template: "[%{site_name}] %{topic_title}"
       text_body_template: |
diff --git a/spec/models/user_email_observer_spec.rb b/spec/models/user_email_observer_spec.rb
index 0f1150c4d..c0b8da164 100644
--- a/spec/models/user_email_observer_spec.rb
+++ b/spec/models/user_email_observer_spec.rb
@@ -99,6 +99,14 @@ describe UserEmailObserver do
     include_examples "enqueue_public"
   end
 
+  context 'user_linked' do
+    let(:type) { :user_linked }
+    let(:delay) { SiteSetting.email_time_window_mins.minutes }
+    let!(:notification) { create_notification(11) }
+
+    include_examples "enqueue_public"
+  end
+
   context 'user_posted' do
     let(:type) { :user_posted }
     let(:delay) { SiteSetting.email_time_window_mins.minutes }