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:
@@ -11,6 +11,7 @@ use App\Jobs\VolumeCloneJob;
|
||||
use App\Models\Environment;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Support\ValidationPatterns;
|
||||
use Livewire\Component;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
@@ -42,14 +43,14 @@ class CloneMe extends Component
|
||||
|
||||
public bool $cloneVolumeData = false;
|
||||
|
||||
protected $messages = [
|
||||
'selectedServer' => 'Please select a server.',
|
||||
'selectedDestination' => 'Please select a server & destination.',
|
||||
'newName.required' => 'Please enter a name for the new project or environment.',
|
||||
'newName.regex' => 'The name may only contain letters, numbers, spaces, dashes, underscores, and dots.',
|
||||
'newName.min' => 'The name must be at least 3 characters.',
|
||||
'newName.max' => 'The name may not be greater than 255 characters.',
|
||||
];
|
||||
protected function messages(): array
|
||||
{
|
||||
return array_merge([
|
||||
'selectedServer' => 'Please select a server.',
|
||||
'selectedDestination' => 'Please select a server & destination.',
|
||||
'newName.required' => 'Please enter a name for the new project or environment.',
|
||||
], ValidationPatterns::nameMessages());
|
||||
}
|
||||
|
||||
public function mount($project_uuid)
|
||||
{
|
||||
@@ -93,7 +94,7 @@ class CloneMe extends Component
|
||||
try {
|
||||
$this->validate([
|
||||
'selectedDestination' => 'required',
|
||||
'newName' => ['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'],
|
||||
'newName' => ValidationPatterns::nameRules(),
|
||||
]);
|
||||
if ($type === 'project') {
|
||||
$foundProject = Project::where('name', $this->newName)->first();
|
||||
|
||||
Reference in New Issue
Block a user