Skip to content

Commit

Permalink
Merge pull request #142 from alphagov/unsubscribe_link
Browse files Browse the repository at this point in the history
Unsubscribe link
  • Loading branch information
BlessedDev authored May 20, 2024
2 parents 757eafc + 8bfc9ce commit dea03d6
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 6.1.0

* Adds a `one_click_unsubscribe_url` parameter to `send_email` so services can allow users to easily unsubscribe from distribution lists.
* Adds a `one_click_unsubscribe_url` attribute to `Notification` class, so responses for get_notification include the unsubscribe link.

## 6.0.0

* Removes the `is_csv` parameter from `prepare_upload`
Expand Down
27 changes: 18 additions & 9 deletions bin/test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,14 @@ def test_template_preview(response)
end

def test_send_email_endpoint(client)
email_resp = client.send_email(email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
template_id: ENV['EMAIL_TEMPLATE_ID'],
personalisation: { "name" => "some name" },
reference: "some reference",
email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
email_resp = client.send_email(
email_address: ENV['FUNCTIONAL_TEST_EMAIL'],
template_id: ENV['EMAIL_TEMPLATE_ID'],
personalisation: { "name" => "some name" },
reference: "some reference",
email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/[email protected]"
)
test_notification_response_data_type(email_resp, 'email')
email_resp
end
Expand All @@ -130,7 +133,8 @@ def test_send_email_endpoint_with_document(client)
template_id: ENV['EMAIL_TEMPLATE_ID'],
personalisation: { name: Notifications.prepare_upload(f) },
reference: "some reference",
email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'])
email_reply_to_id: ENV['EMAIL_REPLY_TO_ID'],
one_click_unsubscribe_url: "https://www.clovercouncil.gov.uk/[email protected]")
end

test_notification_response_data_type(email_resp, 'email')
Expand Down Expand Up @@ -319,7 +323,8 @@ def expected_fields_in_precompiled_letter_response
def expected_fields_in_email_content
%w(from_email
body
subject)
subject
one_click_unsubscribe_url)
end

def expected_fields_in_sms_content
Expand All @@ -342,7 +347,8 @@ def expected_fields_in_email_notification
template
body
subject
created_at)
created_at
one_click_unsubscribe_url)
end

def expected_fields_in_email_notification_that_are_nil
Expand Down Expand Up @@ -381,7 +387,8 @@ def expected_fields_in_sms_notification_that_are_nil
postcode
subject
created_by_name
postage)
postage
one_click_unsubscribe_url)
end

def expected_fields_in_letter_notification
Expand Down Expand Up @@ -410,6 +417,7 @@ def expected_fields_in_letter_notification_that_are_nil
line_5
line_6
created_by_name
one_click_unsubscribe_url
)
end

Expand Down Expand Up @@ -441,6 +449,7 @@ def expected_fields_in_precompiled_letter_notification_that_are_nil
phone_number
postcode
sent_at
one_click_unsubscribe_url
)
end

Expand Down
1 change: 1 addition & 0 deletions lib/notifications/client/notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Notification
created_at
completed_at
created_by_name
one_click_unsubscribe_url
).freeze

attr_reader(*FIELDS)
Expand Down
2 changes: 2 additions & 0 deletions lib/notifications/client/speaker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def initialize(secret_token = nil, base_url = nil)
# id of the email address that replies to email notifications will be sent to
# @option form_data [String] :sms_sender_id
# id of the sender to be used for an sms notification
# @option form_data [String] :one_click_unsubscribe_url
# link that end user can click to unsubscribe from the distribution list. We will pass this link in the email headers.
# @see #perform_request!
def post(kind, form_data)
request = Net::HTTP::Post.new(
Expand Down
2 changes: 1 addition & 1 deletion lib/notifications/client/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

module Notifications
class Client
VERSION = "6.0.0".freeze
VERSION = "6.1.0".freeze
end
end

0 comments on commit dea03d6

Please sign in to comment.