Skip to content

Lg 6230 mfa selection count#6358

Merged
SammySteiner merged 25 commits intomainfrom
LG-6230-mfa-selection-count
May 18, 2022
Merged

Lg 6230 mfa selection count#6358
SammySteiner merged 25 commits intomainfrom
LG-6230-mfa-selection-count

Conversation

@SammySteiner
Copy link
Contributor

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

  • Update presenters with disabled? method to determine if the mfa option should be disabled.
  • Presenter options should also know if they are default checked.
  • There is a new style-guide release to cover these styles
  • New SVG icons for the illustrated options work with filter now that we've removed the white background layer so we can grey out the icons with css
  • Updated tests

Example

Screen Shot 2022-05-16 at 4 52 50 PM

@SammySteiner
Copy link
Contributor Author

Checkbox looked funny on zoomed out browser, here's a normal pic:
Screen Shot 2022-05-16 at 4 54 06 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SammySteiner SammySteiner force-pushed the LG-6230-mfa-selection-count branch from 6adac77 to b2af80d Compare May 17, 2022 13:21
@SammySteiner SammySteiner requested review from jmdembe and mdiarra3 May 17, 2022 14:29
Comment on lines +18 to +28
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. looks like this top branch is not covered by tests
  2. the return keyword is not needed
  3. We can take advantage of Rails I18n built in pluralization: https://guides.rubyonrails.org/i18n.html#pluralization

So this can all be:

Suggested change
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'

Comment on lines +34 to +46
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment about pluralization and %{count}

attr_reader :configuration, :user

def initialize(configuration = nil)
def initialize(configuration = nil, user = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe consider making these keyword arguments?
Or could we derive user from configuration?

def piv_cac_option
return [] unless current_device_is_desktop?
[TwoFactorAuthentication::PivCacSelectionPresenter.new]
[TwoFactorAuthentication::PivCacSelectionPresenter.new(nil, @user)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Suggested change
[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 %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

SammySteiner and others added 8 commits May 17, 2022 14:24
…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>
end
end

def mfa_configuration_count; end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this default to zero? or should it throw unimplemented?

Suggested change
def mfa_configuration_count; end
def mfa_configuration_count
raise NotImplementedError
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

SammySteiner and others added 2 commits May 18, 2022 13:25
…_presenter.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
…nter.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
SammySteiner and others added 4 commits May 18, 2022 13:26
…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>
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one last change and then good to go I think

…resenter_spec.rb

Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@SammySteiner SammySteiner merged commit fb1d776 into main May 18, 2022
@SammySteiner SammySteiner deleted the LG-6230-mfa-selection-count branch May 18, 2022 19:11
@aduth aduth mentioned this pull request Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants