mirror of
https://github.com/MrUnknownDE/panel.git
synced 2026-04-19 06:43:45 +02:00
Add test coverage for creating tasks
This commit is contained in:
21
app/Exceptions/Service/ServiceLimitExceededException.php
Normal file
21
app/Exceptions/Service/ServiceLimitExceededException.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Pterodactyl\Exceptions\Service;
|
||||
|
||||
use Throwable;
|
||||
use Pterodactyl\Exceptions\DisplayException;
|
||||
|
||||
class ServiceLimitExceededException extends DisplayException
|
||||
{
|
||||
/**
|
||||
* Exception thrown when something goes over a defined limit, such as allocated
|
||||
* ports, tasks, databases, etc.
|
||||
*
|
||||
* @param string $message
|
||||
* @param \Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $message, Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, $previous, self::LEVEL_WARNING);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ use Pterodactyl\Exceptions\Http\HttpForbiddenException;
|
||||
use Pterodactyl\Transformers\Api\Client\TaskTransformer;
|
||||
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
|
||||
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
|
||||
use Pterodactyl\Exceptions\Service\ServiceLimitExceededException;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use Pterodactyl\Http\Requests\Api\Client\Servers\Schedules\StoreTaskRequest;
|
||||
|
||||
@@ -44,11 +45,15 @@ class ScheduleTaskController extends ClientApiController
|
||||
* @return array
|
||||
*
|
||||
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
||||
* @throws \Pterodactyl\Exceptions\Service\ServiceLimitExceededException
|
||||
*/
|
||||
public function store(StoreTaskRequest $request, Server $server, Schedule $schedule)
|
||||
{
|
||||
if ($schedule->server_id !== $server->id) {
|
||||
throw new NotFoundHttpException;
|
||||
$limit = config('pterodactyl.client_features.schedules.per_schedule_task_limit', 10);
|
||||
if ($schedule->tasks()->count() >= $limit) {
|
||||
throw new ServiceLimitExceededException(
|
||||
"Schedules may not have more than {$limit} tasks associated with them. Creating this task would put this schedule over the limit."
|
||||
);
|
||||
}
|
||||
|
||||
$lastTask = $schedule->tasks->last();
|
||||
|
||||
Reference in New Issue
Block a user