-
Notifications
You must be signed in to change notification settings - Fork 166
LG-677 Add confirm screen on account reset cancel #2525
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| module AccountReset | ||
| class CancelController < ApplicationController | ||
| before_action :check_feature_enabled | ||
|
|
||
| def show | ||
| return render :show unless token | ||
|
|
||
| result = AccountReset::ValidateCancelToken.new(token).call | ||
| track_event(result) | ||
|
|
||
| if result.success? | ||
| handle_valid_token | ||
| else | ||
| handle_invalid_token(result) | ||
| end | ||
| end | ||
|
|
||
| def create | ||
| result = AccountReset::Cancel.new(params[:token]).call | ||
| result = AccountReset::Cancel.new(session[:cancel_token]).call | ||
|
|
||
| analytics.track_event(Analytics::ACCOUNT_RESET, result.to_h) | ||
| track_event(result) | ||
|
|
||
| handle_success if result.success? | ||
|
||
|
|
||
|
|
@@ -12,9 +27,31 @@ def create | |
|
|
||
| private | ||
|
|
||
| def check_feature_enabled | ||
| redirect_to root_url unless FeatureManagement.account_reset_enabled? | ||
| end | ||
|
|
||
| def track_event(result) | ||
| analytics.track_event(Analytics::ACCOUNT_RESET, result.to_h) | ||
| end | ||
|
|
||
| def handle_valid_token | ||
| session[:cancel_token] = token | ||
| redirect_to url_for | ||
| end | ||
|
|
||
| def handle_invalid_token(result) | ||
| flash[:error] = result.errors[:token].first | ||
| redirect_to root_url | ||
| end | ||
|
|
||
| def handle_success | ||
| sign_out if current_user | ||
| flash[:success] = t('two_factor_authentication.account_reset.successful_cancel') | ||
| end | ||
|
|
||
| def token | ||
| params[:token] | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| module AccountReset | ||
| class ValidateCancelToken | ||
|
||
| include ActiveModel::Model | ||
| include CancelTokenValidator | ||
|
|
||
| def initialize(token) | ||
| @token = token | ||
| end | ||
|
|
||
| def call | ||
| @success = valid? | ||
|
|
||
| FormResponse.new(success: success, errors: errors.messages, extra: extra_analytics_attributes) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :success, :token | ||
|
|
||
| def user | ||
| account_reset_request&.user || AnonymousUser.new | ||
| end | ||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| event: 'visit', | ||
| user_id: user.uuid, | ||
| } | ||
| end | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| module AccountReset | ||
| module CancelTokenValidator | ||
| extend ActiveSupport::Concern | ||
|
|
||
| included do | ||
| validates :token, presence: { message: I18n.t('errors.account_reset.cancel_token_missing') } | ||
| validate :valid_token | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :token | ||
|
|
||
| def valid_token | ||
| return if account_reset_request | ||
|
|
||
| errors.add(:token, I18n.t('errors.account_reset.cancel_token_invalid')) if token | ||
| end | ||
|
|
||
| def account_reset_request | ||
| @account_reset_request ||= AccountResetRequest.find_by(request_token: token) | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| - title t('account_reset.cancel_request.title') | ||
|
|
||
| h1.h3.my0 = t('account_reset.cancel_request.title') | ||
| br | ||
| h4.my2 = t('account_reset.cancel_request.are_you_sure') | ||
|
|
||
| = button_to t('account_reset.cancel_request.cancel_button'), \ | ||
| account_reset_cancel_path, method: :post, \ | ||
| class: 'btn btn-primary btn-wide' | ||
| br | ||
| br | ||
| hr | ||
| = link_to t('account_reset.cancel_request.cancel'), root_url |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| --- | ||
| en: | ||
| account_reset: | ||
| cancel_request: | ||
| are_you_sure: Are you sure you want to cancel your delete account request? | ||
| cancel: Exit | ||
|
||
| cancel_button: Cancel delete account | ||
| title: Cancel delete account | ||
| confirm_delete_account: | ||
| cta: You may %{link} or close this window if you're done. | ||
| info: The account for <strong>%{email}</strong> has been deleted. We sent an | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| require 'rails_helper' | ||
|
|
||
| describe 'account_reset/cancel/show.html.slim' do | ||
| it 'has a localized title' do | ||
| expect(view).to receive(:title).with(t('account_reset.cancel_request.title')) | ||
|
|
||
| render | ||
| end | ||
|
|
||
| it 'has button to cancel request' do | ||
| render | ||
| expect(rendered).to have_button t('account_reset.cancel_request.cancel_button') | ||
| end | ||
| end |
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.
If there isn't a token, we want to know about it, and display a helpful message to the user. This keeps it consistent with what
AccountReset::Canceldoes. Since the token validation now happens in two classes, it probably makes sense to extract it into a validator as Jim suggested, and include it in both classes.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.
Agreed. I'll need to refactor cancel now to use the validator
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.
I just copied what DeleteAccountController was doing and it renders a missing token with no message. They will get an error message either way because the post won't work.
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.
Yeah, I realized after I made that comment that this is because of the whole remove the token from the URL thing.