Skip to content

Commit

Permalink
feat: improve account recovery integration
Browse files Browse the repository at this point in the history
Jira-Id: CP-7340
  • Loading branch information
victor authored and jaroslavas committed Feb 2, 2024
1 parent ed3cdae commit 24c344c
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "external/protoncore"]
path = external/protoncore
url = ../../shared/protoncore
tag = 18.0.1
tag = 19.0.0
[submodule "tunnelkit"]
path = external/tunnelkit
url = ../tunnelkit
Expand Down
3 changes: 2 additions & 1 deletion apps/ios/ProtonVPN/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ extension AppDelegate {
}
ObservabilityEnv.current.setupWorld(requestPerformer: apiService)

if FeatureFlagsRepository.shared.isEnabled(CoreFeatureFlagType.accountRecovery) {
// For now, the Push Notification part of Account Recovery is not ready, so we won't even be registering
if false && FeatureFlagsRepository.shared.isEnabled(CoreFeatureFlagType.accountRecovery) {
pushNotificationService.setup()

let vpnHandler = AccountRecoveryHandler()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class AppSessionManagerImplementation: AppSessionRefresherImplementation, AppSes
propertiesManager.userRole = properties.userRole
propertiesManager.userAccountCreationDate = properties.userCreateTime
propertiesManager.userLocation = properties.location
propertiesManager.userAccountRecovery = properties.userAccountRecovery
if let clientConfig = properties.clientConfig {
propertiesManager.openVpnConfig = clientConfig.openVPNConfig
propertiesManager.wireguardConfig = clientConfig.wireGuardConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,9 @@ extension NavigationService: SettingsService {
}

func makeAccountRecoveryViewController() -> AccountRecoveryViewController {
AccountRecoveryModule.settingsViewController(networking.apiService)
AccountRecoveryModule.settingsViewController(networking.apiService) { [weak self] accountRecovery in
self?.propertiesManager.userAccountRecovery = accountRecovery
}
}
}

Expand Down Expand Up @@ -427,7 +429,7 @@ extension NavigationService: ConnectionStatusService {
// MARK: Account Recovery
extension NavigationService {
func presentAccountRecoveryViewController() {
guard FeatureFlagsRepository.shared.isEnabled(CoreFeatureFlagType.accountRecovery) else { return }
guard FeatureFlagsRepository.shared.isEnabled(AccountRecoveryModule.feature) else { return }

let viewController = makeAccountRecoveryViewController()
self.windowService.addToStack(viewController, checkForDuplicates: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import UIKit
import Dependencies

import ProtonCoreAccountRecovery
import ProtonCoreDataModel
import ProtonCoreFeatureFlags
import ProtonCoreUIFoundations

Expand Down Expand Up @@ -96,15 +97,14 @@ final class SettingsViewModel {
self.protocolService = protocolService
self.vpnGateway = vpnGateway

isAccountRecoveryEnabled = FeatureFlagsRepository.shared.isEnabled(CoreFeatureFlagType.accountRecovery)
isAccountRecoveryEnabled = FeatureFlagsRepository.shared.isEnabled(AccountRecoveryModule.feature)

if appSessionManager.sessionStatus == .established {
sessionEstablished(vpnGateway: vpnGateway)
}

if isAccountRecoveryEnabled {
self.accountRecoveryRepository = AccountRecoveryRepository(apiService: factory.makeNetworking().apiService)
refreshAccountRecoveryState()
}
startObserving()
}
Expand Down Expand Up @@ -141,9 +141,15 @@ final class SettingsViewModel {
return vpnGateway.connection == .connected || vpnGateway.connection == .disconnected
}

var shouldShowAccountRecovery: Bool = false
var accountRecoveryStateText: String = ""
var accountRecoveryImage: UIImage?
var shouldShowAccountRecovery: Bool {
accountRecoveryStatus?.isVisibleInSettings ?? false
}
var accountRecoveryStateText: String {
accountRecoveryStatus?.valueForSettingsItem ?? ""
}
var accountRecoveryImage: UIImage? {
accountRecoveryStatus?.imageForSettingsItem
}

// MARK: - Header section
func viewForFooter() -> UIView {
Expand Down Expand Up @@ -219,9 +225,6 @@ final class SettingsViewModel {
}

private var accountSection: TableViewSection {
if isAccountRecoveryEnabled {
refreshAccountRecoveryState()
}

let username: String = authKeychain.username ?? Localizable.unavailable
let accountPlanName: String
Expand Down Expand Up @@ -250,7 +253,12 @@ final class SettingsViewModel {
return TableViewSection(title: Localizable.account, cells: [cell])
}
}


private var accountRecoveryStatus: AccountRecovery? {
propertiesManager.userAccountRecovery

}

private var securitySection: TableViewSection {
let vpnProtocol = propertiesManager.vpnProtocol

Expand Down Expand Up @@ -663,22 +671,10 @@ final class SettingsViewModel {
private func pushAccountRecoveryViewController() {
assert(isAccountRecoveryEnabled, "This function shall only be called when AccountRecovery flag is true.")
guard let pushHandler = pushHandler else { return }
let accountRecoveryViewController = AccountRecoveryModule.settingsViewController(networking.apiService)
let accountRecoveryViewController = settingsService.makeAccountRecoveryViewController()
pushHandler(accountRecoveryViewController)
}

private func refreshAccountRecoveryState() {
assert(isAccountRecoveryEnabled, "This function shall only be called when AccountRecovery flag is true.")
Task {

guard let accountRecoveryRepository = accountRecoveryRepository, let status = await accountRecoveryRepository.accountRecoveryStatus()
else { return }
shouldShowAccountRecovery = status.shouldShowSettingsItem
accountRecoveryStateText = status.valueForSettingsItem
accountRecoveryImage = status.imageForSettingsItem
}
}

private func pushProtocolViewController() {
let vpnProtocolViewModel = VpnProtocolViewModel(connectionProtocol: propertiesManager.connectionProtocol,
smartProtocolConfig: propertiesManager.smartProtocolConfig,
Expand Down
2 changes: 1 addition & 1 deletion external/protoncore
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public struct VpnProperties {
public let clientConfig: ClientConfig?
public let userRole: UserRole
public let userCreateTime: Date?
public let userAccountRecovery: AccountRecovery?

public init(serverModels: [ServerModel], vpnCredentials: VpnCredentials, location: UserLocation?, clientConfig: ClientConfig?, user: User?) {
self.serverModels = serverModels
self.vpnCredentials = vpnCredentials
self.location = location
self.clientConfig = clientConfig
self.userRole = .init(rawValue: user?.role ?? 0) ?? .noOrganization

self.userAccountRecovery = user?.accountRecovery

if let createTime = user?.createTime {
self.userCreateTime = Date(timeIntervalSince1970: createTime)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public protocol PropertiesManagerProtocol: AnyObject {
var userDataDisclaimerAgreed: Bool { get set }
var userRole: UserRole { get set }
var userAccountCreationDate: Date? { get set }
var userAccountRecovery: AccountRecovery? { get set }

var trialWelcomed: Bool { get set }
var warnedTrialExpiring: Bool { get set }
Expand Down Expand Up @@ -247,6 +248,8 @@ public class PropertiesManager: PropertiesManagerProtocol {

public var onAlternativeRoutingChange: ((Bool) -> Void)?

public var userAccountRecovery: ProtonCoreDataModel.AccountRecovery?

public var blockOneTimeAnnouncement: Bool {
defaults.bool(forKey: Keys.blockOneTimeAnnouncement.rawValue)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public class PropertiesManagerMock: PropertiesManagerProtocol {
set { queue.sync { _partnerTypes = newValue } }
}

public var userAccountRecovery: ProtonCoreDataModel.AccountRecovery?
public var userRole: UserRole = .noOrganization
public var excludeLocalNetworks: Bool = true {
didSet {
Expand Down

0 comments on commit 24c344c

Please sign in to comment.