feat: report page, take action on reports
This commit is contained in:
parent
a0ba712632
commit
cacd3a30b7
14 changed files with 502 additions and 14 deletions
|
@ -113,24 +113,30 @@ public readonly struct Snowflake(ulong value) : IEquatable<Snowflake>
|
|||
) => writer.WriteStringValue(value.Value.ToString());
|
||||
}
|
||||
|
||||
private class JsonConverter : JsonConverter<Snowflake>
|
||||
private class JsonConverter : JsonConverter<Snowflake?>
|
||||
{
|
||||
public override void WriteJson(
|
||||
JsonWriter writer,
|
||||
Snowflake value,
|
||||
Snowflake? value,
|
||||
JsonSerializer serializer
|
||||
)
|
||||
{
|
||||
writer.WriteValue(value.Value.ToString());
|
||||
if (value != null)
|
||||
writer.WriteValue(value.Value.ToString());
|
||||
else
|
||||
writer.WriteNull();
|
||||
}
|
||||
|
||||
public override Snowflake ReadJson(
|
||||
public override Snowflake? ReadJson(
|
||||
JsonReader reader,
|
||||
Type objectType,
|
||||
Snowflake existingValue,
|
||||
Snowflake? existingValue,
|
||||
bool hasExistingValue,
|
||||
JsonSerializer serializer
|
||||
) => ulong.Parse((string)reader.Value!);
|
||||
) =>
|
||||
reader.TokenType is not (JsonToken.None or JsonToken.Null)
|
||||
? ulong.Parse((string)reader.Value!)
|
||||
: null;
|
||||
}
|
||||
|
||||
private class TypeConverter : System.ComponentModel.TypeConverter
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
// ReSharper disable NotAccessedPositionalProperty.Global
|
||||
using Foxnouns.Backend.Database;
|
||||
using Foxnouns.Backend.Database.Models;
|
||||
using Foxnouns.Backend.Utils;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NodaTime;
|
||||
|
@ -80,15 +81,17 @@ public record CreateReportRequest(ReportReason Reason, string? Context = null);
|
|||
|
||||
public record IgnoreReportRequest(string? Reason = null);
|
||||
|
||||
public record WarnUserRequest(
|
||||
string Reason,
|
||||
FieldsToClear[]? ClearFields = null,
|
||||
Snowflake? MemberId = null,
|
||||
Snowflake? ReportId = null
|
||||
);
|
||||
public class WarnUserRequest
|
||||
{
|
||||
public required string Reason { get; init; }
|
||||
public FieldsToClear[]? ClearFields { get; init; }
|
||||
public Snowflake? MemberId { get; init; }
|
||||
public Snowflake? ReportId { get; init; }
|
||||
}
|
||||
|
||||
public record SuspendUserRequest(string Reason, bool ClearProfile, Snowflake? ReportId = null);
|
||||
|
||||
[JsonConverter(typeof(ScreamingSnakeCaseEnumConverter))]
|
||||
public enum FieldsToClear
|
||||
{
|
||||
DisplayName,
|
||||
|
|
|
@ -154,6 +154,12 @@ public class ModerationService(
|
|||
target.DeletedAt = clock.GetCurrentInstant();
|
||||
target.DeletedBy = moderator.Id;
|
||||
|
||||
if (report != null)
|
||||
{
|
||||
report.Status = ReportStatus.Closed;
|
||||
db.Update(report);
|
||||
}
|
||||
|
||||
if (!clearProfile)
|
||||
{
|
||||
db.Update(target);
|
||||
|
@ -334,6 +340,12 @@ public class ModerationService(
|
|||
db.Update(targetUser);
|
||||
}
|
||||
|
||||
if (report != null)
|
||||
{
|
||||
report.Status = ReportStatus.Closed;
|
||||
db.Update(report);
|
||||
}
|
||||
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
return entry;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue