Add nests & eggs

Cleanup middleware handling and parameters on controllers...
This commit is contained in:
Dane Everitt 2018-01-27 12:38:56 -06:00
parent de07b3cc7f
commit 8afced3410
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
26 changed files with 737 additions and 446 deletions

View file

@ -0,0 +1,46 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Allocations;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class StoreAllocationRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
/**
* @var int
*/
protected $permission = AdminAcl::WRITE;
/**
* @return array
*/
public function rules(): array
{
return [
'ip' => 'required|string',
'alias' => 'sometimes|nullable|string|max:255',
'ports' => 'required|array',
'ports.*' => 'string',
];
}
/**
* @return array
*/
public function validated()
{
$data = parent::validated();
return [
'allocation_ip' => $data['ip'],
'allocation_ports' => $data['ports'],
'allocation_alias' => $data['alias'],
];
}
}

View file

@ -3,9 +3,11 @@
namespace Pterodactyl\Http\Requests\Api\Application;
use Pterodactyl\Models\ApiKey;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Illuminate\Foundation\Http\FormRequest;
use Pterodactyl\Exceptions\PterodactylException;
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
abstract class ApplicationApiRequest extends FormRequest
@ -73,6 +75,25 @@ abstract class ApplicationApiRequest extends FormRequest
return $this->attributes->get('api_key');
}
/**
* Grab a model from the route parameters. If no model exists under
* the specified key a default response is returned.
*
* @param string $model
* @param mixed $default
* @return mixed
*/
public function getModel(string $model, $default = null)
{
$parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model);
if (! is_null($parameterKey)) {
$model = $this->route()->parameter($parameterKey);
}
return $model ?? $default;
}
/*
* Determine if the request passes the authorization check as well
* as the exists check.

View file

@ -0,0 +1,29 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetEggRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_EGGS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
/**
* Determine if the requested egg exists for the selected nest.
*
* @return bool
*/
public function resourceExists(): bool
{
return $this->getModel('nest')->id === $this->getModel('egg')->nest_id;
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetEggsRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_EGGS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
}

View file

@ -0,0 +1,19 @@
<?php
namespace Pterodactyl\Http\Requests\Api\Application\Nests;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
class GetNestsRequest extends ApplicationApiRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_NESTS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
}