2020-03-22 13:56:15 -07:00
<? php
2026-10-05 18:10:18 -04:00
declare ( strict_types = 1 );
2020-03-22 13:56:15 -07:00
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Schedules ;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Contracts\Http\ClientPermissionsRequest ;
use Pterodactyl\Enum\Permissions ;
2020-03-22 13:56:15 -07:00
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest ;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Models\Schedule ;
use Pterodactyl\Models\Server ;
use Pterodactyl\Models\Task ;
2020-03-22 13:56:15 -07:00
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException ;
2026-10-05 18:10:18 -04:00
use UnexpectedValueException ;
2020-03-22 13:56:15 -07:00
2026-10-05 18:10:18 -04:00
class ViewScheduleRequest extends ClientApiRequest implements ClientPermissionsRequest
2020-03-22 13:56:15 -07:00
{
/**
* Determine if this resource can be viewed.
*/
public function authorize () : bool
{
2026-10-05 18:10:18 -04:00
if ( ! parent :: authorize ()) {
2020-03-22 13:56:15 -07:00
return false ;
}
2026-10-05 18:10:18 -04:00
$server = $this -> parameter ( 'server' , Server :: class );
$route = $this -> route ();
throw_if ( $route === null , UnexpectedValueException :: class , 'The schedule request does not have an active route.' );
$schedule = $route -> parameter ( 'schedule' );
2020-03-22 13:56:15 -07:00
// If the schedule does not belong to this server throw a 404 error. Also throw an
// error if the task being requested does not belong to the associated schedule.
2026-10-05 18:10:18 -04:00
if ( $schedule instanceof Schedule ) {
$task = $route -> parameter ( 'task' );
throw_if ( $schedule -> server_id !== $server -> id || ( $task instanceof Task && $task -> schedule_id !== $schedule -> id ), NotFoundHttpException :: class , 'The requested resource does not exist on the system.' );
2020-03-22 13:56:15 -07:00
}
return true ;
}
public function permission () : string
{
2026-10-05 18:10:18 -04:00
return Permissions :: ScheduleRead -> value ;
2020-03-22 13:56:15 -07:00
}
}