Chat plugins: Make viewing source respect /permissions

This commit is contained in:
Annika
2020-10-28 15:39:41 -07:00
parent 3c23ce3a44
commit 62f1bd14fc
4 changed files with 9 additions and 10 deletions

View File

@@ -1298,7 +1298,7 @@ export const commands: ChatCommands = {
if (!this.runBroadcast()) return;
if (!room.settings.introMessage) return this.sendReply("This room does not have an introduction set.");
this.sendReply('|raw|<div class="infobox infobox-limited">' + room.settings.introMessage.replace(/\n/g, '') + '</div>');
if (!this.broadcasting && user.can('declare', null, room) && cmd !== 'topic') {
if (!this.broadcasting && user.can('declare', null, room, 'roomintro') && cmd !== 'topic') {
const code = Utils.escapeHTML(room.settings.introMessage).replace(/\n/g, '<br />');
this.sendReplyBox(`<details open><summary>Source:</summary><code style="white-space: pre-wrap; display: table; tab-size: 3">/roomintro ${code}</code></details>`);
}
@@ -1345,7 +1345,7 @@ export const commands: ChatCommands = {
this.checkCan('mute', null, room);
if (!room.settings.staffMessage) return this.sendReply("This room does not have a staff introduction set.");
this.sendReply(`|raw|<div class="infobox">${room.settings.staffMessage.replace(/\n/g, ``)}</div>`);
if (user.can('ban', null, room) && cmd !== 'stafftopic') {
if (user.can('ban', null, room, 'staffintro') && cmd !== 'stafftopic') {
const code = Utils.escapeHTML(room.settings.staffMessage).replace(/\n/g, '<br />');
this.sendReplyBox(`<details open><summary>Source:</summary><code style="white-space: pre-wrap; display: table; tab-size: 3">/staffintro ${code}</code></details>`);
}

View File

@@ -316,11 +316,10 @@ export const commands: ChatCommands = {
buff += '</table>';
this.sendReply(`|raw|<div class="infobox-limited">${buff}</div>`);
if (!this.broadcasting && user.can('ban', null, room) && events.length === 1) {
if (!this.broadcasting && user.can('ban', null, room, 'roomevents view') && events.length === 1) {
const event = events[0];
this.sendReplyBox(
Utils.html`<code>/roomevents add ${event.eventName} |` +
Utils.html`${event.date} | ${event.desc}</code>`
Utils.html`<code>/roomevents add ${event.eventName} | ${event.date} | ${event.desc}</code>`
);
}
},

View File

@@ -156,7 +156,7 @@ export const pages: PageTable = {
if (aliases.length) {
buf += `<hr /><strong>Aliases:</strong> ${aliases.join(', ')}`;
}
if (user.can('ban', null, room)) {
if (user.can('ban', null, room, 'addfaq')) {
const src = Utils.escapeHTML(topic).replace(/\n/g, `<br />`);
buf += `<hr /><details><summary>Raw text</summary>`;
buf += `<code style="white-space: pre-wrap; display: table; tab-size: 3;">/addfaq ${key}, ${src}</code></details>`;

View File

@@ -528,11 +528,11 @@ export class User extends Chat.MessageContext {
const status = statusMessage + (this.userMessage || '');
return status;
}
can(permission: RoomPermission, target: User | null, room: BasicRoom): boolean;
can(permission: RoomPermission, target: User | null, room: BasicRoom, cmd?: string): boolean;
can(permission: GlobalPermission, target?: User | null): boolean;
can(permission: RoomPermission & GlobalPermission, target: User | null, room?: BasicRoom | null): boolean;
can(permission: string, target: User | null = null, room: BasicRoom | null = null): boolean {
return Auth.hasPermission(this, permission, target, room);
can(permission: RoomPermission & GlobalPermission, target: User | null, room?: BasicRoom | null, cmd?: string): boolean;
can(permission: string, target: User | null = null, room: BasicRoom | null = null, cmd?: string): boolean {
return Auth.hasPermission(this, permission, target, room, cmd);
}
/**
* Special permission check for system operators