Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Refactor (#175)
Leendert de Borst92e2de76ba64
diff --git a/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor b/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razorindex 06a1e6afd..14b79d16a 100644--- a/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor+++ b/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor@@ -16,7 +16,7 @@/// Gets or sets the list of email claims to display./// </summary>[Parameter]- public List<UserEmailClaim> EmailClaimList { get; set; } = new();+ public List<UserEmailClaim> EmailClaimList { get; set; } = [];private string SortColumn { get; set; } = "CreatedAt";private SortDirection SortDirection { get; set; } = SortDirection.Descending;@@ -36,21 +36,14 @@StateHasChanged();}- private IEnumerable<UserEmailClaim> SortList(List<UserEmailClaim> emailClaims, string sortColumn, SortDirection sortDirection)+ private static IEnumerable<UserEmailClaim> SortList(List<UserEmailClaim> emailClaims, string sortColumn, SortDirection sortDirection){return sortColumn switch{- "Id" => SortProperty(emailClaims, e => e.Id, sortDirection),- "CreatedAt" => SortProperty(emailClaims, e => e.CreatedAt, sortDirection),- "Address" => SortProperty(emailClaims, e => e.Address, sortDirection),+ "Id" => SortableTable.SortListByProperty(emailClaims, e => e.Id, sortDirection),+ "CreatedAt" => SortableTable.SortListByProperty(emailClaims, e => e.CreatedAt, sortDirection),+ "Address" => SortableTable.SortListByProperty(emailClaims, e => e.Address, sortDirection),_ => emailClaims};}-- private IEnumerable<T> SortProperty<T, TKey>(IEnumerable<T> source, Func<T, TKey> keySelector, SortDirection direction)- {- return direction == SortDirection.Ascending- ? source.OrderBy(keySelector)- : source.OrderByDescending(keySelector);- }}diff --git a/src/AliasVault.Admin/Main/Pages/Users/View/Components/RefreshTokenTable.razor b/src/AliasVault.Admin/Main/Pages/Users/View/Components/RefreshTokenTable.razorindex 022785ae0..49796e568 100644--- a/src/AliasVault.Admin/Main/Pages/Users/View/Components/RefreshTokenTable.razor+++ b/src/AliasVault.Admin/Main/Pages/Users/View/Components/RefreshTokenTable.razor@@ -21,7 +21,7 @@/// Gets or sets the list of refresh tokens to display./// </summary>[Parameter]- public List<AliasVaultUserRefreshToken> RefreshTokenList { get; set; } = new();+ public List<AliasVaultUserRefreshToken> RefreshTokenList { get; set; } = [];/// <summary>/// Gets or sets the event callback to revoke a refresh token.@@ -50,26 +50,19 @@StateHasChanged();}- private IEnumerable<AliasVaultUserRefreshToken> SortList(List<AliasVaultUserRefreshToken> refreshTokens, string sortColumn, SortDirection sortDirection)+ private static IEnumerable<AliasVaultUserRefreshToken> SortList(List<AliasVaultUserRefreshToken> refreshTokens, string sortColumn, SortDirection sortDirection){return sortColumn switch{- "Id" => SortProperty(refreshTokens, r => r.Id, sortDirection),- "DeviceIdentifier" => SortProperty(refreshTokens, r => r.DeviceIdentifier, sortDirection),- "IpAddress" => SortProperty(refreshTokens, r => r.IpAddress, sortDirection),- "CreatedAt" => SortProperty(refreshTokens, r => r.CreatedAt, sortDirection),- "ExpireDate" => SortProperty(refreshTokens, r => r.ExpireDate, sortDirection),+ "Id" => SortableTable.SortListByProperty(refreshTokens, r => r.Id, sortDirection),+ "DeviceIdentifier" => SortableTable.SortListByProperty(refreshTokens, r => r.DeviceIdentifier, sortDirection),+ "IpAddress" => SortableTable.SortListByProperty(refreshTokens, r => r.IpAddress, sortDirection),+ "CreatedAt" => SortableTable.SortListByProperty(refreshTokens, r => r.CreatedAt, sortDirection),+ "ExpireDate" => SortableTable.SortListByProperty(refreshTokens, r => r.ExpireDate, sortDirection),_ => refreshTokens};}- private IEnumerable<T> SortProperty<T, TKey>(IEnumerable<T> source, Func<T, TKey> keySelector, SortDirection direction)- {- return direction == SortDirection.Ascending- ? source.OrderBy(keySelector)- : source.OrderByDescending(keySelector);- }-private async Task RevokeRefreshToken(AliasVaultUserRefreshToken entry){await OnRevokeToken.InvokeAsync(entry);diff --git a/src/AliasVault.Admin/Main/Pages/Users/View/Components/VaultTable.razor b/src/AliasVault.Admin/Main/Pages/Users/View/Components/VaultTable.razorindex 3a04328b2..ebccee2d3 100644--- a/src/AliasVault.Admin/Main/Pages/Users/View/Components/VaultTable.razor+++ b/src/AliasVault.Admin/Main/Pages/Users/View/Components/VaultTable.razor@@ -38,7 +38,7 @@/// Gets or sets the list of vaults to display./// </summary>[Parameter]- public List<Vault> VaultList { get; set; } = new();+ public List<Vault> VaultList { get; set; } = [];/// <summary>/// Gets or sets the event callback to make a vault current.@@ -74,29 +74,22 @@StateHasChanged();}- private IEnumerable<Vault> SortList(List<Vault> vaults, string sortColumn, SortDirection sortDirection)+ private static IEnumerable<Vault> SortList(List<Vault> vaults, string sortColumn, SortDirection sortDirection){return sortColumn switch{- "Id" => SortProperty(vaults, v => v.Id, sortDirection),- "CreatedAt" => SortProperty(vaults, v => v.CreatedAt, sortDirection),- "UpdatedAt" => SortProperty(vaults, v => v.UpdatedAt, sortDirection),- "FileSize" => SortProperty(vaults, v => v.FileSize, sortDirection),- "Version" => SortProperty(vaults, v => v.Version, sortDirection),- "RevisionNumber" => SortProperty(vaults, v => v.RevisionNumber, sortDirection),- "CredentialsCount" => SortProperty(vaults, v => v.CredentialsCount, sortDirection),- "EmailClaimsCount" => SortProperty(vaults, v => v.EmailClaimsCount, sortDirection),+ "Id" => SortableTable.SortListByProperty(vaults, v => v.Id, sortDirection),+ "CreatedAt" => SortableTable.SortListByProperty(vaults, v => v.CreatedAt, sortDirection),+ "UpdatedAt" => SortableTable.SortListByProperty(vaults, v => v.UpdatedAt, sortDirection),+ "FileSize" => SortableTable.SortListByProperty(vaults, v => v.FileSize, sortDirection),+ "Version" => SortableTable.SortListByProperty(vaults, v => v.Version, sortDirection),+ "RevisionNumber" => SortableTable.SortListByProperty(vaults, v => v.RevisionNumber, sortDirection),+ "CredentialsCount" => SortableTable.SortListByProperty(vaults, v => v.CredentialsCount, sortDirection),+ "EmailClaimsCount" => SortableTable.SortListByProperty(vaults, v => v.EmailClaimsCount, sortDirection),_ => vaults};}- private IEnumerable<T> SortProperty<T, TKey>(IEnumerable<T> source, Func<T, TKey> keySelector, SortDirection direction)- {- return direction == SortDirection.Ascending- ? source.OrderBy(keySelector)- : source.OrderByDescending(keySelector);- }-private static bool HasPasswordChanged(Vault current, Vault previous){return current.Salt != previous.Salt || current.Verifier != previous.Verifier;diff --git a/src/Shared/AliasVault.RazorComponents/Tables/SortableTable.razor b/src/Shared/AliasVault.RazorComponents/Tables/SortableTable.razorindex da326b62c..c0352bc23 100644--- a/src/Shared/AliasVault.RazorComponents/Tables/SortableTable.razor+++ b/src/Shared/AliasVault.RazorComponents/Tables/SortableTable.razor@@ -66,6 +66,16 @@/// </summary>[Parameter] public EventCallback<(string, SortDirection)> OnSortChanged { get; set; }+ /// <summary>+ /// Sorts the list of items by the specified column and direction.+ /// </summary>+ public static IEnumerable<T> SortListByProperty<T, TKey>(IEnumerable<T> source, Func<T, TKey> keySelector, SortDirection direction)+ {+ return direction == SortDirection.Ascending+ ? source.OrderBy(keySelector)+ : source.OrderByDescending(keySelector);+ }+private async Task OnSort(string columnName){if (SortColumn == columnName)@@ -82,4 +92,4 @@await OnSortChanged.InvokeAsync((SortColumn, SortDirection));}-}\ No newline at end of file+}