Refactor and improve the unban command.

We no longer want to accept an argument for the list. We will just
find all appropriate policies and remove them, like we do with the
unban prompt (which we still might want to update to use the new
`--no-confirm` prompt later).

We fix the bugs where the unban command was inviting users regardless
of whether the `--invite` option was provided.

The unban command now uses a preview which shows all the policies that
will have to be removed to unban a user, all the rooms they will need
to be unbanned from, and any rooms that they will be invited to if the
`--invite` option is used.
This commit is contained in:
gnuxie
2025-02-14 13:34:37 +00:00
parent 9587d6fcba
commit a45d308597
8 changed files with 1070 additions and 268 deletions

View File

@@ -25,7 +25,7 @@ import {
} from "matrix-protection-suite";
import { createMock } from "ts-auto-mock";
import expect from "expect";
import { DraupnirUnbanCommand } from "../../../src/commands/Unban";
import { DraupnirUnbanCommand } from "../../../src/commands/unban/Unban";
import ManagementRoomOutput from "../../../src/managementroom/ManagementRoomOutput";
import { UnlistedUserRedactionQueue } from "../../../src/queues/UnlistedUserRedactionQueue";
@@ -129,7 +129,7 @@ describe("Test the DraupnirUnbanCommand", function () {
DraupnirUnbanCommand,
{
policyRoomManager: mockPolicyRoomManager,
setMembership: protectedRoomsSet.setRoomMembership,
setRoomMembership: protectedRoomsSet.setRoomMembership,
managementRoomOutput: createMock<ManagementRoomOutput>(),
roomResolver,
watchedPolicyRooms: protectedRoomsSet.watchedPolicyRooms,
@@ -142,12 +142,14 @@ describe("Test the DraupnirUnbanCommand", function () {
return Ok(undefined);
},
}),
setMembership: protectedRoomsSet.setMembership,
setPoliciesMatchingMembership:
protectedRoomsSet.setPoliciesMatchingMembership.currentRevision,
},
{
rest: ["spam"],
},
MatrixUserID.fromUserID(ExistingBanUserID),
policyRoom
MatrixUserID.fromUserID(ExistingBanUserID)
);
expect(banResult.isOkay).toBe(true);
const membership = protectedRoomsSet.setRoomMembership.getRevision(
@@ -159,7 +161,7 @@ describe("Test the DraupnirUnbanCommand", function () {
);
}
expect(membership.membershipForUser(ExistingBanUserID)?.membership).toBe(
Membership.Leave
Membership.Ban
);
});
});