Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure messageBox and Toolbox are not visible to unauthorized users in read-only room #874

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: ensure messageBox and Toolbar are not visible to unauthorized us…
…ers in read-only room
  • Loading branch information
SinghaAnirban005 committed Jan 12, 2025
commit d0de85612b733771cf142f25adc40cbafe3c4c64
9 changes: 5 additions & 4 deletions packages/react/src/views/ChatHeader/ChatHeader.js
Original file line number Diff line number Diff line change
@@ -154,19 +154,20 @@ const ChatHeader = ({
};

const setMessageAllowed = async () => {
const permissionRes = await RCInstance.permissionInfo();
const channelRolesRes = await RCInstance.getChannelRoles(
isChannelPrivate
);

if (permissionRes.success && channelRolesRes.success) {
const postMsgRoles = permissionRes.update[140]?.roles || [];
if (channelRolesRes.success) {
const channelLevelRoles = channelRolesRes.roles
.filter((chRole) => chRole.u?._id === authenticatedUserId)
.flatMap((chRole) => chRole.roles);

const allRoles = [...channelLevelRoles, ...workspaceLevelRoles];
const canSendMsg = postMsgRoles.some((role) => allRoles.includes(role));
const canSendMsg =
allRoles.includes('admin') ||
allRoles.includes('moderator') ||
allRoles.includes('owner');

setCanSendMsg(canSendMsg);
}
27 changes: 16 additions & 11 deletions packages/react/src/views/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
@@ -465,7 +465,7 @@ const ChatInput = ({ scrollToBottom }) => {
status={
editMessage.msg || editMessage.attachments
? 'Editing Message'
: isChannelReadOnly
: isChannelReadOnly && canSendMsg && isUserAuthenticated
? 'This room is read only'
: undefined
}
@@ -529,7 +529,10 @@ const ChatInput = ({ scrollToBottom }) => {
? 'This room is read only'
: 'Sign in to chat'
}
css={styles.textInput}
css={css`
${styles.textInput}
${!canSendMsg && isUserAuthenticated && `text-align: center;`}
`}
onChange={onTextChange}
onBlur={() => {
sendTypingStop();
@@ -547,22 +550,24 @@ const ChatInput = ({ scrollToBottom }) => {
`}
>
{isUserAuthenticated ? (
<ActionButton
ghost
size="large"
onClick={() => sendMessage()}
type="primary"
disabled={disableButton || isRecordingMessage}
icon="send"
/>
canSendMsg ? (
<ActionButton
ghost
size="large"
onClick={() => sendMessage()}
type="primary"
disabled={disableButton || isRecordingMessage}
icon="send"
/>
) : null
) : (
<Button onClick={onJoin} type="primary" disabled={isLoginIn}>
{isLoginIn ? <Throbber /> : 'JOIN'}
</Button>
)}
</Box>
</Box>
{isUserAuthenticated && (
{isUserAuthenticated && canSendMsg && (
<ChatInputFormattingToolbar
messageRef={messageRef}
inputRef={inputRef}
Loading