Skip to content

Commit

Permalink
fix: Looking at the user's permission before rendering the 'Start Cal…
Browse files Browse the repository at this point in the history
…l' button on UserInfo (#31600)
  • Loading branch information
Gustrb committed Feb 5, 2024
1 parent c2ca061 commit ed45125
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/small-beers-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Looking at the user's permission before rendering the 'Start Call' button on the UserInfo panel, so if the user does not have the permissions, the button does not show
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IUser } from '@rocket.chat/core-typings';
import { isRoomFederated } from '@rocket.chat/core-typings';
import { useTranslation, useUserRoom, useUserId, useUserSubscriptionByName } from '@rocket.chat/ui-contexts';
import { useTranslation, useUserRoom, useUserId, useUserSubscriptionByName, useSetting, usePermission } from '@rocket.chat/ui-contexts';
import { useMemo } from 'react';

import { closeUserCard } from '../../../../../../app/ui/client/lib/userCard';
Expand All @@ -20,6 +20,9 @@ export const useCallAction = (user: Pick<IUser, '_id' | 'username'>): UserInfoAc
const isRinging = useVideoConfIsRinging();
const ownUserId = useUserId();

const enabledForDMs = useSetting('VideoConf_Enable_DMs');
const permittedToCallManagement = usePermission('call-management', room?._id);

const videoCallOption = useMemo(() => {
const action = async (): Promise<void> => {
if (isCalling || isRinging || !room) {
Expand All @@ -35,15 +38,18 @@ export const useCallAction = (user: Pick<IUser, '_id' | 'username'>): UserInfoAc
}
};

return room && !isRoomFederated(room) && user._id !== ownUserId
const shouldShowStartCall =
room && !isRoomFederated(room) && user._id !== ownUserId && enabledForDMs && permittedToCallManagement && !isCalling && !isRinging;

return shouldShowStartCall
? {
content: t('Start_call'),
icon: 'phone' as const,
onClick: action,
type: 'communication' as UserInfoActionType,
}
: undefined;
}, [t, room, dispatchPopup, dispatchWarning, isCalling, isRinging, ownUserId, user._id]);
}, [room, user._id, ownUserId, enabledForDMs, permittedToCallManagement, isCalling, isRinging, t, dispatchPopup, dispatchWarning]);

return videoCallOption;
};

0 comments on commit ed45125

Please sign in to comment.