ui(admin): allow editing allocations for servers

This commit is contained in:
Matthew Penner 2021-09-15 15:37:17 -06:00
parent 656ac62ad2
commit a6ab61adba
No known key found for this signature in database
GPG key ID: 030E4AB751DC756F
13 changed files with 219 additions and 84 deletions

View file

@ -6,6 +6,8 @@ use Pterodactyl\Models\Node;
use Illuminate\Http\Response;
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\Exceptions\Http\QueryValueOutOfRangeHttpException;
@ -46,7 +48,16 @@ class AllocationController extends ApplicationApiController
}
$allocations = QueryBuilder::for(Allocation::query()->where('node_id', '=', $node->id))
->allowedFilters(['id', 'ip', 'port', 'alias', 'server_id'])
->allowedFilters([
'id', 'ip', 'port', 'alias',
AllowedFilter::callback('server_id', function (Builder $query, $value) {
if ($value === '0') {
$query->whereNull('server_id');
} else {
$query->where('server_id', '=', $value);
}
}),
])
->allowedSorts(['id', 'ip', 'port', 'server_id'])
->paginate($perPage);

View file

@ -28,6 +28,12 @@ class UpdateServerRequest extends ApplicationApiRequest
'databases' => $rules['database_limit'],
'allocations' => $rules['allocation_limit'],
'backups' => $rules['backup_limit'],
'allocation_id' => 'bail|exists:allocations,id',
'add_allocations' => 'bail|array',
'add_allocations.*' => 'integer',
'remove_allocations' => 'bail|array',
'remove_allocations.*' => 'integer',
];
}
@ -52,6 +58,10 @@ class UpdateServerRequest extends ApplicationApiRequest
'database_limit' => array_get($data, 'databases'),
'allocation_limit' => array_get($data, 'allocations'),
'backup_limit' => array_get($data, 'backups'),
'allocation_id' => array_get($data, 'allocation_id'),
'add_allocations' => array_get($data, 'add_allocations'),
'remove_allocations' => array_get($data, 'remove_allocations'),
];
}
}