Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Services/Servers/GetUserPermissionsService.php
10276 views
1
<?php
2
3
namespace Pterodactyl\Services\Servers;
4
5
use Pterodactyl\Models\User;
6
use Pterodactyl\Models\Server;
7
8
class GetUserPermissionsService
9
{
10
/**
11
* Returns the server specific permissions that a user has. This checks
12
* if they are an admin or a subuser for the server. If no permissions are
13
* found, an empty array is returned.
14
*/
15
public function handle(Server $server, User $user): array
16
{
17
if ($user->root_admin || $user->id === $server->owner_id) {
18
$permissions = ['*'];
19
20
if ($user->root_admin) {
21
$permissions[] = 'admin.websocket.errors';
22
$permissions[] = 'admin.websocket.install';
23
$permissions[] = 'admin.websocket.transfer';
24
}
25
26
return $permissions;
27
}
28
29
/** @var \Pterodactyl\Models\Subuser|null $subuserPermissions */
30
$subuserPermissions = $server->subusers()->where('user_id', $user->id)->first();
31
32
return $subuserPermissions ? $subuserPermissions->permissions : [];
33
}
34
}
35
36