Skip to content

Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.

Show amount of emails received in user email claim page (#349)

Leendert de Borstb845245728f6
diff --git a/src/AliasVault.Admin/Main/Models/UserEmailClaimWithCount.cs b/src/AliasVault.Admin/Main/Models/UserEmailClaimWithCount.cs
new file mode 100644
index 000000000..8149256cb
--- /dev/null
+++ b/src/AliasVault.Admin/Main/Models/UserEmailClaimWithCount.cs
@@ -0,0 +1,49 @@
+//-----------------------------------------------------------------------
+// <copyright file="UserEmailClaimWithCount.cs" company="lanedirt">
+// Copyright (c) lanedirt. All rights reserved.
+// Licensed under the MIT license. See LICENSE.md file in the project root for full license information.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace AliasVault.Admin.Main.Models;
+
+/// <summary>
+/// User email claim view model with count.
+/// </summary>
+public class UserEmailClaimWithCount
+{
+ /// <summary>
+ /// Gets or sets the id.
+ /// </summary>
+ public Guid Id { get; set; }
+
+ /// <summary>
+ /// Gets or sets the address.
+ /// </summary>
+ public string Address { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the address local.
+ /// </summary>
+ public string AddressLocal { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the address domain.
+ /// </summary>
+ public string AddressDomain { get; set; } = string.Empty;
+
+ /// <summary>
+ /// Gets or sets the created at timestamp.
+ /// </summary>
+ public DateTime CreatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the updated at timestamp.
+ /// </summary>
+ public DateTime UpdatedAt { get; set; }
+
+ /// <summary>
+ /// Gets or sets the email count.
+ /// </summary>
+ public int EmailCount { get; set; }
+}
diff --git a/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor b/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
index 14b79d16a..4061b2941 100644
--- a/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
+++ b/src/AliasVault.Admin/Main/Pages/Users/View/Components/EmailClaimTable.razor
@@ -7,6 +7,7 @@
<SortableTableColumn IsPrimary="true">@entry.Id</SortableTableColumn>
<SortableTableColumn>@entry.CreatedAt.ToString("yyyy-MM-dd HH:mm")</SortableTableColumn>
<SortableTableColumn>@entry.Address</SortableTableColumn>
+ <SortableTableColumn>@entry.EmailCount</SortableTableColumn>
</SortableTableRow>
}
</SortableTable>
@@ -16,7 +17,7 @@
/// Gets or sets the list of email claims to display.
/// </summary>
[Parameter]
- public List<UserEmailClaim> EmailClaimList { get; set; } = [];
+ public List<UserEmailClaimWithCount> EmailClaimList { get; set; } = [];
private string SortColumn { get; set; } = "CreatedAt";
private SortDirection SortDirection { get; set; } = SortDirection.Descending;
@@ -25,9 +26,10 @@
new TableColumn { Title = "ID", PropertyName = "Id" },
new TableColumn { Title = "Created", PropertyName = "CreatedAt" },
new TableColumn { Title = "Email", PropertyName = "Address" },
+ new TableColumn { Title = "Email Count", PropertyName = "EmailCount" },
];
- private IEnumerable<UserEmailClaim> SortedEmailClaimList => SortList(EmailClaimList, SortColumn, SortDirection);
+ private IEnumerable<UserEmailClaimWithCount> SortedEmailClaimList => SortList(EmailClaimList, SortColumn, SortDirection);
private void HandleSortChanged((string column, SortDirection direction) sort)
{
@@ -36,13 +38,14 @@
StateHasChanged();
}
- private static IEnumerable<UserEmailClaim> SortList(List<UserEmailClaim> emailClaims, string sortColumn, SortDirection sortDirection)
+ private static IEnumerable<UserEmailClaimWithCount> SortList(List<UserEmailClaimWithCount> emailClaims, string sortColumn, SortDirection sortDirection)
{
return sortColumn switch
{
"Id" => SortableTable.SortListByProperty(emailClaims, e => e.Id, sortDirection),
"CreatedAt" => SortableTable.SortListByProperty(emailClaims, e => e.CreatedAt, sortDirection),
"Address" => SortableTable.SortListByProperty(emailClaims, e => e.Address, sortDirection),
+ "EmailCount" => SortableTable.SortListByProperty(emailClaims, e => e.EmailCount, sortDirection),
_ => emailClaims
};
}
diff --git a/src/AliasVault.Admin/Main/Pages/Users/View/Index.razor b/src/AliasVault.Admin/Main/Pages/Users/View/Index.razor
index e5a08113f..ff85a41db 100644
--- a/src/AliasVault.Admin/Main/Pages/Users/View/Index.razor
+++ b/src/AliasVault.Admin/Main/Pages/Users/View/Index.razor
@@ -97,7 +97,7 @@ else
private int TwoFactorKeysCount { get; set; }
private List<AliasVaultUserRefreshToken> RefreshTokenList { get; set; } = [];
private List<Vault> VaultList { get; set; } = [];
- private List<UserEmailClaim> EmailClaimList { get; set; } = [];
+ private List<UserEmailClaimWithCount> EmailClaimList { get; set; } = [];
/// <inheritdoc />
protected override async Task OnInitializedAsync()
@@ -171,7 +171,18 @@ else
.ToListAsync();
// Load all email claims for this user.
- EmailClaimList = await DbContext.UserEmailClaims.Where(x => x.UserId == User.Id)
+ EmailClaimList = await DbContext.UserEmailClaims
+ .Where(x => x.UserId == User.Id)
+ .Select(x => new UserEmailClaimWithCount
+ {
+ Id = x.Id,
+ Address = x.Address,
+ AddressLocal = x.AddressLocal,
+ AddressDomain = x.AddressDomain,
+ CreatedAt = x.CreatedAt,
+ UpdatedAt = x.UpdatedAt,
+ EmailCount = DbContext.Emails.Count(e => e.To == x.Address)
+ })
.OrderBy(x => x.CreatedAt)
.ToListAsync();