-
Notifications
You must be signed in to change notification settings - Fork 166
Make phone number non-editable LG-1722 #3253
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 11 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
fae29d1
LG-1722
cpbgsa be85740
cleanup in isle user_phone_form
cpbgsa 344edc3
fixed spec:
cpbgsa 75982fb
cleaned up user form specs
cpbgsa a947a02
removed outdated specs
cpbgsa 7f7b0c9
removed outdated specs
cpbgsa 9bd5b97
moved specs around
cpbgsa 03c87e8
cleaned specs
cpbgsa df25606
added more relevant tests
cpbgsa da4d88d
cleanup
cpbgsa f37431f
Merge branch 'master' into no-phone-edit-LG-1722
cpbgsa b506f6b
renamed user_phone_form to new_phone_form and related
cpbgsa 3a1ebd3
linting
cpbgsa 0be6f94
readded specs
cpbgsa 08258f9
linting
cpbgsa ae7e6a8
Merge branch 'master' into no-phone-edit-LG-1722
cpbgsa f40bf6b
changed the params required for edit vs new phone form
cpbgsa cbf874f
modified the partials used by the new phone forms to take into consid…
cpbgsa 63bc9b2
fixed spec
cpbgsa 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| class EditPhoneForm | ||
| include ActiveModel::Model | ||
| include RememberDeviceConcern | ||
|
|
||
| validates :otp_delivery_preference, inclusion: { in: %w[voice sms] } | ||
|
|
||
| attr_accessor :phone, :otp_delivery_preference, :otp_make_default_number, :phone_configuration | ||
|
|
||
| def initialize(user, phone_configuration) | ||
| self.user = user | ||
| self.phone_configuration = phone_configuration | ||
| self.otp_make_default_number = true if default_phone_configuration? | ||
| end | ||
|
|
||
| def submit(params) | ||
| ingest_submitted_params(params) | ||
| success = valid? | ||
|
|
||
| self.phone = submitted_phone unless success | ||
| revoke_remember_device(user) if success | ||
| FormResponse.new(success: success, errors: errors.messages, extra: extra_analytics_attributes) | ||
| end | ||
|
|
||
| def delivery_preference_sms? | ||
| phone_configuration&.delivery_preference == 'sms' | ||
| end | ||
|
|
||
| def delivery_preference_voice? | ||
| phone_configuration&.delivery_preference == 'voice' | ||
| end | ||
|
|
||
| def phone_config_changed? | ||
| return true if phone_configuration&.delivery_preference != otp_delivery_preference | ||
| return true if otp_make_default_number && !default_phone_configuration? | ||
| false | ||
| end | ||
|
|
||
| # :reek:FeatureEnvy | ||
| def masked_number | ||
| phone_number = phone_configuration.phone | ||
| return '' if !phone_number || phone_number.blank? | ||
| "***-***-#{phone_number[-4..-1]}" | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_accessor :user, :submitted_phone | ||
|
|
||
| def extra_analytics_attributes | ||
| { | ||
| otp_delivery_preference: otp_delivery_preference, | ||
| } | ||
| end | ||
|
|
||
| def ingest_submitted_params(params) | ||
| delivery_prefs = params[:otp_delivery_preference] | ||
| default_prefs = params[:otp_make_default_number] | ||
|
|
||
| self.otp_delivery_preference = delivery_prefs if delivery_prefs | ||
| self.otp_make_default_number = true if default_prefs | ||
| end | ||
|
|
||
| def default_phone_configuration? | ||
| phone_configuration == user.default_phone_configuration | ||
| 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 |
|---|---|---|
|
|
@@ -7,17 +7,12 @@ class UserPhoneForm | |
| validates :otp_delivery_preference, inclusion: { in: %w[voice sms] } | ||
|
|
||
| attr_accessor :phone, :international_code, :otp_delivery_preference, | ||
| :otp_make_default_number, :phone_configuration | ||
| :otp_make_default_number | ||
|
|
||
| def initialize(user, phone_configuration) | ||
| def initialize(user) | ||
| self.user = user | ||
| self.phone_configuration = phone_configuration | ||
| if phone_configuration.nil? | ||
| self.otp_delivery_preference = user.otp_delivery_preference | ||
| else | ||
| prefill_phone_number(phone_configuration) | ||
| end | ||
| self.otp_make_default_number = true if default_phone_configuration? | ||
| self.otp_delivery_preference = user.otp_delivery_preference | ||
| self.otp_make_default_number = false | ||
| end | ||
|
|
||
| def submit(params) | ||
|
|
@@ -32,23 +27,15 @@ def submit(params) | |
| end | ||
|
|
||
| def delivery_preference_sms? | ||
| return true if phone_configuration.blank? | ||
| phone_configuration&.delivery_preference == 'sms' | ||
| true | ||
| end | ||
|
|
||
| def delivery_preference_voice? | ||
| phone_configuration&.delivery_preference == 'voice' | ||
| false | ||
| end | ||
|
|
||
| def already_has_phone? | ||
| formatted_user_phone != phone && user.phone_configurations.map(&:phone).include?(phone) | ||
| end | ||
|
|
||
| def phone_config_changed? | ||
| return true if formatted_user_phone != phone | ||
| return true if phone_configuration&.delivery_preference != otp_delivery_preference | ||
| return true if otp_make_default_number && !default_phone_configuration? | ||
| false | ||
| user.phone_configurations.map(&:phone).include?(phone) | ||
|
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. not covered
Contributor
Author
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. fixed |
||
| end | ||
|
|
||
| # :reek:FeatureEnvy | ||
|
|
@@ -92,12 +79,4 @@ def ingest_submitted_params(params) | |
| self.otp_delivery_preference = delivery_prefs if delivery_prefs | ||
| self.otp_make_default_number = true if default_prefs | ||
| end | ||
|
|
||
| def default_phone_configuration? | ||
| phone_configuration == user.default_phone_configuration | ||
| end | ||
|
|
||
| def formatted_user_phone | ||
| phone_configuration&.formatted_phone | ||
| 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 |
|---|---|---|
| @@ -1,21 +1,36 @@ | ||
| <% title t('titles.edit_info.phone') %><h1 class="h3 my0"> | ||
| <% title t('titles.edit_info.phone') %> | ||
| <h1 class="h3 my0"> | ||
| <%= t('headings.edit_info.phone') %> | ||
| </h1> | ||
|
|
||
| </h1><%= render 'users/shared/phone_form', | ||
| http_method: :put, | ||
| target_url: manage_phone_path, | ||
| button: t('forms.buttons.submit.confirm_change') %> | ||
| <%= simple_form_for(@edit_phone_form, | ||
| html: {autocomplete: 'off', method: :put, role: 'form'}, | ||
| data: {international_phone_form: true}, | ||
| url: manage_phone_path) do |f| %> | ||
|
|
||
| <% if MfaPolicy.new(current_user).more_than_two_factors_enabled? && @user_phone_form.phone.present? %> | ||
| <br /> | ||
| <div class="mb1 h4"> | ||
| <%= t('two_factor_authentication.phone_label') %>: | ||
| <strong><%= @edit_phone_form.masked_number %></strong> | ||
| </div><br/> | ||
|
|
||
| <%= render 'users/shared/otp_delivery_preference_selection', | ||
| form_obj: @edit_phone_form %> | ||
| <% if TwoFactorAuthentication::PhonePolicy.new(current_user).enabled? %> | ||
| <%= render 'users/shared/otp_make_default_number', | ||
| form_obj: @edit_phone_form %> | ||
| <% end %> | ||
| <%= f.button :submit, t('forms.buttons.submit.confirm_change'), class: 'no-auto-enable btn-wide' %> | ||
| <% end %> | ||
|
|
||
|
|
||
| <% 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_url(id: params[:id]), | ||
| class: 'btn btn-danger btn-wide', | ||
| method: :delete %> | ||
| <%= button_to t('forms.phone.buttons.delete'), manage_phone_path(id: params[:id]), | ||
| class: 'btn btn-danger btn-wide', | ||
| method: :delete %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <%= render 'shared/cancel', link: account_path %> | ||
|
|
||
| <%= stylesheet_link_tag 'intl-tel-number/intlTelInput' %> | ||
| <%= javascript_pack_tag 'intl-tel-input' %> |
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 was deleted.
Oops, something went wrong.
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.
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.
not covered
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.
added test