@@ -96,16 +96,17 @@ $team->users()
96
96
$team->allUsers()
97
97
98
98
// Determine if the given user is a team member...
99
- $team->hasUser(object $user)
99
+ // Accepts user object
100
+ $team->hasUser($user)
100
101
101
102
// Adds a user to the team with a specified role by role ID or code
102
- $team->addUser(object $user, string $role_keyword)
103
+ $team->addUser($user, $role_keyword)
103
104
104
105
// Update the role of a specific user within the team
105
- $team->updateUser(object $user, string $role_keyword)
106
+ $team->updateUser($user, $role_keyword)
106
107
107
108
// Remove the given user from the team.
108
- $team->deleteUser(object $user);
109
+ $team->deleteUser($user);
109
110
110
111
// Get all the abilities belong to the team.
111
112
$team->abilities()
@@ -114,43 +115,46 @@ $team->abilities()
114
115
$team->roles()
115
116
116
117
// Return the user role object from the team
117
- $team->userRole(object $user)
118
+ $team->userRole($user)
118
119
119
- // Check if the team has a specific role by ID or code or any roles at all
120
- $team->hasRole(int|string|null $keyword )
120
+ // Check if the team has a specific role by ID or code or any roles at all if null
121
+ $team->hasRole($role_keyword )
121
122
122
123
// Get the role from the team by role id or code
123
- $team->getRole(int|string $keyword )
124
+ $team->getRole($role_keyword )
124
125
125
126
// Add new role to the team
126
- $team->addRole(string $code, array $permissions, string|null $name, string|null $description)
127
+ $team->addRole($code, $permissions, $name, $description)
127
128
128
129
// Update the role in the team
129
- $team->updateRole(int|string $keyword, array $permissions, string|null $name, string|null $description)
130
+ // Name and description is nullable when no changes needed
131
+ $team->updateRole($role_keyword, $permissions, $name, $description)
130
132
131
133
// Deletes the given role from team
132
- $team->deleteRole(int|string $keyword )
134
+ $team->deleteRole($role_keyword )
133
135
134
136
// Get all groups of the team.
135
137
$team->groups()
136
138
137
139
// Get team group by its id or code
138
- $team->getGroup(int|string $keyword )
140
+ $team->getGroup($group_keyword )
139
141
140
142
// Add new group to the team
141
- $team->addGroup(string $code, array|null $permissions = [], string|null $name)
143
+ $team->addGroup($code, $permissions, $name)
142
144
143
145
// Update the group in the team
144
- $team->updateGroup(int|string $keyword, array|null $permissions, string|null $name)
146
+ $team->updateGroup($group_keyword, $permissions, $name)
145
147
146
148
// Delete group from the team
147
- $team->deleteGroup(int|string $keyword )
149
+ $team->deleteGroup($group_keyword )
148
150
149
151
// Determine if the team has a member with the given email address...
150
- $team->hasUserWithEmail(array $email)
152
+ $team->hasUserWithEmail($email)
151
153
152
154
// Determine if the given user is a team member with the given permission...
153
- $team->userHasPermission(object $user, string|array $permissions, bool $require = false)
155
+ // $require = true (all permissions in the array are required)
156
+ // $require = false (only one or more permission in the array are required)
157
+ $team->userHasPermission($user, $permissions, $require)
154
158
155
159
// Returns all team invitations
156
160
$team->invitations()
@@ -167,48 +171,50 @@ Users
167
171
The ` Jurager\Teams\Traits\HasTeams ` trait provides methods to inspect a user's teams:
168
172
169
173
``` php
170
- // Access the team's that a user belongs to...
171
- $user->teams : Illuminate\Database\Eloquent\Collection
174
+ // Access the teams that a user belongs to...
175
+ $user->teams
172
176
173
177
// Access all of a user's owned teams...
174
- $user->ownedTeams : Illuminate\Database\Eloquent\Collection
178
+ $user->ownedTeams
175
179
176
180
// Access all the team's (including owned teams) that a user belongs to...
177
- $user->allTeams() : Illuminate\Database\Eloquent\Collection
181
+ $user->allTeams()
178
182
179
183
// Determine if a user owns a given team...
180
- $user->ownsTeam(object $team) : bool
184
+ $user->ownsTeam($team)
181
185
182
186
// Determine if a user belongs to a given team...
183
- $user->belongsToTeam(object $team) : bool
187
+ $user->belongsToTeam($team)
184
188
185
189
// Get the role that the user is assigned on the team...
186
- $user->teamRole(object $team) : \Jurager\Teams\Role
190
+ $user->teamRole($team)
187
191
188
- // Determine if the user has the given role on the given team...
189
- $user->hasTeamRole(object $team, string|array 'admin', bool $require = false) : bool
192
+ // Determine if the user has the given role (or roles if array passed) on the given team...
193
+ // $require = true (all roles in the array are required)
194
+ // $require = false (only one or more role in the array are required)
195
+ $user->hasTeamRole($team, 'admin', $require)
190
196
191
197
// Access an array of all permissions a user has for a given team...
192
- // Scope identifies which model to take permissions from, by default getting all permissions ( ex. 'role', 'group')
193
- $user->teamPermissions(object $team, string|null $scope = null) : array
198
+ // Scope identifies which model to take permissions from, by default if null - getting all permissions ( ex. 'role', 'group')
199
+ $user->teamPermissions($team, $scope)
194
200
195
- // Determine if a user has a given team permission...
201
+ // Determine if a user has a given team permission or permissions if array passed ...
196
202
// $require = true (all permissions in the array are required)
197
203
// $require = false (only one or more permission in the array are required)
198
204
// $scope - identifies in which model to check permissions, by default in all ( ex. 'role', 'group')
199
- $user->hasTeamPermission(object $team, string|array 'server:create', bool $require = false, string|null $scope = null) : bool
205
+ $user->hasTeamPermission($team, 'server:create', $require, $scope)
200
206
201
207
// Get list of abilities or forbidden abilities for users on certain model
202
- $user->teamAbilities(object $team, object $server) : mixed
208
+ $user->teamAbilities($team, $server)
203
209
204
210
// Determine if a user has a given ability on certain model...
205
- $user->hasTeamAbility(object $team, string 'server:edit', object $server) : bool
211
+ $user->hasTeamAbility($team, 'server:edit', $server)
206
212
207
213
// Add an ability for user to action on certain model, if not found, will create a new one
208
- $user->allowTeamAbility(object $team, string 'server:edit', object $server) : bool
214
+ $user->allowTeamAbility($team, 'server:edit', $server)
209
215
210
216
// Forbid an ability for user to action on certain model, used in case if global ability or role allowing this action
211
- $user->forbidTeamAbility(object $team, string 'server:edit', object $server) : bool
217
+ $user->forbidTeamAbility($team, 'server:edit', $server)
212
218
```
213
219
214
220
These methods enable you to efficiently manage and inspect a user's teams, roles, permissions, and abilities within your application.
@@ -268,7 +274,7 @@ To ensure that incoming requests initiated by a team member can be executed by t
268
274
** Example** : Check if a user within a team has permission to update a server
269
275
270
276
``` php
271
- return $user->hasTeamPermission(object $team, string 'server:update');
277
+ return $user->hasTeamPermission($team, 'server:update');
272
278
```
273
279
274
280
Abilities
@@ -280,18 +286,20 @@ Abilities
280
286
281
287
Adding abilities to users is easy — just pass the ability name, and it’ll be created automatically if it doesn’t exist.
282
288
283
- To grant a user the ability to edit an article within a team, simply provide the relevant entities, such as the article and team objects:
289
+ To grant a user the ability to edit an article within a team, simply provide the relevant entities, such as the article and team objects
290
+
291
+ If ` $target_entity ` is null, target for ability defaults to user:
284
292
285
293
``` php
286
- $user->allowTeamAbility(object $team, string $action, object $action_entity, object|null $target_entity = null )
294
+ $user->allowTeamAbility($team, $action, $action_entity, $target_entity)
287
295
```
288
296
289
297
### Checking an Ability
290
298
291
299
To verify if a user has a specific ability within the context of a team, based on various permission levels (role, group, user, and global), you can use the following method:
292
300
293
301
``` php
294
- User::hasTeamAbility(object $team, string 'edit_post', object $post);
302
+ User::hasTeamAbility($team, 'edit_post', $post);
295
303
```
296
304
297
305
This method checks if the user can perform the specified ability (e.g., 'edit_post') on the given entity (e.g., a post) within the context of the specified team. It takes into account the user's role, groups, global permissions, and any entity-specific access rules.
@@ -332,9 +340,11 @@ If the **allowed** value is greater than or equal to the **forbidden** value, th
332
340
333
341
### Forbidding an Ability
334
342
335
- To prevent a user from having a specific ability (even if their role allows it), use the following method:
343
+ To prevent a user from having a specific ability (even if their role allows it), use the following method.
344
+
345
+ If ` $target_entity ` is null, target for ability defaults to user:
336
346
``` php
337
- User::forbidTeamAbility(object $team, string $action, object $action_entity, object|null $target_entity = null )
347
+ User::forbidTeamAbility($team, $action, $action_entity,$target_entity)
338
348
```
339
349
340
350
Groups
@@ -358,31 +368,33 @@ The `Jurager\Teams\Traits\HasTeams` trait provides methods to inspect a user's t
358
368
359
369
``` php
360
370
// Add new group to the team
361
- $team->addGroup(string $code, array $permissions = [], string|null $name)
371
+ // If $name is null, str::studly of $code will be used
372
+ $team->addGroup($code, $permissions, $name)
362
373
363
374
// Update the group in the team, if permissions is empty array all exiting permissions will be detached
364
- $team->updateGroup(int|string $keyword, array $permissions => [], string|null $name)
375
+ // If $name is null, str::studly of $code will be used
376
+ $team->updateGroup($group_keyword, $permissions, $name)
365
377
366
378
// Delete group from the team
367
- $team->deleteGroup(string $code )
379
+ $team->deleteGroup($group_keyword )
368
380
369
381
// Get all groups of the team.
370
382
$team->groups();
371
383
372
- // Check if the team has a specific group by ID or code or any groups at all
373
- $team->hasGroup(int|string|null $keyword )
384
+ // Check if the team has a specific group by ID or code or any groups at all if null passed
385
+ $team->hasGroup($group_keyword )
374
386
375
387
// Get team group by its code
376
- $group = $team->getGroup(int|string $keyword );
388
+ $group = $team->getGroup($group_keyword );
377
389
378
390
// Get all group users
379
391
$group->users();
380
392
381
393
// Attach users or user to a group
382
- $group->attachUser(Collection|Model $user);
394
+ $group->attachUser($user);
383
395
384
396
// Detach users or user from group
385
- $group->detachUser(Collection|Model $user);
397
+ $group->detachUser($user);
386
398
```
387
399
388
400
Middlewares
@@ -443,10 +455,10 @@ For **OR** operations, use the pipe symbol:
443
455
For ** AND** functionality:
444
456
445
457
``` php
446
- 'middleware' => ['role:admin|root,team_id,require']
458
+ 'middleware' => ['role:admin|root,{ team_id} ,require']
447
459
// $user->hasTeamRole($team, ['admin', 'root'], require: true);
448
460
449
- 'middleware' => ['permission:edit-post|edit-user,team_id,require']
461
+ 'middleware' => ['permission:edit-post|edit-user,{ team_id} ,require']
450
462
// $user->hasTeamPermission($team, ['edit-post', 'edit-user'], require: true);
451
463
```
452
464
0 commit comments