Update logic for tracking a server's transfer state

This commit is contained in:
Matthew Penner 2020-12-16 09:34:47 -07:00
parent 5d03c0d2e5
commit e6c4a68e4a
20 changed files with 206 additions and 74 deletions

View file

@ -9,7 +9,6 @@ use Pterodactyl\Contracts\Repository\ServerRepositoryInterface;
use Symfony\Component\HttpKernel\Exception\ConflictHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class AuthenticateServerAccess
{
@ -24,7 +23,6 @@ class AuthenticateServerAccess
* @var string[]
*/
protected $except = [
'api:client:server.view',
'api:client:server.ws',
];
@ -65,17 +63,26 @@ class AuthenticateServerAccess
}
}
if ($server->suspended && !$request->routeIs('api:client:server.resources')) {
if ($server->suspended && ! $request->routeIs('api:client:server.resources')) {
throw new BadRequestHttpException(
'This server is currently suspended and the functionality requested is unavailable.'
);
}
if (! $server->isInstalled()) {
// Throw an exception for all server routes; however if the user is an admin and requesting the
// server details, don't throw the exception for them.
if (! $user->root_admin || ($user->root_admin && ! $request->routeIs($this->except))) {
throw new ConflictHttpException('Server has not completed the installation process.');
// Still allow users to get information about there server if it is installing or being transferred.
if (! $request->routeIs('api:client:server.view')) {
if (! $server->isInstalled()) {
// Throw an exception for all server routes; however if the user is an admin and requesting the
// server details, don't throw the exception for them.
if (! $user->root_admin || ($user->root_admin && ! $request->routeIs($this->except))) {
throw new ConflictHttpException('Server has not completed the installation process.');
}
}
if ($server->transfer !== null) {
if (! $user->root_admin || ($user->root_admin && ! $request->routeIs($this->except))) {
throw new ConflictHttpException('Server is currently being transferred.');
}
}
}