[PM-23311] Sync vault before exporting.

This commit is contained in:
André Bispo 2025-07-22 15:52:47 +01:00
parent 17287680d9
commit eb271ae99d
No known key found for this signature in database
GPG Key ID: E5610EF043C76548

View File

@ -429,6 +429,15 @@ class ExportVaultViewModel @Inject constructor(
} }
viewModelScope.launch { viewModelScope.launch {
// Check if the export vault policy prevents exporting the vault.
syncExportVaultPolicy()
if (state.policyPreventsExport) {
updateStateWithError(
message = R.string.disable_personal_vault_export_policy_in_effect.asText(),
)
return@launch
}
val result = vaultRepository.exportVaultDataToString( val result = vaultRepository.exportVaultDataToString(
format = state.exportFormat.toExportFormat( format = state.exportFormat.toExportFormat(
password = if (state.exportFormat == ExportVaultFormat.JSON_ENCRYPTED) { password = if (state.exportFormat == ExportVaultFormat.JSON_ENCRYPTED) {
@ -475,6 +484,15 @@ class ExportVaultViewModel @Inject constructor(
return listOf(CipherType.CARD) return listOf(CipherType.CARD)
} }
private suspend fun syncExportVaultPolicy() {
// Sync vault policies to ensure we have the latest data.
vaultRepository.syncForResult()
// Check if the policy prevents exporting the vault.
state.policyPreventsExport = policyManager
.getActivePolicies(type = PolicyTypeJson.DISABLE_PERSONAL_VAULT_EXPORT)
.any()
}
} }
/** /**
@ -490,7 +508,7 @@ data class ExportVaultState(
val filePasswordInput: String, val filePasswordInput: String,
val passwordInput: String, val passwordInput: String,
val passwordStrengthState: PasswordStrengthState, val passwordStrengthState: PasswordStrengthState,
val policyPreventsExport: Boolean, var policyPreventsExport: Boolean,
val showSendCodeButton: Boolean, val showSendCodeButton: Boolean,
) : Parcelable { ) : Parcelable {
/** /**