2020-03-18 22:28:32 -07:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-03-18 22:28:32 -07:00
|
|
|
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;
|
2020-03-18 22:28:32 -07:00
|
|
|
|
2020-03-22 13:56:15 -07:00
|
|
|
class StoreTaskRequest extends ViewScheduleRequest
|
2020-03-18 22:28:32 -07:00
|
|
|
{
|
|
|
|
|
/**
|
2026-10-05 18:10:18 -04:00
|
|
|
* Creating or changing a task needs permission to update the schedule.
|
2020-03-18 22:28:32 -07:00
|
|
|
*/
|
2020-03-22 13:56:15 -07:00
|
|
|
public function permission(): string
|
2020-03-18 22:28:32 -07:00
|
|
|
{
|
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));
|
2020-03-18 22:28:32 -07:00
|
|
|
}
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
/**
|
|
|
|
|
* @return ValidationRules
|
|
|
|
|
*/
|
2020-03-18 22:28:32 -07:00
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-10-11 06:11:40 -04:00
|
|
|
return CreateScheduleTask::rules($this->input('action') === Task::ACTION_POWER);
|
2020-03-18 22:28:32 -07:00
|
|
|
}
|
|
|
|
|
}
|