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
2 changes: 1 addition & 1 deletion packages/rocketchat-api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RocketChat.API.v1.addRoute('chat.delete', { authRequired: true }, {
return RocketChat.API.v1.failure('The room id provided does not match where the message is from.');
}

if (this.bodyParams.asUser && msg.u._id !== this.userId && !RocketChat.authz.hasPermission(Meteor.userId(), 'force-delete-message', msg.rid)) {
if (this.bodyParams.asUser && msg.u._id !== this.userId && !RocketChat.authz.hasPermission(this.userId, 'force-delete-message', msg.rid)) {
return RocketChat.API.v1.failure('Unauthorized. You must have the permission "force-delete-message" to delete other\'s message as them.');
}

Expand Down
102 changes: 102 additions & 0 deletions tests/end-to-end/api/05-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
credentials,
message,
} from '../../data/api-data.js';
import { password } from '../../data/user';

describe('[Chat]', function() {
this.retries(0);
Expand Down Expand Up @@ -346,6 +347,107 @@ describe('[Chat]', function() {
});
});

describe('[/chat.delete]', () => {
let msgId;
let user;
let userCredentials;
before((done) => {
const username = `user.test.${ Date.now() }`;
const email = `${ username }@rocket.chat`;
request.post(api('users.create'))
.set(credentials)
.send({ email, name: username, username, password })
.end((err, res) => {
user = res.body.user;
done();
});
});
before((done) => {
request.post(api('login'))
.send({
user: user.username,
password,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
userCredentials = {};
userCredentials['X-Auth-Token'] = res.body.data.authToken;
userCredentials['X-User-Id'] = res.body.data.userId;
})
.end(done);
});
after((done) => {
request.post(api('users.delete')).set(credentials).send({
userId: user._id,
}).end(done);
user = undefined;
});
beforeEach((done) => {
request.post(api('chat.sendMessage'))
.set(credentials)
.send({
message: {
rid: 'GENERAL',
msg: 'Sample message',
},
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
msgId = res.body.message._id;
})
.end(done);
});
it('should delete a message successfully', (done) => {
request.post(api('chat.delete'))
.set(credentials)
.send({
roomId: 'GENERAL',
msgId,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});
it('sending message as another user...', (done) => {
request.post(api('chat.sendMessage'))
.set(userCredentials)
.send({
message: {
rid: 'GENERAL',
msg: 'Sample message',
},
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
msgId = res.body.message._id;
})
.end(done);
});
it('should delete a message successfully when the user deletes a message send by another user', (done) => {
request.post(api('chat.delete'))
.set(credentials)
.send({
roomId: 'GENERAL',
msgId,
asUser: true,
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});
});

describe('/chat.search', () => {
it('should return a list of messages when execute successfully', (done) => {
request.get(api('chat.search'))
Expand Down