mirror of
https://github.com/aliasvault/aliasvault.git
synced 2026-05-18 21:40:41 -04:00
Get latest vault by revision number instead of updated at timestamp (#347)
This commit is contained in:
@@ -8,3 +8,14 @@
|
||||
Title="AliasVault Admin"
|
||||
Description="Welcome to the AliasVault admin portal.">
|
||||
</PageHeader>
|
||||
|
||||
@code {
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
base.OnInitialized();
|
||||
|
||||
// Redirect to users page.
|
||||
NavigationService.RedirectTo("/users");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ else
|
||||
<h3 class="mb-4 text-xl font-semibold dark:text-white">User</h3>
|
||||
<div class="mb-4">
|
||||
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Id</label>
|
||||
<div>@Id</div>
|
||||
<div class="text-gray-900 dark:text-white">@Id</div>
|
||||
</div>
|
||||
<div class="mb-4">
|
||||
<label class="block mb-2 text-sm font-medium text-gray-900 dark:text-white">Username</label>
|
||||
<div>@Obj?.UserName</div>
|
||||
<div class="text-gray-900 dark:text-white">@Obj?.UserName</div>
|
||||
</div>
|
||||
<div class="flex space-x-3">
|
||||
<Button Color="danger" OnClick="DeleteConfirm">Yes, I'm sure</Button>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
{
|
||||
<span class="bg-blue-100 text-blue-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-blue-900 dark:text-blue-300">Current</span>
|
||||
}
|
||||
@if (_previousEntry != null && HasPasswordChanged(entry, _previousEntry))
|
||||
@if (_previousEntry != null && HasPasswordChanged(entry, SortedVaultList))
|
||||
{
|
||||
<span class="bg-green-100 text-green-800 text-xs font-medium mr-2 px-2.5 py-0.5 rounded dark:bg-green-900 dark:text-green-300">Password Changed</span>
|
||||
}
|
||||
@@ -46,7 +46,7 @@
|
||||
[Parameter]
|
||||
public EventCallback<Vault> OnMakeCurrent { get; set; }
|
||||
|
||||
private string SortColumn { get; set; } = "UpdatedAt";
|
||||
private string SortColumn { get; set; } = "RevisionNumber";
|
||||
private SortDirection SortDirection { get; set; } = SortDirection.Descending;
|
||||
private Vault? _previousEntry;
|
||||
|
||||
@@ -90,9 +90,21 @@
|
||||
};
|
||||
}
|
||||
|
||||
private static bool HasPasswordChanged(Vault current, Vault previous)
|
||||
/// <summary>
|
||||
/// Checks if the password has changed between the current and previous vault entry based on revision number..
|
||||
/// </summary>
|
||||
private static bool HasPasswordChanged(Vault current, IEnumerable<Vault> vaultList)
|
||||
{
|
||||
return current.Salt != previous.Salt || current.Verifier != previous.Verifier;
|
||||
// Get the previous vault entry to compare to based on revision number.
|
||||
var previousEntry = vaultList.FirstOrDefault(v => v.RevisionNumber == current.RevisionNumber - 1);
|
||||
|
||||
if (previousEntry == null)
|
||||
{
|
||||
// If the previous entry is null it means we have nothing to compare to so assume that it has not changed.
|
||||
return false;
|
||||
}
|
||||
|
||||
return current.Salt != previousEntry?.Salt || current.Verifier != previousEntry?.Verifier;
|
||||
}
|
||||
|
||||
private async Task MakeCurrentAsync(Vault vault)
|
||||
|
||||
@@ -64,7 +64,7 @@ public static class AuthHelper
|
||||
public static (string Salt, string Verifier, string EncryptionType, string EncryptionSettings) GetUserLatestVaultEncryptionSettings(AliasVaultUser user)
|
||||
{
|
||||
// Retrieve latest vault of user which contains the encryption settings.
|
||||
var latestVault = user.Vaults.OrderByDescending(x => x.UpdatedAt).Select(x => new { x.Salt, x.Verifier, x.EncryptionType, x.EncryptionSettings }).First();
|
||||
var latestVault = user.Vaults.OrderByDescending(x => x.RevisionNumber).Select(x => new { x.Salt, x.Verifier, x.EncryptionType, x.EncryptionSettings }).First();
|
||||
return (latestVault.Salt, latestVault.Verifier, latestVault.EncryptionType, latestVault.EncryptionSettings);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user