[NEW] REST API: channels.setDefault (#10941)

[NEW] REST API endpoint `channels.setDefault`
pull/11187/head^2
フィンメーラ 7 years ago committed by Rodrigo Nascimento
parent 17a63ec2ee
commit 5f9ec717ba
  1. 22
      packages/rocketchat-api/server/v1/channels.js
  2. 2
      packages/rocketchat-i18n/i18n/en.i18n.json
  3. 21
      tests/end-to-end/api/02-channels.js

@ -747,6 +747,28 @@ RocketChat.API.v1.addRoute('channels.setCustomFields', { authRequired: true }, {
}
});
RocketChat.API.v1.addRoute('channels.setDefault', { authRequired: true }, {
post() {
if (typeof this.bodyParams.default === 'undefined') {
return RocketChat.API.v1.failure('The bodyParam "default" is required', 'error-channels-setdefault-is-same');
}
const findResult = findChannelByIdOrName({ params: this.requestParams() });
if (findResult.default === this.bodyParams.default) {
return RocketChat.API.v1.failure('The channel default setting is the same as what it would be changed to.', 'error-channels-setdefault-missing-default-param');
}
Meteor.runAsUser(this.userId, () => {
Meteor.call('saveRoomSettings', findResult._id, 'default', this.bodyParams.default.toString());
});
return RocketChat.API.v1.success({
channel: RocketChat.models.Rooms.findOneById(findResult._id, { fields: RocketChat.API.v1.defaultFieldsToExclude })
});
}
});
RocketChat.API.v1.addRoute('channels.setDescription', { authRequired: true }, {
post() {
if (!this.bodyParams.description || !this.bodyParams.description.trim()) {

@ -1003,6 +1003,8 @@
"error-avatar-invalid-url": "Invalid avatar URL: __url__",
"error-avatar-url-handling": "Error while handling avatar setting from a URL (__url__) for __username__",
"error-cant-invite-for-direct-room": "Can't invite user to direct rooms",
"error-channels-setdefault-is-same": "The channel default setting is the same as what it would be changed to.",
"error-channels-setdefault-missing-default-param": "The bodyParam 'default' is required",
"error-could-not-change-email": "Could not change email",
"error-could-not-change-name": "Could not change name",
"error-could-not-change-username": "Could not change username",

@ -727,6 +727,27 @@ describe('[Channels]', function() {
.end(done);
});
it('/channels.setDefault', async(done) => {
const roomInfo = await getRoomInfo(channel._id);
request.post(api('channels.setDefault'))
.set(credentials)
.send({
roomId: channel._id,
default: true
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.nested.property('channel._id');
expect(res.body).to.have.nested.property('channel.name', `EDITED${ apiPublicChannelName }`);
expect(res.body).to.have.nested.property('channel.t', 'c');
expect(res.body).to.have.nested.property('channel.msgs', roomInfo.channel.msgs);
})
.end(done);
});
it('/channels.leave', async(done) => {
const roomInfo = await getRoomInfo(channel._id);

Loading…
Cancel
Save