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
22 changes: 22 additions & 0 deletions packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,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",
Expand Down
21 changes: 21 additions & 0 deletions tests/end-to-end/api/02-channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down