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

Expect Object from getGrants #10

Closed
OR13 opened this issue Jul 2, 2017 · 3 comments
Closed

Expect Object from getGrants #10

OR13 opened this issue Jul 2, 2017 · 3 comments
Labels
bug To be fixed.

Comments

@OR13
Copy link

OR13 commented Jul 2, 2017

describe('grantList', async () => {

  var grantList = [
    { role: 'admin', resource: 'video', action: 'create:any', attributes: ['*'] }
  ];

  it('should initialize ac from grantList', async () => {
    var ac = new AccessControl(grantList)
    let grants = ac.getGrants()
    console.log(grants)
    })
})

Outputs:

[ { role: 'admin',
resource: 'video',
action: 'create:any',
attributes: [ '*' ] } ]

I am expecting an object, like in the tests:

https://github.com/onury/accesscontrol/blob/master/lib/AccessControl.js#L130

When i mix my approach:

describe('grantList', async () => {
    var grantList = [
        { role: 'admin', resource: 'video', action: 'create:any', attributes: ['*'] }
    ];

    it('should initialize ac from grantList', async () => {
        var ac = new AccessControl(grantList)
        ac
        .grant('user')
        .readAny(['profile', 'video'], ['', '!id', '!password'])
        .createOwn(['profile', 'video'])
        .deleteOwn(['video']);
        // logging underlying grants model
        console.log(ac.getGrants());
    })
})

I get this mixd output:

[ { role: 'admin',
    resource: 'video',
    action: 'create:any',
    attributes: [ '*' ] },
  user: { profile: { 'read:any': [Array], 'create:own': [Array] },
    video: 
     { 'read:any': [Array],
       'create:own': [Array],
       'delete:own': [Array] } } ]

I guess I am expecting the types to be the same.

Really, I'd love to export as a grantList or an Object, depending on the situation.

@onury onury added the bug To be fixed. label Jul 2, 2017
@onury
Copy link
Owner

onury commented Jul 2, 2017

Nice catch. Thanks.
The constructor takes the grants parameter as is. This is a bug. It should be processed like the .setGrants(obj) method does.

I'll fix this shortly but if this is too urgent pls use .setGrants() instead of the constructor for now.

Option to export grants as an object or array was already in todo list. I'll see if it'll make its way to this release.

@OR13
Copy link
Author

OR13 commented Jul 2, 2017

wow, thanks for the quick reply!

Your solution works :)

Before using setGrants I was seeing:

TypeError: Cannot read property '$extend' of undefined

when checking permissions like so:

let permission = ac.can('admin').createAny('video')

I'm trying to create an equivalence between your library and an Ethereum Smart contract, I imagine I will have many more questions :)

onury added a commit that referenced this issue Jul 2, 2017
@onury
Copy link
Owner

onury commented Jul 2, 2017

You're welcome. I don't have too much knowledge about Ethereum though.

v1.5.2 is released with a fix.

I need time for adding support for exporting grants as a flat list. This is a bit tricky bec. of hierarchical role inheritance.

Closing this. Pls re-open or create a new issue if needed.
cheers.

@onury onury closed this as completed Jul 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug To be fixed.
Projects
None yet
Development

No branches or pull requests

2 participants