Honor configured room admins during room binding recovery
This commit is contained in:
1 parent
8a87c893fd
commit
fb954b5ecf
4 files changed
+6
-8
No files matched your search
+1
-1
@@ -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.
|
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
|
### Check-in commands
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
|
|
||||||
管理员可用 `/config`(`!配置`)查看当前房间 ID、语言、时区和报表设置。`!配置 语言 英文` 立即生效;`!配置 报表 关` 在签到插件下次启动时生效。
|
管理员可用 `/config`(`!配置`)查看当前房间 ID、语言、时区和报表设置。`!配置 语言 英文` 立即生效;`!配置 报表 关` 在签到插件下次启动时生效。
|
||||||
|
|
||||||
如果配置给一个无域名的房间 ID 误加了 `:域名`,可在实际房间发送 `!配置` 查看提示,再发 `!配置 绑定`。仅限配置 `admins` 名单内且达到该房间管理权限阈值的人。机器人必须已加入该房间,没有加入旧 ID 对应的房间,且候选房间必须唯一。绑定保存到数据库,保留原配置和数据范围,服务下次启动时使用正确的 ID。此命令需要机器人能够读到消息;缺失的历史解密密钥需要单独处理。
|
如果配置给一个无域名的房间 ID 误加了 `:域名`,可在实际房间发送 `!配置` 查看提示,再发 `!配置 绑定`。只有该房间配置的 `admins` 成员可执行绑定恢复,名单内账号在任何原生权限分下均可操作。机器人必须已加入该房间,没有加入旧 ID 对应的房间,且候选房间必须唯一。绑定保存到数据库,保留原配置和数据范围,服务下次启动时使用正确的 ID。此命令需要机器人能够读到消息;缺失的历史解密密钥需要单独处理。
|
||||||
|
|
||||||
### 签到命令
|
### 签到命令
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const room = roomSchema.parse({ account: 'test', admins: [admin], roomId: id + '
|
|||||||
const msg = message('/config bind', admin, id);
|
const msg = message('/config bind', admin, id);
|
||||||
function fixture() {
|
function fixture() {
|
||||||
return { store: memoryStores()('bindings'), transport: { getJoinedRooms: jest.fn(async () => [id]),
|
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 () => {
|
it('shows the recovery command before binding the event room and recording its actor', async () => {
|
||||||
const { store, transport } = fixture();
|
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);
|
expect(transport.send.mock.calls[0]).toContain(id);
|
||||||
await recoverBinding(room, msg, store, transport);
|
await recoverBinding(room, msg, store, transport);
|
||||||
expect(await store.get(bindingKey(room))).toEqual({ id, actor: admin });
|
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();
|
const { transport, store } = fixture();
|
||||||
|
transport.getPowerLevel.mockResolvedValue(100);
|
||||||
await recoverBinding(room, { ...msg, userId: '@other:example.org' }, store, transport);
|
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]);
|
transport.getJoinedRooms.mockResolvedValueOnce([room.roomId, id]);
|
||||||
await recoverBinding(room, msg, store, transport);
|
await recoverBinding(room, msg, store, transport);
|
||||||
await recoverBinding(room, { ...msg, text: '/config bind !other:example.org' }, store, transport);
|
await recoverBinding(room, { ...msg, text: '/config bind !other:example.org' }, store, transport);
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export function recoveryRooms(rooms: RoomConfig[], account: string): Map<string,
|
|||||||
|
|
||||||
export interface BindingTransport {
|
export interface BindingTransport {
|
||||||
getJoinedRooms(): Promise<string[]>;
|
getJoinedRooms(): Promise<string[]>;
|
||||||
getPowerLevel(roomId: string, userId: string): Promise<number>;
|
|
||||||
send(roomId: string, text: string, eventId?: string): Promise<string>;
|
send(roomId: string, text: string, eventId?: string): Promise<string>;
|
||||||
}
|
}
|
||||||
export const bindingKey = (room: RoomConfig) => JSON.stringify([room.account, room.roomId]);
|
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;
|
if (!match) return;
|
||||||
const joined = await transport.getJoinedRooms();
|
const joined = await transport.getJoinedRooms();
|
||||||
if (!joined.includes(msg.roomId) || joined.includes(room.roomId)) return;
|
if (!joined.includes(msg.roomId) || joined.includes(room.roomId)) return;
|
||||||
if (!(await transport.getPowerLevel(msg.roomId, msg.userId) >= room.adminPowerLevel)) return;
|
|
||||||
if (match[1]) {
|
if (match[1]) {
|
||||||
await store.set(bindingKey(room), { id: msg.roomId, actor: msg.userId });
|
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);
|
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);
|
||||||
|
|||||||
Reference in new issue
Block a user