yiisoft / rbac-db

yiisoft/db adapter for RBAC.
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
15 stars 6 forks source link

`userHasPermission` cannot detect permissions under the role #80

Closed niqingyang closed 5 months ago

niqingyang commented 5 months ago

What steps will reproduce the problem?

userHasPermission cannot detect permissions under the role when there is only one record in table yii_rbac_item_child

$manager = new \Yiisoft\Rbac\Manager(
  new \Yiisoft\Rbac\Db\ItemsStorage($db, 'yii_rbac_item', 'yii_rbac_item_child'),
  new  \Yiisoft\Rbac\Db\AssignmentsStorage($db, 'yii_rbac_assignment')
);

$manager->addRole(new \Yiisoft\Rbac\Role('admin'));
$manager->addPermission(new \Yiisoft\Rbac\Permission('post:create'));
$manager->addChild('admin', 'post:create');
$manager->assign('admin', 1);

$result = $manager->userHasPermission(1, 'post:create');

What is the expected result?

$result is true

What do you get instead?

$result is false

Additional info

Q A
Version 2.0.0
PHP version 8.2.19
MySql version 5.7
Operating system windows