onury / accesscontrol

Role and Attribute based Access Control for Node.js
https://onury.io/accesscontrol
MIT License
2.21k stars 178 forks source link

wilcard for user and resource #58

Open joneldiablo opened 6 years ago

joneldiablo commented 6 years ago

I want to do this:

let grantsObject = {
        '*': {
          '*': {
            'create:any': ['!*'],
            'read:any': ['!*'],
            'update:any': ['!*'],
            'delete:any': ['!*']
          }
        }
      };
//......... add more reading database
const ac = new AccessControl(grantsObject);

but I having this error: Unhandled rejection AccessControlError: Cannot use reserved name "*" for a resource.

so, is there any way to add a default permission for all users and all resources?

gregwym commented 5 years ago

In our case, we would like to grant anyone permission to read:own any resources. Seems not possible at the moment.

gausie commented 5 years ago

To expand on this, I'd love an api like this:

ac.grant('user').resource('resource_one').action('create', 'any')
ac.grant('user').resource('resource_two').action('edit', 'own')

allowing

ac.grant('user').resource('resource_one').action('*', 'any')

or

ac.grant('admin').resource('*').action('*', 'any')

or some other combination that you could imagine!

anodynos commented 5 years ago

There's an (intermediate) solution to your problems https://github.com/anodynos/accesscontrol-re :-)

hamxabaig commented 3 years ago

I want to do this:

let grantsObject = {
        '*': {
          '*': {
            'create:any': ['!*'],
            'read:any': ['!*'],
            'update:any': ['!*'],
            'delete:any': ['!*']
          }
        }
      };
//......... add more reading database
const ac = new AccessControl(grantsObject);

but I having this error: Unhandled rejection AccessControlError: Cannot use reserved name "*" for a resource.

so, is there any way to add default permission for all users and all resources?

I think instead of granting all permissions to all roles using *. Have a default role that is granted to everyone and then use that role to grant all permissions.