feat(validation): centralize validation patterns for names and descriptions
- Introduced `ValidationPatterns` class to standardize validation rules and messages for name and description fields across the application. - Updated various components and models to utilize the new validation patterns, ensuring consistent sanitization and validation logic. - Replaced the `HasSafeNameAttribute` trait with `HasSafeStringAttribute` to enhance attribute handling and maintain consistency in name sanitization. - Enhanced the `CleanupNames` command to align with the new validation rules, allowing for a broader range of valid characters in names.
This commit is contained in:
@@ -4,8 +4,8 @@ namespace App\Livewire\Project;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Models\Project;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Validate;
|
||||
use Livewire\Component;
|
||||
|
||||
class EnvironmentEdit extends Component
|
||||
@@ -17,17 +17,22 @@ class EnvironmentEdit extends Component
|
||||
#[Locked]
|
||||
public $environment;
|
||||
|
||||
#[Validate(['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'])]
|
||||
public string $name;
|
||||
|
||||
#[Validate(['nullable', 'string', 'max:255'])]
|
||||
public ?string $description = null;
|
||||
|
||||
protected $messages = [
|
||||
'name.regex' => 'The environment name may only contain letters, numbers, spaces, dashes, underscores, and dots.',
|
||||
'name.min' => 'The environment name must be at least 3 characters.',
|
||||
'name.max' => 'The environment name may not be greater than 255 characters.',
|
||||
];
|
||||
protected function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => ValidationPatterns::nameRules(),
|
||||
'description' => ValidationPatterns::descriptionRules(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function messages(): array
|
||||
{
|
||||
return ValidationPatterns::combinedMessages();
|
||||
}
|
||||
|
||||
public function mount(string $project_uuid, string $environment_uuid)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user