-
Notifications
You must be signed in to change notification settings - Fork 166
[LG-424] disable phone by deleting #2578
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
17 commits
Select commit
Hold shift + click to select a range
8fee8c7
[LG-424] disable phone by deleting
jgsmith-usds 08a09ed
fix lints
jgsmith-usds 368e17b
Add translations
jgsmith-usds 6e69b7e
add analytics and update text/UX
jgsmith-usds 6b2ec85
delint
jgsmith-usds 3ddd94a
fix button name in spec
jgsmith-usds c075198
Merge branch 'master' into jgs/lg-424-disable-phone-by-deletion
jgsmith-usds 6ab1f04
translation and analytics
jgsmith-usds 49b65ef
fix lints
jgsmith-usds 5587431
Merge branch 'master' into jgs/lg-424-disable-phone-by-deletion
jgsmith-usds 129f4ee
Merge branch 'master' into jgs/lg-424-disable-phone-by-deletion
jgsmith-usds c0fd05f
just a little polish
jgsmith-usds f2aa66c
refactor into validators
jgsmith-usds 5492d35
Merge branch 'master' into jgs/lg-424-disable-phone-by-deletion
jgsmith-usds daf0471
fix test
jgsmith-usds 50510d5
more test coverage
jgsmith-usds 614fb54
Merge branch 'master' into jgs/lg-424-disable-phone-by-deletion
jgsmith-usds 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
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
48 changes: 48 additions & 0 deletions
48
app/forms/two_factor_authentication/phone_deletion_form.rb
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,48 @@ | ||
| module TwoFactorAuthentication | ||
| class PhoneDeletionForm | ||
| include ActiveModel::Model | ||
|
|
||
| attr_reader :user, :configuration | ||
|
|
||
| validates :user, multiple_mfa_options: true | ||
| validates :configuration, allow_nil: true, owned_by_user: true | ||
|
|
||
| def initialize(user, configuration) | ||
| @user = user | ||
| @configuration = configuration | ||
| end | ||
|
|
||
| def submit | ||
| success = configuration.blank? || valid? && configuration_destroyed | ||
|
|
||
| FormResponse.new(success: success, errors: errors.messages, extra: extra_analytics_attributes) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| configuration_present: configuration.present?, | ||
| configuration_id: configuration&.id, | ||
| configuration_owner: configuration&.user&.uuid, | ||
| mfa_method_counts: MfaContext.new(user.reload).enabled_two_factor_configuration_counts_hash, | ||
| } | ||
| end | ||
|
|
||
| def configuration_destroyed | ||
| if configuration.destroy != false | ||
| user.phone_configurations.reload | ||
| update_remember_device_revoked_at | ||
| true | ||
| else | ||
| errors.add(:configuration, :not_destroyed, message: 'cannot delete phone') | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def update_remember_device_revoked_at | ||
| attributes = { remember_device_revoked_at: Time.zone.now } | ||
| UpdateUser.new(user: user, attributes: attributes).call | ||
| end | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the attack vector here? The user and configuration that are passed in to the form are based on the current user. In what scenario would the configuration not be owned by the user? |
||
| 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class MultipleMfaOptionsValidator < ActiveModel::EachValidator | ||
| # :reek:UtilityFunction | ||
| def validate_each(record, attribute, value) | ||
| return if MfaPolicy.new(value).multiple_factors_enabled? | ||
| record.errors.add attribute, 'must have multiple MFA configurations' | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| class OwnedByUserValidator < ActiveModel::EachValidator | ||
| # :reek:UtilityFunction | ||
| def validate_each(record, attribute, value) | ||
| return if value.user&.id == record.user&.id | ||
| record.errors.add attribute, 'must be owned by the user' | ||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| = link_to path do | ||
| span.hide | ||
| = name | ||
| = t('forms.buttons.manage') |
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
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
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
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
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.