From fb954b5ecfa1a9bcbebbe59af02a50009da51aa2 Mon Sep 17 00:00:00 2001 From: eskima Date: Sat, 21 Nov 2026 00:52:06 +0800 Subject: [PATCH] Honor configured room admins during room binding recovery --- README.en.md | 2 +- README.md | 2 +- src/core/plugin/room-binding.spec.ts | 8 ++++---- src/core/plugin/room-binding.ts | 2 -- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/README.en.md b/README.en.md index ae49d0d..2c59325 100644 --- a/README.en.md +++ b/README.en.md @@ -40,7 +40,7 @@ An administrator is a user in the room's `admins` list or with a native Matrix p Administrators can inspect the current room ID, language, timezone and report settings with `/config` or `!config`. `!config language en` applies immediately. `!config reports off` applies the next time the check-in plugin starts. -If a domainless room ID was configured with an extra server suffix, send `!config` in the actual room, then `!config bind`. Recovery requires a unique candidate, a sender listed in `admins` with sufficient native room power, and bot membership in the actual room but not the configured room. The database stores the correction for the next service start and keeps the original data scope. The command requires a readable message and cannot restore missing encryption keys. +If a domainless room ID was configured with an extra server suffix, send `!config` in the actual room, then `!config bind`. Recovery requires a unique candidate, a sender listed in the room’s `admins` at any native power level, and bot membership in the actual room but not the configured room. The database stores the correction for the next service start and keeps the original data scope. The command requires a readable message and cannot restore missing encryption keys. ### Check-in commands diff --git a/README.md b/README.md index 31040f9..509d278 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ 管理员可用 `/config`(`!配置`)查看当前房间 ID、语言、时区和报表设置。`!配置 语言 英文` 立即生效;`!配置 报表 关` 在签到插件下次启动时生效。 -如果配置给一个无域名的房间 ID 误加了 `:域名`,可在实际房间发送 `!配置` 查看提示,再发 `!配置 绑定`。仅限配置 `admins` 名单内且达到该房间管理权限阈值的人。机器人必须已加入该房间,没有加入旧 ID 对应的房间,且候选房间必须唯一。绑定保存到数据库,保留原配置和数据范围,服务下次启动时使用正确的 ID。此命令需要机器人能够读到消息;缺失的历史解密密钥需要单独处理。 +如果配置给一个无域名的房间 ID 误加了 `:域名`,可在实际房间发送 `!配置` 查看提示,再发 `!配置 绑定`。只有该房间配置的 `admins` 成员可执行绑定恢复,名单内账号在任何原生权限分下均可操作。机器人必须已加入该房间,没有加入旧 ID 对应的房间,且候选房间必须唯一。绑定保存到数据库,保留原配置和数据范围,服务下次启动时使用正确的 ID。此命令需要机器人能够读到消息;缺失的历史解密密钥需要单独处理。 ### 签到命令 diff --git a/src/core/plugin/room-binding.spec.ts b/src/core/plugin/room-binding.spec.ts index ed4dbdd..32f2802 100644 --- a/src/core/plugin/room-binding.spec.ts +++ b/src/core/plugin/room-binding.spec.ts @@ -8,7 +8,7 @@ const room = roomSchema.parse({ account: 'test', admins: [admin], roomId: id + ' const msg = message('/config bind', admin, id); function fixture() { return { store: memoryStores()('bindings'), transport: { getJoinedRooms: jest.fn(async () => [id]), - getPowerLevel: jest.fn(async () => 100), send: jest.fn(async () => '$event') } }; + getPowerLevel: jest.fn(async () => 0), send: jest.fn(async () => '$event') } }; } it('shows the recovery command before binding the event room and recording its actor', async () => { const { store, transport } = fixture(); @@ -17,12 +17,12 @@ it('shows the recovery command before binding the event room and recording its a expect(transport.send.mock.calls[0]).toContain(id); await recoverBinding(room, msg, store, transport); expect(await store.get(bindingKey(room))).toEqual({ id, actor: admin }); + expect(transport.getPowerLevel).not.toHaveBeenCalled(); }); -it('refuses unlisted senders, insufficient power and ambiguous joined rooms', async () => { +it('refuses unlisted senders even with high power, and ambiguous joined rooms', async () => { const { transport, store } = fixture(); + transport.getPowerLevel.mockResolvedValue(100); await recoverBinding(room, { ...msg, userId: '@other:example.org' }, store, transport); - transport.getPowerLevel.mockResolvedValueOnce(50); - await recoverBinding(room, msg, store, transport); transport.getJoinedRooms.mockResolvedValueOnce([room.roomId, id]); await recoverBinding(room, msg, store, transport); await recoverBinding(room, { ...msg, text: '/config bind !other:example.org' }, store, transport); diff --git a/src/core/plugin/room-binding.ts b/src/core/plugin/room-binding.ts index e2bfc33..8c3f2e9 100644 --- a/src/core/plugin/room-binding.ts +++ b/src/core/plugin/room-binding.ts @@ -22,7 +22,6 @@ export function recoveryRooms(rooms: RoomConfig[], account: string): Map; - getPowerLevel(roomId: string, userId: string): Promise; send(roomId: string, text: string, eventId?: string): Promise; } export const bindingKey = (room: RoomConfig) => JSON.stringify([room.account, room.roomId]); @@ -32,7 +31,6 @@ export async function recoverBinding(room: RoomConfig, msg: InboundMessage, stor if (!match) return; const joined = await transport.getJoinedRooms(); if (!joined.includes(msg.roomId) || joined.includes(room.roomId)) return; - if (!(await transport.getPowerLevel(msg.roomId, msg.userId) >= room.adminPowerLevel)) return; if (match[1]) { await store.set(bindingKey(room), { id: msg.roomId, actor: msg.userId }); await transport.send(msg.roomId, translate({ 'zh-CN': '已保存此房间 ID,服务下次启动时生效。', en: 'Room ID saved. It takes effect at the next service start.' }, room.locale), msg.eventId);