mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-08-28 23:00:45 +00:00
Enable MPS's Member/ServerBanSynchronisationProtections by default.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
import { ActionError,DRAUPNIR_SCHEMA_VERSION_KEY, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, Ok, SchemedDataManager, Value } from "matrix-protection-suite";
|
||||
import { ActionError,ActionException,ActionExceptionKind,DRAUPNIR_SCHEMA_VERSION_KEY, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, Ok, SchemedDataManager, Value, findProtection } from "matrix-protection-suite";
|
||||
|
||||
export const DefaultEnabledProtectionsMigration = new SchemedDataManager<MjolnirEnabledProtectionsEvent>([
|
||||
async function enableBanPropagationByDefault(input) {
|
||||
@@ -12,11 +12,44 @@ export const DefaultEnabledProtectionsMigration = new SchemedDataManager<Mjolnir
|
||||
`The data for ${MjolnirEnabledProtectionsEventType} is corrupted.`
|
||||
);
|
||||
}
|
||||
const banPropagationProtection = findProtection('BanPropagationProtection');
|
||||
if (banPropagationProtection === undefined) {
|
||||
const message = `Cannot find the BanPropagationProtection`;
|
||||
return ActionException.Result(message, {
|
||||
exception: new TypeError(message),
|
||||
exceptionKind: ActionExceptionKind.Unknown,
|
||||
})
|
||||
}
|
||||
const enabled = new Set(input.enabled);
|
||||
enabled.add('BanPropagationProtection');
|
||||
enabled.add(banPropagationProtection.name);
|
||||
return Ok({
|
||||
enabled: [...enabled],
|
||||
[DRAUPNIR_SCHEMA_VERSION_KEY]: 1,
|
||||
});
|
||||
},
|
||||
async function enableMemberAndServerSynchronisationByDefault(input) {
|
||||
if (!Value.Check(MjolnirEnabledProtectionsEvent, input)) {
|
||||
return ActionError.Result(
|
||||
`The data for ${MjolnirEnabledProtectionsEventType} is corrupted.`
|
||||
);
|
||||
}
|
||||
const enabledProtections = new Set(input.enabled);
|
||||
// we go through the process of finding them just so we can be sure that we spell their names correctly.
|
||||
const memberBanSynchronisationProtection = findProtection('MemberBanSynchronisationProtection');
|
||||
const serverBanSynchronisationProtection = findProtection('ServerBanSynchronisationProtection');
|
||||
if (memberBanSynchronisationProtection === undefined || serverBanSynchronisationProtection === undefined) {
|
||||
const message = `Cannot find the member ban or server ban synchronisation protections`;
|
||||
return ActionException.Result(message, {
|
||||
exception: new TypeError(message),
|
||||
exceptionKind: ActionExceptionKind.Unknown
|
||||
});
|
||||
}
|
||||
for (const protection of [memberBanSynchronisationProtection, serverBanSynchronisationProtection]) {
|
||||
enabledProtections.add(protection.name);
|
||||
}
|
||||
return Ok({
|
||||
enabled: [...enabledProtections],
|
||||
[DRAUPNIR_SCHEMA_VERSION_KEY]: 2,
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user