From e052895f28e840eb303150db67a27c9680828bc0 Mon Sep 17 00:00:00 2001 From: Sam Simpson Date: Fri, 16 Feb 2018 13:07:25 +0000 Subject: [PATCH 1/3] Add channels.setAnnouncement API method --- packages/rocketchat-api/server/v1/channels.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 3c150d14ccd41..b7225dc1d1ac8 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -742,6 +742,28 @@ RocketChat.API.v1.addRoute('channels.setTopic', { authRequired: true }, { } }); +RocketChat.API.v1.addRoute('channels.setAnnouncement', { authRequired: true }, { + post() { + if (!this.bodyParams.announcement || !this.bodyParams.announcement.trim()) { + return RocketChat.API.v1.failure('The bodyParam "announcement" is required'); + } + + const findResult = findChannelByIdOrName({ params: this.requestParams() }); + + if (findResult.announcement == this.bodyParams.announcement) { + return RocketChat.ApI.v1.failure('The channel topic is the same as what it would be changed to.'); + } + + Meteor.runAsUser(this.userId, () => { + Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement); + }); + + return RocketChat.API.v1.success({ + announcement: this.bodyParams.announcement + }); + } +}); + RocketChat.API.v1.addRoute('channels.setType', { authRequired: true }, { post() { if (!this.bodyParams.type || !this.bodyParams.type.trim()) { From 0d2b0f413f79e4ef9ddcfd080346288cda3e74e1 Mon Sep 17 00:00:00 2001 From: Sam Simpson Date: Fri, 16 Feb 2018 13:21:33 +0000 Subject: [PATCH 2/3] Add channels.setAnnouncement test --- packages/rocketchat-api/server/v1/channels.js | 4 ---- tests/end-to-end/api/02-channels.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index b7225dc1d1ac8..5df1aae3726d6 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -750,10 +750,6 @@ RocketChat.API.v1.addRoute('channels.setAnnouncement', { authRequired: true }, { const findResult = findChannelByIdOrName({ params: this.requestParams() }); - if (findResult.announcement == this.bodyParams.announcement) { - return RocketChat.ApI.v1.failure('The channel topic is the same as what it would be changed to.'); - } - Meteor.runAsUser(this.userId, () => { Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement); }); diff --git a/tests/end-to-end/api/02-channels.js b/tests/end-to-end/api/02-channels.js index 784263e7b8ce0..c46a319c5ef62 100644 --- a/tests/end-to-end/api/02-channels.js +++ b/tests/end-to-end/api/02-channels.js @@ -231,6 +231,22 @@ describe('[Channels]', function() { .end(done); }); + it('/channels.setAnnouncement', (done) => { + request.post(api('channels.setAnnouncement')) + .set(credentials) + .send({ + roomId: channel._id, + announcement: 'this is an announcement of a channel for api tests' + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.nested.property('announcement', 'this is an announcement of a channel for api tests'); + }) + .end(done); + }); + it('/channels.setPurpose', (done) => { request.post(api('channels.setPurpose')) .set(credentials) From 613d47f22913d7953c4fdc4e5dfc86b8937eda95 Mon Sep 17 00:00:00 2001 From: Sam Simpson Date: Fri, 16 Feb 2018 13:35:33 +0000 Subject: [PATCH 3/3] Replaced spaces with tabs in setAnnouncement method --- packages/rocketchat-api/server/v1/channels.js | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 5df1aae3726d6..a1a07ea3156a3 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -743,21 +743,21 @@ RocketChat.API.v1.addRoute('channels.setTopic', { authRequired: true }, { }); RocketChat.API.v1.addRoute('channels.setAnnouncement', { authRequired: true }, { - post() { - if (!this.bodyParams.announcement || !this.bodyParams.announcement.trim()) { - return RocketChat.API.v1.failure('The bodyParam "announcement" is required'); - } + post() { + if (!this.bodyParams.announcement || !this.bodyParams.announcement.trim()) { + return RocketChat.API.v1.failure('The bodyParam "announcement" is required'); + } - const findResult = findChannelByIdOrName({ params: this.requestParams() }); + const findResult = findChannelByIdOrName({ params: this.requestParams() }); - Meteor.runAsUser(this.userId, () => { - Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement); - }); + Meteor.runAsUser(this.userId, () => { + Meteor.call('saveRoomSettings', findResult._id, 'roomAnnouncement', this.bodyParams.announcement); + }); - return RocketChat.API.v1.success({ - announcement: this.bodyParams.announcement - }); - } + return RocketChat.API.v1.success({ + announcement: this.bodyParams.announcement + }); + } }); RocketChat.API.v1.addRoute('channels.setType', { authRequired: true }, {