mirror of
https://github.com/pelican-dev/panel.git
synced 2025-05-20 05:14:46 +02:00

* Not found property rule * Make these “better” * Day 1 * Day 2 * Day 3 * Dat 4 * Remove disabled check * Day 4 continued * Run pint * Final changes hopefully * Pint fixes * Fix again * Reset these * Update app/Filament/Admin/Pages/Health.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> * Update app/Traits/CheckMigrationsTrait.php Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com> --------- Co-authored-by: MartinOscar <40749467+rmartinoscar@users.noreply.github.com>
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Servers;
|
|
|
|
use App\Models\User;
|
|
use App\Models\Server;
|
|
|
|
class GetUserPermissionsService
|
|
{
|
|
/**
|
|
* Returns the server specific permissions that a user has. This checks
|
|
* if they are an admin, the owner or a subuser for the server. If no
|
|
* permissions are found, an empty array is returned.
|
|
*
|
|
* @return string[]
|
|
*/
|
|
public function handle(Server $server, User $user): array
|
|
{
|
|
if ($user->isAdmin() && ($user->can('view server', $server) || $user->can('update server', $server))) {
|
|
$permissions = $user->can('update server', $server) ? ['*'] : ['websocket.connect', 'backup.read'];
|
|
|
|
$permissions[] = 'admin.websocket.errors';
|
|
$permissions[] = 'admin.websocket.install';
|
|
$permissions[] = 'admin.websocket.transfer';
|
|
|
|
return $permissions;
|
|
}
|
|
|
|
if ($user->id === $server->owner_id) {
|
|
return ['*'];
|
|
}
|
|
|
|
/** @var \App\Models\Subuser|null $subuserPermissions */
|
|
$subuserPermissions = $server->subusers()->where('user_id', $user->id)->first();
|
|
|
|
return $subuserPermissions ? $subuserPermissions->permissions : [];
|
|
}
|
|
}
|