[backend/core] Fix policy configuration endpoint not updating the configuration correctly depending on JSON format
This commit is contained in:
parent
f98d9ce711
commit
23d2664376
2 changed files with 8 additions and 6 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue