2020-04-17 17:21:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Services\Servers;
|
|
|
|
|
|
|
|
use Pterodactyl\Models\User;
|
|
|
|
use Pterodactyl\Models\Server;
|
|
|
|
|
|
|
|
class GetUserPermissionsService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns the server specific permissions that a user has. This checks
|
|
|
|
* if they are an admin or a subuser for the server. If no permissions are
|
|
|
|
* found, an empty array is returned.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function handle(Server $server, User $user): array
|
2020-04-17 17:21:15 +00:00
|
|
|
{
|
|
|
|
if ($user->root_admin || $user->id === $server->owner_id) {
|
|
|
|
$permissions = ['*'];
|
|
|
|
|
|
|
|
if ($user->root_admin) {
|
|
|
|
$permissions[] = 'admin.websocket.errors';
|
|
|
|
$permissions[] = 'admin.websocket.install';
|
2020-12-16 16:34:47 +00:00
|
|
|
$permissions[] = 'admin.websocket.transfer';
|
2020-04-17 17:21:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $permissions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @var \Pterodactyl\Models\Subuser|null $subuserPermissions */
|
2020-08-20 03:21:12 +00:00
|
|
|
$subuserPermissions = $server->subusers()->where('user_id', $user->id)->first();
|
2020-04-17 17:21:15 +00:00
|
|
|
|
|
|
|
return $subuserPermissions ? $subuserPermissions->permissions : [];
|
|
|
|
}
|
|
|
|
}
|