fix for bug stopping vault timeout to never (#1618)

- use nullable int on settings page and in vault service
This commit is contained in:
Jake Fink 2021-10-29 10:31:38 -04:00 committed by GitHub
parent 0f992d27b3
commit 318a3e4de9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 9 deletions

View file

@ -58,7 +58,7 @@ namespace Bit.App.Pages
}; };
private Policy _vaultTimeoutPolicy; private Policy _vaultTimeoutPolicy;
private int _vaultTimeout; private int? _vaultTimeout;
public SettingsPageViewModel() public SettingsPageViewModel()
{ {
@ -223,7 +223,7 @@ namespace Bit.App.Pages
await _vaultTimeoutService.LockAsync(true, true); await _vaultTimeoutService.LockAsync(true, true);
} }
public async Task VaultTimeoutAsync(bool promptOptions = true, int newTimeout = 0) public async Task VaultTimeoutAsync(bool promptOptions = true, int? newTimeout = 0)
{ {
var oldTimeout = _vaultTimeout; var oldTimeout = _vaultTimeout;
@ -240,7 +240,7 @@ namespace Bit.App.Pages
var cleanSelection = selection.Replace("✓ ", string.Empty); var cleanSelection = selection.Replace("✓ ", string.Empty);
var selectionOption = _vaultTimeouts.FirstOrDefault(o => o.Key == cleanSelection); var selectionOption = _vaultTimeouts.FirstOrDefault(o => o.Key == cleanSelection);
_vaultTimeoutDisplayValue = selectionOption.Key; _vaultTimeoutDisplayValue = selectionOption.Key;
newTimeout = selectionOption.Value.GetValueOrDefault(); newTimeout = selectionOption.Value;
} }
if (_vaultTimeoutPolicy != null) if (_vaultTimeoutPolicy != null)
@ -441,7 +441,7 @@ namespace Bit.App.Pages
securityItems.Insert(1, new SettingsPageListItem securityItems.Insert(1, new SettingsPageListItem
{ {
Name = AppResources.Custom, Name = AppResources.Custom,
Time = TimeSpan.FromMinutes(Math.Abs((double)_vaultTimeout)), Time = TimeSpan.FromMinutes(Math.Abs((double)_vaultTimeout.GetValueOrDefault())),
}); });
} }
if (_vaultTimeoutPolicy != null) if (_vaultTimeoutPolicy != null)

View file

@ -17,6 +17,6 @@ namespace Bit.Core.Abstractions
Task LockAsync(bool allowSoftLock = false, bool userInitiated = false); Task LockAsync(bool allowSoftLock = false, bool userInitiated = false);
Task LogOutAsync(); Task LogOutAsync();
Task SetVaultTimeoutOptionsAsync(int? timeout, string action); Task SetVaultTimeoutOptionsAsync(int? timeout, string action);
Task<int> GetVaultTimeout(); Task<int?> GetVaultTimeout();
} }
} }

View file

@ -86,7 +86,7 @@ namespace Bit.Core.Services
return; return;
} }
var vaultTimeoutMinutes = await GetVaultTimeout(); var vaultTimeoutMinutes = await GetVaultTimeout();
if (vaultTimeoutMinutes < 0) if (vaultTimeoutMinutes < 0 || vaultTimeoutMinutes == null)
{ {
return; return;
} }
@ -178,8 +178,8 @@ namespace Bit.Core.Services
await _storageService.RemoveAsync(Constants.ProtectedPin); await _storageService.RemoveAsync(Constants.ProtectedPin);
} }
public async Task<int> GetVaultTimeout() { public async Task<int?> GetVaultTimeout() {
var vaultTimeout = (await _storageService.GetAsync<int?>(Constants.VaultTimeoutKey)).GetValueOrDefault(-1); var vaultTimeout = await _storageService.GetAsync<int?>(Constants.VaultTimeoutKey);
if (await _policyService.PolicyAppliesToUser(PolicyType.MaximumVaultTimeout)) { if (await _policyService.PolicyAppliesToUser(PolicyType.MaximumVaultTimeout)) {
var policy = (await _policyService.GetAll(PolicyType.MaximumVaultTimeout)).First(); var policy = (await _policyService.GetAll(PolicyType.MaximumVaultTimeout)).First();
@ -190,7 +190,7 @@ namespace Bit.Core.Services
return vaultTimeout; return vaultTimeout;
} }
var timeout = Math.Min(vaultTimeout, policyTimeout.Value); var timeout = vaultTimeout.HasValue ? Math.Min(vaultTimeout.Value, policyTimeout.Value) : policyTimeout.Value;
if (timeout < 0) { if (timeout < 0) {
timeout = policyTimeout.Value; timeout = policyTimeout.Value;