Skip to content

Commit

Permalink
chore: don't allow to report own messages and user actions menu divid…
Browse files Browse the repository at this point in the history
…ers (#30173)
  • Loading branch information
yash-rajpal committed Aug 28, 2023
1 parent 470c29d commit 1fbbb62
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-icons-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Don't allow to report self messages
15 changes: 8 additions & 7 deletions apps/meteor/app/ui-utils/client/lib/messageActionDefault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,16 @@ Meteor.startup(async () => {
const { message = messageArgs(this).msg, chat } = props;
await chat?.messageEditing.editMessage(message);
},
condition({ message, subscription, settings, room }) {
condition({ message, subscription, settings, room, user }) {
if (subscription == null) {
return false;
}
if (isRoomFederated(room)) {
return message.u._id === Meteor.userId();
return message.u._id === user?._id;
}
const canEditMessage = hasAtLeastOnePermission('edit-message', message.rid);
const isEditAllowed = settings.Message_AllowEditing;
const editOwn = message.u && message.u._id === Meteor.userId();
const editOwn = message.u && message.u._id === user?._id;
if (!(canEditMessage || (isEditAllowed && editOwn))) {
return false;
}
Expand Down Expand Up @@ -214,12 +214,12 @@ Meteor.startup(async () => {
async action(this: unknown, _, { message = messageArgs(this).msg, chat }) {
await chat?.flows.requestMessageDeletion(message);
},
condition({ message, subscription, room, chat }) {
condition({ message, subscription, room, chat, user }) {
if (!subscription) {
return false;
}
if (isRoomFederated(room)) {
return message.u._id === Meteor.userId();
return message.u._id === user?._id;
}
const isLivechatRoom = roomCoordinator.isLivechatRoom(room.t);
if (isLivechatRoom) {
Expand Down Expand Up @@ -248,11 +248,12 @@ Meteor.startup(async () => {
},
});
},
condition({ subscription, room }) {
condition({ subscription, room, message, user }) {
const isLivechatRoom = roomCoordinator.isLivechatRoom(room.t);
if (isLivechatRoom) {
if (isLivechatRoom || message.u._id === user?._id) {
return false;
}

return Boolean(subscription);
},
order: 9,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const useRemoveUserAction = (
content: room?.teamMain ? t('Remove_from_team') : t('Remove_from_room'),
icon: 'cross' as const,
onClick: removeUserOptionAction,
type: 'management' as const,
type: 'moderation' as const,
variant: 'danger' as const,
}
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const useReportUser = (user: Pick<IUser, '_id' | 'username' | 'name'>): U
icon: 'warning' as const,
content: t('Report'),
onClick: action,
type: 'management' as const,
type: 'moderation' as const,
variant: 'danger' as const,
}
: undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useRedirectModerationConsole } from './actions/useRedirectModerationCon
import { useRemoveUserAction } from './actions/useRemoveUserAction';
import { useReportUser } from './actions/useReportUser';

export type UserInfoActionType = 'communication' | 'privileges' | 'management';
export type UserInfoActionType = 'communication' | 'privileges' | 'management' | 'moderation';

export type UserInfoAction = {
content: string;
Expand Down

0 comments on commit 1fbbb62

Please sign in to comment.