Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation & missing reserved vars to EggVariables #954

Merged
merged 5 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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;
Expand Down Expand Up @@ -189,8 +190,11 @@ public function form(Form $form): Form
->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.',
RMartinOscar marked this conversation as resolved.
Show resolved Hide resolved
])
->required(),
TextInput::make('default_value')->maxLength(255),
Expand Down
4 changes: 4 additions & 0 deletions app/Filament/Admin/Resources/EggResource/Pages/EditEgg.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -180,8 +181,11 @@ public function form(Form $form): Form
->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),
Expand Down
2 changes: 1 addition & 1 deletion app/Models/EggVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading