Add promise support to built-in model ACL#3163
Conversation
|
Can one of the admins verify this patch? |
2 similar comments
|
Can one of the admins verify this patch? |
|
Can one of the admins verify this patch? |
|
@bajtos @superkhau please review so we can land this before #2971 |
common/models/acl.js
Outdated
| if (err) return cb(err); | ||
| if (err) { | ||
| return cb(err); | ||
| } |
There was a problem hiding this comment.
this change is not required
common/models/acl.js
Outdated
| if (err || !role) return cb(err, role); | ||
| if (err || !role) { | ||
| return cb(err, role); | ||
| } |
test/acl.test.js
Outdated
|
|
||
| describe('security ACLs', function() { | ||
| it('supports checkPermission() returning a promise', function(done) { | ||
| ACL.create({ |
There was a problem hiding this comment.
return ACL.create({
principalType: ACL.USER,
principalId: 'u001',
model: 'testModel',
property: ACL.ALL,
accessType: ACL.ALL,
permission: ACL.ALLOW,
})
.then(function() {
return ACL.checkPermission(ACL.USER, 'u001', 'testModel', 'name', ACL.ALL);
})
.then(function(access) {
assert(access.permission === ACL.ALLOW);
});
There was a problem hiding this comment.
See http://loopback.io/doc/en/contrib/style-guide.html for more info on promise style tests in mocha
There was a problem hiding this comment.
hi @superkhau : i am aware of mocha with promise, i thought you'd like to stick to the origin test file style. as per recent @bajtos PR where the callback style is still used (e.g. here in role.test.js)
i'll modify to use mocha with promises
There was a problem hiding this comment.
I vaguely remember there was a reason for using callback-style tests when verifying Promise-based API, but I cannot recall what was it. As I was reviewing the code in this patch, I didn't see why the new style should not work, so let's stick to what our style guide says.
test/acl.test.js
Outdated
| .catch(done); | ||
| }); | ||
|
|
||
| it('should support checkAccessForContext() returning a promise', function(done) { |
test/acl.test.js
Outdated
|
|
||
| ACL.checkAccessForContext({ | ||
| principals: [ | ||
| {type: ACL.USER, id: 'u001'}, |
test/acl.test.js
Outdated
| ], | ||
| }); | ||
|
|
||
| ACL.checkAccessForContext({ |
There was a problem hiding this comment.
return ACL.checkAccess...
test/role.test.js
Outdated
| expect(u.id).to.eql(user.id); | ||
| done(); | ||
| }) | ||
| .catch(done); |
test/acl.test.js
Outdated
|
|
||
| describe('security ACLs', function() { | ||
| it('supports checkPermission() returning a promise', function(done) { | ||
| ACL.create({ |
There was a problem hiding this comment.
See http://loopback.io/doc/en/contrib/style-guide.html for more info on promise style tests in mocha
test/role.test.js
Outdated
| }); | ||
| }); | ||
|
|
||
| it('should support ACL.resolvePrincipal() returning a promise', function(done) { |
test/role.test.js
Outdated
| }); | ||
| }); | ||
|
|
||
| it('should support ACL.isMappedToRole() returning a promise', function(done) { |
test/role.test.js
Outdated
| }); | ||
|
|
||
| it('should support ACL.isMappedToRole() returning a promise', function(done) { | ||
| ACL.isMappedToRole(ACL.USER, user.username, 'admin') |
test/role.test.js
Outdated
| ACL.isMappedToRole(ACL.USER, user.username, 'admin') | ||
| .then(function(flag) { | ||
| expect(flag).to.eql(true); | ||
| done(); |
test/role.test.js
Outdated
| it('should support ACL.isMappedToRole() returning a promise', function(done) { | ||
| ACL.isMappedToRole(ACL.USER, user.username, 'admin') | ||
| .then(function(flag) { | ||
| expect(flag).to.eql(true); |
There was a problem hiding this comment.
expect(flag).to.be.true();
test/role.test.js
Outdated
| expect(flag).to.eql(true); | ||
| done(); | ||
| }) | ||
| .catch(done); |
49ed5bb to
31a9591
Compare
|
@superkhau : ready for review + rebased |
31a9591 to
57e844f
Compare
57e844f to
7e7e393
Compare
bajtos
left a comment
There was a problem hiding this comment.
The code changes LGTM, thank you @ebarault for the contribution!
I changed the commit message to follow our style, see http://loopback.io/doc/en/contrib/git-commit-messages.html.
|
@superkhau thank you for the detailed review! |
|
@slnode test please |
7e7e393 to
a63fad4
Compare
|
@slnode test please |
|
Landed, thank you for the contribution! And sorry for the comment spam, our CI was acting up a bit today 😕 |
Description
None of the functions from built-in acl.js currently support promises. this PR adds promise support by using loopback utils helper
Related issues
related issue: #418
related PR (similar for built-in role model) : #3146
Checklist
guide