-
Notifications
You must be signed in to change notification settings - Fork 15
[CAPT-1862] Add unsubscribe functionality #3445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
13fdbca
add unsubscribe functionality
asmega 07c149f
unsubscribe soft deletes reminder
asmega 41d0557
reminders now supports reverse soft delete
asmega 11136dd
update analytics config with reminders#deleted_at
asmega 8ea3507
reminders now uses Deletable module
asmega f7bb8bd
tweak unsubscribe copy
asmega 984532c
refactor to use named method
asmega 89a772b
unsubscribe copy tweaks
asmega f6cbb11
update global support email address
asmega b320903
tweak reminder confirmation copy
asmega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
class UnsubscribeController < ApplicationController | ||
skip_forgery_protection | ||
|
||
def show | ||
@form = Unsubscribe::ConfirmationForm.new(form_params) | ||
|
||
if @form.reminder.nil? | ||
render "subscription_not_found" | ||
end | ||
end | ||
|
||
def create | ||
@form = Unsubscribe::ConfirmationForm.new(form_params) | ||
|
||
if @form.reminder.nil? | ||
head :bad_request | ||
else | ||
@form.reminder.mark_as_deleted! | ||
end | ||
end | ||
|
||
private | ||
|
||
def form_params | ||
params.permit([:id]) | ||
end | ||
|
||
def current_journey_routing_name | ||
params[:journey] | ||
end | ||
helper_method :current_journey_routing_name | ||
|
||
def current_journey | ||
Journeys.for_routing_name(params[:journey]) | ||
end | ||
helper_method :current_journey | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Unsubscribe | ||
class ConfirmationForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attribute :id, :string | ||
|
||
def reminder | ||
@reminder ||= Reminder.not_deleted.find_by(id:) | ||
end | ||
|
||
def obfuscasted_email | ||
head, tail = reminder.email_address.split("@") | ||
|
||
mask = case head.size | ||
when 1, 2, 3 | ||
"*" * head.size | ||
else | ||
[head[0], "*" * (head.length - 2), head[-1]].join | ||
end | ||
|
||
[mask, "@", tail].join | ||
end | ||
|
||
def journey_name | ||
default = I18n.t("journey_name", scope: reminder.journey::I18N_NAMESPACE).downcase | ||
I18n.t("policy_short_name", scope: reminder.journey::I18N_NAMESPACE, default:).downcase | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,8 @@ def mark_as_deleted! | |
|
||
update!(deleted_at: Time.zone.now) | ||
end | ||
|
||
def undelete! | ||
update!(deleted_at: nil) | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= content_for(:page_title) { "Unsubscribe" } %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= govuk_panel(title_text: "Unsubscribe complete") %> | ||
|
||
<p class="govuk-body"> | ||
You will no longer receive your <%= @form.journey_name %> reminder to <%= @form.obfuscasted_email %>. | ||
</p> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<%= content_for(:page_title) { "Unsubscribe" } %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<%= form_with model: @form, | ||
url: unsubscribe_index_path, | ||
scope: "", | ||
builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> | ||
|
||
<%= f.hidden_field :id %> | ||
|
||
<h1 class="govuk-heading-l"> | ||
Are you sure you wish to unsubscribe from your reminder? | ||
</h1> | ||
|
||
<p class="govuk-body"> | ||
You will no longer receive reminders regarding future application windows for targeted retention incentive payments from the Department for Education. | ||
<p> | ||
|
||
<p class="govuk-body"> | ||
However, if you have already submitted a claim for a targeted retention incentive payment, you will still continue to receive updates about the progress of your claim. | ||
<p> | ||
|
||
<p class="govuk-body"> | ||
You may also continue to receive communications related to the Claim Additional Payments service. Please email <%= govuk_mail_to I18n.t(:support_email_address) %> if you no longer want to receive emails. | ||
<p> | ||
|
||
<%= f.govuk_submit "Unsubscribe" %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h1 class="govuk-heading-l"> | ||
We can’t find your subscription | ||
</h1> | ||
|
||
<p class="govuk-body"> | ||
You may have already unsubscribed. If you haven’t, check your email and copy the link again. | ||
</p> | ||
|
||
<p class="govuk-body"> | ||
If you need more help, contact support at <%= govuk_mail_to I18n.t("support_email_address", scope: [current_journey::I18N_NAMESPACE]), I18n.t("support_email_address", scope: [current_journey::I18N_NAMESPACE]) %> | ||
</p> | ||
</div> | ||
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ shared: | |
- itt_subject | ||
- sent_one_time_password_at | ||
- journey_class | ||
- deleted_at | ||
:tasks: | ||
- id | ||
- name | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,11 @@ def matches?(request) | |
end | ||
end | ||
|
||
resources :unsubscribe, | ||
path: "/unsubscribe/:resource_class", | ||
constraints: {resource_class: /reminders/}, | ||
only: [:create, :show] | ||
|
||
Comment on lines
+68
to
+72
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
scope constraints: {journey: /further-education-payments|additional-payments/} do | ||
resources :reminders, | ||
only: [:show, :update], | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddDeletedAtToReminders < ActiveRecord::Migration[8.0] | ||
def change | ||
add_column :reminders, :deleted_at, :datetime | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "rails_helper" | ||
|
||
RSpec.feature "unsubscribe from reminders" do | ||
let(:reminder) do | ||
create( | ||
:reminder, | ||
journey_class: Journeys::FurtherEducationPayments.to_s | ||
) | ||
end | ||
|
||
scenario "happy path" do | ||
visit "/#{reminder.journey::ROUTING_NAME}/unsubscribe/reminders/#{reminder.id}" | ||
expect(page).to have_content "Are you sure you wish to unsub" | ||
|
||
click_button("Unsubscribe") | ||
|
||
expect(reminder.reload.deleted_at).to be_present | ||
|
||
expect(page).to have_content "Unsubscribe complete" | ||
end | ||
|
||
scenario "when reminder does not exist" do | ||
visit "/#{reminder.journey::ROUTING_NAME}/unsubscribe/reminders/idonotexist" | ||
expect(page).to have_content "We can’t find your subscription" | ||
end | ||
|
||
context "when reminder already soft deleted" do | ||
let(:reminder) do | ||
create( | ||
:reminder, | ||
:soft_deleted, | ||
journey_class: Journeys::FurtherEducationPayments.to_s | ||
) | ||
end | ||
|
||
scenario "cannot find subscription" do | ||
visit "/#{reminder.journey::ROUTING_NAME}/unsubscribe/reminders/#{reminder.id}" | ||
expect(page).to have_content "We can’t find your subscription" | ||
end | ||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.