Skip to content

Commit 9e2b9ab

Browse files
authored
Merge pull request #47 from HashGateApp/main
2 parents 9b20288 + f97d2cd commit 9e2b9ab

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,32 @@ To ensure that incoming requests initiated by a team member can be executed by t
283283
return $user->hasTeamPermission($team, 'server:update');
284284
```
285285

286+
### Wildcard Permissions
287+
288+
You can choose to enable wildcard permissions in the config. Enabling wildcards will allow you to specify permission node(s) that grants a user all access if they have that permission attached to them.
289+
```php
290+
/*
291+
|--------------------------------------------------------------------------
292+
| Wildcard Permissions
293+
|--------------------------------------------------------------------------
294+
| Configure wildcard permission nodes, allowing you to specify super admin
295+
| permission node(s) that allows a user to perform all actions on a team.
296+
*/
297+
'wildcards' => [
298+
'enabled' => false,
299+
'nodes' => [
300+
'*',
301+
'*.*',
302+
'all'
303+
]
304+
]
305+
```
306+
307+
In the example configuration above, users with the permission nodes of "\*" or "\*.\*" or "all" would be allowed to perform all actions on their team.
308+
309+
> [!NOTE]
310+
> This configuration does not grant global team access. It only allows you to grant all permissions to a user or role in the team
311+
286312
Abilities
287313
-------------------------------------------
288314

config/teams.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,21 @@
8686
'middleware' => 'web'
8787
]
8888
],
89+
90+
/*
91+
|--------------------------------------------------------------------------
92+
| Wildcard Permissions
93+
|--------------------------------------------------------------------------
94+
| Configure wildcard permission nodes, allowing you to specify super admin
95+
| permission node(s) that allows a user to perform all actions on a team.
96+
*/
97+
'wildcards' => [
98+
'enabled' => false,
99+
'nodes' => [
100+
'*',
101+
'*.*',
102+
'all'
103+
]
104+
]
105+
89106
];

src/Traits/HasTeams.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,20 @@ private function checkPermissionWildcard(array $userPermissions, string $permiss
463463
{
464464
// Generate all possible wildcards from the permission segments
465465
$segments = collect(explode('.', $permission));
466+
466467
$codes = $segments->map(function ($item, $key) use ($segments) {
467468
return $segments->take($key + 1)->implode('.') . ($key + 1 === $segments->count() ? '' : '.*') ;
468469
});
469470

471+
// Add in the optional wildcard permissions
472+
if(Config::get('teams.wildcards.enabled', false)) {
473+
// Build the code collection
474+
$wildcardCodes = collect(Config::get('teams.wildcards.nodes', []));
475+
476+
// Replace codes with the new codes
477+
$codes = $wildcardCodes->merge($codes);
478+
}
479+
470480
return !empty(array_intersect($codes->all(), $userPermissions));
471481
}
472482
}

0 commit comments

Comments
 (0)