Fix exception thrown when accessing /nests/:id/eggs/:id API endpoint

This commit is contained in:
Dane Everitt 2018-02-24 11:11:57 -06:00
parent e7e50bc45d
commit 620c624e6f
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
3 changed files with 16 additions and 8 deletions

View File

@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
This project follows [Semantic Versioning](http://semver.org) guidelines. This project follows [Semantic Versioning](http://semver.org) guidelines.
## v0.7.2 (Derelict Dermodactylus)
### Fixed
* Fixes an exception thrown when trying to access the `/nests/:id/eggs/:id` API endpoint.
## v0.7.1 (Derelict Dermodactylus) ## v0.7.1 (Derelict Dermodactylus)
### Fixed ### Fixed
* Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted. * Fixes an exception when no token is entered on the 2-Factor enable/disable page and the form is submitted.

View File

@ -9,6 +9,7 @@ use Illuminate\Foundation\Http\FormRequest;
use Pterodactyl\Exceptions\PterodactylException; use Pterodactyl\Exceptions\PterodactylException;
use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings; use Pterodactyl\Http\Middleware\Api\ApiSubstituteBindings;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\InvalidParameterException;
abstract class ApplicationApiRequest extends FormRequest abstract class ApplicationApiRequest extends FormRequest
{ {
@ -76,22 +77,23 @@ abstract class ApplicationApiRequest extends FormRequest
} }
/** /**
* Grab a model from the route parameters. If no model exists under * Grab a model from the route parameters. If no model is found in the
* the specified key a default response is returned. * binding mappings an exception will be thrown.
* *
* @param string $model * @param string $model
* @param mixed $default
* @return mixed * @return mixed
*
* @throws \Symfony\Component\Routing\Exception\InvalidParameterException
*/ */
public function getModel(string $model, $default = null) public function getModel(string $model)
{ {
$parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model); $parameterKey = array_get(array_flip(ApiSubstituteBindings::getMappings()), $model);
if (! is_null($parameterKey)) { if (is_null($parameterKey)) {
$model = $this->route()->parameter($parameterKey); throw new InvalidParameterException;
} }
return $model ?? $default; return $this->route()->parameter($parameterKey);
} }
/* /*

View File

@ -2,6 +2,8 @@
namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs; namespace Pterodactyl\Http\Requests\Api\Application\Nests\Eggs;
use Pterodactyl\Models\Egg;
use Pterodactyl\Models\Nest;
use Pterodactyl\Services\Acl\Api\AdminAcl; use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest; use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
@ -24,6 +26,6 @@ class GetEggRequest extends ApplicationApiRequest
*/ */
public function resourceExists(): bool public function resourceExists(): bool
{ {
return $this->getModel('nest')->id === $this->getModel('egg')->nest_id; return $this->getModel(Nest::class)->id === $this->getModel(Egg::class)->nest_id;
} }
} }