From dc9c11ec5209fe44de5212be58da4ea2c08b781c Mon Sep 17 00:00:00 2001 From: sam Date: Fri, 27 Dec 2024 13:21:02 -0500 Subject: [PATCH] feat: return reports in audit log entries --- .../Moderation/AuditLogController.cs | 4 +++- Foxnouns.Backend/Dto/Moderation.cs | 13 +++++++++++- .../Services/ModerationRendererService.cs | 16 +++++++++++++- .../src/lib/api/models/moderation.ts | 12 ++++++++++- .../components/admin/AuditLogEntryCard.svelte | 21 ++++++++++++++++++- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/Foxnouns.Backend/Controllers/Moderation/AuditLogController.cs b/Foxnouns.Backend/Controllers/Moderation/AuditLogController.cs index b2d0581..304cfa4 100644 --- a/Foxnouns.Backend/Controllers/Moderation/AuditLogController.cs +++ b/Foxnouns.Backend/Controllers/Moderation/AuditLogController.cs @@ -43,7 +43,9 @@ public class AuditLogController(DatabaseContext db, ModerationRendererService mo _ => limit, }; - IQueryable query = db.AuditLog.OrderByDescending(e => e.Id); + IQueryable query = db + .AuditLog.Include(e => e.Report) + .OrderByDescending(e => e.Id); if (before != null) query = query.Where(e => e.Id < before.Value); diff --git a/Foxnouns.Backend/Dto/Moderation.cs b/Foxnouns.Backend/Dto/Moderation.cs index c9489ed..7d6b5b8 100644 --- a/Foxnouns.Backend/Dto/Moderation.cs +++ b/Foxnouns.Backend/Dto/Moderation.cs @@ -41,12 +41,23 @@ public record AuditLogResponse( AuditLogEntity? TargetUser, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] AuditLogEntity? TargetMember, - [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Snowflake? ReportId, + [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] PartialReport? Report, AuditLogEntryType Type, string? Reason, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string[]? ClearedFields ); +public record PartialReport( + Snowflake Id, + Snowflake ReporterId, + Snowflake TargetUserId, + [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] + Snowflake? TargetMemberId, + ReportReason Reason, + string? Context, + ReportTargetType TargetType +); + public record NotificationResponse( Snowflake Id, NotificationType Type, diff --git a/Foxnouns.Backend/Services/ModerationRendererService.cs b/Foxnouns.Backend/Services/ModerationRendererService.cs index 04ef46b..c1d259a 100644 --- a/Foxnouns.Backend/Services/ModerationRendererService.cs +++ b/Foxnouns.Backend/Services/ModerationRendererService.cs @@ -46,12 +46,26 @@ public class ModerationRendererService( public AuditLogResponse RenderAuditLogEntry(AuditLogEntry entry) { + PartialReport? report = null; + if (entry.Report != null) + { + report = new PartialReport( + entry.Report.Id, + entry.Report.ReporterId, + entry.Report.TargetUserId, + entry.Report.TargetMemberId, + entry.Report.Reason, + entry.Report.Context, + entry.Report.TargetType + ); + } + return new AuditLogResponse( Id: entry.Id, Moderator: ToEntity(entry.ModeratorId, entry.ModeratorUsername)!, TargetUser: ToEntity(entry.TargetUserId, entry.TargetUsername), TargetMember: ToEntity(entry.TargetMemberId, entry.TargetMemberName), - ReportId: entry.ReportId, + Report: report, Type: entry.Type, Reason: entry.Reason, ClearedFields: entry.ClearedFields diff --git a/Foxnouns.Frontend/src/lib/api/models/moderation.ts b/Foxnouns.Frontend/src/lib/api/models/moderation.ts index f0e112b..5fbf9fa 100644 --- a/Foxnouns.Frontend/src/lib/api/models/moderation.ts +++ b/Foxnouns.Frontend/src/lib/api/models/moderation.ts @@ -45,7 +45,7 @@ export type AuditLogEntry = { moderator: AuditLogEntity; target_user?: AuditLogEntity; target_member?: AuditLogEntity; - report_id?: string; + report?: PartialReport; type: AuditLogEntryType; reason: string | null; cleared_fields?: string[]; @@ -59,3 +59,13 @@ export enum AuditLogEntryType { WarnUserAndClearProfile = "WARN_USER_AND_CLEAR_PROFILE", SuspendUser = "SUSPEND_USER", } + +export type PartialReport = { + id: string; + reporter_id: string; + target_user_id: string; + target_member_id?: string; + reason: ReportReason; + context: string | null; + target_type: "USER" | "MEMBER"; +}; diff --git a/Foxnouns.Frontend/src/lib/components/admin/AuditLogEntryCard.svelte b/Foxnouns.Frontend/src/lib/components/admin/AuditLogEntryCard.svelte index 2391b57..45d1ada 100644 --- a/Foxnouns.Frontend/src/lib/components/admin/AuditLogEntryCard.svelte +++ b/Foxnouns.Frontend/src/lib/components/admin/AuditLogEntryCard.svelte @@ -39,12 +39,31 @@ {date} + + {#if entry.type === "IGNORE_REPORT"} + {#if entry.report} +
+ Report +
    +
  • From: {entry.report.reporter_id}
  • +
  • Target: {entry.report.target_user_id}
  • +
  • Reason: {entry.report.reason}
  • + {#if entry.report.context} +
  • Context: {entry.report.context}
  • + {/if} +
+
+ {:else} +

(the ignored report has been deleted)

+ {/if} + {/if} + {#if reason}
Reason {@html reason}
{:else} - (no reason given) +

(no reason given)

{/if}