Skip to content

Conversation

@ebarault
Copy link
Contributor

@ebarault ebarault commented Jan 30, 2017

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

  • None

Checklist

  • New tests added or existing tests modified to cover all changes
  • Code conforms with the style
    guide

@slnode
Copy link

slnode commented Jan 30, 2017

Can one of the admins verify this patch?

2 similar comments
@slnode
Copy link

slnode commented Jan 30, 2017

Can one of the admins verify this patch?

@slnode
Copy link

slnode commented Jan 30, 2017

Can one of the admins verify this patch?

@ebarault
Copy link
Contributor Author

@bajtos @superkhau please review so we can land this before #2971

@ebarault ebarault mentioned this pull request Jan 30, 2017
2 tasks
if (err) return cb(err);
if (err) {
return cb(err);
}
Copy link
Contributor

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

if (err || !role) return cb(err, role);
if (err || !role) {
return cb(err, role);
}
Copy link
Contributor

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({
Copy link
Contributor

@superkhau superkhau Jan 30, 2017

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);
  });

Copy link
Contributor

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

Copy link
Contributor Author

@ebarault ebarault Jan 30, 2017

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

Copy link
Member

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) {
Copy link
Contributor

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'},
Copy link
Contributor

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({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ACL.checkAccess...

expect(u.id).to.eql(user.id);
done();
})
.catch(done);
Copy link
Contributor

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({
Copy link
Contributor

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

});
});

it('should support ACL.resolvePrincipal() returning a promise', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove should and done

});
});

it('should support ACL.isMappedToRole() returning a promise', function(done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove should and done

});

it('should support ACL.isMappedToRole() returning a promise', function(done) {
ACL.isMappedToRole(ACL.USER, user.username, 'admin')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return ACL.isMapped...

ACL.isMappedToRole(ACL.USER, user.username, 'admin')
.then(function(flag) {
expect(flag).to.eql(true);
done();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove done

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);
Copy link
Contributor

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();

expect(flag).to.eql(true);
done();
})
.catch(done);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove catch

@ebarault ebarault force-pushed the feature/promisify-acl branch 4 times, most recently from 49ed5bb to 31a9591 Compare January 30, 2017 21:55
@ebarault
Copy link
Contributor Author

ebarault commented Jan 30, 2017

@superkhau : ready for review + rebased

@ebarault ebarault force-pushed the feature/promisify-acl branch from 31a9591 to 57e844f Compare January 30, 2017 22:09
@superkhau superkhau requested a review from bajtos January 31, 2017 05:18
@superkhau superkhau added this to the Sprint 28 milestone Jan 31, 2017
@superkhau
Copy link
Contributor

@ebarault Thanks for the contribution. LGTM. @bajtos For final review/input though.

@bajtos bajtos force-pushed the feature/promisify-acl branch from 57e844f to 7e7e393 Compare January 31, 2017 11:51
Copy link
Member

@bajtos bajtos left a 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.

@bajtos
Copy link
Member

bajtos commented Jan 31, 2017

@superkhau thank you for the detailed review!

@bajtos
Copy link
Member

bajtos commented Jan 31, 2017

@slnode test please

@bajtos bajtos force-pushed the feature/promisify-acl branch from 7e7e393 to a63fad4 Compare January 31, 2017 13:09
@bajtos
Copy link
Member

bajtos commented Jan 31, 2017

@slnode test please

@bajtos bajtos changed the title adding promise support in built-in model ACL Add promise support to built-in model ACL Jan 31, 2017
@bajtos bajtos merged commit c099d8c into strongloop:master Jan 31, 2017
@bajtos
Copy link
Member

bajtos commented Jan 31, 2017

Landed, thank you for the contribution!

And sorry for the comment spam, our CI was acting up a bit today 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants