mirror of
https://github.com/twofas/2fas-ios.git
synced 2024-11-22 02:10:19 +01:00
TF-1518/TF-1519 Fix for clearing sync storage
This commit is contained in:
parent
088df2e345
commit
78080b7cc4
@ -45,7 +45,7 @@ public protocol CloudBackupStateInteracting: AnyObject {
|
||||
|
||||
var successSyncDate: Date? { get }
|
||||
func saveSuccessSyncDate()
|
||||
func clearSavesuccessSync()
|
||||
func clearSaveSuccessSync()
|
||||
}
|
||||
|
||||
/// Use one instance per use case
|
||||
@ -152,7 +152,7 @@ extension CloudBackupStateInteractor: CloudBackupStateInteracting {
|
||||
mainRepository.saveSuccessSyncDate(Date())
|
||||
}
|
||||
|
||||
func clearSavesuccessSync() {
|
||||
func clearSaveSuccessSync() {
|
||||
Log("CloudBackupStateInteractor - clearSavesuccessSync", module: .interactor)
|
||||
mainRepository.saveSuccessSyncDate(nil)
|
||||
}
|
||||
|
@ -250,7 +250,8 @@ public final class InteractorFactory {
|
||||
public func mdmInteractor() -> MDMInteracting {
|
||||
MDMInteractor(
|
||||
mainRepository: MainRepositoryImpl.shared,
|
||||
pairingInteractor: pairingWebExtensionInteractor()
|
||||
pairingInteractor: pairingWebExtensionInteractor(),
|
||||
cloudBackupStateInteractor: cloudBackupStateInteractor(listenerID: "MDMInteractor")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Common
|
||||
|
||||
public protocol MDMInteracting: AnyObject {
|
||||
var isBackupBlocked: Bool { get }
|
||||
@ -34,10 +35,25 @@ public protocol MDMInteracting: AnyObject {
|
||||
final class MDMInteractor {
|
||||
private let mainRepository: MainRepository
|
||||
private let pairingInteractor: PairingWebExtensionInteracting
|
||||
private let cloudBackupStateInteractor: CloudBackupStateInteracting
|
||||
|
||||
init(mainRepository: MainRepository, pairingInteractor: PairingWebExtensionInteracting) {
|
||||
private var syncDetermined = false
|
||||
private var syncDisabled = false
|
||||
|
||||
init(
|
||||
mainRepository: MainRepository,
|
||||
pairingInteractor: PairingWebExtensionInteracting,
|
||||
cloudBackupStateInteractor: CloudBackupStateInteracting
|
||||
) {
|
||||
self.mainRepository = mainRepository
|
||||
self.pairingInteractor = pairingInteractor
|
||||
self.cloudBackupStateInteractor = cloudBackupStateInteractor
|
||||
|
||||
cloudBackupStateInteractor.stateChanged = { [weak self] in self?.syncStateDetermined() }
|
||||
cloudBackupStateInteractor.startMonitoring()
|
||||
if cloudBackupStateInteractor.isBackupEnabled {
|
||||
syncStateDetermined()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +71,7 @@ extension MDMInteractor: MDMInteracting {
|
||||
}
|
||||
|
||||
var isLockoutAttemptsChangeBlocked: Bool {
|
||||
mainRepository.mdmLockoutAttepts != nil
|
||||
mainRepository.mdmLockoutAttempts != nil
|
||||
}
|
||||
|
||||
var isLockoutBlockTimeChangeBlocked: Bool {
|
||||
@ -71,24 +87,50 @@ extension MDMInteractor: MDMInteracting {
|
||||
}
|
||||
|
||||
func apply() {
|
||||
if isBackupBlocked && mainRepository.isCloudBackupConnected {
|
||||
mainRepository.clearBackup()
|
||||
if syncDetermined {
|
||||
disableSyncIfNecessary()
|
||||
}
|
||||
|
||||
if isBiometryBlocked && mainRepository.isBiometryEnabled {
|
||||
Log("MDMInteractor - disabling Biometry", module: .interactor)
|
||||
mainRepository.disableBiometry()
|
||||
}
|
||||
|
||||
if isBrowserExtensionBlocked && pairingInteractor.hasActiveBrowserExtension {
|
||||
Log("MDMInteractor - disabling Browser Extension", module: .interactor)
|
||||
pairingInteractor.disableExtension(completion: { _ in })
|
||||
}
|
||||
|
||||
if let lockoutAttepts = mainRepository.mdmLockoutAttepts {
|
||||
mainRepository.setAppLockAttempts(lockoutAttepts)
|
||||
if let lockoutAttempts = mainRepository.mdmLockoutAttempts {
|
||||
Log("MDMInteractor - setting Lockout Attemtps", module: .interactor)
|
||||
mainRepository.setAppLockAttempts(lockoutAttempts)
|
||||
}
|
||||
|
||||
if let blockTime = mainRepository.mdmLockoutBlockTime {
|
||||
Log("MDMInteractor - setting Lockout Block Time", module: .interactor)
|
||||
mainRepository.setAppLockBlockTime(blockTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension MDMInteractor {
|
||||
func syncStateDetermined() {
|
||||
guard !syncDetermined else { return }
|
||||
Log("MDMInteractor - syncStateDetermined", module: .interactor)
|
||||
syncDetermined = true
|
||||
cloudBackupStateInteractor.stopMonitoring()
|
||||
disableSyncIfNecessary()
|
||||
}
|
||||
|
||||
func disableSyncIfNecessary() {
|
||||
Log(
|
||||
"MDMInteractor - disableSyncIfNecessary: Backup enabled: \(cloudBackupStateInteractor.isBackupEnabled)",
|
||||
module: .interactor
|
||||
)
|
||||
if isBackupBlocked && cloudBackupStateInteractor.isBackupEnabled && !syncDisabled {
|
||||
Log("MDMInteractor - disableSyncIfNecessary - Clearing", module: .interactor)
|
||||
syncDisabled = true
|
||||
mainRepository.clearBackup()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ protocol MainRepository: AnyObject {
|
||||
var mdmIsBackupBlocked: Bool { get }
|
||||
var mdmIsBiometryBlocked: Bool { get }
|
||||
var mdmIsBrowserExtensionBlocked: Bool { get }
|
||||
var mdmLockoutAttepts: AppLockAttempts? { get }
|
||||
var mdmLockoutAttempts: AppLockAttempts? { get }
|
||||
var mdmLockoutBlockTime: AppLockBlockTime? { get }
|
||||
var mdmIsPasscodeRequried: Bool { get }
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ extension MainRepositoryImpl {
|
||||
mdmRepository.isBrowserExtensionBlocked
|
||||
}
|
||||
|
||||
var mdmLockoutAttepts: AppLockAttempts? {
|
||||
var mdmLockoutAttempts: AppLockAttempts? {
|
||||
mdmRepository.lockoutAttepts
|
||||
}
|
||||
|
||||
|
@ -473,16 +473,16 @@ final class CloudKit {
|
||||
Log("CloudKit - finishedFetchingZoneChange", module: .cloudSync)
|
||||
zoneUpdated = false
|
||||
|
||||
if UIApplication.shared.applicationState == .background {
|
||||
abortSync?()
|
||||
syncTokenHandler.prepare()
|
||||
clearRecordChanges()
|
||||
operation?.cancel()
|
||||
operation = nil
|
||||
return
|
||||
}
|
||||
|
||||
DispatchQueue.main.async {
|
||||
if UIApplication.shared.applicationState == .background {
|
||||
self.abortSync?()
|
||||
self.syncTokenHandler.prepare()
|
||||
self.clearRecordChanges()
|
||||
self.operation?.cancel()
|
||||
self.operation = nil
|
||||
return
|
||||
}
|
||||
|
||||
if !self.deletedRecords.isEmpty {
|
||||
Log("CloudKit - deletedRecords not empty", module: .cloudSync)
|
||||
self.deletedEntries?(self.deletedRecords.map { (name: $0.record.recordName, type: $0.type) })
|
||||
|
@ -119,7 +119,7 @@ extension MainModuleInteractor: MainModuleInteracting {
|
||||
}
|
||||
|
||||
func clearSavesuccessSync() {
|
||||
cloudBackupStateInteractor.clearSavesuccessSync()
|
||||
cloudBackupStateInteractor.clearSaveSuccessSync()
|
||||
}
|
||||
|
||||
// MARK: - New app version
|
||||
|
@ -46,20 +46,25 @@ extension BackupMenuPresenter {
|
||||
footer: footer
|
||||
)
|
||||
|
||||
let exportEnabled = interactor.exportEnabled && interactor.isBackupAllowed
|
||||
let fileBackup = BackupMenuSection(
|
||||
title: T.Backup.fileBackup,
|
||||
cells: [
|
||||
.init(
|
||||
title: T.Backup.import,
|
||||
action: .importFile
|
||||
),
|
||||
let exportEnabled = interactor.exportEnabled
|
||||
var cells: [BackupMenuCell] = [
|
||||
.init(
|
||||
title: T.Backup.import,
|
||||
action: .importFile
|
||||
)
|
||||
]
|
||||
if interactor.isBackupAllowed {
|
||||
cells.append(
|
||||
.init(
|
||||
title: T.Backup.export,
|
||||
action: .exportFile,
|
||||
isEnabled: exportEnabled
|
||||
)
|
||||
],
|
||||
)
|
||||
}
|
||||
let fileBackup = BackupMenuSection(
|
||||
title: T.Backup.fileBackup,
|
||||
cells: cells,
|
||||
footer: T.Backup.fileBackupOfflineTitle
|
||||
)
|
||||
|
||||
@ -82,7 +87,7 @@ extension BackupMenuPresenter {
|
||||
|
||||
menu.append(fileBackup)
|
||||
|
||||
if interactor.isCloudBackupConnected {
|
||||
if interactor.isCloudBackupConnected && interactor.isBackupAllowed {
|
||||
menu.append(cloudBackupDeletition)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user