Skip to content

Commit 94bbfe2

Browse files
authored
Merge pull request #714 from kenjis/docs-permissions
docs: improve descriptions on permissions
2 parents ce68e9f + 387f3b7 commit 94bbfe2

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

docs/authorization.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,20 @@ public $permissions = [
8080
## Assigning Permissions to Groups
8181

8282
In order to grant any permissions to a group, they must have the permission assigned to the group, within the `AuthGroups`
83-
config file, under the `$matrix` property. The matrix is an associative array with the group name as the key,
83+
config file, under the `$matrix` property.
84+
85+
> **Note** This defines **group-level permissons**.
86+
87+
The matrix is an associative array with the group name as the key,
8488
and an array of permissions that should be applied to that group.
8589

8690
```php
8791
public $matrix = [
88-
'admin' => ['admin.access', 'users.create', 'users.edit', 'users.delete', 'beta.access'],
92+
'admin' => [
93+
'admin.access',
94+
'users.create', 'users.edit', 'users.delete',
95+
'beta.access'
96+
],
8997
];
9098
```
9199

@@ -104,8 +112,8 @@ The `Authorizable` trait on the `User` entity provides the following methods to
104112
#### can()
105113

106114
Allows you to check if a user is permitted to do a specific action. The only argument is the permission string. Returns
107-
boolean `true`/`false`. Will check the user's direct permissions first, and then check against all of the user's groups
108-
permissions to determine if they are allowed.
115+
boolean `true`/`false`. Will check the user's direct permissions (**user-level permissions**) first, and then check against all of the user's groups
116+
permissions (**group-level permissions**) to determine if they are allowed.
109117

110118
```php
111119
if ($user->can('users.create')) {
@@ -133,6 +141,10 @@ if (! $user->hasPermission('users.create')) {
133141
}
134142
```
135143

144+
> **Note** This method checks only **user-level permissions**, and does not check
145+
> group-level permissions. If you want to check if the user can do something,
146+
> use the `$user->can()` method instead.
147+
136148
#### Authorizing via Routes
137149

138150
You can restrict access to a route or route group through a
@@ -168,7 +180,7 @@ override the group, so it's possible that a user can perform an action that thei
168180

169181
#### addPermission()
170182

171-
Adds one or more permissions to the user. If a permission doesn't exist, a `CodeIgniter\Shield\Authorization\AuthorizationException`
183+
Adds one or more **user-level** permissions to the user. If a permission doesn't exist, a `CodeIgniter\Shield\Authorization\AuthorizationException`
172184
is thrown.
173185

174186
```php
@@ -177,7 +189,7 @@ $user->addPermission('users.create', 'users.edit');
177189

178190
#### removePermission()
179191

180-
Removes one or more permissions from a user. If a permission doesn't exist, a `CodeIgniter\Shield\Authorization\AuthorizationException`
192+
Removes one or more **user-level** permissions from a user. If a permission doesn't exist, a `CodeIgniter\Shield\Authorization\AuthorizationException`
181193
is thrown.
182194

183195
```php
@@ -186,7 +198,7 @@ $user->removePermission('users.delete');
186198

187199
#### syncPermissions()
188200

189-
Updates the user's permissions to only include the permissions in the given list. Any existing permissions on that user
201+
Updates the user's **user-level** permissions to only include the permissions in the given list. Any existing permissions on that user
190202
not in this list will be removed.
191203

192204
```php
@@ -195,12 +207,14 @@ $user->syncPermissions('admin.access', 'beta.access');
195207

196208
#### getPermissions()
197209

198-
Returns all permissions this user has assigned directly to them.
210+
Returns all **user-level** permissions this user has assigned directly to them.
199211

200212
```php
201213
$user->getPermissions();
202214
```
203215

216+
> **Note** This method does not return **group-level permissions**.
217+
204218
## Managing User Groups
205219

206220
#### addGroup()

src/Config/AuthGroups.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ class AuthGroups extends BaseConfig
2020
* --------------------------------------------------------------------
2121
* Groups
2222
* --------------------------------------------------------------------
23-
* An associative array of the available groups in the system, where the keys are
24-
* the group names and the values are arrays of the group info.
23+
* An associative array of the available groups in the system, where the keys
24+
* are the group names and the values are arrays of the group info.
2525
*
26-
* Whatever value you assign as the key will be used to refer to the group when using functions such as:
26+
* Whatever value you assign as the key will be used to refer to the group
27+
* when using functions such as:
2728
* $user->addGroup('superadmin');
2829
*
2930
* @var array<string, array<string, string>>
@@ -57,8 +58,7 @@ class AuthGroups extends BaseConfig
5758
* --------------------------------------------------------------------
5859
* Permissions
5960
* --------------------------------------------------------------------
60-
* The available permissions in the system. Each system is defined
61-
* where the key is the
61+
* The available permissions in the system.
6262
*
6363
* If a permission is not listed here it cannot be used.
6464
*/
@@ -77,6 +77,8 @@ class AuthGroups extends BaseConfig
7777
* Permissions Matrix
7878
* --------------------------------------------------------------------
7979
* Maps permissions to groups.
80+
*
81+
* This defines group-level permissions.
8082
*/
8183
public array $matrix = [
8284
'superadmin' => [

0 commit comments

Comments
 (0)