yiisoft / yii2

Yii 2: The Fast, Secure and Professional PHP Framework
http://www.yiiframework.com
BSD 3-Clause "New" or "Revised" License
14.23k stars 6.91k forks source link

Describe ability for assign/revoke Permissions, not only Roles #14041

Open Insolita opened 7 years ago

Insolita commented 7 years ago

What steps will reproduce the problem?

These thoughts are inspired by the article https://habrahabr.ru/post/327170/ (Russian Article) As matter of fact rbac/ManagerInterface implementations can assign and revoke yii\rbac\Permission objects as well as \yii\rbac\Role but this ability not clear https://github.com/yiisoft/yii2/blob/master/framework/rbac/ManagerInterface.php#L185 I think that will be right to change phpdoc like

 /**
     * Assigns a role or permission to a user.
     *
     * @param Role|Permission $item
     * @param string|int $userId the user ID (see [[\yii\web\User::id]])
     * @return Assignment the role/permission assignment information.
     * @throws \Exception if the role/permission has already been assigned to the user
     */
    public function assign($item, $userId);

and revoke method also - For prevent strange inventions such as described in article blocking permissions This is often used practice for simple applications when user has one Role and set of Permissions which by default may be predefined accordingly Role, but should be able for individually modification. Also this way allow to make clear interface for end-manager - open user profile and fill checkboxes with neccesary permissions instead of bulding hierarchy.

samdark commented 7 years ago

It's not advertised for a reason. Not having roles could easily make assignments unmanageable.