[NEW] Route to get updated roles after a date (#16610)

pull/16128/head^2
Ashwani Yadav 6 years ago committed by GitHub
parent caf630e993
commit ad176ef1fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      app/api/server/v1/roles.js
  2. 8
      app/models/server/models/Roles.js
  3. 27
      tests/end-to-end/api/13-roles.js

@ -13,6 +13,23 @@ API.v1.addRoute('roles.list', { authRequired: true }, {
},
});
API.v1.addRoute('roles.sync', { authRequired: true }, {
get() {
const { updatedSince } = this.queryParams;
if (isNaN(Date.parse(updatedSince))) {
throw new Meteor.Error('error-updatedSince-param-invalid', 'The "updatedSince" query parameter must be a valid date.');
}
return API.v1.success({
roles: {
update: Roles.findByUpdatedDate(new Date(updatedSince), { fields: API.v1.defaultFieldsToExclude }).fetch(),
remove: Roles.trashFindDeletedAfter(new Date(updatedSince)).fetch(),
},
});
},
});
API.v1.addRoute('roles.create', { authRequired: true }, {
post() {
check(this.bodyParams, {

@ -85,6 +85,14 @@ export class Roles extends Base {
return this.findOne(query, options);
}
findByUpdatedDate(updatedAfterDate, options) {
const query = {
_updatedAt: { $gte: new Date(updatedAfterDate) },
};
return this.find(query, options);
}
canAddUserToRole(uid, roleName, scope) {
const role = this.findOne({ _id: roleName }, { fields: { scope: 1 } });
if (!role) {

@ -35,6 +35,33 @@ describe('[Roles]', function() {
});
});
describe('GET [/roles.sync]', () => {
it('should return an array of roles which are updated after updatedSice date when search by "updatedSince" query parameter', (done) => {
request.get(api('roles.sync?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('roles');
expect(res.body.roles).to.have.property('update').and.to.be.an('array');
expect(res.body.roles).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('roles.sync?updatedSince=fsafdf'))
.set(credentials)
.expect('Content-Type', 'application/json')
.expect(400)
.expect((res) => {
expect(res.body).to.have.property('success', false);
})
.end(done);
});
});
describe('POST [/roles.create]', () => {
it('should create a new role with Users scope', (done) => {
request.post(api('roles.create'))

Loading…
Cancel
Save