mirror of
https://github.com/pterodactyl/panel.git
synced 2024-11-22 09:02:28 +01:00
Add support for filtering allocations to determine if they're assigned or not; closes #3872
This commit is contained in:
parent
1ae98604a4
commit
634b80ed42
@ -5,6 +5,9 @@ namespace Pterodactyl\Http\Controllers\Api\Application\Nodes;
|
||||
use Pterodactyl\Models\Node;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Pterodactyl\Models\Allocation;
|
||||
use Spatie\QueryBuilder\QueryBuilder;
|
||||
use Spatie\QueryBuilder\AllowedFilter;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Pterodactyl\Services\Allocations\AssignmentService;
|
||||
use Pterodactyl\Services\Allocations\AllocationDeletionService;
|
||||
use Pterodactyl\Transformers\Api\Application\AllocationTransformer;
|
||||
@ -43,7 +46,20 @@ class AllocationController extends ApplicationApiController
|
||||
*/
|
||||
public function index(GetAllocationsRequest $request, Node $node): array
|
||||
{
|
||||
$allocations = $node->allocations()->paginate($request->query('per_page') ?? 50);
|
||||
$allocations = QueryBuilder::for($node->allocations())
|
||||
->allowedFilters([
|
||||
AllowedFilter::exact('ip'),
|
||||
AllowedFilter::exact('port'),
|
||||
'ip_alias',
|
||||
AllowedFilter::callback('server_id', function (Builder $builder, $value) {
|
||||
if (empty($value) || is_bool($value) || !ctype_digit((string) $value)) {
|
||||
return $builder->whereNull('server_id');
|
||||
}
|
||||
|
||||
return $builder->where('server_id', $value);
|
||||
}),
|
||||
])
|
||||
->paginate($request->query('per_page') ?? 50);
|
||||
|
||||
return $this->fractal->collection($allocations)
|
||||
->transformWith($this->getTransformer(AllocationTransformer::class))
|
||||
|
Loading…
Reference in New Issue
Block a user