[PM-1567] Fix for vault timeout 'never' not persisting (#2440)

This commit is contained in:
mp-bw 2023-03-24 16:34:48 -04:00 committed by GitHub
parent 3e76f6b054
commit 80e38f8669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -526,8 +526,7 @@ namespace Bit.Core.Services
{
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
await GetDefaultStorageOptionsAsync());
return await GetValueAsync<int?>(Constants.VaultTimeoutKey(reconciledOptions.UserId), reconciledOptions) ??
Constants.VaultTimeoutDefault;
return await GetValueAsync<int?>(Constants.VaultTimeoutKey(reconciledOptions.UserId), reconciledOptions);
}
public async Task SetVaultTimeoutAsync(int? value, string userId = null)
@ -542,7 +541,7 @@ namespace Bit.Core.Services
var reconciledOptions = ReconcileOptions(new StorageOptions { UserId = userId },
await GetDefaultStorageOptionsAsync());
return await GetValueAsync<VaultTimeoutAction?>(Constants.VaultTimeoutActionKey(reconciledOptions.UserId),
reconciledOptions) ?? VaultTimeoutAction.Lock;
reconciledOptions);
}
public async Task SetVaultTimeoutActionAsync(VaultTimeoutAction? value, string userId = null)
@ -1444,6 +1443,14 @@ namespace Bit.Core.Services
}
_state.Accounts[account.Profile.UserId] = account;
}
// Check if account has logged in before by checking a guaranteed non-null pref
if (await GetVaultTimeoutActionAsync(account.Profile.UserId) == null)
{
// Account has never logged in, set defaults
await SetVaultTimeoutAsync(Constants.VaultTimeoutDefault, account.Profile.UserId);
await SetVaultTimeoutActionAsync(VaultTimeoutAction.Lock, account.Profile.UserId);
}
}
private StorageOptions ReconcileOptions(StorageOptions requestedOptions, StorageOptions defaultOptions)