BIT-1729: Re-load the options to apply policy values (#1000)

This commit is contained in:
David Perez
2024-02-13 12:53:12 -06:00
committed by Álison Fernandes
parent 6bfb9440b5
commit 5928987a9b
2 changed files with 75 additions and 6 deletions

View File

@@ -101,10 +101,7 @@ class GeneratorViewModel @Inject constructor(
init {
stateFlow.onEach { savedStateHandle[KEY_STATE] = it }.launchIn(viewModelScope)
when (val selectedType = mutableStateFlow.value.selectedType) {
is Passcode -> loadPasscodeOptions(selectedType, usePolicyDefault = true)
is Username -> loadUsernameOptions(selectedType)
}
loadOptions()
policyManager
.getActivePoliciesFlow<PolicyInformation.PasswordGenerator>()
.map { GeneratorAction.Internal.PasswordGeneratorPolicyReceive(it) }
@@ -251,6 +248,13 @@ class GeneratorViewModel @Inject constructor(
//region Generation Handlers
private fun loadOptions() {
when (val selectedType = state.selectedType) {
is Passcode -> loadPasscodeOptions(selectedType = selectedType, usePolicyDefault = true)
is Username -> loadUsernameOptions(selectedType = selectedType)
}
}
@Suppress("CyclomaticComplexMethod")
private fun loadPasscodeOptions(selectedType: Passcode, usePolicyDefault: Boolean) {
val passwordType = if (usePolicyDefault) {
@@ -652,6 +656,7 @@ class GeneratorViewModel @Inject constructor(
action: GeneratorAction.Internal.PasswordGeneratorPolicyReceive,
) {
mutableStateFlow.update { it.copy(isUnderPolicy = action.policies.any()) }
loadOptions()
}
//endregion Generated Field Handlers