From 40cc33fcfdf763f9b59e09b68f28700476a06bef Mon Sep 17 00:00:00 2001 From: Mia <49593536+mia-pi-git@users.noreply.github.com> Date: Mon, 4 Jan 2021 12:15:42 -0600 Subject: [PATCH] Chat: Add support for private pages (#7877) --- server/chat.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/server/chat.ts b/server/chat.ts index 68026434b9..244d9bd5af 100644 --- a/server/chat.ts +++ b/server/chat.ts @@ -278,6 +278,19 @@ export class PageContext extends MessageContext { return true; } + privatelyCheckCan(permission: RoomPermission, target: User | null, room: Room): boolean; + privatelyCheckCan(permission: GlobalPermission, target?: User | null): boolean; + privatelyCheckCan(permission: string, target: User | null = null, room: Room | null = null) { + if (!this.user.can(permission as any, target, room as any)) { + this.pageDoesNotExist(); + } + return true; + } + + pageDoesNotExist(): never { + throw new Chat.ErrorMessage(`Page "${this.pageid}" not found`); + } + requireRoom(pageid?: string) { const room = this.extractRoom(pageid); if (!room) { @@ -334,15 +347,12 @@ export class PageContext extends MessageContext { } handler = handler[parts.shift() || 'default']; } - if (typeof handler !== 'function') { - this.errorReply(`Page "${this.pageid}" not found`); - return; - } this.args = parts; let res; try { + if (typeof handler !== 'function') this.pageDoesNotExist(); res = await handler.call(this, parts, this.user, this.connection); } catch (err) { if (err.name?.endsWith('ErrorMessage')) {