-
Notifications
You must be signed in to change notification settings - Fork 166
LG-2246 Fix phone edit authorization issues #3410
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
9 commits
Select commit
Hold shift + click to select a range
9e14c6c
LG-2246 Fix phone edit authorization issues
jmhooper 84b5256
Add analytics events
jmhooper 4ef8508
fix test
jmhooper 2bdd35f
lint
jmhooper 331914d
add tests
jmhooper d87482f
delint
jmhooper cbe7e61
more linter stuff
jmhooper ef7c584
add add phone spec
jmhooper 1a1b558
Dont let a user delete an MFA method if they will drop below 2 methods
jmhooper 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
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,65 @@ | ||
| module Users | ||
| class EditPhoneController < ReauthnRequiredController | ||
| include RememberDeviceConcern | ||
|
|
||
| before_action :confirm_two_factor_authenticated | ||
| before_action :confirm_user_can_edit_phone | ||
| before_action :confirm_user_can_remove_phone, only: %i[destroy] | ||
|
|
||
| def edit | ||
| analytics.track_event(Analytics::PHONE_CHANGE_VIEWED) | ||
| @edit_phone_form = EditPhoneForm.new(current_user, phone_configuration) | ||
| end | ||
|
|
||
| def update | ||
| @edit_phone_form = EditPhoneForm.new(current_user, phone_configuration) | ||
| result = @edit_phone_form.submit(edit_phone_params) | ||
| analytics.track_event(Analytics::PHONE_CHANGE_SUBMITTED, result.to_h) | ||
| if result.success? | ||
| redirect_to account_url | ||
| else | ||
| render :edit | ||
| end | ||
| end | ||
|
|
||
| def destroy | ||
| track_deletion_analytics_event | ||
| phone_configuration.destroy! | ||
| revoke_remember_device(current_user) | ||
| flash[:success] = t('two_factor_authentication.phone.delete.success') | ||
| redirect_to account_url | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def confirm_user_can_edit_phone | ||
| render_not_found if phone_configuration.nil? | ||
| false | ||
| end | ||
|
|
||
| def confirm_user_can_remove_phone | ||
| return if MfaPolicy.new(current_user).more_than_two_factors_enabled? | ||
| flash[:error] = t('two_factor_authentication.phone.delete.failure') | ||
| redirect_to account_url | ||
| false | ||
| end | ||
|
|
||
| def track_deletion_analytics_event | ||
| analytics.track_event( | ||
| Analytics::PHONE_DELETION, | ||
| success: true, | ||
| phone_configuration_id: phone_configuration.id, | ||
| ) | ||
| create_user_event(:phone_removed) | ||
| end | ||
|
|
||
| def phone_configuration | ||
| @phone_configuration ||= current_user.phone_configurations.find_by(id: params[:id]) | ||
| end | ||
|
|
||
| def edit_phone_params | ||
| params.require(:edit_phone_form).permit(:delivery_preference, | ||
| :make_default_number) | ||
| 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
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
34 changes: 34 additions & 0 deletions
34
app/views/users/edit_phone/_delivery_preference_selection.html.erb
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,34 @@ | ||
| <div class="mb3"> | ||
| <fieldset class="m0 p0 border-none"> | ||
| <legend class="mb1 h4 serif bold"> | ||
| <%= t('two_factor_authentication.otp_delivery_preference.title') %> | ||
| </legend> | ||
| <p class="mt0 mb2" id="otp_delivery_preference_instruction"> | ||
| <%= t('two_factor_authentication.otp_delivery_preference.instruction') %> | ||
| </p> | ||
| <label | ||
| class="btn-border col-12 sm-col-5 sm-mr2 mb2 sm-mb0" | ||
| for='edit_phone_form_delivery_preference_sms' | ||
| > | ||
| <div class="radio"> | ||
| <%= radio_button_tag 'edit_phone_form[delivery_preference]', | ||
| :sms, @edit_phone_form.delivery_preference_sms?, | ||
| class: :otp_delivery_preference_sms %> | ||
| <span class="indicator"></span> | ||
| <%= t('two_factor_authentication.otp_delivery_preference.sms') %> | ||
| </div> | ||
| </label> | ||
| <label | ||
| class="btn-border col-12 sm-col-5 mb0" | ||
| for='edit_phone_form_delivery_preference_voice' | ||
| > | ||
| <div class="radio"> | ||
| <%= radio_button_tag 'edit_phone_form[delivery_preference]', | ||
| :voice, @edit_phone_form.delivery_preference_voice?, | ||
| class: :otp_delivery_preference_voice %> | ||
| <span class="indicator"></span> | ||
| <%= t('two_factor_authentication.otp_delivery_preference.voice') %> | ||
| </div> | ||
| </label> | ||
| </fieldset> | ||
| </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,18 @@ | ||
| <div class="mb3"> | ||
| <fieldset class="m0 p0 border-none"> | ||
| <legend class="mb1 h4 serif bold"> | ||
| <%= t('two_factor_authentication.otp_make_default_number.title') %> | ||
| </legend> | ||
| <p class="mt0 mb2" id="otp_make_default_number_instruction"> | ||
| <%= t('two_factor_authentication.otp_make_default_number.instruction') %> | ||
| </p> | ||
| <label class="btn-border col-8"> | ||
| <div class="checkbox"> | ||
| <%= check_box_tag 'edit_phone_form[make_default_number]', | ||
| :otp_make_default_number, @edit_phone_form.default_phone_configuration? %> | ||
| <span class="indicator"></span> | ||
| <%= t('two_factor_authentication.otp_make_default_number.label') %> | ||
| </div> | ||
| </label> | ||
| </fieldset> | ||
| </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,8 @@ | ||
| <% if MfaPolicy.new(current_user).more_than_two_factors_enabled? %> | ||
| <br/> | ||
| <div class="sm-col-8 mb3"> | ||
| <%= button_to t('forms.phone.buttons.delete'), manage_phone_path(id: @phone_configuration.id), | ||
| class: 'btn btn-danger btn-wide', | ||
| method: :delete %> | ||
| </div> | ||
| <% 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <% title t('titles.edit_info.phone') %> | ||
| <h1 class="h3 my0"> | ||
| <%= t('headings.edit_info.phone') %> | ||
| </h1> | ||
|
|
||
| <%= simple_form_for(@edit_phone_form, | ||
| html: {autocomplete: 'off', method: :put, role: 'form'}, | ||
| url: manage_phone_path(id: @phone_configuration.id)) do |f| %> | ||
|
|
||
| <div class="mb1 h4"> | ||
| <%= t('two_factor_authentication.phone_label') %>: | ||
| <strong><%= @edit_phone_form.masked_number %></strong> | ||
| </div><br/> | ||
|
|
||
| <%= render 'delivery_preference_selection' %> | ||
| <%= render 'make_default_number' %> | ||
|
|
||
| <%= f.button :submit, t('forms.buttons.submit.confirm_change'), class: 'no-auto-enable btn-wide' %> | ||
| <% end %> | ||
|
|
||
| <%= render 'remove_phone' %> | ||
|
|
||
| <%= render 'shared/cancel', link: account_path %> |
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.