From c52e4581a57c47e90e8871067f7bdca84f937bbb Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Mon, 2 Apr 2018 10:41:50 -0300 Subject: [PATCH 1/3] Add field to indicate whether the oauth service is customized and change the file --- packages/rocketchat-api/server/v1/misc.js | 23 ----------------- packages/rocketchat-api/server/v1/settings.js | 24 ++++++++++++++++++ tests/end-to-end/api/00-miscellaneous.js | 24 ------------------ tests/end-to-end/api/08-settings.js | 25 +++++++++++++++++++ 4 files changed, 49 insertions(+), 47 deletions(-) diff --git a/packages/rocketchat-api/server/v1/misc.js b/packages/rocketchat-api/server/v1/misc.js index 05fee75aec6b..b15c2d1e456d 100644 --- a/packages/rocketchat-api/server/v1/misc.js +++ b/packages/rocketchat-api/server/v1/misc.js @@ -18,29 +18,6 @@ RocketChat.API.v1.addRoute('info', { authRequired: false }, { } }); -RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { - get() { - const mountOAuthServices = () => { - const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch(); - - return oAuthServicesEnabled.map((service) => { - return { - id: service._id, - name: service.service, - appId: service.appId || service.clientId, - buttonLabelText: service.buttonLabelText || '', - buttonColor: service.buttonColor || '', - buttonLabelColor: service.buttonLabelColor || '' - }; - }); - }; - - return RocketChat.API.v1.success({ - services: mountOAuthServices() - }); - } -}); - RocketChat.API.v1.addRoute('me', { authRequired: true }, { get() { const me = _.pick(this.user, [ diff --git a/packages/rocketchat-api/server/v1/settings.js b/packages/rocketchat-api/server/v1/settings.js index 3662ba148530..20f7b907a59f 100644 --- a/packages/rocketchat-api/server/v1/settings.js +++ b/packages/rocketchat-api/server/v1/settings.js @@ -29,6 +29,30 @@ RocketChat.API.v1.addRoute('settings.public', { authRequired: false }, { } }); +RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { + get() { + const mountOAuthServices = () => { + const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch(); + + return oAuthServicesEnabled.map((service) => { + return { + id: service._id, + name: service.service, + appId: service.appId || service.clientId, + buttonLabelText: service.buttonLabelText || '', + buttonColor: service.buttonColor || '', + buttonLabelColor: service.buttonLabelColor || '', + custom: Boolean(service.custom) + }; + }); + }; + + return RocketChat.API.v1.success({ + services: mountOAuthServices() + }); + } +}); + RocketChat.API.v1.addRoute('settings', { authRequired: true }, { get() { const { offset, count } = this.getPaginationItems(); diff --git a/tests/end-to-end/api/00-miscellaneous.js b/tests/end-to-end/api/00-miscellaneous.js index d655110d4c74..a84da2e293f6 100644 --- a/tests/end-to-end/api/00-miscellaneous.js +++ b/tests/end-to-end/api/00-miscellaneous.js @@ -73,29 +73,5 @@ describe('miscellaneous', function() { .end(done); }); - describe('/settings.oauth', () => { - it('should have return list of available oauth services when user is not logged', (done) => { - request.get(api('settings.oauth')) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('services').and.to.be.an('array'); - }) - .end(done); - }); - - it('should have return list of available oauth services when user is logged', (done) => { - request.get(api('settings.oauth')) - .set(credentials) - .expect('Content-Type', 'application/json') - .expect(200) - .expect((res) => { - expect(res.body).to.have.property('success', true); - expect(res.body).to.have.property('services').and.to.be.an('array'); - }) - .end(done); - }); - }); }); diff --git a/tests/end-to-end/api/08-settings.js b/tests/end-to-end/api/08-settings.js index fa6cd5b0a65b..d1c0fd0a0303 100644 --- a/tests/end-to-end/api/08-settings.js +++ b/tests/end-to-end/api/08-settings.js @@ -65,4 +65,29 @@ describe('[Settings]', function() { .end(done); }); }); + + describe('/settings.oauth', () => { + it('should have return list of available oauth services when user is not logged', (done) => { + request.get(api('settings.oauth')) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('services').and.to.be.an('array'); + }) + .end(done); + }); + + it('should have return list of available oauth services when user is logged', (done) => { + request.get(api('settings.oauth')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('services').and.to.be.an('array'); + }) + .end(done); + }); + }); }); From 71b11e8535a28084ea4dd7b5cfbe101b718ea213 Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Mon, 2 Apr 2018 15:09:09 -0300 Subject: [PATCH 2/3] change comparision with boolean --- packages/rocketchat-api/server/v1/settings.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-api/server/v1/settings.js b/packages/rocketchat-api/server/v1/settings.js index 20f7b907a59f..6f4a4f822263 100644 --- a/packages/rocketchat-api/server/v1/settings.js +++ b/packages/rocketchat-api/server/v1/settings.js @@ -42,7 +42,7 @@ RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { buttonLabelText: service.buttonLabelText || '', buttonColor: service.buttonColor || '', buttonLabelColor: service.buttonLabelColor || '', - custom: Boolean(service.custom) + custom: String(service.custom).toLowerCase() === 'true' }; }); }; From 45dab3cbcf3b7d21f3e2ce90ecb0908d7cdff93b Mon Sep 17 00:00:00 2001 From: Marcos Defendi Date: Thu, 5 Apr 2018 16:21:36 -0300 Subject: [PATCH 3/3] Add missing fields when oauth service is custom --- packages/rocketchat-api/server/v1/settings.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rocketchat-api/server/v1/settings.js b/packages/rocketchat-api/server/v1/settings.js index 6f4a4f822263..fc333c1994ac 100644 --- a/packages/rocketchat-api/server/v1/settings.js +++ b/packages/rocketchat-api/server/v1/settings.js @@ -35,14 +35,17 @@ RocketChat.API.v1.addRoute('settings.oauth', { authRequired: false }, { const oAuthServicesEnabled = ServiceConfiguration.configurations.find({}).fetch(); return oAuthServicesEnabled.map((service) => { + if (service.custom) { + return { ...service }; + } return { id: service._id, name: service.service, - appId: service.appId || service.clientId, + clientId: service.appId || service.clientId, buttonLabelText: service.buttonLabelText || '', buttonColor: service.buttonColor || '', buttonLabelColor: service.buttonLabelColor || '', - custom: String(service.custom).toLowerCase() === 'true' + custom: false }; }); }; @@ -114,7 +117,7 @@ RocketChat.API.v1.addRoute('service.configurations', { authRequired: false }, { const ServiceConfiguration = Package['service-configuration'].ServiceConfiguration; return RocketChat.API.v1.success({ - configurations: ServiceConfiguration.configurations.find({}, {fields: {secret: 0}}).fetch() + configurations: ServiceConfiguration.configurations.find({}, { fields: { secret: 0 } }).fetch() }); } });