Skip to content

Commit b36fd42

Browse files
committed
Update README.md
1 parent 8444a48 commit b36fd42

File tree

1 file changed

+62
-50
lines changed

1 file changed

+62
-50
lines changed

README.md

+62-50
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,17 @@ $team->users()
9696
$team->allUsers()
9797

9898
// Determine if the given user is a team member...
99-
$team->hasUser(object $user)
99+
// Accepts user object
100+
$team->hasUser($user)
100101

101102
// 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)
103104

104105
// Update the role of a specific user within the team
105-
$team->updateUser(object $user, string $role_keyword)
106+
$team->updateUser($user, $role_keyword)
106107

107108
// Remove the given user from the team.
108-
$team->deleteUser(object $user);
109+
$team->deleteUser($user);
109110

110111
// Get all the abilities belong to the team.
111112
$team->abilities()
@@ -114,43 +115,46 @@ $team->abilities()
114115
$team->roles()
115116

116117
// Return the user role object from the team
117-
$team->userRole(object $user)
118+
$team->userRole($user)
118119

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)
121122

122123
// Get the role from the team by role id or code
123-
$team->getRole(int|string $keyword)
124+
$team->getRole($role_keyword)
124125

125126
// 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)
127128

128129
// 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)
130132

131133
// Deletes the given role from team
132-
$team->deleteRole(int|string $keyword)
134+
$team->deleteRole($role_keyword)
133135

134136
// Get all groups of the team.
135137
$team->groups()
136138

137139
// Get team group by its id or code
138-
$team->getGroup(int|string $keyword)
140+
$team->getGroup($group_keyword)
139141

140142
// Add new group to the team
141-
$team->addGroup(string $code, array|null $permissions = [], string|null $name)
143+
$team->addGroup($code, $permissions, $name)
142144

143145
// 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)
145147

146148
// Delete group from the team
147-
$team->deleteGroup(int|string $keyword)
149+
$team->deleteGroup($group_keyword)
148150

149151
// Determine if the team has a member with the given email address...
150-
$team->hasUserWithEmail(array $email)
152+
$team->hasUserWithEmail($email)
151153

152154
// 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)
154158

155159
// Returns all team invitations
156160
$team->invitations()
@@ -167,48 +171,50 @@ Users
167171
The `Jurager\Teams\Traits\HasTeams` trait provides methods to inspect a user's teams:
168172

169173
```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
172176

173177
// Access all of a user's owned teams...
174-
$user->ownedTeams : Illuminate\Database\Eloquent\Collection
178+
$user->ownedTeams
175179

176180
// Access all the team's (including owned teams) that a user belongs to...
177-
$user->allTeams() : Illuminate\Database\Eloquent\Collection
181+
$user->allTeams()
178182

179183
// Determine if a user owns a given team...
180-
$user->ownsTeam(object $team) : bool
184+
$user->ownsTeam($team)
181185

182186
// Determine if a user belongs to a given team...
183-
$user->belongsToTeam(object $team) : bool
187+
$user->belongsToTeam($team)
184188

185189
// Get the role that the user is assigned on the team...
186-
$user->teamRole(object $team) : \Jurager\Teams\Role
190+
$user->teamRole($team)
187191

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)
190196

191197
// 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)
194200

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...
196202
// $require = true (all permissions in the array are required)
197203
// $require = false (only one or more permission in the array are required)
198204
// $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)
200206

201207
// 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)
203209

204210
// 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)
206212

207213
// 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)
209215

210216
// 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)
212218
```
213219

214220
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
268274
**Example**: Check if a user within a team has permission to update a server
269275

270276
```php
271-
return $user->hasTeamPermission(object $team, string 'server:update');
277+
return $user->hasTeamPermission($team, 'server:update');
272278
```
273279

274280
Abilities
@@ -280,18 +286,20 @@ Abilities
280286

281287
Adding abilities to users is easy — just pass the ability name, and it’ll be created automatically if it doesn’t exist.
282288

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:
284292

285293
```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)
287295
```
288296

289297
### Checking an Ability
290298

291299
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:
292300

293301
```php
294-
User::hasTeamAbility(object $team, string 'edit_post', object $post);
302+
User::hasTeamAbility($team, 'edit_post', $post);
295303
```
296304

297305
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
332340

333341
### Forbidding an Ability
334342

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:
336346
```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)
338348
```
339349

340350
Groups
@@ -358,31 +368,33 @@ The `Jurager\Teams\Traits\HasTeams` trait provides methods to inspect a user's t
358368

359369
```php
360370
// 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)
362373

363374
// 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)
365377

366378
// Delete group from the team
367-
$team->deleteGroup(string $code)
379+
$team->deleteGroup($group_keyword)
368380

369381
// Get all groups of the team.
370382
$team->groups();
371383

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)
374386

375387
// Get team group by its code
376-
$group = $team->getGroup(int|string $keyword);
388+
$group = $team->getGroup($group_keyword);
377389

378390
// Get all group users
379391
$group->users();
380392

381393
// Attach users or user to a group
382-
$group->attachUser(Collection|Model $user);
394+
$group->attachUser($user);
383395

384396
// Detach users or user from group
385-
$group->detachUser(Collection|Model $user);
397+
$group->detachUser($user);
386398
```
387399

388400
Middlewares
@@ -443,10 +455,10 @@ For **OR** operations, use the pipe symbol:
443455
For **AND** functionality:
444456

445457
```php
446-
'middleware' => ['role:admin|root,team_id,require']
458+
'middleware' => ['role:admin|root,{team_id},require']
447459
// $user->hasTeamRole($team, ['admin', 'root'], require: true);
448460

449-
'middleware' => ['permission:edit-post|edit-user,team_id,require']
461+
'middleware' => ['permission:edit-post|edit-user,{team_id},require']
450462
// $user->hasTeamPermission($team, ['edit-post', 'edit-user'], require: true);
451463
```
452464

0 commit comments

Comments
 (0)