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: Check for room scoped permissions for creating discussions #30497

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/sweet-chefs-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Check for room scoped permissions for starting discussions
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Meteor.startup(() => {
return false;
}

return uid !== user._id ? hasPermission('start-discussion-other-user') : hasPermission('start-discussion');
return uid !== user._id ? hasPermission('start-discussion-other-user', room._id) : hasPermission('start-discussion', room._id);
},
order: 1,
group: 'menu',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export const createDiscussion = async (
});
}

if (!(await hasAtLeastOnePermissionAsync(userId, ['start-discussion', 'start-discussion-other-user']))) {
if (!(await hasAtLeastOnePermissionAsync(userId, ['start-discussion', 'start-discussion-other-user'], prid))) {
throw new Meteor.Error('error-action-not-allowed', 'You are not allowed to create a discussion', { method: 'createDiscussion' });
}
const user = await Users.findOneById(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const CreateDiscussionAction = ({ room }: { room: IRoom }) => {
setModal(<CreateDiscussion onClose={() => setModal(null)} defaultParentRoom={room?.prid || room?._id} />);

const discussionEnabled = useSetting('Discussion_enabled') as boolean;
const canStartDiscussion = usePermission('start-discussion');
const canSstartDiscussionOtherUser = usePermission('start-discussion-other-user');
const canStartDiscussion = usePermission('start-discussion', room._id);
const canSstartDiscussionOtherUser = usePermission('start-discussion-other-user', room._id);

const allowDiscussion = room && discussionEnabled && !isRoomFederated(room) && (canStartDiscussion || canSstartDiscussionOtherUser);

Expand Down
Loading