Skip to content

Commit

Permalink
Fix protections config set/add/remove commands. (#638)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
Gnuxie authored Dec 9, 2024
1 parent 6f7a13e commit 6137927
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 20 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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/[email protected].0",
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/[email protected].0",
"matrix-protection-suite": "npm:@gnuxie/[email protected].1",
"matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/[email protected].1",
"parse-duration": "^1.0.2",
"pg": "^8.8.0",
"shell-quote": "^1.7.3",
Expand Down
16 changes: 14 additions & 2 deletions src/commands/DraupnirCommandTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@
// https://github.com/the-draupnir-project/Draupnir
// </text>

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);
3 changes: 1 addition & 2 deletions src/commands/ProtectionsCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 13 additions & 1 deletion src/safemode/commands/SafeModeCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down
4 changes: 4 additions & 0 deletions test/unit/commands/BanCommandTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MatrixRoomIDPresentationType,
MatrixUserIDPresentationType,
PromptRequiredError,
StandardCommandTable,
} from "@the-draupnir-project/interface-manager";
import {
MatrixRoomID,
Expand All @@ -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() {
Expand Down Expand Up @@ -72,6 +74,7 @@ describe("Test the DraupnirBanCommand", function () {
const { protectedRoomsSet, policyRoomManager } =
await createProtectedRooms();
const banResult = await CommandExecutorHelper.parseAndInvoke(
dummyTable,
DraupnirBanCommand,
{
policyRoomManager,
Expand Down Expand Up @@ -104,6 +107,7 @@ describe("Test the DraupnirBanCommand", function () {
);
}
const banResult = await CommandExecutorHelper.parseAndInvoke(
dummyTable,
DraupnirBanCommand,
{
policyRoomManager,
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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/[email protected].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/[email protected].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/[email protected].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/[email protected].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"
Expand Down

0 comments on commit 6137927

Please sign in to comment.