feat(cleanup): add command for sanitizing name fields across models
- Introduced `CleanupNames` command to sanitize name fields by removing invalid characters, ensuring only letters, numbers, spaces, dashes, underscores, and dots are retained. - Implemented options for dry run, model-specific cleaning, database backup, and forced execution. - Updated `Init` command to call the new `cleanup:names` command. - Enhanced project and environment validation to enforce name sanitization rules. - Added `HasSafeNameAttribute` trait to relevant models for consistent name handling.
This commit is contained in:
@@ -9,12 +9,18 @@ use Visus\Cuid2\Cuid2;
|
||||
|
||||
class AddEmpty extends Component
|
||||
{
|
||||
#[Validate(['required', 'string', 'min:3'])]
|
||||
#[Validate(['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'])]
|
||||
public string $name;
|
||||
|
||||
#[Validate(['nullable', 'string'])]
|
||||
public string $description = '';
|
||||
|
||||
protected $messages = [
|
||||
'name.regex' => 'The name may only contain letters, numbers, spaces, dashes, underscores, and dots.',
|
||||
'name.min' => 'The name must be at least 3 characters.',
|
||||
'name.max' => 'The name may not be greater than 255 characters.',
|
||||
];
|
||||
|
||||
public function submit()
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -45,7 +45,10 @@ class CloneMe extends Component
|
||||
protected $messages = [
|
||||
'selectedServer' => 'Please select a server.',
|
||||
'selectedDestination' => 'Please select a server & destination.',
|
||||
'newName' => 'Please enter a name for the new project or environment.',
|
||||
'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.',
|
||||
];
|
||||
|
||||
public function mount($project_uuid)
|
||||
@@ -90,7 +93,7 @@ class CloneMe extends Component
|
||||
try {
|
||||
$this->validate([
|
||||
'selectedDestination' => 'required',
|
||||
'newName' => 'required',
|
||||
'newName' => ['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'],
|
||||
]);
|
||||
if ($type === 'project') {
|
||||
$foundProject = Project::where('name', $this->newName)->first();
|
||||
|
||||
@@ -10,12 +10,18 @@ class Edit extends Component
|
||||
{
|
||||
public Project $project;
|
||||
|
||||
#[Validate(['required', 'string', 'min:3', 'max:255'])]
|
||||
#[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 name may only contain letters, numbers, spaces, dashes, underscores, and dots.',
|
||||
'name.min' => 'The name must be at least 3 characters.',
|
||||
'name.max' => 'The name may not be greater than 255 characters.',
|
||||
];
|
||||
|
||||
public function mount(string $project_uuid)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -17,12 +17,18 @@ class EnvironmentEdit extends Component
|
||||
#[Locked]
|
||||
public $environment;
|
||||
|
||||
#[Validate(['required', 'string', 'min:3', 'max:255'])]
|
||||
#[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.',
|
||||
];
|
||||
|
||||
public function mount(string $project_uuid, string $environment_uuid)
|
||||
{
|
||||
try {
|
||||
|
||||
@@ -12,12 +12,18 @@ class Show extends Component
|
||||
{
|
||||
public Project $project;
|
||||
|
||||
#[Validate(['required', 'string', 'min:3'])]
|
||||
#[Validate(['required', 'string', 'min:3', 'max:255', 'regex:/^[a-zA-Z0-9\s\-_.]+$/'])]
|
||||
public string $name;
|
||||
|
||||
#[Validate(['nullable', 'string'])]
|
||||
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.',
|
||||
];
|
||||
|
||||
public function mount(string $project_uuid)
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user