Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Create new permission.listAll endpoint to be able to use updatedSince parameter #12748

Merged
merged 4 commits into from
Dec 21, 2018
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
39 changes: 36 additions & 3 deletions packages/rocketchat-api/server/v1/permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});

Expand Down
41 changes: 41 additions & 0 deletions tests/end-to-end/api/11-permissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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 = [
Expand Down