Conversation
config/i18n-tasks.yml
Outdated
There was a problem hiding this comment.
I'd have a soft-preference to either using the inline comment hint or just avoid the dynamic key, since it'd be easier to maintain over time closer to the source.
There was a problem hiding this comment.
I refactored this since the method in all 6 files was going to get long and put it into the presenter, with a mfa_config_count method that I could override in each individual presenter since that was the only real difference. Backup codes needed to be separate, but this is cleaner overall.
…ed methods as selected and disabled, LG-6230
6adac77 to
b2af80d
Compare
app/presenters/two_factor_authentication/auth_app_selection_presenter.rb
Outdated
Show resolved
Hide resolved
| if user.backup_code_configurations.unused.count == 1 | ||
| return t( | ||
| 'two_factor_authentication.two_factor_choice_options.unused_backup_code', | ||
| count: mfa_configuration_count, | ||
| ) | ||
| else | ||
| return t( | ||
| 'two_factor_authentication.two_factor_choice_options.unused_backup_code_plural', | ||
| count: mfa_configuration_count, | ||
| ) | ||
| end |
There was a problem hiding this comment.
- looks like this top branch is not covered by tests
- the
returnkeyword is not needed - We can take advantage of Rails I18n built in pluralization: https://guides.rubyonrails.org/i18n.html#pluralization
So this can all be:
| if user.backup_code_configurations.unused.count == 1 | |
| return t( | |
| 'two_factor_authentication.two_factor_choice_options.unused_backup_code', | |
| count: mfa_configuration_count, | |
| ) | |
| else | |
| return t( | |
| 'two_factor_authentication.two_factor_choice_options.unused_backup_code_plural', | |
| count: mfa_configuration_count, | |
| ) | |
| end | |
| t( | |
| 'two_factor_authentication.two_factor_choice_options.unused_backup_code', | |
| count: mfa_configuration_count, | |
| ) |
If we change the translations to be structured like:
two_factor_authentication:
two_factor_choice_options:
unused_backup_code:
one: 'one thing'
other: '%{count} things'
app/presenters/two_factor_authentication/piv_cac_selection_presenter.rb
Outdated
Show resolved
Hide resolved
| def mfa_configuration | ||
| return '' if !disabled? | ||
| if mfa_configuration_count == 1 | ||
| return t( | ||
| 'two_factor_authentication.two_factor_choice_options.configurations_added', | ||
| count: mfa_configuration_count, | ||
| ) | ||
| else | ||
| return t( | ||
| 'two_factor_authentication.two_factor_choice_options.configurations_added_plural', | ||
| count: mfa_configuration_count, | ||
| ) | ||
| end |
There was a problem hiding this comment.
same comment about pluralization and %{count}
| attr_reader :configuration, :user | ||
|
|
||
| def initialize(configuration = nil) | ||
| def initialize(configuration = nil, user = nil) |
There was a problem hiding this comment.
Maybe consider making these keyword arguments?
Or could we derive user from configuration?
app/presenters/two_factor_authentication/webauthn_platform_selection_presenter.rb
Outdated
Show resolved
Hide resolved
| def piv_cac_option | ||
| return [] unless current_device_is_desktop? | ||
| [TwoFactorAuthentication::PivCacSelectionPresenter.new] | ||
| [TwoFactorAuthentication::PivCacSelectionPresenter.new(nil, @user)] |
There was a problem hiding this comment.
I'd recommend using the attr accessor here (and in all these methods), because direct instance variable access will quietly return nil if typoed, but methods will throw errors
| [TwoFactorAuthentication::PivCacSelectionPresenter.new(nil, @user)] | |
| [TwoFactorAuthentication::PivCacSelectionPresenter.new(nil, user)] |
| ) do %> | ||
| <%= image_tag(asset_url("mfa-options/#{option.type}.svg"), alt: "#{option.label} icon", class: 'usa-checkbox__image') %> | ||
| <div class="usa-checkbox__label--text"><%= option.label %> | ||
| <div class="usa-checkbox__label--text"><%= option.label %> <%= option.mfa_configuration %> |
There was a problem hiding this comment.
WDYT of renaming this method to mfa_configuration_description or something? Based on the name of the method it sounds like a type or something not user-facing
…esenter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…senter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…ection_presenter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
app/presenters/two_factor_authentication/backup_code_selection_presenter.rb
Outdated
Show resolved
Hide resolved
app/presenters/two_factor_authentication/phone_selection_presenter.rb
Outdated
Show resolved
Hide resolved
| end | ||
| end | ||
|
|
||
| def mfa_configuration_count; end |
There was a problem hiding this comment.
should this default to zero? or should it throw unimplemented?
| def mfa_configuration_count; end | |
| def mfa_configuration_count | |
| raise NotImplementedError | |
| end |
There was a problem hiding this comment.
I'm not sure NotImplementedError is the right approach here, https://ruby-doc.org/core-2.3.0/NotImplementedError.html, seems to be more about having things be not implemented depending on the environment or os.
There are some presenters that inherit the selection presenter and they should not get mfa_configuration_description/count called on them. I'm happy those returning nothing in that case as we have no requirements for what they should/would return if they are needed.
app/presenters/two_factor_authentication/webauthn_selection_presenter.rb
Outdated
Show resolved
Hide resolved
spec/presenters/two_factor_authentication/webauthn_platform_selection_presenter_spec.rb
Outdated
Show resolved
Hide resolved
spec/presenters/two_factor_authentication/webauthn_selection_presenter_spec.rb
Outdated
Show resolved
Hide resolved
spec/views/partials/multi_factor_authentication/_mfa_selection.html.erb_spec.rb
Outdated
Show resolved
Hide resolved
…_presenter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…nter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…esenter.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…lection_presenter_spec.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…resenter_spec.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
….html.erb_spec.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
zachmargolis
left a comment
There was a problem hiding this comment.
one last change and then good to go I think
spec/presenters/two_factor_authentication/auth_app_selection_presenter_spec.rb
Outdated
Show resolved
Hide resolved
…resenter_spec.rb Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>

What
After users create an account with 1 mfa method, they are now shown a message suggesting they create a second mfa configuration. If they so choose, we want to display the mfa option they've already configured as checked and disabled.
How
Example