feat: return reports in audit log entries

This commit is contained in:
sam 2024-12-27 13:21:02 -05:00
parent 53006ea313
commit dc9c11ec52
Signed by: sam
GPG key ID: B4EF20DDE721CAA1
5 changed files with 61 additions and 5 deletions

View file

@ -43,7 +43,9 @@ public class AuditLogController(DatabaseContext db, ModerationRendererService mo
_ => limit, _ => limit,
}; };
IQueryable<AuditLogEntry> query = db.AuditLog.OrderByDescending(e => e.Id); IQueryable<AuditLogEntry> query = db
.AuditLog.Include(e => e.Report)
.OrderByDescending(e => e.Id);
if (before != null) if (before != null)
query = query.Where(e => e.Id < before.Value); query = query.Where(e => e.Id < before.Value);

View file

@ -41,12 +41,23 @@ public record AuditLogResponse(
AuditLogEntity? TargetUser, AuditLogEntity? TargetUser,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
AuditLogEntity? TargetMember, AuditLogEntity? TargetMember,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Snowflake? ReportId, [property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] PartialReport? Report,
AuditLogEntryType Type, AuditLogEntryType Type,
string? Reason, string? Reason,
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string[]? ClearedFields [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( public record NotificationResponse(
Snowflake Id, Snowflake Id,
NotificationType Type, NotificationType Type,

View file

@ -46,12 +46,26 @@ public class ModerationRendererService(
public AuditLogResponse RenderAuditLogEntry(AuditLogEntry entry) 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( return new AuditLogResponse(
Id: entry.Id, Id: entry.Id,
Moderator: ToEntity(entry.ModeratorId, entry.ModeratorUsername)!, Moderator: ToEntity(entry.ModeratorId, entry.ModeratorUsername)!,
TargetUser: ToEntity(entry.TargetUserId, entry.TargetUsername), TargetUser: ToEntity(entry.TargetUserId, entry.TargetUsername),
TargetMember: ToEntity(entry.TargetMemberId, entry.TargetMemberName), TargetMember: ToEntity(entry.TargetMemberId, entry.TargetMemberName),
ReportId: entry.ReportId, Report: report,
Type: entry.Type, Type: entry.Type,
Reason: entry.Reason, Reason: entry.Reason,
ClearedFields: entry.ClearedFields ClearedFields: entry.ClearedFields

View file

@ -45,7 +45,7 @@ export type AuditLogEntry = {
moderator: AuditLogEntity; moderator: AuditLogEntity;
target_user?: AuditLogEntity; target_user?: AuditLogEntity;
target_member?: AuditLogEntity; target_member?: AuditLogEntity;
report_id?: string; report?: PartialReport;
type: AuditLogEntryType; type: AuditLogEntryType;
reason: string | null; reason: string | null;
cleared_fields?: string[]; cleared_fields?: string[];
@ -59,3 +59,13 @@ export enum AuditLogEntryType {
WarnUserAndClearProfile = "WARN_USER_AND_CLEAR_PROFILE", WarnUserAndClearProfile = "WARN_USER_AND_CLEAR_PROFILE",
SuspendUser = "SUSPEND_USER", 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";
};

View file

@ -39,12 +39,31 @@
<small class="text-secondary">{date}</small> <small class="text-secondary">{date}</small>
</h6> </h6>
{#if entry.type === "IGNORE_REPORT"}
{#if entry.report}
<details>
<summary>Report</summary>
<ul>
<li><strong>From:</strong> {entry.report.reporter_id}</li>
<li><strong>Target:</strong> {entry.report.target_user_id}</li>
<li><strong>Reason:</strong> {entry.report.reason}</li>
{#if entry.report.context}
<li><strong>Context:</strong> {entry.report.context}</li>
{/if}
</ul>
</details>
{:else}
<p><em>(the ignored report has been deleted)</em></p>
{/if}
{/if}
{#if reason} {#if reason}
<details> <details>
<summary>Reason</summary> <summary>Reason</summary>
{@html reason} {@html reason}
</details> </details>
{:else} {:else}
<em>(no reason given)</em> <p><em>(no reason given)</em></p>
{/if} {/if}
</div> </div>