From 613792769f867806a147d5ba5864666aeee31eb3 Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Mon, 9 Dec 2024 16:56:29 +0000 Subject: [PATCH] Fix protections config set/add/remove commands. (#638) * Stop using `setSerializedValue` on protection settings. We don't need it now that we've updated the command reader. * Update interface-manager and MPS. * Enable standard presentation type translators. This will fix issues with the ban command reason. --- package.json | 6 +++--- src/commands/DraupnirCommandTable.ts | 16 +++++++++++++-- src/commands/ProtectionsCommands.tsx | 3 +-- src/safemode/commands/SafeModeCommands.tsx | 14 ++++++++++++- test/unit/commands/BanCommandTest.ts | 4 ++++ yarn.lock | 24 +++++++++++----------- 6 files changed, 47 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 36da030b..3abddb37 100644 --- a/package.json +++ b/package.json @@ -56,7 +56,7 @@ "@sentry/node": "^7.17.2", "@sentry/tracing": "^7.17.2", "@sinclair/typebox": "0.33.17", - "@the-draupnir-project/interface-manager": "2.6.0", + "@the-draupnir-project/interface-manager": "3.0.0", "@the-draupnir-project/matrix-basic-types": "^0.2.0", "await-lock": "^2.2.2", "better-sqlite3": "^9.4.3", @@ -70,8 +70,8 @@ "jsdom": "^24.0.0", "matrix-appservice-bridge": "^10.3.1", "matrix-bot-sdk": "npm:@vector-im/matrix-bot-sdk@^0.7.1-element.6", - "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@2.1.0", - "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@2.1.0", + "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@2.1.1", + "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@2.1.1", "parse-duration": "^1.0.2", "pg": "^8.8.0", "shell-quote": "^1.7.3", diff --git a/src/commands/DraupnirCommandTable.ts b/src/commands/DraupnirCommandTable.ts index 0694d95a..1ad30e76 100644 --- a/src/commands/DraupnirCommandTable.ts +++ b/src/commands/DraupnirCommandTable.ts @@ -7,8 +7,20 @@ // https://github.com/the-draupnir-project/Draupnir // -import { StandardCommandTable } from "@the-draupnir-project/interface-manager"; +import { + StandardCommandTable, + StringFromMatrixEventReferenceTranslator, + StringFromMatrixRoomAliasTranslator, + StringFromMatrixRoomIDTranslator, + StringFromMatrixUserIDTranslator, + StringFromNumberTranslator, +} from "@the-draupnir-project/interface-manager"; export const DraupnirTopLevelCommands = new StandardCommandTable( "draupnir top level" -); +) + .internPresentationTypeTranslator(StringFromNumberTranslator) + .internPresentationTypeTranslator(StringFromMatrixRoomIDTranslator) + .internPresentationTypeTranslator(StringFromMatrixRoomAliasTranslator) + .internPresentationTypeTranslator(StringFromMatrixUserIDTranslator) + .internPresentationTypeTranslator(StringFromMatrixEventReferenceTranslator); diff --git a/src/commands/ProtectionsCommands.tsx b/src/commands/ProtectionsCommands.tsx index ef8b7964..cc5d5445 100644 --- a/src/commands/ProtectionsCommands.tsx +++ b/src/commands/ProtectionsCommands.tsx @@ -169,8 +169,7 @@ export const DraupnirProtectionsConfigSetCommand = describeCommand({ const details = detailsResult.ok; const newSettings = details.description .toMirror() - // we have to reserialize or present the argument or we'll be SOL. - .setSerializedValue(details.previousSettings, settingName, String(value)); + .setValue(details.previousSettings, settingName, value); if (isError(newSettings)) { return newSettings; } diff --git a/src/safemode/commands/SafeModeCommands.tsx b/src/safemode/commands/SafeModeCommands.tsx index d5b04cea..3b3b2c60 100644 --- a/src/safemode/commands/SafeModeCommands.tsx +++ b/src/safemode/commands/SafeModeCommands.tsx @@ -2,13 +2,25 @@ // // SPDX-License-Identifier: AFL-3.0 -import { StandardCommandTable } from "@the-draupnir-project/interface-manager"; +import { + StandardCommandTable, + StringFromMatrixEventReferenceTranslator, + StringFromMatrixRoomAliasTranslator, + StringFromMatrixRoomIDTranslator, + StringFromMatrixUserIDTranslator, + StringFromNumberTranslator, +} from "@the-draupnir-project/interface-manager"; import { SafeModeHelpCommand } from "./HelpCommand"; import { SafeModeStatusCommand } from "./StatusCommand"; import { SafeModeRestartCommand } from "./RestartDraupnirCommand"; import { SafeModeRecoverCommand } from "./RecoverCommand"; export const SafeModeCommands = new StandardCommandTable("safe mode") + .internPresentationTypeTranslator(StringFromNumberTranslator) + .internPresentationTypeTranslator(StringFromMatrixRoomIDTranslator) + .internPresentationTypeTranslator(StringFromMatrixRoomAliasTranslator) + .internPresentationTypeTranslator(StringFromMatrixUserIDTranslator) + .internPresentationTypeTranslator(StringFromMatrixEventReferenceTranslator) .internCommand(SafeModeHelpCommand, ["draupnir", "help"]) .internCommand(SafeModeStatusCommand, ["draupnir", "status"]) .internCommand(SafeModeRecoverCommand, ["draupnir", "recover"]) diff --git a/test/unit/commands/BanCommandTest.ts b/test/unit/commands/BanCommandTest.ts index a0892da1..0c53808d 100644 --- a/test/unit/commands/BanCommandTest.ts +++ b/test/unit/commands/BanCommandTest.ts @@ -7,6 +7,7 @@ import { MatrixRoomIDPresentationType, MatrixUserIDPresentationType, PromptRequiredError, + StandardCommandTable, } from "@the-draupnir-project/interface-manager"; import { MatrixRoomID, @@ -29,6 +30,7 @@ import { createMock } from "ts-auto-mock"; import expect from "expect"; import { DraupnirBanCommand } from "../../../src/commands/Ban"; +const dummyTable = new StandardCommandTable("test"); const DraupnirUserID = `@draupnir:ourserver.example.com` as StringUserID; async function createProtectedRooms() { @@ -72,6 +74,7 @@ describe("Test the DraupnirBanCommand", function () { const { protectedRoomsSet, policyRoomManager } = await createProtectedRooms(); const banResult = await CommandExecutorHelper.parseAndInvoke( + dummyTable, DraupnirBanCommand, { policyRoomManager, @@ -104,6 +107,7 @@ describe("Test the DraupnirBanCommand", function () { ); } const banResult = await CommandExecutorHelper.parseAndInvoke( + dummyTable, DraupnirBanCommand, { policyRoomManager, diff --git a/yarn.lock b/yarn.lock index b949d107..34b909f0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -335,10 +335,10 @@ resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" integrity sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA== -"@the-draupnir-project/interface-manager@2.6.0": - version "2.6.0" - resolved "https://registry.yarnpkg.com/@the-draupnir-project/interface-manager/-/interface-manager-2.6.0.tgz#45c912a0dda36db295bb24560ecc050a9111202b" - integrity sha512-l1v+acM/WK6J8jR29ZX3wPv5k7BPtfpq6EwnRJwPViEfJvNAc2NJDr7pIHrUSpVpJz2we/mW5WWxRejG/Di+4Q== +"@the-draupnir-project/interface-manager@3.0.0": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@the-draupnir-project/interface-manager/-/interface-manager-3.0.0.tgz#8aedad18be4f33a098e5dc2e74ed8590ca1aba68" + integrity sha512-TRPBf+JqcwHS8ARp2FXQhIGcvBrXhUEB16oCKQAybUqMN6f9G7hKP0WQnT1A+IK9xWkG1eAtyUf2HX1LUzwLxg== dependencies: "@gnuxie/super-cool-stream" "^0.2.1" "@gnuxie/typescript-result" "^1.0.0" @@ -2645,17 +2645,17 @@ matrix-appservice@^2.0.0: request-promise "^4.2.6" sanitize-html "^2.11.0" -"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@2.1.0": - version "2.1.0" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-2.1.0.tgz#a95b2045cba89799839467bc23c0e2d88a51b377" - integrity sha512-ki6gSPhXyD/v7veOya/34KBTCG7SPusxDDJRx7fdkNn3UPoGxqGIvrH+rGn3meOSbJkYHkr4zZ+HO+sJ6VpJkg== +"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@2.1.1": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-2.1.1.tgz#30f46d70b9c39d4d51535f2ec34ff5bf9429b3d6" + integrity sha512-mF0MM/MiAYhWtRTy9TlBHVXomOoJ2dYnS/8NG3h1b71XJuhrgGmpgVfbJJV8dJ4aeIcwhTARf/1fJ5muLGavPQ== dependencies: "@gnuxie/typescript-result" "^1.0.0" -"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@2.1.0": - version "2.1.0" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-2.1.0.tgz#5bd19d07400ef35c29a3fd18f33196d5f814e65f" - integrity sha512-mQrpyoJulflfkyDB6BZI3SGCqW3sMemKRKMSSkp3TA+RM+sIWfocaMLrUBVdMSzPKFzs2vanJHx2qQzNFteUZw== +"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@2.1.1": + version "2.1.1" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-2.1.1.tgz#82ca4ae80d400c51fb232c6ab1fb26782ba7d006" + integrity sha512-fIYw1LSBtqiNsGYA4OMxieeDmED4uGKPqBE2p4D7xW7d8RlgDSrmxUGrddSqiCcJKYjwKmy5V4c7YOpusIioHg== dependencies: "@gnuxie/typescript-result" "^1.0.0" await-lock "^2.2.2"