Fix display of navbar links to admins, closes #1920
This commit is contained in:
parent
4193c5f664
commit
e969344f3b
8 changed files with 67 additions and 39 deletions
37
app/Services/Servers/GetUserPermissionsService.php
Normal file
37
app/Services/Servers/GetUserPermissionsService.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?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.
|
||||
*
|
||||
* @param \Pterodactyl\Models\Server $server
|
||||
* @param \Pterodactyl\Models\User $user
|
||||
* @return string[]
|
||||
*/
|
||||
public function handle(Server $server, User $user)
|
||||
{
|
||||
if ($user->root_admin || $user->id === $server->owner_id) {
|
||||
$permissions = ['*'];
|
||||
|
||||
if ($user->root_admin) {
|
||||
$permissions[] = 'admin.websocket.errors';
|
||||
$permissions[] = 'admin.websocket.install';
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
/** @var \Pterodactyl\Models\Subuser|null $subuserPermissions */
|
||||
$subuserPermissions = $server->subusers->where('user_id', $user->id)->first();
|
||||
|
||||
return $subuserPermissions ? $subuserPermissions->permissions : [];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue