Skip to content

Commit

Permalink
[FIX] Add oauth services missing fields, and indicate whether the oau…
Browse files Browse the repository at this point in the history
…th service is customized (#10299)

[FIX] REST API OAuth services endpoint were missing fields and flag to indicate custom services
  • Loading branch information
MarcosSpessatto authored and rodrigok committed Apr 19, 2018
1 parent fb3a6d9 commit 45f611e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 48 deletions.
23 changes: 0 additions & 23 deletions packages/rocketchat-api/server/v1/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
29 changes: 28 additions & 1 deletion packages/rocketchat-api/server/v1/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ 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) => {
if (service.custom) {
return { ...service };
}
return {
id: service._id,
name: service.service,
clientId: service.appId || service.clientId,
buttonLabelText: service.buttonLabelText || '',
buttonColor: service.buttonColor || '',
buttonLabelColor: service.buttonLabelColor || '',
custom: false
};
});
};

return RocketChat.API.v1.success({
services: mountOAuthServices()
});
}
});

RocketChat.API.v1.addRoute('settings', { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
Expand Down Expand Up @@ -90,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()
});
}
});
24 changes: 0 additions & 24 deletions tests/end-to-end/api/00-miscellaneous.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

});
25 changes: 25 additions & 0 deletions tests/end-to-end/api/08-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

0 comments on commit 45f611e

Please sign in to comment.