Path: blob/1.0-develop/app/Policies/ServerPolicy.php
10283 views
<?php12namespace Pterodactyl\Policies;34use Pterodactyl\Models\User;5use Pterodactyl\Models\Server;67class ServerPolicy8{9/**10* Checks if the user has the given permission on/for the server.11*/12protected function checkPermission(User $user, Server $server, string $permission): bool13{14$subuser = $server->subusers->where('user_id', $user->id)->first();15if (!$subuser || empty($permission)) {16return false;17}1819return in_array($permission, $subuser->permissions);20}2122/**23* Runs before any of the functions are called. Used to determine if user is root admin, if so, ignore permissions.24*/25public function before(User $user, string $ability, Server $server): bool26{27if ($user->root_admin || $server->owner_id === $user->id) {28return true;29}3031return $this->checkPermission($user, $server, $ability);32}3334/**35* This is a horrendous hack to avoid Laravel's "smart" behavior that does36* not call the before() function if there isn't a function matching the37* policy permission.38*/39public function __call(string $name, mixed $arguments)40{41// do nothing42}43}444546