Berichten: badge met aantal nieuwe berichten bij het menu-item (lichte unread-count-endpoint, 60 s verversing en bij focus, direct bijgewerkt bij openen)
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 10s
Continuous Integration / config-asf (pull_request) Successful in 19s
Continuous Integration / backend-build (pull_request) Successful in 1m19s
Continuous Integration / frontend-prepare (pull_request) Successful in 32s
Continuous Integration / compile-sites (pull_request) Successful in 1m1s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m20s
Continuous Integration / frontend-build (pull_request) Successful in 35s
Continuous Integration / backend-test (pull_request) Successful in 2m20s
Continuous Integration / frontend-lint (pull_request) Successful in 36s
Continuous Integration / frontend-test (pull_request) Successful in 1m16s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 10s
Continuous Integration / config-asf (pull_request) Successful in 19s
Continuous Integration / backend-build (pull_request) Successful in 1m19s
Continuous Integration / frontend-prepare (pull_request) Successful in 32s
Continuous Integration / compile-sites (pull_request) Successful in 1m1s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m20s
Continuous Integration / frontend-build (pull_request) Successful in 35s
Continuous Integration / backend-test (pull_request) Successful in 2m20s
Continuous Integration / frontend-lint (pull_request) Successful in 36s
Continuous Integration / frontend-test (pull_request) Successful in 1m16s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,17 @@ public class ContactAdminControllerTests
|
||||
ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() },
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public async Task UnreadCount_ReturnsOnlyTheNumber_AndIsAdminOnlyLikeTheRestOfTheController()
|
||||
{
|
||||
_service.CountUnreadAsync(Arg.Any<CancellationToken>()).Returns(3);
|
||||
|
||||
var result = await Messages().UnreadCount(CancellationToken.None);
|
||||
|
||||
result.Should().BeOfType<OkObjectResult>().Which.Value.Should().Be(new ContactUnreadCount(3));
|
||||
typeof(ContactMessagesAdminController).GetCustomAttribute<AuthorizeAttribute>()!.Policy.Should().Be("AdminOnly");
|
||||
}
|
||||
|
||||
private ContactSettingsController Settings(Guid? userId = null)
|
||||
{
|
||||
var http = new DefaultHttpContext();
|
||||
@@ -242,6 +253,7 @@ public class ContactAdminControllerTests
|
||||
.Should().BeEquivalentTo(
|
||||
[
|
||||
"GET contact-messages",
|
||||
"GET contact-messages/unread-count",
|
||||
"GET contact-messages/{id:guid}",
|
||||
"PATCH contact-messages/{id:guid}",
|
||||
"DELETE contact-messages/{id:guid}",
|
||||
|
||||
@@ -161,6 +161,18 @@ public class ContactAdminServiceTests
|
||||
(await h.Sut.ListAsync("read", 1, 25, CancellationToken.None))!.UnreadCount.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TheLightUnreadCount_IsTheSameNumber_ForThisSiteOnly()
|
||||
{
|
||||
using var h = new AdminHarness();
|
||||
h.Add(ContactMessageStatus.New);
|
||||
h.Add(ContactMessageStatus.Read);
|
||||
h.Add(ContactMessageStatus.Spam);
|
||||
h.Add(ContactMessageStatus.New, site: "another-site");
|
||||
|
||||
(await h.Sut.CountUnreadAsync(CancellationToken.None)).Should().Be(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task OtherSitesMessages_AreInvisible()
|
||||
{
|
||||
|
||||
@@ -74,6 +74,12 @@ public class ContactMessagesAdminController(IContactAdminService service, IOptio
|
||||
return result is null ? ContactProblems.Invalid(options.Value.ProblemTypeBase, "query") : Ok(result);
|
||||
}
|
||||
|
||||
/// <summary>A light count for the badge in the menu; a separate route so the page does not have to fetch a list.</summary>
|
||||
[HttpGet("unread-count")]
|
||||
[ProducesResponseType(typeof(ContactUnreadCount), StatusCodes.Status200OK, "application/json")]
|
||||
public async Task<IActionResult> UnreadCount(CancellationToken cancellationToken)
|
||||
=> Ok(new ContactUnreadCount(await service.CountUnreadAsync(cancellationToken)));
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
[ProducesResponseType(typeof(ContactMessageDetail), StatusCodes.Status200OK, "application/json")]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
|
||||
@@ -17,6 +17,10 @@ public record ContactMessageListItem(
|
||||
string Status,
|
||||
string MailStatus);
|
||||
|
||||
/// <summary>Only the number of new (unread) messages: a small answer for the badge in the admin menu.</summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactUnreadCount(int UnreadCount);
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactMessageList(
|
||||
IReadOnlyList<ContactMessageListItem> Items,
|
||||
|
||||
@@ -17,6 +17,9 @@ public interface IContactAdminService
|
||||
|
||||
Task<ContactMessageDetail?> GetAsync(Guid id, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>The number of new messages of this site (spam and read ones do not count).</summary>
|
||||
Task<int> CountUnreadAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>Null when the message does not exist.</summary>
|
||||
Task<ContactMessageDetail?> SetStatusAsync(Guid id, ContactMessageStatus status, CancellationToken cancellationToken);
|
||||
|
||||
@@ -75,6 +78,9 @@ public sealed class ContactAdminService(
|
||||
page, pageSize, total, unread);
|
||||
}
|
||||
|
||||
public Task<int> CountUnreadAsync(CancellationToken cancellationToken)
|
||||
=> repository.CountUnreadAsync(options.Value.EffectiveSiteId, cancellationToken);
|
||||
|
||||
public async Task<ContactMessageDetail?> GetAsync(Guid id, CancellationToken cancellationToken)
|
||||
{
|
||||
var message = await repository.GetAsync(options.Value.EffectiveSiteId, id, cancellationToken);
|
||||
|
||||
Reference in New Issue
Block a user