From a07df4c67bb418398aec48955ffdb74b6ad9eaaf Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Sat, 17 Feb 2024 06:16:42 +0300 Subject: [PATCH] Add unsubscribe link to diary comment notification email --- app/mailers/user_mailer.rb | 1 + .../diary_comment_notification.html.erb | 3 +++ .../diary_comment_notification.text.erb | 2 ++ config/locales/en.yml | 2 ++ test/mailers/user_mailer_test.rb | 15 +++++++++++++++ 5 files changed, 23 insertions(+) diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index d1ad60b2c..0894b972d 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -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) diff --git a/app/views/user_mailer/diary_comment_notification.html.erb b/app/views/user_mailer/diary_comment_notification.html.erb index 7f9368fe3..dab4510ed 100644 --- a/app/views/user_mailer/diary_comment_notification.html.erb +++ b/app/views/user_mailer/diary_comment_notification.html.erb @@ -15,4 +15,7 @@ :commenturl => link_to(@commenturl, @commenturl) + tag.br, :replyurl => link_to(@replyurl, @replyurl) %>

+

<%= t ".footer_unsubscribe_html", + :unsubscribeurl => link_to(@unsubscribeurl, @unsubscribeurl) %> +

<% end %> diff --git a/app/views/user_mailer/diary_comment_notification.text.erb b/app/views/user_mailer/diary_comment_notification.text.erb index cbf9ddaa0..13aa460f1 100644 --- a/app/views/user_mailer/diary_comment_notification.text.erb +++ b/app/views/user_mailer/diary_comment_notification.text.erb @@ -7,3 +7,5 @@ == <%= t '.footer', :readurl => @readurl, :commenturl => @commenturl, :replyurl => @replyurl %> + +<%= t '.footer_unsubscribe', :unsubscribeurl => @unsubscribeurl %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 338f2c087..3159dd128 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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}," diff --git a/test/mailers/user_mailer_test.rb b/test/mailers/user_mailer_test.rb index 751adcd82..998e97330 100644 --- a/test/mailers/user_mailer_test.rb +++ b/test/mailers/user_mailer_test.rb @@ -53,4 +53,19 @@ class UserMailerTest < ActionMailer::TestCase assert_match("Jack & Jill
", email.text_part.body.to_s) assert_match("Jack & Jill <br>", 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 -- 2.45.1