Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
57498582
Commit
57498582
authored
Apr 04, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adjusted guide
parent
40eb1166
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
48 deletions
+71
-48
authorization.md
docs/guide/authorization.md
+71
-48
No files found.
docs/guide/authorization.md
View file @
57498582
...
@@ -121,71 +121,94 @@ class PhpManager extends \yii\rbac\PhpManager
...
@@ -121,71 +121,94 @@ 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
[
// HERE ARE YOUR MANAGEMENT TASKS
'rules'
=>
[
'manageThing0'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
$rule
->
name
=>
serialize
(
$notGuest
),
'manageThing1'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
'manageThing2'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
'manageThing3'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
// AND THE ROLES
'guest'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'Guest'
,
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
],
'items'
=>
[
// HERE ARE YOUR MANAGEMENT TASKS
'manageThing0'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
'manageThing1'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
'manageThing2'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
'manageThing3'
=>
[
'type'
=>
Item
::
TYPE_OPERATION
,
'description'
=>
'...'
,
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
// AND THE ROLES
'guest'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'Guest'
,
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
'user'
=>
[
'user'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'User'
,
'description'
=>
'User'
,
'children'
=>
[
'children'
=>
[
'guest'
,
'guest'
,
'manageThing0'
,
// User can edit thing0
'manageThing0'
,
// User can edit thing0
],
'ruleName'
=>
$notGuest
->
name
,
'data'
=>
NULL
],
],
'bizRule'
=>
'return !Yii::$app->user->isGuest;'
,
'data'
=>
NULL
],
'moderator'
=>
[
'moderator'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'Moderator'
,
'description'
=>
'Moderator'
,
'children'
=>
[
'children'
=>
[
'user'
,
// Can manage all that user can
'user'
,
// Can manage all that user can
'manageThing1'
,
// and also thing1
'manageThing1'
,
// and also thing1
],
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
],
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
'admin'
=>
[
'admin'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'Admin'
,
'description'
=>
'Admin'
,
'children'
=>
[
'children'
=>
[
'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
],
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
],
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
'godmode'
=>
[
'godmode'
=>
[
'type'
=>
Item
::
TYPE_ROLE
,
'type'
=>
Item
::
TYPE_ROLE
,
'description'
=>
'Super admin'
,
'description'
=>
'Super admin'
,
'children'
=>
[
'children'
=>
[
'admin'
,
// can do all that admin can
'admin'
,
// can do all that admin can
'manageThing3'
,
// and also thing3
'manageThing3'
,
// and also thing3
],
'ruleName'
=>
NULL
,
'data'
=>
NULL
],
],
'bizRule'
=>
NULL
,
'data'
=>
NULL
],
],
];
];
```
```
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment