Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Role inheritance does not work #43

Closed
miladabc opened this issue Feb 16, 2020 · 1 comment
Closed

Role inheritance does not work #43

miladabc opened this issue Feb 16, 2020 · 1 comment

Comments

@miladabc
Copy link

Bug Report

Extending roles does not work as expected.
Code sample is taken from documentation.

script.js:

const roleAcl = require("role-acl");
const ac = new roleAcl();

ac.grant('user')
    .execute('read').on('video')
  .grant('admin')
    .extend('user')
    .execute('create').on('video')
    .execute('update').on('video')
    .execute('delete').on('video');
/path/to/script.js:8
  .execute('create')
   ^

TypeError: ac.grant(...).execute(...).on(...).grant(...).extend(...).execute is not a function
    at Object.<anonymous> (/path/to/script.js:8:6)

Environment

  • node version: 12.15.0
  • role-acl version: 4.3.2
  • os: Ubuntu 18.04
@miladabc miladabc changed the title Extending roles does not work Role inheritance does not work Feb 16, 2020
@koladilip
Copy link
Contributor

Try this:

ac.grant('user')
    .execute('read').on('video')
  .grant('admin')
    .extendSync('user')
    .execute('create').on('video')
    .execute('update').on('video')
    .execute('delete').on('video');

or

(await ac.grant('user')
    .execute('read').on('video')
  .grant('admin')
    .extend('user'))
    .execute('create').on('video')
    .execute('update').on('video')
    .execute('delete').on('video');

extend is promise function so you need to user await before chaining with another execute on that, otherwise, you can use extendSync which is a sync function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants