Skip to content

Pass custom data to assert function #5

@epaezrubio

Description

@epaezrubio

It would be a nice touch if I was able to use a fourth argument in the assertion function to verify against single instances or other arbitrary custom data. Example, considering the current identity name to be Dezmond:

var ownPost = { 
    owner: "Dezmond"
}

var post = { 
    owner: "Foo"
}

AclService.allow('Manager', 'Post');
AclService.allow('User', 'Post', null, function (role, resource, privilege, data) {
    return role.name === data.owner;
});

AclService.can('Manager', 'Post', null, post) // true
AclService.can('User', 'Post', null, ownPost) // true
AclService.can('User', 'Post', null, post) // false
AclService.can('User', 'Post', null) // true

This would add way more flexibility to how one can use the can or isAllowed functions and, if I'm not wrong, it doesn't break any current interface.

I'd be happy to submit a PR implementing this feature.

Best.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions