From ef0050be5d2ed2f20963ab1f256dc4a69700508d Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Wed, 4 Dec 2024 13:05:43 +0000 Subject: [PATCH] WIP one click unsub with patched mail-notify --- Gemfile | 2 +- Gemfile.lock | 24 +++++++++++++++--------- app/mailers/reminder_mailer.rb | 7 ++++++- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/Gemfile b/Gemfile index c0143dedd6..c5f8446646 100644 --- a/Gemfile +++ b/Gemfile @@ -33,7 +33,7 @@ gem "omniauth_openid_connect" gem "omniauth-rails_csrf_protection" # ActionMailer support for GOV.UK Notify -gem "mail-notify" +gem "mail-notify", github: "asmega/mail-notify", branch: "one-click-unsubscribe" # Database based asynchronous priority queue system gem "delayed_job_active_record" diff --git a/Gemfile.lock b/Gemfile.lock index 8a008c0606..e0c402d8e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,19 @@ GIT multi_xml (~> 0.6.0) request_store_rails (~> 2) +GIT + remote: https://github.com/asmega/mail-notify.git + revision: bc8c25aa43ebc8d664f3c1760bf05ae9bd96796a + branch: one-click-unsubscribe + specs: + mail-notify (2.0.0) + actionmailer (>= 5.2.8.1) + actionpack (>= 5.2.8.1) + actionview (>= 5.2.8.1) + activesupport (>= 5.2.8.1) + notifications-ruby-client (~> 6.0) + rack (>= 2.1.4.1) + GIT remote: https://github.com/microsoft/ApplicationInsights-Ruby.git revision: 5db6b4ad65262d23f26b678143a4a1fd7939e5c2 @@ -321,13 +334,6 @@ GEM net-imap net-pop net-smtp - mail-notify (2.0.0) - actionmailer (>= 5.2.8.1) - actionpack (>= 5.2.8.1) - actionview (>= 5.2.8.1) - activesupport (>= 5.2.8.1) - notifications-ruby-client (~> 6.0) - rack (>= 2.1.4.1) marcel (1.0.4) matrix (0.4.2) method_source (1.1.0) @@ -359,7 +365,7 @@ GEM racc (~> 1.4) nokogiri (1.16.7-x86_64-linux) racc (~> 1.4) - notifications-ruby-client (6.1.0) + notifications-ruby-client (6.2.0) jwt (>= 1.5, < 3) omniauth (2.1.2) hashie (>= 3.4.6) @@ -875,7 +881,7 @@ DEPENDENCIES jwt launchy listen (>= 3.0.5, < 3.10) - mail-notify + mail-notify! nanoid omniauth omniauth-rails_csrf_protection diff --git a/app/mailers/reminder_mailer.rb b/app/mailers/reminder_mailer.rb index 54313f5cc6..280edba745 100644 --- a/app/mailers/reminder_mailer.rb +++ b/app/mailers/reminder_mailer.rb @@ -44,7 +44,8 @@ def reminder_set(reminder) to: @reminder.email_address, reply_to_id: GENERIC_NOTIFY_REPLY_TO_ID, subject: @subject, - personalisation: + personalisation:, + one_click_unsubscribe_url: one_click_unsubscribe_url(reminder:) ) end @@ -75,6 +76,10 @@ def unsubscribe_url(reminder:) "https://#{ENV["CANONICAL_HOSTNAME"]}/#{reminder.journey::ROUTING_NAME}/unsubscribe/reminders/#{reminder.id}" end + def one_click_unsubscribe_url(reminder:) + "https://#{ENV["CANONICAL_HOSTNAME"]}/#{reminder.journey::ROUTING_NAME}/unsubscribe/reminders?id=#{reminder.id}" + end + def extract_first_name(fullname) (fullname || "").split(" ").first end