Regression: Fix new 'message-impersonate' permission blocking livechat messages (#21961)

pull/21963/head^2
pierre-lehnen-rc 5 years ago committed by GitHub
parent d46177dc59
commit 657dfaa74b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      app/lib/server/functions/sendMessage.js

@ -127,7 +127,7 @@ const validateAttachment = (attachment) => {
const validateBodyAttachments = (attachments) => attachments.map(validateAttachment);
const validateMessage = (message, userId) => {
const validateMessage = (message, room, user) => {
check(message, objectMaybeIncluding({
_id: String,
msg: String,
@ -141,8 +141,12 @@ const validateMessage = (message, userId) => {
blocks: [Match.Any],
}));
if ((message.alias || message.avatar) && !hasPermission(userId, 'message-impersonate', message.rid)) {
throw new Error('Not enough permission');
if (message.alias || message.avatar) {
const isLiveChatGuest = !message.avatar && user.token && user.token === room.v?.token;
if (!isLiveChatGuest && !hasPermission(user._id, 'message-impersonate', room._id)) {
throw new Error('Not enough permission');
}
}
if (Array.isArray(message.attachments) && message.attachments.length) {
@ -155,7 +159,7 @@ export const sendMessage = function(user, message, room, upsert = false) {
return false;
}
validateMessage(message, user._id);
validateMessage(message, room, user);
if (!message.ts) {
message.ts = new Date();

Loading…
Cancel
Save