-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add promise support to built-in model ACL #3163
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change is not required
common/models/acl.js
Outdated
| if (err || !role) return cb(err, role); | ||
| if (err || !role) { | ||
| return cb(err, role); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove should
test/acl.test.js
Outdated
|
|
||
| ACL.checkAccessForContext({ | ||
| principals: [ | ||
| {type: ACL.USER, id: 'u001'}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent is off
test/acl.test.js
Outdated
| ], | ||
| }); | ||
|
|
||
| ACL.checkAccessForContext({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ACL.checkAccess...
test/role.test.js
Outdated
| expect(u.id).to.eql(user.id); | ||
| done(); | ||
| }) | ||
| .catch(done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove catch
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove should and done
test/role.test.js
Outdated
| }); | ||
| }); | ||
|
|
||
| it('should support ACL.isMappedToRole() returning a promise', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove should and done
test/role.test.js
Outdated
| }); | ||
|
|
||
| it('should support ACL.isMappedToRole() returning a promise', function(done) { | ||
| ACL.isMappedToRole(ACL.USER, user.username, 'admin') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ACL.isMapped...
test/role.test.js
Outdated
| ACL.isMappedToRole(ACL.USER, user.username, 'admin') | ||
| .then(function(flag) { | ||
| expect(flag).to.eql(true); | ||
| done(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect(flag).to.be.true();
test/role.test.js
Outdated
| expect(flag).to.eql(true); | ||
| done(); | ||
| }) | ||
| .catch(done); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove catch
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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