Contactbeheer: berichten, schakelaar en tweelaagse poort voor het formulier
Beheerroutes zonder /admin-segment op contact-messages (lijst met spam apart en ongelezen-teller zonder spam, detail, status, verwijderen, opnieuw versturen met eigen limiet) en contact-settings voor de CMS-schakelaar, allemaal AdminOnly. Het formulier is alleen open als de hostvlag EN de CMS-schakelaar (standaard uit) aan staan; de hostvlag wordt eerst gecontroleerd zodat de database niet wordt aangeraakt. Bij uitgeschakelde host antwoorden de beheerroutes 404. OpenAPI-document bijgewerkt. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using SlpModularCms.Modules.Contact.Data.Entities;
|
||||
|
||||
namespace SlpModularCms.Modules.Contact.Models;
|
||||
|
||||
// JSON shapes of the management routes. Statuses are lower-camel strings:
|
||||
// status: new | read | archived | spam | converted
|
||||
// mailStatus: pending | sent | failed | notApplicable
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactMessageListItem(
|
||||
string Id,
|
||||
DateTimeOffset ReceivedAt,
|
||||
string Name,
|
||||
string Email,
|
||||
string Subject,
|
||||
string Status,
|
||||
string MailStatus);
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactMessageList(
|
||||
IReadOnlyList<ContactMessageListItem> Items,
|
||||
int Page,
|
||||
int PageSize,
|
||||
int TotalCount,
|
||||
int UnreadCount);
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactMessageDetail(
|
||||
string Id,
|
||||
DateTimeOffset ReceivedAt,
|
||||
string Name,
|
||||
string Email,
|
||||
string Subject,
|
||||
string Message,
|
||||
string Status,
|
||||
string MailStatus,
|
||||
int MailAttempts,
|
||||
string? MailError,
|
||||
DateTimeOffset RetentionUntil);
|
||||
|
||||
/// <summary>Body of PATCH /contact-messages/{id}. Nullable so a missing field is reported in our own shape.</summary>
|
||||
public record UpdateContactMessageStatusRequest(string? Status);
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactResendResult(string MailStatus, int MailAttempts, bool Mailed);
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public record ContactSettingsDto(bool Enabled, bool HostEnabled);
|
||||
|
||||
/// <summary>Body of PUT /contact-settings. Nullable so a missing or non-boolean value is reported as errors.enabled.</summary>
|
||||
public record UpdateContactSettingsRequest(bool? Enabled);
|
||||
|
||||
/// <summary>The wire names of the statuses.</summary>
|
||||
public static class ContactStatusNames
|
||||
{
|
||||
public static string Of(ContactMessageStatus status) => status switch
|
||||
{
|
||||
ContactMessageStatus.New => "new",
|
||||
ContactMessageStatus.Read => "read",
|
||||
ContactMessageStatus.Archived => "archived",
|
||||
ContactMessageStatus.Spam => "spam",
|
||||
ContactMessageStatus.Converted => "converted",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(status)),
|
||||
};
|
||||
|
||||
public static string Of(ContactMailStatus status) => status switch
|
||||
{
|
||||
ContactMailStatus.Pending => "pending",
|
||||
ContactMailStatus.Sent => "sent",
|
||||
ContactMailStatus.Failed => "failed",
|
||||
ContactMailStatus.NotApplicable => "notApplicable",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(status)),
|
||||
};
|
||||
|
||||
/// <summary>Parses a filter value (case-insensitive); only the statuses that can be listed.</summary>
|
||||
public static bool TryParseListable(string? value, out ContactMessageStatus status)
|
||||
{
|
||||
status = default;
|
||||
switch (value?.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "new": status = ContactMessageStatus.New; return true;
|
||||
case "read": status = ContactMessageStatus.Read; return true;
|
||||
case "archived": status = ContactMessageStatus.Archived; return true;
|
||||
case "spam": status = ContactMessageStatus.Spam; return true;
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Parses a value an administrator may set: new, read or archived.</summary>
|
||||
public static bool TryParseSettable(string? value, out ContactMessageStatus status)
|
||||
=> TryParseListable(value, out status) && status != ContactMessageStatus.Spam;
|
||||
}
|
||||
Reference in New Issue
Block a user