From f1d85c67f1a6f5ab36d3853975651a8e4fd2a23c Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 8 May 2023 14:12:54 -0700 Subject: [PATCH 1/5] Make validation match database fields Signed-off-by: snipe --- app/Models/Location.php | 11 ++++++----- app/Models/Supplier.php | 12 ++++++------ app/Models/User.php | 5 +++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/Models/Location.php b/app/Models/Location.php index c3ddaa7598..2f4e78dcc7 100755 --- a/app/Models/Location.php +++ b/app/Models/Location.php @@ -26,11 +26,12 @@ class Location extends SnipeModel protected $table = 'locations'; protected $rules = [ 'name' => 'required|min:2|max:255|unique_undeleted', - 'city' => 'min:2|max:255|nullable', - 'country' => 'min:2|max:255|nullable', - 'address' => 'max:80|nullable', - 'address2' => 'max:80|nullable', - 'zip' => 'min:3|max:12|nullable', + 'address' => 'max:191|nullable', + 'address2' => 'max:191|nullable', + 'city' => 'max:191|nullable', + 'state' => 'min:2|max:191|nullable', + 'country' => 'min:2|max:191|nullable', + 'zip' => 'max:10|nullable', 'manager_id' => 'exists:users,id|nullable', 'parent_id' => 'non_circular:locations,id', ]; diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index fa00fbad2a..e198d10c10 100755 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -16,17 +16,17 @@ class Supplier extends SnipeModel protected $table = 'suppliers'; protected $rules = [ - 'name' => 'required|min:1|max:255|unique_undeleted', - 'address' => 'max:250|nullable', - 'address2' => 'max:250|nullable', - 'city' => 'max:255|nullable', - 'state' => 'max:32|nullable', - 'country' => 'max:3|nullable', + 'name' => 'required|min:1|max:255|unique_undeleted', 'fax' => 'min:7|max:35|nullable', 'phone' => 'min:7|max:35|nullable', 'contact' => 'max:100|nullable', 'notes' => 'max:191|nullable', // Default string length is 191 characters.. 'email' => 'email|max:150|nullable', + 'address' => 'max:250|nullable', + 'address2' => 'max:250|nullable', + 'city' => 'max:191|nullable', + 'state' => 'min:2|max:191|nullable', + 'country' => 'min:2|max:191|nullable', 'zip' => 'max:10|nullable', 'url' => 'sometimes|nullable|string|max:250', ]; diff --git a/app/Models/User.php b/app/Models/User.php index 36e1c8ac47..1e63ebad71 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -98,6 +98,11 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo 'start_date' => 'nullable|date_format:Y-m-d', 'end_date' => 'nullable|date_format:Y-m-d|after_or_equal:start_date', 'autoassign_licenses' => 'boolean', + 'address' => 'max:191|nullable', + 'city' => 'max:191|nullable', + 'state' => 'min:2|max:191|nullable', + 'country' => 'min:2|max:191|nullable', + 'zip' => 'max:10|nullable', ]; /** From f84f4ffe9950e2c14daa70ae959b37cb87ad0aa4 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 8 May 2023 14:13:06 -0700 Subject: [PATCH 2/5] Migration to embiggen state fields Signed-off-by: snipe --- ...8_132921_increase_state_to_more_than_3.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 database/migrations/2023_05_08_132921_increase_state_to_more_than_3.php diff --git a/database/migrations/2023_05_08_132921_increase_state_to_more_than_3.php b/database/migrations/2023_05_08_132921_increase_state_to_more_than_3.php new file mode 100644 index 0000000000..7ffc0c3860 --- /dev/null +++ b/database/migrations/2023_05_08_132921_increase_state_to_more_than_3.php @@ -0,0 +1,40 @@ +string('state', 191)->nullable()->default(null)->change(); + }); + + Schema::table('suppliers', function (Blueprint $table) { + $table->string('state', 191)->nullable()->default(null)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('users', function (Blueprint $table) { + $table->string('state', 3)->nullable()->default(null)->change(); + }); + + Schema::table('suppliers', function (Blueprint $table) { + $table->string('state', 32)->nullable()->default(null)->change(); + }); + } +} From 277618bf16a3fee912b2e8cbab695169ca15da31 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 8 May 2023 14:13:24 -0700 Subject: [PATCH 3/5] Added maxlenth to form fields Signed-off-by: snipe --- resources/views/partials/forms/edit/address.blade.php | 10 +++++----- resources/views/users/edit.blade.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/partials/forms/edit/address.blade.php b/resources/views/partials/forms/edit/address.blade.php index b33673381a..c8bf734033 100644 --- a/resources/views/partials/forms/edit/address.blade.php +++ b/resources/views/partials/forms/edit/address.blade.php @@ -1,7 +1,7 @@
{{ Form::label('address', trans('general.address'), array('class' => 'col-md-3 control-label')) }}
- {{Form::text('address', old('address', $item->address), array('class' => 'form-control', 'aria-label'=>'address')) }} + {{Form::text('address', old('address', $item->address), array('class' => 'form-control', 'aria-label'=>'address', 'maxlength'=>'191')) }} {!! $errors->first('address', '') !!}
@@ -9,13 +9,13 @@
- {{Form::text('address2', old('address2', $item->address2), array('class' => 'form-control', 'aria-label'=>'address2')) }} + {{Form::text('address2', old('address2', $item->address2), array('class' => 'form-control', 'aria-label'=>'address2', 'maxlength'=>'191')) }} {!! $errors->first('address2', '') !!}
- {{ Form::label('city', trans('general.city'), array('class' => 'col-md-3 control-label')) }} + {{ Form::label('city', trans('general.city'), array('class' => 'col-md-3 control-label', 'maxlength'=>'191')) }}
{{Form::text('city', old('city', $item->city), array('class' => 'form-control', 'aria-label'=>'city')) }} {!! $errors->first('city', '') !!} @@ -23,7 +23,7 @@
- {{ Form::label('state', trans('general.state'), array('class' => 'col-md-3 control-label')) }} + {{ Form::label('state', trans('general.state'), array('class' => 'col-md-3 control-label', 'maxlength'=>'191')) }}
{{Form::text('state', old('state', $item->state), array('class' => 'form-control', 'aria-label'=>'state')) }} {!! $errors->first('state', '') !!} @@ -40,7 +40,7 @@
- {{ Form::label('zip', trans('general.zip'), array('class' => 'col-md-3 control-label')) }} + {{ Form::label('zip', trans('general.zip'), array('class' => 'col-md-3 control-label', 'maxlength'=>'10')) }}
{{Form::text('zip', old('zip', $item->zip), array('class' => 'form-control')) }} {!! $errors->first('zip', '') !!} diff --git a/resources/views/users/edit.blade.php b/resources/views/users/edit.blade.php index 34005e9bc7..a8b5ddf05e 100755 --- a/resources/views/users/edit.blade.php +++ b/resources/views/users/edit.blade.php @@ -441,7 +441,7 @@
- + {!! $errors->first('state', '') !!}
From 5960a5425d561271ba0b35da50b8d8bcdd56fa92 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 8 May 2023 14:48:26 -0700 Subject: [PATCH 4/5] Pass filename to pre-import backup Signed-off-by: snipe --- app/Http/Controllers/Api/ImportController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ImportController.php b/app/Http/Controllers/Api/ImportController.php index 914c16f8da..2d7e2f7d78 100644 --- a/app/Http/Controllers/Api/ImportController.php +++ b/app/Http/Controllers/Api/ImportController.php @@ -160,7 +160,7 @@ class ImportController extends Controller // Run a backup immediately before processing if ($request->get('run-backup')) { \Log::debug('Backup manually requested via importer'); - Artisan::call('backup:run'); + Artisan::call('snipeit:backup', ['--filename' => 'pre-import-backup-'.date('Y-m-d-H:i:s')]); } else { \Log::debug('NO BACKUP requested via importer'); } From 332b017dccc6b815f3f7804fad44d52eb2313fe9 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 8 May 2023 15:00:02 -0700 Subject: [PATCH 5/5] Pass filename for manual backups Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index c65dbc7d27..c626203cfc 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -1094,7 +1094,7 @@ class SettingsController extends Controller public function postBackups() { if (! config('app.lock_passwords')) { - Artisan::call('backup:run'); + Artisan::call('snipeit:backup', ['--filename' => 'manual-backup-'.date('Y-m-d-H:i:s')]); $output = Artisan::output(); // Backup completed