diff --git a/packages/rocketchat-api/server/v1/permissions.js b/packages/rocketchat-api/server/v1/permissions.js index 18b8ac69c9883..4bbe0707336b1 100644 --- a/packages/rocketchat-api/server/v1/permissions.js +++ b/packages/rocketchat-api/server/v1/permissions.js @@ -20,13 +20,46 @@ RocketChat.API.v1.addRoute('permissions', { authRequired: true }, { }, }); +// DEPRECATED +// TODO: Remove this after three versions have been released. That means at 0.85 this should be gone. RocketChat.API.v1.addRoute('permissions.list', { authRequired: true }, { get() { const result = Meteor.runAsUser(this.userId, () => Meteor.call('permissions/get')); - return RocketChat.API.v1.success({ - permissions: result, - }); + return RocketChat.API.v1.success(this.deprecationWarning({ + endpoint: 'permissions.list', + versionWillBeRemove: '0.85', + response: { + permissions: result, + }, + })); + }, +}); + +RocketChat.API.v1.addRoute('permissions.listAll', { authRequired: true }, { + get() { + const { updatedSince } = this.queryParams; + + let updatedSinceDate; + if (updatedSince) { + if (isNaN(Date.parse(updatedSince))) { + throw new Meteor.Error('error-roomId-param-invalid', 'The "updatedSince" query parameter must be a valid date.'); + } else { + updatedSinceDate = new Date(updatedSince); + } + } + + let result; + Meteor.runAsUser(this.userId, () => result = Meteor.call('permissions/get', updatedSinceDate)); + + if (Array.isArray(result)) { + result = { + update: result, + remove: [], + }; + } + + return RocketChat.API.v1.success(result); }, }); diff --git a/tests/end-to-end/api/11-permissions.js b/tests/end-to-end/api/11-permissions.js index 20b19d7efc865..42637e927bfe1 100644 --- a/tests/end-to-end/api/11-permissions.js +++ b/tests/end-to-end/api/11-permissions.js @@ -25,6 +25,8 @@ describe('[Permissions]', function() { }); }); + // DEPRECATED + // TODO: Remove this after three versions have been released. That means at 0.85 this should be gone. describe('[/permissions.list]', () => { it('should return all permissions that exists on the server, with respective roles', (done) => { request.get(api('permissions.list')) @@ -44,6 +46,45 @@ describe('[Permissions]', function() { }); }); + describe('[/permissions.listAll]', () => { + it('should return an array with update and remove properties', (done) => { + request.get(api('permissions.listAll')) + .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('update').and.to.be.an('array'); + expect(res.body).to.have.property('remove').and.to.be.an('array'); + }) + .end(done); + }); + + it('should return an array with update and remov properties when search by "updatedSince" query parameter', (done) => { + request.get(api('permissions.listAll?updatedSince=2018-11-27T13:52:01Z')) + .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('update').and.to.be.an('array'); + expect(res.body).to.have.property('remove').and.to.be.an('array'); + }) + .end(done); + }); + + it('should return an error when updatedSince query parameter is not a valid ISODate string', (done) => { + request.get(api('permissions.listAll?updatedSince=fsafdf')) + .set(credentials) + .expect('Content-Type', 'application/json') + .expect(400) + .expect((res) => { + expect(res.body).to.have.property('success', false); + }) + .end(done); + }); + }); + describe('[/permissions.update]', () => { it('should change the permissions on the server', (done) => { const permissions = [