Skip to content

Commit 295e951

Browse files
fix: DM from a deactivated user not in read-only (#40767)
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent f1091be commit 295e951

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

.changeset/early-deer-fry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
---
4+
5+
Fixes an issue that allowed users to create a DM and send messages to a deactivated account

apps/meteor/app/lib/server/functions/createDirectRoom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ export async function createDirectRoom(
8282

8383
const isNewRoom = !room;
8484

85+
// Mirror setUserActiveStatus: a 1-on-1 DM containing a deactivated user is read-only
86+
const isReadOnlyForDeactivatedMember = uids.length === 2 && roomMembers.some((member) => member.active === false);
87+
8588
const roomInfo = {
8689
t: 'd',
8790
usernames,
@@ -90,6 +93,7 @@ export async function createDirectRoom(
9093
ts: new Date(),
9194
uids,
9295
...roomExtraData,
96+
...(isReadOnlyForDeactivatedMember && { ro: true, reactWhenReadOnly: false }),
9397
};
9498

9599
if (isNewRoom) {

apps/meteor/tests/end-to-end/api/methods.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,6 +2802,7 @@ describe('Meteor.methods', () => {
28022802
let testUserCredentials: Credentials;
28032803
let dmId: IRoom['_id'];
28042804
let dmTestId: IRoom['_id'];
2805+
let dmWithDeactivatedId: IRoom['_id'];
28052806

28062807
before(async () => {
28072808
testUser = await createUser();
@@ -2857,6 +2858,7 @@ describe('Meteor.methods', () => {
28572858
Promise.all([
28582859
deleteRoom({ type: 'd', roomId: dmId }),
28592860
deleteRoom({ type: 'd', roomId: dmTestId }),
2861+
...(dmWithDeactivatedId ? [deleteRoom({ type: 'd', roomId: dmWithDeactivatedId })] : []),
28602862
deleteUser(testUser),
28612863
deleteUser(testUser2),
28622864
]),
@@ -2997,6 +2999,41 @@ describe('Meteor.methods', () => {
29972999
.catch(done);
29983000
});
29993001

3002+
it('should create a new direct conversation as readonly when the target user is already deactivated', async () => {
3003+
const createRes = await request
3004+
.post(methodCall('createDirectMessage'))
3005+
.set(credentials)
3006+
.send({
3007+
message: JSON.stringify({
3008+
method: 'createDirectMessage',
3009+
params: [testUser2.username],
3010+
id: 'id',
3011+
msg: 'method',
3012+
}),
3013+
});
3014+
3015+
const createResult = JSON.parse(createRes.body.message);
3016+
expect(createResult.result).to.be.an('object');
3017+
expect(createResult.result).to.have.property('rid').that.is.an('string');
3018+
dmWithDeactivatedId = createResult.result.rid;
3019+
3020+
const roomRes = await request
3021+
.post(methodCall('getRoomByTypeAndName'))
3022+
.set(credentials)
3023+
.send({
3024+
message: JSON.stringify({
3025+
method: 'getRoomByTypeAndName',
3026+
params: ['d', dmWithDeactivatedId],
3027+
id: 'id',
3028+
msg: 'method',
3029+
}),
3030+
});
3031+
3032+
expect(roomRes.body.success).to.equal(true);
3033+
const result = JSON.parse(roomRes.body.message);
3034+
expect(result.result.ro).to.equal(true);
3035+
});
3036+
30003037
it('should activate another user', (done) => {
30013038
void request
30023039
.post(methodCall('setUserActiveStatus'))

0 commit comments

Comments
 (0)