forked from Alex/Pterodactyl-Panel
api(application): fix requests
This commit is contained in:
parent
409c081275
commit
5737b5dc5d
@ -7,6 +7,7 @@ use Webmozart\Assert\Assert;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Pterodactyl\Http\Controllers\Controller;
|
||||
use Pterodactyl\Extensions\Spatie\Fractalistic\Fractal;
|
||||
use Pterodactyl\Transformers\Api\Application\BaseTransformer;
|
||||
@ -45,9 +46,6 @@ abstract class ApplicationApiController extends Controller
|
||||
/**
|
||||
* Perform dependency injection of certain classes needed for core functionality
|
||||
* without littering the constructors of classes that extend this abstract.
|
||||
*
|
||||
* @param \Pterodactyl\Extensions\Spatie\Fractalistic\Fractal $fractal
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*/
|
||||
public function loadDependencies(Fractal $fractal, Request $request)
|
||||
{
|
||||
@ -58,17 +56,18 @@ abstract class ApplicationApiController extends Controller
|
||||
/**
|
||||
* Return an instance of an application transformer.
|
||||
*
|
||||
* @param string $abstract
|
||||
*
|
||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
public function getTransformer(string $abstract)
|
||||
{
|
||||
/** @var \Pterodactyl\Transformers\Api\Application\BaseTransformer $transformer */
|
||||
$transformer = Container::getInstance()->make($abstract);
|
||||
$transformer->setRootAdmin($this->request->user()->root_admin);
|
||||
|
||||
$apiKey = $this->request->attributes->get('api_key');
|
||||
$transformer->setKey($this->request->attributes->get('api_key'));
|
||||
$transformer->setRootAdmin($this->request->user()->root_admin);
|
||||
|
||||
Assert::isInstanceOf($transformer, BaseTransformer::class);
|
||||
|
||||
@ -77,8 +76,6 @@ abstract class ApplicationApiController extends Controller
|
||||
|
||||
/**
|
||||
* Return a HTTP/204 response for the API.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
protected function returnNoContent(): Response
|
||||
{
|
||||
|
@ -16,20 +16,9 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
|
||||
|
||||
class AuthenticateKey
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Auth\AuthManager
|
||||
*/
|
||||
private $auth;
|
||||
|
||||
/**
|
||||
* @var \Illuminate\Contracts\Encryption\Encrypter
|
||||
*/
|
||||
private $encrypter;
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Contracts\Repository\ApiKeyRepositoryInterface
|
||||
*/
|
||||
private $repository;
|
||||
private AuthManager $auth;
|
||||
private Encrypter $encrypter;
|
||||
private ApiKeyRepositoryInterface $repository;
|
||||
|
||||
/**
|
||||
* AuthenticateKey constructor.
|
||||
|
@ -9,15 +9,8 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteAllocationRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
protected string $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested allocation exists and belongs to the node that
|
||||
|
@ -8,15 +8,8 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetAllocationsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
protected string $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
|
||||
/**
|
||||
* Determine if the node that we are requesting the allocations
|
||||
|
@ -7,15 +7,8 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreAllocationRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
protected string $resource = AdminAcl::RESOURCE_ALLOCATIONS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
@ -27,10 +20,7 @@ class StoreAllocationRequest extends ApplicationApiRequest
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validated()
|
||||
public function validated(): array
|
||||
{
|
||||
$data = parent::validated();
|
||||
|
||||
|
@ -15,10 +15,8 @@ abstract class ApplicationApiRequest extends FormRequest
|
||||
/**
|
||||
* Tracks if the request has been validated internally or not to avoid
|
||||
* making duplicate validation calls.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $hasValidated = false;
|
||||
private bool $hasValidated = false;
|
||||
|
||||
/**
|
||||
* The resource that should be checked when performing the authorization
|
||||
@ -26,7 +24,7 @@ abstract class ApplicationApiRequest extends FormRequest
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $resource;
|
||||
protected string $resource;
|
||||
|
||||
/**
|
||||
* The permission level that a given API key should have for accessing
|
||||
@ -34,7 +32,7 @@ abstract class ApplicationApiRequest extends FormRequest
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::NONE;
|
||||
protected int $permission = AdminAcl::NONE;
|
||||
|
||||
/**
|
||||
* Determine if the current user is authorized to perform
|
||||
@ -48,7 +46,7 @@ abstract class ApplicationApiRequest extends FormRequest
|
||||
throw new PterodactylException('An ACL resource must be defined on API requests.');
|
||||
}
|
||||
|
||||
if (! is_null($this->user())) {
|
||||
if ($this->key()->key_type === ApiKey::TYPE_ACCOUNT) {
|
||||
return $this->user()->root_admin;
|
||||
}
|
||||
|
||||
|
@ -7,23 +7,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DatabaseNodesRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? ['nodes' => 'required|exists:nodes,id'];
|
||||
|
@ -8,21 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteDatabaseRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested database exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$databaseHost = $this->route()->parameter('databaseHost');
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\DatabaseHost;
|
||||
|
||||
class GetDatabaseRequest extends GetDatabasesRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested database exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$databaseHost = $this->route()->parameter('databaseHost');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetDatabasesRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = Acl::RESOURCE_DATABASE_HOSTS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = Acl::READ;
|
||||
protected string $resource = Acl::RESOURCE_DATABASE_HOSTS;
|
||||
protected int $permission = Acl::READ;
|
||||
}
|
||||
|
@ -8,23 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreDatabaseRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_DATABASE_HOSTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? DatabaseHost::getRules();
|
||||
|
@ -6,13 +6,6 @@ use Pterodactyl\Models\DatabaseHost;
|
||||
|
||||
class UpdateDatabaseRequest extends StoreDatabaseRequest
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? DatabaseHost::getRulesForUpdate($this->route()->parameter('databaseHost')->id);
|
||||
|
@ -8,19 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteEggRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_EGGS;
|
||||
protected string $resource = AdminAcl::RESOURCE_EGGS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested egg exists for the selected nest.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$egg = $this->route()->parameter('egg');
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\Egg;
|
||||
|
||||
class GetEggRequest extends GetEggsRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested egg exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$egg = $this->route()->parameter('egg');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetEggsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_EGGS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
protected string $resource = AdminAcl::RESOURCE_EGGS;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
}
|
||||
|
@ -8,23 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreEggRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_EGGS;
|
||||
protected string $resource = AdminAcl::RESOURCE_EGGS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Egg::getRules();
|
||||
|
@ -6,13 +6,6 @@ use Pterodactyl\Models\Egg;
|
||||
|
||||
class UpdateEggRequest extends StoreEggRequest
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Egg::getRulesForUpdate($this->route()->parameter('egg')->id);
|
||||
|
@ -8,19 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteLocationRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
protected string $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested location exists on the Panel.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$location = $this->route()->parameter('location');
|
||||
|
@ -6,9 +6,6 @@ use Pterodactyl\Models\Location;
|
||||
|
||||
class GetLocationRequest extends GetLocationsRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested location exists on the Panel.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$location = $this->route()->parameter('location');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetLocationsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
protected string $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
}
|
||||
|
@ -8,19 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreLocationRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
protected string $resource = AdminAcl::RESOURCE_LOCATIONS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Rules to validate the request against.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return collect(Location::getRules())->only([
|
||||
@ -29,12 +19,7 @@ class StoreLocationRequest extends ApplicationApiRequest
|
||||
])->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename fields to be more clear in error messages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'long' => 'Location Description',
|
||||
|
@ -6,9 +6,6 @@ use Pterodactyl\Models\Location;
|
||||
|
||||
class UpdateLocationRequest extends StoreLocationRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested location exists on the Panel.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$location = $this->route()->parameter('location');
|
||||
@ -16,9 +13,6 @@ class UpdateLocationRequest extends StoreLocationRequest
|
||||
return $location instanceof Location && $location->exists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rules to validate this request against.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$locationId = $this->route()->parameter('location')->id;
|
||||
|
@ -8,21 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteMountRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested mount exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$mount = $this->route()->parameter('mount');
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\Mount;
|
||||
|
||||
class GetMountRequest extends GetMountsRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested mount exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$mount = $this->route()->parameter('mount');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetMountsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = Acl::RESOURCE_MOUNTS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = Acl::READ;
|
||||
protected string $resource = Acl::RESOURCE_MOUNTS;
|
||||
protected int $permission = Acl::READ;
|
||||
}
|
||||
|
@ -7,23 +7,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class MountEggsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? ['eggs' => 'required|exists:eggs,id'];
|
||||
|
@ -7,23 +7,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class MountNodesRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? ['nodes' => 'required|exists:nodes,id'];
|
||||
|
@ -8,23 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreMountRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_MOUNTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Mount::getRules();
|
||||
|
@ -6,13 +6,6 @@ use Pterodactyl\Models\Mount;
|
||||
|
||||
class UpdateMountRequest extends StoreMountRequest
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Mount::getRulesForUpdate($this->route()->parameter('mount')->id);
|
||||
|
@ -8,21 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteNestRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NESTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_NESTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested nest exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$nest = $this->route()->parameter('nest');
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\Nest;
|
||||
|
||||
class GetNestRequest extends GetNestsRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested nest exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$nest = $this->route()->parameter('nest');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetNestsRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NESTS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
protected string $resource = AdminAcl::RESOURCE_NESTS;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
}
|
||||
|
@ -8,23 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreNestRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NESTS;
|
||||
protected string $resource = AdminAcl::RESOURCE_NESTS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Nest::getRules();
|
||||
|
@ -6,13 +6,6 @@ use Pterodactyl\Models\Nest;
|
||||
|
||||
class UpdateNestRequest extends StoreNestRequest
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? Nest::getRulesForUpdate($this->route()->parameter('nest')->id);
|
||||
|
@ -8,20 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteNodeRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NODES;
|
||||
protected string $resource = AdminAcl::RESOURCE_NODES;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the node being requested for editing exists
|
||||
* on the Panel before validating the data.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$node = $this->route()->parameter('node');
|
||||
|
@ -4,9 +4,6 @@ namespace Pterodactyl\Http\Requests\Api\Application\Nodes;
|
||||
|
||||
class GetDeployableNodesRequest extends GetNodesRequest
|
||||
{
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
|
@ -6,9 +6,6 @@ use Pterodactyl\Models\Node;
|
||||
|
||||
class GetNodeRequest extends GetNodesRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested node exists on the Panel.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$node = $this->route()->parameter('node');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetNodesRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NODES;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
protected string $resource = AdminAcl::RESOURCE_NODES;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
}
|
||||
|
@ -8,15 +8,8 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreNodeRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_NODES;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
protected string $resource = AdminAcl::RESOURCE_NODES;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Validation rules to apply to this request.
|
||||
|
@ -6,14 +6,8 @@ use Pterodactyl\Models\Node;
|
||||
|
||||
class UpdateNodeRequest extends StoreNodeRequest
|
||||
{
|
||||
/**
|
||||
* Apply validation rules to this request. Uses the parent class rules()
|
||||
* function but passes in the rules for updating rather than creating.
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
$nodeId = $this->getModel(Node::class)->id;
|
||||
|
||||
return parent::rules(Node::getRulesForUpdate($nodeId));
|
||||
return parent::rules($rules ?? Node::getRulesForUpdate($this->route()->parameter('node')->id));
|
||||
}
|
||||
}
|
||||
|
@ -8,21 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteRoleRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_ROLES;
|
||||
protected string $resource = AdminAcl::RESOURCE_ROLES;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested role exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$role = $this->route()->parameter('role');
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\AdminRole;
|
||||
|
||||
class GetRoleRequest extends GetRolesRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested role exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$role = $this->route()->parameter('role');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetRolesRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = Acl::RESOURCE_ROLES;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = Acl::READ;
|
||||
protected string $resource = Acl::RESOURCE_ROLES;
|
||||
protected int $permission = Acl::READ;
|
||||
}
|
||||
|
@ -8,23 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreRoleRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_ROLES;
|
||||
protected string $resource = AdminAcl::RESOURCE_ROLES;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? AdminRole::getRules();
|
||||
|
@ -6,13 +6,6 @@ use Pterodactyl\Models\AdminRole;
|
||||
|
||||
class UpdateRoleRequest extends StoreRoleRequest
|
||||
{
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param array|null $rules
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
return $rules ?? AdminRole::getRulesForUpdate($this->route()->parameter('role')->id);
|
||||
|
@ -8,19 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class DeleteUserRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_USERS;
|
||||
protected string $resource = AdminAcl::RESOURCE_USERS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Determine if the requested user exists on the Panel.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$user = $this->route()->parameter('user');
|
||||
|
@ -10,24 +10,10 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetExternalUserRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $userModel;
|
||||
private User $userModel;
|
||||
protected string $resource = AdminAcl::RESOURCE_USERS;
|
||||
protected int $permission = AdminAcl::READ;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_USERS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::READ;
|
||||
|
||||
/**
|
||||
* Determine if the requested external user exists.
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$repository = $this->container->make(UserRepositoryInterface::class);
|
||||
@ -43,9 +29,6 @@ class GetExternalUserRequest extends ApplicationApiRequest
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the user model for the requested external user.
|
||||
*/
|
||||
public function getUserModel(): User
|
||||
{
|
||||
return $this->userModel;
|
||||
|
@ -6,11 +6,6 @@ use Pterodactyl\Models\User;
|
||||
|
||||
class GetUserRequest extends GetUsersRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the requested role exists on the Panel.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function resourceExists(): bool
|
||||
{
|
||||
$user = $this->route()->parameter('user');
|
||||
|
@ -7,13 +7,6 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class GetUsersRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = Acl::RESOURCE_USERS;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = Acl::READ;
|
||||
protected string $resource = Acl::RESOURCE_USERS;
|
||||
protected int $permission = Acl::READ;
|
||||
}
|
||||
|
@ -8,19 +8,9 @@ use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
|
||||
|
||||
class StoreUserRequest extends ApplicationApiRequest
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $resource = AdminAcl::RESOURCE_USERS;
|
||||
protected string $resource = AdminAcl::RESOURCE_USERS;
|
||||
protected int $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $permission = AdminAcl::WRITE;
|
||||
|
||||
/**
|
||||
* Return the validation rules for this request.
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
$rules = $rules ?? User::getRules();
|
||||
@ -40,10 +30,7 @@ class StoreUserRequest extends ApplicationApiRequest
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function validated()
|
||||
public function validated(): array
|
||||
{
|
||||
$data = parent::validated();
|
||||
|
||||
@ -55,12 +42,7 @@ class StoreUserRequest extends ApplicationApiRequest
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename some fields to be more user friendly.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'external_id' => 'Third Party Identifier',
|
||||
|
@ -6,13 +6,8 @@ use Pterodactyl\Models\User;
|
||||
|
||||
class UpdateUserRequest extends StoreUserRequest
|
||||
{
|
||||
/**
|
||||
* Return the validation rules for this request.
|
||||
*/
|
||||
public function rules(array $rules = null): array
|
||||
{
|
||||
$userId = $this->getModel(User::class)->id;
|
||||
|
||||
return parent::rules(User::getRulesForUpdate($userId));
|
||||
return parent::rules($rules ?? User::getRulesForUpdate($this->route()->parameter('user')->id));
|
||||
}
|
||||
}
|
||||
|
@ -17,20 +17,12 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
{
|
||||
public const RESPONSE_TIMEZONE = 'UTC';
|
||||
|
||||
/**
|
||||
* @var \Pterodactyl\Models\ApiKey
|
||||
*/
|
||||
private ApiKey $key;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private bool $rootAdmin;
|
||||
|
||||
/**
|
||||
* Return the resource name for the JSONAPI output.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getResourceName(): string;
|
||||
|
||||
@ -48,8 +40,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
/**
|
||||
* Set the HTTP request class being used for this request.
|
||||
*
|
||||
* @param \Pterodactyl\Models\ApiKey $key
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setKey(ApiKey $key)
|
||||
@ -61,8 +51,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
|
||||
/**
|
||||
* Return the request instance being used for this transformer.
|
||||
*
|
||||
* @return \Pterodactyl\Models\ApiKey
|
||||
*/
|
||||
public function getKey(): ApiKey
|
||||
{
|
||||
@ -72,8 +60,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @param bool $rootAdmin
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRootAdmin(bool $rootAdmin)
|
||||
@ -85,8 +71,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
|
||||
/**
|
||||
* ?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRootAdmin(): bool
|
||||
{
|
||||
@ -97,10 +81,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
* Determine if the API key loaded onto the transformer has permission
|
||||
* to access a different resource. This is used when including other
|
||||
* models on a transformation request.
|
||||
*
|
||||
* @param string $resource
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorize(string $resource): bool
|
||||
{
|
||||
@ -115,9 +95,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
* Create a new instance of the transformer and pass along the currently
|
||||
* set API key.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return \Pterodactyl\Transformers\Api\Application\BaseTransformer
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
@ -138,10 +115,6 @@ abstract class BaseTransformer extends TransformerAbstract
|
||||
|
||||
/**
|
||||
* Return an ISO-8601 formatted timestamp to use in the API response.
|
||||
*
|
||||
* @param string $timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function formatTimestamp(string $timestamp): string
|
||||
{
|
||||
|
@ -41,6 +41,7 @@ class LocationTransformer extends BaseTransformer
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
*/
|
||||
public function includeServers(Location $location)
|
||||
@ -59,7 +60,9 @@ class LocationTransformer extends BaseTransformer
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection|\League\Fractal\Resource\NullResource
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
* @throws \Pterodactyl\Exceptions\Transformer\InvalidTransformerLevelException
|
||||
|
||||
*/
|
||||
public function includeNodes(Location $location)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase
|
||||
['object', 'attributes' => ['id', 'short', 'long', 'created_at', 'updated_at']],
|
||||
['object', 'attributes' => ['id', 'short', 'long', 'created_at', 'updated_at']],
|
||||
],
|
||||
'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages']],
|
||||
'meta' => ['pagination' => ['total', 'count', 'per_page', 'current_page', 'total_pages', 'links']],
|
||||
]);
|
||||
|
||||
$response
|
||||
@ -38,9 +38,10 @@ class LocationControllerTest extends ApplicationApiIntegrationTestCase
|
||||
'pagination' => [
|
||||
'total' => 2,
|
||||
'count' => 2,
|
||||
'per_page' => 100,
|
||||
'per_page' => 10,
|
||||
'current_page' => 1,
|
||||
'total_pages' => 1,
|
||||
'links' => [],
|
||||
],
|
||||
],
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user