Skip to content

Commit 8e1aa15

Browse files
committed
Fixes a bug that would cause non-editable variables on the front-end to throw a validation error
1 parent e2cdb3b commit 8e1aa15

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111
* `[rc.2]` — Fix data integrity exception occuring due to invalid data being passed to server creation service on the API.
1212
* `[rc.2]` — Fix data integrity exception that could occur when an email containing non-username characters was passed.
1313
* `[rc.2]` — Fix data integrity exception occurring when no default value is provided for an egg variable.
14+
* `[rc.2]` — Fixes a bug that would cause non-editable variables on the front-end to throw a validation error.
1415

1516
### Added
1617
* Added ability to search the following API endpoints: list users, list servers, and list locations.

app/Http/Controllers/Server/Settings/StartupController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function index(Request $request): View
8181
* @return \Illuminate\Http\RedirectResponse
8282
*
8383
* @throws \Pterodactyl\Exceptions\DisplayException
84+
* @throws \Illuminate\Validation\ValidationException
8485
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
8586
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
8687
*/

app/Services/Servers/VariableValidatorService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public function handle(int $egg, array $fields = []): Collection
7676

7777
$data = $rules = $customAttributes = [];
7878
foreach ($variables as $variable) {
79+
// Don't attempt to validate variables if they aren't user editable
80+
// and we're not running this at an admin level.
81+
if (! $variable->user_editable && ! $this->isUserLevel(User::USER_LEVEL_ADMIN)) {
82+
continue;
83+
}
84+
7985
$data['environment'][$variable->env_variable] = array_get($fields, $variable->env_variable);
8086
$rules['environment.' . $variable->env_variable] = $variable->rules;
8187
$customAttributes['environment.' . $variable->env_variable] = trans('validation.internal.variable_value', ['env' => $variable->name]);

tests/Unit/Services/Servers/VariableValidatorServiceTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,12 @@ public function testValidatorShouldThrowExceptionWhenAValidationErrorIsEncounter
128128
$messages = $exception->validator->getMessageBag()->all();
129129

130130
$this->assertNotEmpty($messages);
131-
$this->assertSame(4, count($messages));
131+
$this->assertSame(2, count($messages));
132132

133-
for ($i = 0; $i < 4; $i++) {
133+
// We only expect to get the first two variables form the getVariableCollection
134+
// function here since those are the only two that are editable, and the others
135+
// should be discarded and not validated.
136+
for ($i = 0; $i < 2; $i++) {
134137
$this->assertSame(trans('validation.required', [
135138
'attribute' => trans('validation.internal.variable_value', ['env' => $variables[$i]->name]),
136139
]), $messages[$i]);
@@ -148,8 +151,8 @@ private function getVariableCollection(): Collection
148151
return collect(
149152
[
150153
factory(EggVariable::class)->states('editable', 'viewable')->make(),
151-
factory(EggVariable::class)->states('viewable')->make(),
152154
factory(EggVariable::class)->states('editable')->make(),
155+
factory(EggVariable::class)->states('viewable')->make(),
153156
factory(EggVariable::class)->make(),
154157
]
155158
);

0 commit comments

Comments
 (0)