Skip to content

Commit

Permalink
Fix room permission
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Oct 16, 2023
1 parent 6a7abd6 commit 14990dc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/meteor/app/lib/server/startup/mentionUserNotInChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { callbacks } from '../../../../lib/callbacks';
import { getUserDisplayName } from '../../../../lib/getUserDisplayName';
import { isTruthy } from '../../../../lib/isTruthy';
import { i18n } from '../../../../server/lib/i18n';
import { hasAtLeastOnePermissionAsync, hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';

const permissionsToAddUserToRoom = ['add-user-to-joined-room', 'add-user-to-any-c-room', 'add-user-to-any-p-room'];
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';

const APP_ID = 'mention-core';
const getBlocks = (mentions: IMessage['mentions'], messageId: string, lng: string | undefined) => {
Expand Down Expand Up @@ -87,9 +85,12 @@ callbacks.add(
return message;
}

const canAddUsers = await hasAtLeastOnePermissionAsync(message.u._id, permissionsToAddUserToRoom, message.rid);
const canAddUsersToThisRoom = await hasPermissionAsync(message.u._id, 'add-user-to-joined-room', message.rid);
const canAddToAnyRoom = await (room.t === 'c'
? hasPermissionAsync(message.u._id, 'add-user-to-any-c-room')
: hasPermissionAsync(message.u._id, 'add-user-to-any-p-room'));
const canDMUsers = await hasPermissionAsync(message.u._id, 'create-d'); // TODO: Perhaps check if user has DM with mentioned user (might be too expensive)

const canAddUsers = canAddUsersToThisRoom || canAddToAnyRoom;
const { language } = (await Users.findOneById(message.u._id)) || {};

const actionBlocks = getBlocks(mentionsUsersNotInChannel, message._id, language);
Expand Down

0 comments on commit 14990dc

Please sign in to comment.