8000 PM-10276: Set up unlock: enable pin unlock by matt-livefront · Pull Request #867 · bitwarden/ios · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

PM-10276: Set up unlock: enable pin unlock #867

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 5 commits into from
Sep 13, 2024

Conversation

matt-livefront
Copy link
Collaborator
@matt-livefront matt-livefront commented Aug 23, 2024

🎟️ Tracking

PM-10276
PM-10277

📔 Objective

This enables toggling pin unlock on the setup up unlock screen as part of account setup.

📸 Screenshots

Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-08-23.at.11.36.19.mp4

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
codecov bot commented Aug 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.54%. Comparing base (aa6ba21) to head (9ebf6b3).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #867      +/-   ##
==========================================
- Coverage   88.77%   88.54%   -0.24%     
==========================================
  Files         617      618       +1     
  Lines       30898    38908    +8010     
==========================================
+ Hits        27430    34450    +7020     
- Misses       3468     4458     +990     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor
github-actions bot commented Aug 23, 2024

Logo
Checkmarx One – Scan Summary & Detailsd96ca3c4-ca53-450e-bd0a-0bfb96bcaf6f

No New Or Fixed Issues Found

Comment on lines 108 to 115
do {
try await services.authRepository.allowBioMetricUnlock(enabled)
return try await services.biometricsRepository.getBiometricUnlockStatus()
} catch {
services.errorReporter.log(error: error)
showAlert(.defaultAlert(title: Localizations.anErrorHasOccurred))
return try? await services.biometricsRepository.getBiometricUnlockStatus()
}
Copy link
Member

Choose a reason for hiding this comment

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

🤔 This line return try? await services.biometricsRepository.getBiometricUnlockStatus() is the same as the above one but with try? so why not return nil directly at the end of the catch? Can getBiometricUnlockStatus() change somehow in between? If so, could a comment be added how that situation may happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a bit of an edge case. If authRepository.allowBioMetricUnlock() throws an error, I'd still want to return the current unlock status. Returning nil will ultimately remove the biometrics toggle from the screen, since we use that to determine whether biometrics are available or not. I can add a comment.

Comment on lines 120 to 140
if enabled {
let pin = try await showEnterPinAlert(showAlert: showAlert)
guard !pin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return false }

let userHasMasterPassword = try await services.stateService.getUserHasMasterPassword()
let biometricType = services.biometricsRepository.getBiometricAuthenticationType()
let requirePasswordAfterRestart = if userHasMasterPassword {
await showUnlockWithPinAlert(biometricType: biometricType, showAlert: showAlert)
} else {
false
}

try await services.authRepository.setPins(
pin,
requirePasswordAfterRestart: requirePasswordAfterRestart
)
} else {
try await services.authRepository.clearPins()
}

return enabled
Copy link
Member

Choose a reason for hiding this comment

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

⛏️ Could we use guard to reduce nesting?

Suggested change
if enabled {
let pin = try await showEnterPinAlert(showAlert: showAlert)
guard !pin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return false }
let userHasMasterPassword = try await services.stateService.getUserHasMasterPassword()
let biometricType = services.biometricsRepository.getBiometricAuthenticationType()
let requirePasswordAfterRestart = if userHasMasterPassword {
await showUnlockWithPinAlert(biometricType: biometricType, showAlert: showAlert)
} else {
false
}
try await services.authRepository.setPins(
pin,
requirePasswordAfterRestart: requirePasswordAfterRestart
)
} else {
try await services.authRepository.clearPins()
}
return enabled
guard enabled else {
try await services.authRepository.clearPins()
return false
}
let pin = try await showEnterPinAlert(showAlert: showAlert)
guard !pin.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return false }
let userHasMasterPassword = try await services.stateService.getUserHasMasterPassword()
let biometricType = services.biometricsRepository.getBiometricAuthenticationType()
let requirePasswordAfterRestart = if userHasMasterPassword {
await showUnlockWithPinAlert(biometricType: biometricType, showAlert: showAlert)
} else {
false
}
try await services.authRepository.setPins(
pin,
requirePasswordAfterRestart: requirePasswordAfterRestart
)
return true

fedemkr
fedemkr previously approved these changes Aug 26, 2024
@@ -90,7 +96,9 @@ final class AccountSecurityProcessor: StateProcessor<
case let .sessionTimeoutValueChanged(newValue):
setVaultTimeout(value: newValue)
case let .toggleUnlockWithPINCode(isOn):
toggleUnlockWithPIN(isOn)
Task {
await toggleUnlockWithPIN(isOn)
Copy link
Collaborator
@phil-livefront phil-livefront Aug 27, 2024

Choose a reason for hiding this comment

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

should this be an Effect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I can change that.

phil-livefront
phil-livefront previously approved these changes Sep 11, 2024
Copy link
Collaborator
@phil-livefront phil-livefront left a comment

Choose a reason for hiding this comment

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

Looks good! a couple questions but nothing blocking an approval.

switch unlockMethod {
case .biometrics:
Task {
Task {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should this be an Effect instead?

@@ -5,17 +5,19 @@
class VaultUnlockSetupProcessor: StateProcessor<VaultUnlockSetupState, VaultUnlockSetupAction, VaultUnlockSetupEffect> {
// MARK: Types

typealias Services = HasAuthRepository
typealias Services = DefaultVaultUnlockSetupHelper.Services
& HasBiometricsRepository
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we nuke HasBiometricsRepository since its within DefaultVaultUnlockSetupHelper.Services?

/// A default implementation of `VaultUnlockSetupHelper` which is used to set up vault unlock methods.
///
@MainActor
class DefaultVaultUnlockSetupHelper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just curious, why not make this a service itself?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We've used this concept of a helper elsewhere to extract logic from the processor or share logic between multiple processors. In this case, while not directly showing alerts, it does end up creating alerts that should be shown. So I feel like it belongs in the UI layer rather than the service layer.

Copy link
Collaborator
@phil-livefront phil-livefront left a comment

Choose a reason for hiding this comment

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

👍

@matt-livefront matt-livefront merged commit 85732a9 into main Sep 13, 2024
8 checks passed
@matt-livefront matt-livefront deleted the matt/PM-10276-set-up-unlock-pin branch September 13, 2024 14:23
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
0