-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3445 from DFE-Digital/unsubscribe
[CAPT-1862] Add unsubscribe functionality
- Loading branch information
Showing
38 changed files
with
428 additions
and
137 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.