]> git.openstreetmap.org Git - rails.git/commitdiff
Add unsubscribe link to diary comment notification email
authorAnton Khorev <tony29@yandex.ru>
Sat, 17 Feb 2024 03:16:42 +0000 (06:16 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 17 Feb 2024 03:16:42 +0000 (06:16 +0300)
app/mailers/user_mailer.rb
app/views/user_mailer/diary_comment_notification.html.erb
app/views/user_mailer/diary_comment_notification.text.erb
config/locales/en.yml
test/mailers/user_mailer_test.rb

index d1ad60b2cad9c1d9aa2aa6ce150bd77999edc3ce..0894b972d7e0735d2e146054636d93a923f0b7ef 100644 (file)
@@ -97,6 +97,7 @@ class UserMailer < ApplicationMailer
       @readurl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "comment#{comment.id}")
       @commenturl = diary_entry_url(comment.diary_entry.user, comment.diary_entry, :anchor => "newcomment")
       @replyurl = new_message_url(comment.user, :message => { :title => "Re: #{comment.diary_entry.title}" })
+      @unsubscribeurl = diary_entry_unsubscribe_url(comment.diary_entry.user, comment.diary_entry)
       @author = @from_user
 
       attach_user_avatar(comment.user)
index 7f9368fe33b038bb25c2e185c7f07d2b8fb917ef..dab4510edb9467538558ce6dec62da05b1c7b4a6 100644 (file)
@@ -15,4 +15,7 @@
            :commenturl => link_to(@commenturl, @commenturl) + tag.br,
            :replyurl => link_to(@replyurl, @replyurl) %>
   </p>
+  <p><%= t ".footer_unsubscribe_html",
+           :unsubscribeurl => link_to(@unsubscribeurl, @unsubscribeurl) %>
+  </p>
 <% end %>
index cbf9ddaa056d271432de8e8fc38a9cae3c942d88..13aa460f1f8fec9a01682541f6cf2a239465026d 100644 (file)
@@ -7,3 +7,5 @@
 ==
 
 <%= t '.footer', :readurl => @readurl, :commenturl => @commenturl, :replyurl => @replyurl %>
+
+<%= t '.footer_unsubscribe', :unsubscribeurl => @unsubscribeurl %>
index 338f2c0874542f2b7e9021d84458562fa786a960..3159dd128dee630105e8379503ff631cfaf3f010 100644 (file)
@@ -1577,6 +1577,8 @@ en:
       header_html: "%{from_user} has commented on the OpenStreetMap diary entry with the subject %{subject}:"
       footer: "You can also read the comment at %{readurl} and you can comment at %{commenturl} or send a message to the author at %{replyurl}"
       footer_html: "You can also read the comment at %{readurl} and you can comment at %{commenturl} or send a message to the author at %{replyurl}"
+      footer_unsubscribe: "You can unsubscribe from the discussion at %{unsubscribeurl}"
+      footer_unsubscribe_html: "You can unsubscribe from the discussion at %{unsubscribeurl}"
     message_notification:
       subject: "[OpenStreetMap] %{message_title}"
       hi: "Hi %{to_user},"
index 751adcd82dc361583bf4e8ea7ca4ad8a8d3ac8f9..998e97330059c4ab4cd41a019851131cda35893d 100644 (file)
@@ -53,4 +53,19 @@ class UserMailerTest < ActionMailer::TestCase
     assert_match("Jack & Jill <br>", email.text_part.body.to_s)
     assert_match("Jack &amp; Jill &lt;br&gt;", email.html_part.body.to_s)
   end
+
+  def test_diary_comment_notification
+    create(:language, :code => "en")
+    user = create(:user)
+    other_user = create(:user)
+    diary_entry = create(:diary_entry, :user => user)
+    diary_comment = create(:diary_comment, :diary_entry => diary_entry)
+    email = UserMailer.diary_comment_notification(diary_comment, other_user)
+    body = Rails::Dom::Testing.html_document_fragment.parse(email.html_part.body)
+
+    url = Rails.application.routes.url_helpers.diary_entry_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
+    unsubscribe_url = Rails.application.routes.url_helpers.diary_entry_unsubscribe_url(user, diary_entry, :host => Settings.server_url, :protocol => Settings.server_protocol)
+    assert_select body, "a[href^='#{url}']"
+    assert_select body, "a[href='#{unsubscribe_url}']", :count => 1
+  end
 end