diff --git a/Iceshrimp.Backend/Controllers/Web/AdminController.cs b/Iceshrimp.Backend/Controllers/Web/AdminController.cs index f87bd63a..bcac9823 100644 --- a/Iceshrimp.Backend/Controllers/Web/AdminController.cs +++ b/Iceshrimp.Backend/Controllers/Web/AdminController.cs @@ -14,6 +14,7 @@ using Iceshrimp.Backend.Core.Helpers; using Iceshrimp.Backend.Core.Middleware; using Iceshrimp.Backend.Core.Services; using Iceshrimp.Backend.Core.Tasks; +using Iceshrimp.Shared.Configuration; using Iceshrimp.Shared.Schemas.Web; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -207,14 +208,13 @@ public class AdminController( string name, [SwaggerBodyExample("{\n \"enabled\": true\n}")] JsonDocument body ) { - // @formatter:off var type = await policySvc.GetConfigurationType(name) ?? throw GracefulException.NotFound("Policy not found"); - var data = body.Deserialize(type) as IPolicyConfiguration ?? throw GracefulException.BadRequest("Invalid policy config"); - if (data.GetType() != type) throw GracefulException.BadRequest("Invalid policy config"); - // @formatter:on + var data = body.Deserialize(type, JsonSerialization.Options) as IPolicyConfiguration; + if (data?.GetType() != type) throw GracefulException.BadRequest("Invalid policy config"); + var serialized = JsonSerializer.Serialize(data, type, JsonSerialization.Options); await db.PolicyConfiguration - .Upsert(new PolicyConfiguration { Name = name, Data = JsonSerializer.Serialize(data) }) + .Upsert(new PolicyConfiguration { Name = name, Data = serialized }) .On(p => new { p.Name }) .RunAsync(); diff --git a/Iceshrimp.Backend/Core/Services/PolicyService.cs b/Iceshrimp.Backend/Core/Services/PolicyService.cs index 7a1e709f..0f15f1e5 100644 --- a/Iceshrimp.Backend/Core/Services/PolicyService.cs +++ b/Iceshrimp.Backend/Core/Services/PolicyService.cs @@ -4,6 +4,7 @@ using System.Text.Json; using Iceshrimp.AssemblyUtils; using Iceshrimp.Backend.Core.Database; using Iceshrimp.Backend.Core.Helpers; +using Iceshrimp.Shared.Configuration; using Microsoft.EntityFrameworkCore; namespace Iceshrimp.Backend.Core.Services; @@ -52,7 +53,8 @@ public class PolicyService(IServiceScopeFactory scopeFactory) config.Name); if (match == null) continue; - var deserialized = JsonSerializer.Deserialize(config.Data, match) as IPolicyConfiguration; + var deserialized = + JsonSerializer.Deserialize(config.Data, match, JsonSerialization.Options) as IPolicyConfiguration; if (deserialized?.Apply() is { } policy) policies.Add(policy); }