-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LG-13001 remove nullify from EmailAddress model :identities (#11172)
* changelog: Upcoming Features, Partner account, Select email to share with partner * add select email form, build out show and create actions in controller * add feature flag * add additional email if have only 1 * add styles to make display match design better * update translations * fix typo in zh * updated completion show spec * add spec for select_email/show view * add spec for select email controller * fix duplicate key entry * fix missing key * adds email_address_id column to Identities table to track selected email address for sp * add SAML, rename sp_email session key, improve syntax * add checking for selected sp email to authentication on existing account * fix lint errors and bug when adding sp for the first time * add in missing email_address_id * include expectation of email_address_id value * fix app_name error in yml * mising translated app_name * add missing token to view * fix test assertion * clean up text syntax * revise test assertion * be more explicit about a fallback email to get the login id * add sign_in test where an alternate email is selected * add SAML example for switching email * authorization_controller update session syntax * add feature flags * remove stray comment * rename form to build_ * added association to identity model and updated methods that use email_address_id * refactor email_address_id method * make sure listed emails are confirmed * adds validation if email belongs to user * utilize StatusPageComponent * add spec to check email ownership * fix broken merge item and lint error * remove unneeded block markup * bind the multiple emails conditional in an elsif * leverage id instead of email string, clarify how form is validating success * add test at form class to confirm validation, fix id-based test changes and bug introduced at mutliple_emails? * reduce conditional return and fix html formatting * make email_id naming clearer * created separate translation for Email not found error text * remove lint faux pas * remove updating last-sign in upon form submit. rename some variables for consistency. * improve identity querying * check for email id value before trying to find an email address * Add specs for expected behavior after deleting email * markup changes to form page * verify completion at select email cont. account for deleting email that relates to identity, remove no longer needed method in session controller * add needs completion state to controller * change content class to grid-col-fill * add test to attribute assertion, show selected email at completions view * add a logout and explicit login instructions * test change masks problem, reverted * account for deleted or missing email by id * add test for deleted email * update tests to include selected_email_id * add test to account for deleted email * clean up queries add signup before_action test, fix typo, add :nullify * fix variable availability * optimize queries to reduce db load, fixes due to uncovered test failures from last commit, add test coverage for nil email id * take out rescue condition * re-add rescue cases for last_email methods * revise conditional to detect multiple confirmed email addresses * remove unneeded function * add markup to fix button width * remove unnecessary db call at id link * fix some queries, change session to user_session * reset test and select if multiple emails * revise completion show tests * add test cases where select email feature is disabled * correct lint errors * remove unused method and correct for consistent nil-safe * fix email-identity association * email_address_id set at consent but if nil does not change for already consented user * remove commented * change test * remove required email_attribute_id from expectations * ensure selected email is passed to SP * rebase and normalize yaml * remove old migration * replace direct DB call with relationship * changelog: Bug Fixes, Partner accounts, Fixes deletion timeouts caused by original LG-13001 PR * place dependent: nil to satisfy rubocop * delete from user identities email_address_id when email is destoryed * make rubocop happy * move email_address_id nil function to destroy callback * move private block after self * rename callback, remove nil dependent * move destroy email tests to model spec --------- Co-authored-by: Andrew Duthie <[email protected]>
- Loading branch information
1 parent
6e8b29e
commit 9383fd8
Showing
34 changed files
with
739 additions
and
24 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
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,54 @@ | ||
# frozen_string_literal: true | ||
|
||
module SignUp | ||
class SelectEmailController < ApplicationController | ||
before_action :confirm_two_factor_authenticated | ||
before_action :verify_needs_completions_screen | ||
|
||
def show | ||
@sp_name = current_sp.friendly_name || sp.agency&.name | ||
@user_emails = user_emails | ||
@last_sign_in_email_address = last_email | ||
@select_email_form = build_select_email_form | ||
end | ||
|
||
def create | ||
@select_email_form = build_select_email_form | ||
|
||
result = @select_email_form.submit(form_params) | ||
if result.success? | ||
user_session[:selected_email_id] = form_params[:selected_email_id] | ||
redirect_to sign_up_completed_path | ||
else | ||
flash[:error] = result.first_error_message | ||
redirect_to sign_up_select_email_path | ||
end | ||
end | ||
|
||
def user_emails | ||
@user_emails = current_user.confirmed_email_addresses | ||
end | ||
|
||
private | ||
|
||
def build_select_email_form | ||
SelectEmailForm.new(current_user) | ||
end | ||
|
||
def form_params | ||
params.fetch(:select_email_form, {}).permit(:selected_email_id) | ||
end | ||
|
||
def last_email | ||
if user_session[:selected_email_id] | ||
user_emails.find(user_session[:selected_email_id]).email | ||
else | ||
EmailContext.new(current_user).last_sign_in_email_address.email | ||
end | ||
end | ||
|
||
def verify_needs_completions_screen | ||
redirect_to account_url unless needs_completion_screen_reason | ||
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
class SelectEmailForm | ||
include ActiveModel::Model | ||
include ActionView::Helpers::TranslationHelper | ||
|
||
attr_reader :user, :selected_email_id | ||
|
||
validate :validate_owns_selected_email | ||
|
||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def submit(params) | ||
@selected_email_id = params[:selected_email_id] | ||
|
||
success = valid? | ||
FormResponse.new(success:, errors:) | ||
end | ||
|
||
private | ||
|
||
def validate_owns_selected_email | ||
return if user.confirmed_email_addresses.exists?(id: selected_email_id) | ||
|
||
errors.add :email, I18n.t( | ||
'email_address.not_found', | ||
), type: :selected_email_id | ||
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.