Finish putting permissions on the API

This commit is contained in:
Dane Everitt 2018-01-13 14:08:19 -06:00
parent d644a53951
commit 11c4f3f6f2
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 434 additions and 82 deletions

View file

@ -0,0 +1,41 @@
<?php
namespace Pterodactyl\Http\Requests\API\Admin\Allocations;
use Pterodactyl\Models\Node;
use Pterodactyl\Models\Allocation;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\API\Admin\ApiAdminRequest;
class DeleteAllocationRequest extends ApiAdminRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
/**
* @var int
*/
protected $permission = AdminAcl::WRITE;
/**
* Determine if the requested allocation exists and belongs to the node that
* is being passed in the URL.
*
* @return bool
*/
public function resourceExists(): bool
{
$node = $this->route()->parameter('node');
$allocation = $this->route()->parameter('allocation');
if ($node instanceof Node && $node->exists) {
if ($allocation instanceof Allocation && $allocation->exists && $allocation->node_id === $node->id) {
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Pterodactyl\Http\Requests\API\Admin\Allocations;
use Pterodactyl\Models\Node;
use Pterodactyl\Services\Acl\Api\AdminAcl;
use Pterodactyl\Http\Requests\API\Admin\ApiAdminRequest;
class GetAllocationsRequest extends ApiAdminRequest
{
/**
* @var string
*/
protected $resource = AdminAcl::RESOURCE_ALLOCATIONS;
/**
* @var int
*/
protected $permission = AdminAcl::READ;
/**
* Determine if the node that we are requesting the allocations
* for exists on the Panel.
*
* @return bool
*/
public function resourceExists(): bool
{
$node = $this->route()->parameter('node');
return $node instanceof Node && $node->exists;
}
}