From 1fcbd49448b072303f9b83ce6375d557709058ae Mon Sep 17 00:00:00 2001 From: taitus Date: Tue, 29 Dec 2020 12:27:35 +0100 Subject: [PATCH] Update "reply" notification email to add unsubscribe link We modified the link that previously redirected us to the "My content" page to redirect us to the new page for managing subscriptions. We also adapted the existing generic text by adding a description of the related notification. --- app/mailers/mailer.rb | 1 + app/views/mailer/reply.html.erb | 9 ++++++++- spec/system/admin/system_emails_spec.rb | 3 +++ spec/system/emails_spec.rb | 10 ++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/mailers/mailer.rb b/app/mailers/mailer.rb index a32cd82dd..d69c8016d 100644 --- a/app/mailers/mailer.rb +++ b/app/mailers/mailer.rb @@ -20,6 +20,7 @@ class Mailer < ApplicationMailer def reply(reply) @email = ReplyEmail.new(reply) @email_to = @email.to + manage_subscriptions_token(@email.recipient) with_user(@email.recipient) do mail(to: @email_to, subject: @email.subject) if @email.can_be_sent? diff --git a/app/views/mailer/reply.html.erb b/app/views/mailer/reply.html.erb index 38419aacf..ac1b7ee55 100644 --- a/app/views/mailer/reply.html.erb +++ b/app/views/mailer/reply.html.erb @@ -18,6 +18,13 @@

- <%= t("mailers.config.manage_email_subscriptions") %> <%= link_to t("account.show.title"), account_url, style: "color: #2895F1; text-decoration:none;" %> + <%= sanitize(t("mailers.config.unsubscribe_text", + notifications: link_to( + t("mailers.config.notifications_link"), + edit_subscriptions_url(token: @token), + style: "color: #2895F1; text-decoration: none;" + ), + notification: User.human_attribute_name(:email_on_comment_reply) + )) %>

diff --git a/spec/system/admin/system_emails_spec.rb b/spec/system/admin/system_emails_spec.rb index cfcd3cf70..b0717c98a 100644 --- a/spec/system/admin/system_emails_spec.rb +++ b/spec/system/admin/system_emails_spec.rb @@ -176,6 +176,9 @@ describe "System Emails" do expect(page).to have_content reply.body expect(page).to have_link "Let's do...", href: comment_url(reply, host: app_host) + expect(page).to have_link("Notifications", + href: edit_subscriptions_url(token: user.subscriptions_token, + host: app_host)) end scenario "#direct_message_for_receiver" do diff --git a/spec/system/emails_spec.rb b/spec/system/emails_spec.rb index 922bdb8e8..a1e525991 100644 --- a/spec/system/emails_spec.rb +++ b/spec/system/emails_spec.rb @@ -198,8 +198,9 @@ describe "Emails" do expect(email).to deliver_to(user) expect(email).not_to have_body_text(debate_path(debate)) expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: user.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') end scenario "Do not send email about own replies to own comments" do @@ -469,8 +470,9 @@ describe "Emails" do expect(email).to deliver_to(user1) expect(email).not_to have_body_text(poll_path(poll)) expect(email).to have_body_text(comment_path(Comment.last)) - expect(email).to have_body_text("To stop receiving these emails change your settings in") - expect(email).to have_body_text(account_path) + expect(email).to have_body_text("To unsubscribe from these emails, visit") + expect(email).to have_body_text(edit_subscriptions_path(token: user1.subscriptions_token)) + expect(email).to have_body_text('and uncheck "Notify me by email when someone replies to my comments"') end end