diff --git a/CHANGELOG.md b/CHANGELOG.md index 61985f147..a5f0db8b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines. * `[rc.2]` — Fix data integrity exception occuring due to invalid data being passed to server creation service on the API. * `[rc.2]` — Fix data integrity exception that could occur when an email containing non-username characters was passed. * `[rc.2]` — Fix data integrity exception occurring when no default value is provided for an egg variable. +* `[rc.2]` — Fixes a bug that would cause non-editable variables on the front-end to throw a validation error. ### Added * Added ability to search the following API endpoints: list users, list servers, and list locations. diff --git a/app/Http/Controllers/Server/Settings/StartupController.php b/app/Http/Controllers/Server/Settings/StartupController.php index 789926922..8f17022b5 100644 --- a/app/Http/Controllers/Server/Settings/StartupController.php +++ b/app/Http/Controllers/Server/Settings/StartupController.php @@ -81,6 +81,7 @@ class StartupController extends Controller * @return \Illuminate\Http\RedirectResponse * * @throws \Pterodactyl\Exceptions\DisplayException + * @throws \Illuminate\Validation\ValidationException * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ diff --git a/app/Services/Servers/VariableValidatorService.php b/app/Services/Servers/VariableValidatorService.php index 54183f492..43685cafb 100644 --- a/app/Services/Servers/VariableValidatorService.php +++ b/app/Services/Servers/VariableValidatorService.php @@ -76,6 +76,12 @@ class VariableValidatorService $data = $rules = $customAttributes = []; foreach ($variables as $variable) { + // Don't attempt to validate variables if they aren't user editable + // and we're not running this at an admin level. + if (! $variable->user_editable && ! $this->isUserLevel(User::USER_LEVEL_ADMIN)) { + continue; + } + $data['environment'][$variable->env_variable] = array_get($fields, $variable->env_variable); $rules['environment.' . $variable->env_variable] = $variable->rules; $customAttributes['environment.' . $variable->env_variable] = trans('validation.internal.variable_value', ['env' => $variable->name]); diff --git a/tests/Unit/Services/Servers/VariableValidatorServiceTest.php b/tests/Unit/Services/Servers/VariableValidatorServiceTest.php index 5af49f436..0ce14eec2 100644 --- a/tests/Unit/Services/Servers/VariableValidatorServiceTest.php +++ b/tests/Unit/Services/Servers/VariableValidatorServiceTest.php @@ -128,9 +128,12 @@ class VariableValidatorServiceTest extends TestCase $messages = $exception->validator->getMessageBag()->all(); $this->assertNotEmpty($messages); - $this->assertSame(4, count($messages)); + $this->assertSame(2, count($messages)); - for ($i = 0; $i < 4; $i++) { + // We only expect to get the first two variables form the getVariableCollection + // function here since those are the only two that are editable, and the others + // should be discarded and not validated. + for ($i = 0; $i < 2; $i++) { $this->assertSame(trans('validation.required', [ 'attribute' => trans('validation.internal.variable_value', ['env' => $variables[$i]->name]), ]), $messages[$i]); @@ -148,8 +151,8 @@ class VariableValidatorServiceTest extends TestCase return collect( [ factory(EggVariable::class)->states('editable', 'viewable')->make(), - factory(EggVariable::class)->states('viewable')->make(), factory(EggVariable::class)->states('editable')->make(), + factory(EggVariable::class)->states('viewable')->make(), factory(EggVariable::class)->make(), ] );