-
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.
- Loading branch information
Showing
26 changed files
with
268 additions
and
133 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.destroy | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Unsubscribe | ||
class ConfirmationForm | ||
include ActiveModel::Model | ||
include ActiveModel::Attributes | ||
|
||
attribute :id, :string | ||
|
||
def reminder | ||
@reminder ||= Reminder.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 | ||
I18n.t("journey_name", scope: reminder.journey::I18N_NAMESPACE).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 |
---|---|---|
@@ -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,27 @@ | ||
<%= 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 <%= @form.journey_name %> reminder? | ||
</h1> | ||
|
||
<p class="govuk-body"> | ||
You will no longer receive your reminder to <%= @form.obfuscasted_email %>. | ||
<p> | ||
|
||
<p class="govuk-body"> | ||
However, you will still continue to receive updates about your claim as it progresses. | ||
<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
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,26 @@ | ||
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" | ||
|
||
expect { | ||
click_button("Unsubscribe") | ||
}.to change(Reminder, :count).by(-1) | ||
|
||
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 | ||
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
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
Oops, something went wrong.