Files

45 lines
1.2 KiB
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Http\Requests\Api\Client\Servers\Schedules;
2026-10-11 06:11:40 -04:00
use Pterodactyl\Actions\Schedules\CreateScheduleTask;
2026-10-05 18:10:18 -04:00
use Pterodactyl\Enum\Permissions;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Task;
class StoreTaskRequest extends ViewScheduleRequest
{
/**
2026-10-05 18:10:18 -04:00
* Creating or changing a task needs permission to update the schedule.
*/
public function permission(): string
{
2026-10-05 18:10:18 -04:00
return Permissions::ScheduleUpdate->value;
}
/**
* The user also needs the permission for the task's action, such as console access for
* a command task. An unknown action or power signal is left to validation to reject.
*/
public function authorize(): bool
{
if (! parent::authorize()) {
return false;
}
$permission = Task::permissionForAction($this->string('action')->toString(), $this->string('payload')->toString());
return ! $permission instanceof Permissions || $this->user()->can($permission->value, $this->parameter('server', Server::class));
}
2026-10-05 18:10:18 -04:00
/**
* @return ValidationRules
*/
public function rules(): array
{
2026-10-11 06:11:40 -04:00
return CreateScheduleTask::rules($this->input('action') === Task::ACTION_POWER);
}
}