diff --git a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts index f08b3a59..d22afd22 100644 --- a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts +++ b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts @@ -31,6 +31,7 @@ import { DefaultEnabledProtectionsMigration } from "../protections/DefaultEnable import '../protections/DraupnirProtectionsIndex'; import { IConfig } from "../config"; import { runProtectionConfigHooks } from "../protections/ConfigHooks"; +import { makeHandleMissingProtectionPermissions } from "../protections/MissingProtectionPermissions"; const log = new Logger('DraupnirProtectedRoomsSet'); @@ -166,6 +167,10 @@ export async function makeProtectedRoomsSet( protectedRoomsManager.ok, protectionsConfig.ok, userID, + makeHandleMissingProtectionPermissions( + client, + managementRoom.toRoomIDOrAlias() + ) ); return Ok(protectedRoomsSet); } diff --git a/src/protections/MissingProtectionPermissions.tsx b/src/protections/MissingProtectionPermissions.tsx new file mode 100644 index 00000000..6e26ecf4 --- /dev/null +++ b/src/protections/MissingProtectionPermissions.tsx @@ -0,0 +1,84 @@ +// SPDX-FileCopyrightText: 2024 Gnuxie +// +// SPDX-License-Identifier: AFL-3.0 + +import { HandleMissingProtectionPermissions, MatrixRoomReference, ProtectionPermissionsChange, StringRoomID, Task } from "matrix-protection-suite"; +import { renderMatrixAndSend } from "../commands/interface-manager/DeadDocumentMatrix"; +import { MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; +import { JSXFactory } from "../commands/interface-manager/JSXFactory"; +import { DocumentNode } from "../commands/interface-manager/DeadDocument"; +import { renderRoomPill } from "../commands/interface-manager/MatrixHelpRenderer"; + +function renderPermissions( + title: DocumentNode, + permissions: string[] +): DocumentNode { + return permissions.length === 0 + ? + : + {title} + + +} + +function missingPermissionsTotal(change: ProtectionPermissionsChange): number { + return change.permissionsChange.missingEventPermissions.length + + change.permissionsChange.missingPermissions.length + + change.permissionsChange.missingStatePermissions.length +} + +function renderMissingProtectionPermissions( + protectionPermissions: ProtectionPermissionsChange +): DocumentNode { + return
+ The {protectionPermissions.protection.description.name} is missing the following permissions ({missingPermissionsTotal(protectionPermissions)}): + {renderPermissions( + Missing permissions:, + protectionPermissions.permissionsChange.missingPermissions + )} + {renderPermissions( + Missing state permissions:, + protectionPermissions.permissionsChange.missingStatePermissions + )} + {renderPermissions( + Missing event permissions:, + protectionPermissions.permissionsChange.missingEventPermissions + )} +
+} + +function renderMissingProtectionsPermissions( + roomID: StringRoomID, + protectionPermissions: ProtectionPermissionsChange[] +): DocumentNode { + return + There are protections with missing permissions within the room {renderRoomPill(MatrixRoomReference.fromRoomID(roomID, []))}. + + +} + +export function makeHandleMissingProtectionPermissions( + client: MatrixSendClient, + managementRoomID: StringRoomID +): HandleMissingProtectionPermissions { + return function( + roomID, + protectionPermissions + ) { + void Task((async () => { + renderMatrixAndSend( + {renderMissingProtectionsPermissions( + roomID, + protectionPermissions + )}, + managementRoomID, + undefined, + client + ) + })()) + } +}