Add validation & missing reserved vars to EggVariables (#954)

* Add validation & Add missing reserved vars

* env_var not env_name 🤦‍

* Custom validationMessages
This commit is contained in:
MartinOscar 2025-01-28 14:22:03 +01:00 committed by GitHub
parent e352754e6f
commit dde5305b3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View File

@ -4,6 +4,7 @@ namespace App\Filament\Admin\Resources\EggResource\Pages;
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
use App\Filament\Admin\Resources\EggResource;
use App\Models\EggVariable;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Hidden;
@ -189,8 +190,11 @@ class CreateEgg extends CreateRecord
->hintIcon('tabler-code')
->hintIconTooltip(fn ($state) => "{{{$state}}}")
->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
->rules(EggVariable::$validationRules['env_variable'])
->validationMessages([
'unique' => 'A variable with this name already exists.',
'required' => ' The environment variable field is required.',
'*' => 'This environment variable is reserved and cannot be used.',
])
->required(),
TextInput::make('default_value')->maxLength(255),

View File

@ -8,6 +8,7 @@ use App\Filament\Admin\Resources\EggResource\RelationManagers\ServersRelationMan
use App\Filament\Components\Actions\ExportEggAction;
use App\Filament\Components\Actions\ImportEggAction;
use App\Models\Egg;
use App\Models\EggVariable;
use Filament\Actions\DeleteAction;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Fieldset;
@ -180,8 +181,11 @@ class EditEgg extends EditRecord
->hintIcon('tabler-code')
->hintIconTooltip(fn ($state) => "{{{$state}}}")
->unique(modifyRuleUsing: fn (Unique $rule, Get $get) => $rule->where('egg_id', $get('../../id')), ignoreRecord: true)
->rules(EggVariable::$validationRules['env_variable'])
->validationMessages([
'unique' => 'A variable with this name already exists.',
'required' => ' The environment variable field is required.',
'*' => 'This environment variable is reserved and cannot be used.',
])
->required(),
TextInput::make('default_value')->maxLength(255),

View File

@ -37,7 +37,7 @@ class EggVariable extends Model
/**
* Reserved environment variable names.
*/
public const RESERVED_ENV_NAMES = 'SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,SERVER_UUID,UUID';
public const RESERVED_ENV_NAMES = 'P_SERVER_UUID,P_SERVER_ALLOCATION_LIMIT,SERVER_MEMORY,SERVER_IP,SERVER_PORT,ENV,HOME,USER,STARTUP,MODIFIED_STARTUP,SERVER_UUID,UUID,INTERNAL_IP';
/**
* The table associated with the model.