1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-11-26 02:52:30 +01:00

Allow setting the backup limit via the API; closes #2535

This commit is contained in:
Dane Everitt 2020-10-17 14:23:00 -07:00
parent 35f24e7f22
commit 5763493c6c
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
5 changed files with 14 additions and 9 deletions

View File

@ -55,6 +55,7 @@ class StoreServerRequest extends ApplicationApiRequest
'feature_limits' => 'required|array',
'feature_limits.databases' => $rules['database_limit'],
'feature_limits.allocations' => $rules['allocation_limit'],
'feature_limits.backups' => $rules['backup_limit'],
// Placeholders for rules added in withValidator() function.
'allocation.default' => '',
@ -102,6 +103,7 @@ class StoreServerRequest extends ApplicationApiRequest
'start_on_completion' => array_get($data, 'start_on_completion', false),
'database_limit' => array_get($data, 'feature_limits.databases'),
'allocation_limit' => array_get($data, 'feature_limits.allocations'),
'backup_limit' => array_get($data, 'feature_limits.backups'),
];
}

View File

@ -47,6 +47,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
'feature_limits' => 'required|array',
'feature_limits.databases' => $rules['database_limit'],
'feature_limits.allocations' => $rules['allocation_limit'],
'feature_limits.backups' => $rules['backup_limit'],
];
}
@ -60,8 +61,9 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
$data = parent::validated();
$data['allocation_id'] = $data['allocation'];
$data['database_limit'] = $data['feature_limits']['databases'];
$data['allocation_limit'] = $data['feature_limits']['allocations'];
$data['database_limit'] = $data['feature_limits']['databases'] ?? null;
$data['allocation_limit'] = $data['feature_limits']['allocations'] ?? null;
$data['backup_limit'] = $data['feature_limits']['backups'] ?? null;
unset($data['allocation'], $data['feature_limits']);
// Adjust the limits field to match what is expected by the model.
@ -90,6 +92,7 @@ class UpdateServerBuildConfigurationRequest extends ServerWriteRequest
'remove_allocations.*' => 'allocation to remove',
'feature_limits.databases' => 'Database Limit',
'feature_limits.allocations' => 'Allocation Limit',
'feature_limits.backups' => 'Backup Limit',
];
}

View File

@ -122,7 +122,7 @@ class Server extends Model
'installed' => 'in:0,1,2',
'database_limit' => 'present|nullable|integer|min:0',
'allocation_limit' => 'sometimes|nullable|integer|min:0',
'backup_limit' => 'present|integer|min:0',
'backup_limit' => 'present|nullable|integer|min:0',
];
/**

View File

@ -101,9 +101,9 @@ class BuildModificationService
'threads' => array_get($data, 'threads'),
'disk' => array_get($data, 'disk'),
'allocation_id' => array_get($data, 'allocation_id'),
'database_limit' => array_get($data, 'database_limit', 0),
'allocation_limit' => array_get($data, 'allocation_limit', 0),
'backup_limit' => array_get($data, 'backup_limit', 0),
'database_limit' => array_get($data, 'database_limit', 0) ?? null,
'allocation_limit' => array_get($data, 'allocation_limit', 0) ?? null,
'backup_limit' => array_get($data, 'backup_limit', 0) ?? null,
]);
$updateData = $this->structureService->handle($server);

View File

@ -144,9 +144,9 @@ class ServerCreationServiceTest extends IntegrationTestCase
$this->assertFalse($response->suspended);
$this->assertTrue($response->oom_disabled);
$this->assertEmpty($response->database_limit);
$this->assertEmpty($response->allocation_limit);
$this->assertEmpty($response->backup_limit);
$this->assertSame(0, $response->database_limit);
$this->assertSame(0, $response->allocation_limit);
$this->assertSame(0, $response->backup_limit);
}
/**