mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
check policies when trying to store
This commit is contained in:
parent
abe3c44891
commit
7687d3dd7d
1 changed files with 25 additions and 0 deletions
|
|
@ -50,6 +50,31 @@ export const adminUpdatePolicyController: AppController = async (c) => {
|
||||||
try {
|
try {
|
||||||
const req = await c.req.json();
|
const req = await c.req.json();
|
||||||
const parsed = PolicySpecSchema.parse(req);
|
const parsed = PolicySpecSchema.parse(req);
|
||||||
|
|
||||||
|
// Validate each policy against its specific schema
|
||||||
|
const invalidPolicies = parsed.policies.filter(policy => {
|
||||||
|
const policyItem = policyRegistry.available[policy.name];
|
||||||
|
// If policy not found in registry, it's invalid
|
||||||
|
if (!policyItem) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try to parse the policy params against the specific schema
|
||||||
|
policyItem.schema.parse(policy.params);
|
||||||
|
return false; // Not invalid
|
||||||
|
} catch (_) {
|
||||||
|
return true; // Invalid policy
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If any policies are invalid, return an error
|
||||||
|
if (invalidPolicies.length > 0) {
|
||||||
|
return c.json({
|
||||||
|
error: `Invalid policy specification for: ${invalidPolicies.map(p => p.name).join(', ')}`
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
|
||||||
await relay.event(await createPolicyEvent(conf, parsed));
|
await relay.event(await createPolicyEvent(conf, parsed));
|
||||||
return c.json({
|
return c.json({
|
||||||
message: 'Settings saved successfully.',
|
message: 'Settings saved successfully.',
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue