Commit 57498582 by Alexander Makarov

Adjusted guide

parent 40eb1166
...@@ -121,24 +121,47 @@ class PhpManager extends \yii\rbac\PhpManager ...@@ -121,24 +121,47 @@ class PhpManager extends \yii\rbac\PhpManager
} }
``` ```
Now create custom rule class:
```php
namespace app\rbac;
use yii\rbac\Rule;
class NotGuestRule extends Rule
{
public function execute($params, $data)
{
return !Yii::$app->user->isGuest;
}
}
```
Then create permissions hierarchy in `@app/data/rbac.php`: Then create permissions hierarchy in `@app/data/rbac.php`:
```php ```php
<?php <?php
use yii\rbac\Item; use yii\rbac\Item;
use app\rbac\NotGuestRule;
$notGuest = new NotGuestRule();
return [ return [
'rules' => [
$rule->name => serialize($notGuest),
],
'items' => [
// HERE ARE YOUR MANAGEMENT TASKS // HERE ARE YOUR MANAGEMENT TASKS
'manageThing0' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'bizRule' => NULL, 'data' => NULL], 'manageThing0' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'ruleName' => NULL, 'data' => NULL],
'manageThing1' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'bizRule' => NULL, 'data' => NULL], 'manageThing1' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'ruleName' => NULL, 'data' => NULL],
'manageThing2' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'bizRule' => NULL, 'data' => NULL], 'manageThing2' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'ruleName' => NULL, 'data' => NULL],
'manageThing3' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'bizRule' => NULL, 'data' => NULL], 'manageThing3' => ['type' => Item::TYPE_OPERATION, 'description' => '...', 'ruleName' => NULL, 'data' => NULL],
// AND THE ROLES // AND THE ROLES
'guest' => [ 'guest' => [
'type' => Item::TYPE_ROLE, 'type' => Item::TYPE_ROLE,
'description' => 'Guest', 'description' => 'Guest',
'bizRule' => NULL, 'ruleName' => NULL,
'data' => NULL 'data' => NULL
], ],
...@@ -149,7 +172,7 @@ return [ ...@@ -149,7 +172,7 @@ return [
'guest', 'guest',
'manageThing0', // User can edit thing0 'manageThing0', // User can edit thing0
], ],
'bizRule' => 'return !Yii::$app->user->isGuest;', 'ruleName' => $notGuest->name,
'data' => NULL 'data' => NULL
], ],
...@@ -160,7 +183,7 @@ return [ ...@@ -160,7 +183,7 @@ return [
'user', // Can manage all that user can 'user', // Can manage all that user can
'manageThing1', // and also thing1 'manageThing1', // and also thing1
], ],
'bizRule' => NULL, 'ruleName' => NULL,
'data' => NULL 'data' => NULL
], ],
...@@ -171,7 +194,7 @@ return [ ...@@ -171,7 +194,7 @@ return [
'moderator', // can do all the stuff that moderator can 'moderator', // can do all the stuff that moderator can
'manageThing2', // and also manage thing2 'manageThing2', // and also manage thing2
], ],
'bizRule' => NULL, 'ruleName' => NULL,
'data' => NULL 'data' => NULL
], ],
...@@ -182,10 +205,10 @@ return [ ...@@ -182,10 +205,10 @@ return [
'admin', // can do all that admin can 'admin', // can do all that admin can
'manageThing3', // and also thing3 'manageThing3', // and also thing3
], ],
'bizRule' => NULL, 'ruleName' => NULL,
'data' => NULL 'data' => NULL
], ],
],
]; ];
``` ```
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment