Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Http/Requests/Api/Client/Servers/Schedules/ViewScheduleRequest.php
10279 views
1
<?php
2
3
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Schedules;
4
5
use Pterodactyl\Models\Task;
6
use Pterodactyl\Models\Server;
7
use Pterodactyl\Models\Schedule;
8
use Pterodactyl\Models\Permission;
9
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
12
class ViewScheduleRequest extends ClientApiRequest
13
{
14
/**
15
* Determine if this resource can be viewed.
16
*/
17
public function authorize(): bool
18
{
19
if (!parent::authorize()) {
20
return false;
21
}
22
23
$server = $this->route()->parameter('server');
24
$schedule = $this->route()->parameter('schedule');
25
26
// If the schedule does not belong to this server throw a 404 error. Also throw an
27
// error if the task being requested does not belong to the associated schedule.
28
if ($server instanceof Server && $schedule instanceof Schedule) {
29
$task = $this->route()->parameter('task');
30
31
if ($schedule->server_id !== $server->id || ($task instanceof Task && $task->schedule_id !== $schedule->id)) {
32
throw new NotFoundHttpException('The requested resource does not exist on the system.');
33
}
34
}
35
36
return true;
37
}
38
39
public function permission(): string
40
{
41
return Permission::ACTION_SCHEDULE_READ;
42
}
43
}
44
45