Skip to content
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/gold-zoos-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": major
---

Removes deprecated meteor method `muteUserInRoom`
27 changes: 0 additions & 27 deletions apps/meteor/server/methods/muteUserInRoom.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { Message } from '@rocket.chat/core-services';
import type { IRoom } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Rooms, Subscriptions, Users } from '@rocket.chat/models';
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { hasPermissionAsync } from '../../app/authorization/server/functions/hasPermission';
import { methodDeprecationLogger } from '../../app/lib/server/lib/deprecationWarningLogger';
import { notifyOnRoomChangedById } from '../../app/lib/server/lib/notifyListener';
import { RoomMemberActions } from '../../definition/IRoomTypeConfig';
import { callbacks } from '../../lib/callbacks';
Expand Down Expand Up @@ -81,27 +78,3 @@ export const muteUserInRoom = async (fromId: string, data: { rid: IRoom['_id'];

return true;
};

Meteor.methods<ServerMethods>({
async muteUserInRoom(data) {
methodDeprecationLogger.method('muteUserInRoom', '8.0.0', '/v1/rooms.muteUser');

check(
data,
Match.ObjectIncluding({
rid: String,
username: String,
}),
);

const fromId = Meteor.userId();

if (!fromId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', {
method: 'muteUserInRoom',
});
}

return muteUserInRoom(fromId, data);
},
});
235 changes: 0 additions & 235 deletions apps/meteor/tests/end-to-end/api/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3186,241 +3186,6 @@ describe('Meteor.methods', () => {
});
});

describe('[@muteUserInRoom & @unmuteUserInRoom]', () => {
let rid: IRoom['_id'];
let channelName: string;
let testUser: TestUser<IUser>;
let testUserCredentials = {};

before('create test user', async () => {
const username = `user.test.${Date.now()}`;
const email = `${username}@rocket.chat`;

testUser = await createUser({ email, name: username, username, password: username, roles: ['user'] });
});

before('create channel', async () => {
channelName = `methods-test-channel-${Date.now()}`;
rid = (await createRoom({ type: 'c', name: channelName, members: [testUser.username] })).body.channel._id;
});

before('login testUser', async () => {
testUserCredentials = await login(testUser.username, testUser.username);
});

after(() => Promise.all([deleteRoom({ type: 'c', roomId: rid }), deleteUser(testUser)]));

describe('-> standard room', () => {
describe('- when muting a user in a standard room', () => {
it('should mute an user in a standard room', async () => {
await request
.post(methodCall('muteUserInRoom'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'muteUserInRoom',
params: [{ rid, username: testUser.username }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data).not.to.have.a.property('error');
});
});

it('muted user should not be able to send message', async () => {
await request
.post(api('chat.sendMessage'))
.set(testUserCredentials)
.send({
message: {
msg: 'Sample message',
rid,
},
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error').that.is.a('string');
expect(res.body.error).to.equal('You_have_been_muted');
});
});
});

describe('- when unmuting a user in a standard room', () => {
it('should unmute an user in a standard room', async () => {
await request
.post(methodCall('unmuteUserInRoom'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'unmuteUserInRoom',
params: [{ rid, username: testUser.username }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data).not.to.have.a.property('error');
});
});

it('unmuted user should be able to send message', async () => {
await request
.post(api('chat.sendMessage'))
.set(testUserCredentials)
.send({
message: {
msg: 'Sample message',
rid,
},
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});
});
});
});

describe('-> read-only room', () => {
before('set room to read-only', async () => {
await request
.post(api('channels.setReadOnly'))
.set(credentials)
.send({
roomId: rid,
readOnly: true,
})
.expect('Content-Type', 'application/json')
.expect(200);
});

it('should not allow an user to send messages', async () => {
await request
.post(api('chat.sendMessage'))
.set(testUserCredentials)
.send({
message: {
msg: 'Sample message',
rid,
},
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error').that.is.a('string');
expect(res.body.error).to.equal(`You can't send messages because the room is readonly.`);
});
});

describe('- when unmuting a user in a read-only room', () => {
it('should unmute an user in a read-only room', async () => {
await request
.post(methodCall('unmuteUserInRoom'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'unmuteUserInRoom',
params: [{ rid, username: testUser.username }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data).not.to.have.a.property('error');
});
});

it('unmuted user in read-only room should be able to send message', async () => {
await request
.post(api('chat.sendMessage'))
.set(testUserCredentials)
.send({
message: {
msg: 'Sample message',
rid,
},
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
});
});
});

describe('- when muting a user in a read-only room', () => {
it('should mute an user in a read-only room', async () => {
await request
.post(methodCall('muteUserInRoom'))
.set(credentials)
.send({
message: JSON.stringify({
method: 'muteUserInRoom',
params: [{ rid, username: testUser.username }],
id: 'id',
msg: 'method',
}),
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.a.property('success', true);
expect(res.body).to.have.a.property('message').that.is.a('string');
const data = JSON.parse(res.body.message);
expect(data).to.have.a.property('msg', 'result');
expect(data).to.have.a.property('id', 'id');
expect(data).not.to.have.a.property('error');
});
});

it('muted user in read-only room should not be able to send message', async () => {
await request
.post(api('chat.sendMessage'))
.set(testUserCredentials)
.send({
message: {
msg: 'Sample message',
rid,
},
})
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
expect(res.body).to.have.property('error').that.is.a('string');
});
});
});
});
});

describe('[@saveSettings]', () => {
it('should return an error when trying to save a "NaN" value', () => {
void request
Expand Down
Loading