From 43d8474caa4f5ff39c61493a067ecd113f3b13dc Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 6 Feb 2024 17:45:46 -0600 Subject: [PATCH 01/30] a note to remember this tomorrow --- app/Http/Controllers/AssetModelsController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 012f40e39..02d940455 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -513,6 +513,8 @@ class AssetModelsController extends Controller $validator = Validator::make($data, $rules); + // Okay, this is the problem. Seems to be failing every time, kind of makes sense because it looks like + // $rules is an empty array, but I need to wrap my head around this entire method a little more. if($validator->fails()){ return false; } From bcfa913450e96f1248fd45fcaa61c8bc8b79f1e6 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 7 Feb 2024 20:03:37 -0600 Subject: [PATCH 02/30] condition makes this work, needs more testing --- app/Http/Controllers/AssetModelsController.php | 4 ++-- app/Models/CustomFieldset.php | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 02d940455..f1a8c85c2 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -11,6 +11,7 @@ use App\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Input; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Validator; use Redirect; @@ -513,9 +514,8 @@ class AssetModelsController extends Controller $validator = Validator::make($data, $rules); - // Okay, this is the problem. Seems to be failing every time, kind of makes sense because it looks like - // $rules is an empty array, but I need to wrap my head around this entire method a little more. if($validator->fails()){ + Log::debug($validator->errors()); return false; } diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index a62f96d63..0d0f3974f 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -92,8 +92,11 @@ class CustomFieldset extends Model array_push($rule, $field->attributes['format']); $rules[$field->db_column_name()] = $rule; - //add not_array to rules for all fields - $rules[$field->db_column_name()][] = 'not_array'; + // add not_array to rules for all fields + // condition added to fix issue with model default updates + if ($field->element != 'checkbox') { + $rules[$field->db_column_name()][] = 'not_array'; + } } return $rules; From d55358652bc33acd49b153ce81c2379acc1432e3 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 13 Feb 2024 13:45:56 -0600 Subject: [PATCH 03/30] cleanup for pr --- app/Http/Controllers/AssetModelsController.php | 2 -- app/Models/CustomFieldset.php | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index f1a8c85c2..012f40e39 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -11,7 +11,6 @@ use App\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Input; -use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\Validator; use Redirect; @@ -515,7 +514,6 @@ class AssetModelsController extends Controller $validator = Validator::make($data, $rules); if($validator->fails()){ - Log::debug($validator->errors()); return false; } diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index 0d0f3974f..e9be7c53c 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -93,7 +93,7 @@ class CustomFieldset extends Model array_push($rule, $field->attributes['format']); $rules[$field->db_column_name()] = $rule; // add not_array to rules for all fields - // condition added to fix issue with model default updates + // temporary condition added to fix issue with model default updates in the gui if ($field->element != 'checkbox') { $rules[$field->db_column_name()][] = 'not_array'; } From dcf2168454245f1d84a4c8ee3f2c6e706ffc744f Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 13 Feb 2024 19:35:37 -0600 Subject: [PATCH 04/30] initial stuff, need to switch branches --- app/Models/CustomFieldset.php | 7 +++++++ app/Providers/ValidationServiceProvider.php | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index e9be7c53c..373c137bc 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -5,6 +5,8 @@ namespace App\Models; use Gate; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Log; +use Illuminate\Validation\Rule; use Watson\Validating\ValidatingTrait; class CustomFieldset extends Model @@ -97,6 +99,11 @@ class CustomFieldset extends Model if ($field->element != 'checkbox') { $rules[$field->db_column_name()][] = 'not_array'; } + if ($field->element == 'checkbox') { + //Log::alert($field->formatFieldValuesAsArray()); + $values = $field->formatFieldValuesAsArray(); + //$rules[$field->db_column_name()] = 'checkboxes'; + } } return $rules; diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 50468c8d7..754c2de9a 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -2,9 +2,11 @@ namespace App\Providers; +use App\Models\CustomField; use App\Models\Department; use App\Models\Setting; use DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\Rule; use Validator; @@ -294,6 +296,25 @@ class ValidationServiceProvider extends ServiceProvider Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) { return !is_array($value); }); + + Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){ + $options = CustomField::where('db_column', $attribute)->formatFieldValuesAsArray(); + if(!is_array($value)) { + $exploded = explode(',', $value); + $valid = array_intersect($exploded, $options); + if(array_count_values($valid) > 0) { + return true; + } + } + if(is_array($value)) { + $valid = array_intersect($value, $options); + if(array_count_values($valid) > 0) { + return true; + } + } + + + }); } /** From 57a75e68b91e765b6ac205b66db851a1cdb87085 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 00:52:50 -0600 Subject: [PATCH 05/30] maybe i do the inverse here? --- app/Models/CustomFieldset.php | 2 +- app/Providers/ValidationServiceProvider.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index 373c137bc..c73d277a1 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -102,7 +102,7 @@ class CustomFieldset extends Model if ($field->element == 'checkbox') { //Log::alert($field->formatFieldValuesAsArray()); $values = $field->formatFieldValuesAsArray(); - //$rules[$field->db_column_name()] = 'checkboxes'; + $rules[$field->db_column_name()] = 'checkboxes'; } } diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 754c2de9a..860564ec1 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -298,15 +298,15 @@ class ValidationServiceProvider extends ServiceProvider }); Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){ - $options = CustomField::where('db_column', $attribute)->formatFieldValuesAsArray(); + $options = CustomField::where('db_column', $attribute)->first()->formatFieldValuesAsArray(); + // for legacy, allows users to submit a comma separated string of options if(!is_array($value)) { $exploded = explode(',', $value); - $valid = array_intersect($exploded, $options); - if(array_count_values($valid) > 0) { - return true; + $invalid = array_diff($exploded, $options); + if(count($invalid) > 0) { + return false; } - } - if(is_array($value)) { + } else { $valid = array_intersect($value, $options); if(array_count_values($valid) > 0) { return true; From 25241542d2b74c27f03062895ff260e833d11695 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 02:12:31 -0600 Subject: [PATCH 06/30] progress, going to sleep --- .../Controllers/AssetModelsController.php | 6 ++++-- app/Models/CustomFieldset.php | 2 +- app/Providers/ValidationServiceProvider.php | 19 ++++++++++--------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 012f40e39..455fc8249 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -7,6 +7,7 @@ use App\Http\Requests\ImageUploadRequest; use App\Models\Actionlog; use App\Models\Asset; use App\Models\AssetModel; +use App\Models\CustomField; use App\Models\User; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -169,6 +170,7 @@ class AssetModelsController extends Controller if ($this->shouldAddDefaultValues($request->input())) { if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ + //TODO: this needs to return the actual validation errors, will come back to this before opening PR return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error')); } } @@ -489,11 +491,11 @@ class AssetModelsController extends Controller * @param array $defaultValues * @return void */ - private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues) + private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues): bool { $data = array(); foreach ($defaultValues as $customFieldId => $defaultValue) { - $customField = \App\Models\CustomField::find($customFieldId); + $customField = CustomField::find($customFieldId); $data[$customField->db_column] = $defaultValue; } diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index c73d277a1..f5e9897dd 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -102,7 +102,7 @@ class CustomFieldset extends Model if ($field->element == 'checkbox') { //Log::alert($field->formatFieldValuesAsArray()); $values = $field->formatFieldValuesAsArray(); - $rules[$field->db_column_name()] = 'checkboxes'; + $rules[$field->db_column_name()][] = 'checkboxes'; } } diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 860564ec1..0bd201a26 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -297,23 +297,24 @@ class ValidationServiceProvider extends ServiceProvider return !is_array($value); }); + // This is only used in Models/CustomFieldset.php - it does automatic validation for checkboxes by making sure + // that the submitted values actually exist in the options. Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){ $options = CustomField::where('db_column', $attribute)->first()->formatFieldValuesAsArray(); + if(is_array($value)) { + $invalid = array_diff($value, $options); + if(count($invalid) > 0) { + return false; + } + } // for legacy, allows users to submit a comma separated string of options - if(!is_array($value)) { + elseif(!is_array($value)) { $exploded = explode(',', $value); $invalid = array_diff($exploded, $options); if(count($invalid) > 0) { return false; } - } else { - $valid = array_intersect($value, $options); - if(array_count_values($valid) > 0) { - return true; - } - } - - + } else return true; }); } From 72c118a70f2704fb4dc4c038ef16cdc159e996ec Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 11:41:46 -0600 Subject: [PATCH 07/30] cleanup --- app/Models/CustomFieldset.php | 7 +++---- app/Providers/ValidationServiceProvider.php | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index f5e9897dd..4d960ede4 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -94,14 +94,13 @@ class CustomFieldset extends Model array_push($rule, $field->attributes['format']); $rules[$field->db_column_name()] = $rule; - // add not_array to rules for all fields - // temporary condition added to fix issue with model default updates in the gui + + // add not_array to rules for all fields but checkboxes if ($field->element != 'checkbox') { $rules[$field->db_column_name()][] = 'not_array'; } + if ($field->element == 'checkbox') { - //Log::alert($field->formatFieldValuesAsArray()); - $values = $field->formatFieldValuesAsArray(); $rules[$field->db_column_name()][] = 'checkboxes'; } } diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 0bd201a26..835587571 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -314,7 +314,8 @@ class ValidationServiceProvider extends ServiceProvider if(count($invalid) > 0) { return false; } - } else return true; + } + return true; }); } From d9c61fdb025e2751af0584ca2d275a8ead7be570 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 11:52:25 -0600 Subject: [PATCH 08/30] validation msg --- app/Http/Controllers/AssetModelsController.php | 3 +-- resources/lang/en-US/validation.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 455fc8249..34f12b826 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -169,8 +169,7 @@ class AssetModelsController extends Controller $model->fieldset_id = $request->input('fieldset_id'); if ($this->shouldAddDefaultValues($request->input())) { - if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ - //TODO: this needs to return the actual validation errors, will come back to this before opening PR + if ($msg = !$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error')); } } diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 1c6ad8a14..98084afcd 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -105,6 +105,7 @@ return [ 'gte' => [ 'numeric' => 'Value cannot be negative' ], + 'checkboxes' => ':attribute contains invalid options.', /* From fb28882f65d5832b4b7d744af8790c93efaeb35e Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 11:59:14 -0600 Subject: [PATCH 09/30] trim potential spaces --- app/Providers/ValidationServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 835587571..02a2bf313 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -309,7 +309,7 @@ class ValidationServiceProvider extends ServiceProvider } // for legacy, allows users to submit a comma separated string of options elseif(!is_array($value)) { - $exploded = explode(',', $value); + $exploded = array_map('trim', explode(',', $value)); $invalid = array_diff($exploded, $options); if(count($invalid) > 0) { return false; From 1ceb703129974e05e4f77e82a3895bb6b1778070 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 12:44:09 -0600 Subject: [PATCH 10/30] rm var --- app/Http/Controllers/AssetModelsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index 34f12b826..aa4c9dd23 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -169,7 +169,7 @@ class AssetModelsController extends Controller $model->fieldset_id = $request->input('fieldset_id'); if ($this->shouldAddDefaultValues($request->input())) { - if ($msg = !$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ + if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error')); } } From 115e0fc11927e0196bd37f2cc6f3a8168f06019f Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 14 Feb 2024 13:15:23 -0600 Subject: [PATCH 11/30] implode submitted arrays to save --- app/Http/Controllers/Api/AssetsController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index f5168a591..6ef3b3050 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -584,6 +584,11 @@ class AssetsController extends Controller } } } + if ($field->element == 'checkbox') { + if(is_array($field_val)) { + $field_val = implode(',', $field_val); + } + } $asset->{$field->db_column} = $field_val; From c6d85a1b0bb15102a4f1c1e1d15e6633be342996 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 20 Feb 2024 12:23:24 -0600 Subject: [PATCH 12/30] allows arrays on checkbox values --- app/Http/Controllers/Api/AssetsController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 6ef3b3050..dbeb1b6c6 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -663,6 +663,11 @@ class AssetsController extends Controller $asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column)); } } else { + if ($field->element == 'checkbox') { + if(is_array($field_val)) { + $field_val = implode(',', $field_val); + } + } $asset->{$field->db_column} = $request->input($field->db_column); } } From 26728a85addc318c86677b1095377f9e2506bf7f Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 20 Feb 2024 13:18:40 -0600 Subject: [PATCH 13/30] this seems to work for patches --- app/Http/Controllers/Api/AssetsController.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index dbeb1b6c6..292276628 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -556,7 +556,7 @@ class AssetsController extends Controller $model = AssetModel::find($request->input('model_id')); // Check that it's an object and not a collection - // (Sometimes people send arrays here and they shouldn't + // (Sometimes people send arrays here and they shouldn't, unless it's a checkbox) if (($model) && ($model instanceof AssetModel) && ($model->fieldset)) { foreach ($model->fieldset->fields as $field) { @@ -657,18 +657,21 @@ class AssetsController extends Controller // Update custom fields if (($model) && (isset($model->fieldset))) { foreach ($model->fieldset->fields as $field) { + $field_val = $request->input($field->db_column, null); if ($request->has($field->db_column)) { if ($field->field_encrypted == '1') { if (Gate::allows('admin')) { - $asset->{$field->db_column} = \Crypt::encrypt($request->input($field->db_column)); + $asset->{$field->db_column} = Crypt::encrypt($field_val); } - } else { - if ($field->element == 'checkbox') { - if(is_array($field_val)) { - $field_val = implode(',', $field_val); - } + } + if ($field->element == 'checkbox') { + if(is_array($field_val)) { + $field_val = implode(',', $field_val); + $asset->{$field->db_column} = $field_val; } - $asset->{$field->db_column} = $request->input($field->db_column); + } + else { + $asset->{$field->db_column} = $field_val; } } } From d67ff54f4b29e2c8d3d1b5b395cc938df3aa03f5 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 20 Feb 2024 16:20:03 -0600 Subject: [PATCH 14/30] temporary decrypt, almost there --- app/Providers/ValidationServiceProvider.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 02a2bf313..80697ce45 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -6,6 +6,7 @@ use App\Models\CustomField; use App\Models\Department; use App\Models\Setting; use DB; +use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\Log; use Illuminate\Support\ServiceProvider; use Illuminate\Validation\Rule; @@ -300,13 +301,22 @@ class ValidationServiceProvider extends ServiceProvider // This is only used in Models/CustomFieldset.php - it does automatic validation for checkboxes by making sure // that the submitted values actually exist in the options. Validator::extend('checkboxes', function ($attribute, $value, $parameters, $validator){ - $options = CustomField::where('db_column', $attribute)->first()->formatFieldValuesAsArray(); + $field = CustomField::where('db_column', $attribute)->first(); + $options = $field->formatFieldValuesAsArray(); + + // temporarily decrypt for validation + if($field->field_encrypted) { + $value = Crypt::decrypt($value); + } + dump(is_array($value)); + if(is_array($value)) { $invalid = array_diff($value, $options); if(count($invalid) > 0) { return false; } } + // for legacy, allows users to submit a comma separated string of options elseif(!is_array($value)) { $exploded = array_map('trim', explode(',', $value)); @@ -315,6 +325,7 @@ class ValidationServiceProvider extends ServiceProvider return false; } } + return true; }); } From 20dbacd22f5c35a3b5c1a6cb4865d205019e1fe4 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 21 Feb 2024 21:33:34 -0600 Subject: [PATCH 15/30] store good, update needs work --- app/Http/Controllers/Api/AssetsController.php | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 292276628..75d64d440 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -585,6 +585,16 @@ class AssetsController extends Controller } } if ($field->element == 'checkbox') { + if ($field->field_encrypted) { + // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array + $field_val_decrypt = Crypt::decrypt($field_val); + if (is_array($field_val_decrypt)) { + $field_val_decrypt_imploded = implode(',', $field_val_decrypt); + $field_val = Crypt::encrypt($field_val_decrypt_imploded); + } else + $field_val = Crypt::encrypt($field_val_decrypt); + + } if(is_array($field_val)) { $field_val = implode(',', $field_val); } @@ -665,6 +675,16 @@ class AssetsController extends Controller } } if ($field->element == 'checkbox') { + //if ($field->field_encrypted) { + // // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array + // $field_val_decrypt = Crypt::decrypt($field_val); + // if (is_array($field_val_decrypt)) { + // $field_val_decrypt_imploded = implode(',', $field_val_decrypt); + // $field_val = Crypt::encrypt($field_val_decrypt_imploded); + // } else + // $field_val = Crypt::encrypt($field_val_decrypt); + // + //} if(is_array($field_val)) { $field_val = implode(',', $field_val); $asset->{$field->db_column} = $field_val; From 14358651e491fb2725ff1af5b0050675e25c4f49 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 22 Feb 2024 13:28:23 -0600 Subject: [PATCH 16/30] pushing to test other branches --- app/Http/Controllers/Api/AssetsController.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 75d64d440..c3d4ce8d2 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -668,23 +668,26 @@ class AssetsController extends Controller if (($model) && (isset($model->fieldset))) { foreach ($model->fieldset->fields as $field) { $field_val = $request->input($field->db_column, null); + if ($request->has($field->db_column)) { + //if ($field->field_encrypted) { + // // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array + // $field_val_decrypt = Crypt::decrypt($field_val); + // if (is_array($field_val_decrypt)) { + // $field_val_decrypt_imploded = implode(',', $field_val_decrypt); + // $field_val = Crypt::encrypt($field_val_decrypt_imploded); + // } else + // $field_val = Crypt::encrypt($field_val_decrypt); + // + //} if ($field->field_encrypted == '1') { if (Gate::allows('admin')) { $asset->{$field->db_column} = Crypt::encrypt($field_val); } } + if ($field->element == 'checkbox') { - //if ($field->field_encrypted) { - // // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array - // $field_val_decrypt = Crypt::decrypt($field_val); - // if (is_array($field_val_decrypt)) { - // $field_val_decrypt_imploded = implode(',', $field_val_decrypt); - // $field_val = Crypt::encrypt($field_val_decrypt_imploded); - // } else - // $field_val = Crypt::encrypt($field_val_decrypt); - // - //} + if(is_array($field_val)) { $field_val = implode(',', $field_val); $asset->{$field->db_column} = $field_val; From b6fa6cba2244926071281789c2c2fdfead7e2874 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 22 Feb 2024 15:01:14 -0600 Subject: [PATCH 17/30] note before switching tasks --- app/Providers/ValidationServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 80697ce45..71c24694d 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -305,6 +305,8 @@ class ValidationServiceProvider extends ServiceProvider $options = $field->formatFieldValuesAsArray(); // temporarily decrypt for validation + // so, this is breaking patches, i don't really get why. + // is it not encrypted here on an update? need to do more testing. :( if($field->field_encrypted) { $value = Crypt::decrypt($value); } From ad0f873ecee737c73b8d157b89001146c14437ba Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Mar 2024 11:58:00 -0600 Subject: [PATCH 18/30] rm validation stuff --- app/Http/Controllers/Api/AssetsController.php | 22 ------------------- app/Providers/ValidationServiceProvider.php | 8 ------- 2 files changed, 30 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index c3d4ce8d2..7b3db3090 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -585,16 +585,6 @@ class AssetsController extends Controller } } if ($field->element == 'checkbox') { - if ($field->field_encrypted) { - // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array - $field_val_decrypt = Crypt::decrypt($field_val); - if (is_array($field_val_decrypt)) { - $field_val_decrypt_imploded = implode(',', $field_val_decrypt); - $field_val = Crypt::encrypt($field_val_decrypt_imploded); - } else - $field_val = Crypt::encrypt($field_val_decrypt); - - } if(is_array($field_val)) { $field_val = implode(',', $field_val); } @@ -670,24 +660,12 @@ class AssetsController extends Controller $field_val = $request->input($field->db_column, null); if ($request->has($field->db_column)) { - //if ($field->field_encrypted) { - // // to not break a bunch of stuff, we must decrypt + implode if the checkbox value is an array - // $field_val_decrypt = Crypt::decrypt($field_val); - // if (is_array($field_val_decrypt)) { - // $field_val_decrypt_imploded = implode(',', $field_val_decrypt); - // $field_val = Crypt::encrypt($field_val_decrypt_imploded); - // } else - // $field_val = Crypt::encrypt($field_val_decrypt); - // - //} if ($field->field_encrypted == '1') { if (Gate::allows('admin')) { $asset->{$field->db_column} = Crypt::encrypt($field_val); } } - if ($field->element == 'checkbox') { - if(is_array($field_val)) { $field_val = implode(',', $field_val); $asset->{$field->db_column} = $field_val; diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 71c24694d..d13898fb3 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -304,14 +304,6 @@ class ValidationServiceProvider extends ServiceProvider $field = CustomField::where('db_column', $attribute)->first(); $options = $field->formatFieldValuesAsArray(); - // temporarily decrypt for validation - // so, this is breaking patches, i don't really get why. - // is it not encrypted here on an update? need to do more testing. :( - if($field->field_encrypted) { - $value = Crypt::decrypt($value); - } - dump(is_array($value)); - if(is_array($value)) { $invalid = array_diff($value, $options); if(count($invalid) > 0) { From af06b1cd06fb2e11a1e93bf4a96939d44992c668 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Mar 2024 13:37:30 -0600 Subject: [PATCH 19/30] hide encryption option for checkbox and radio --- resources/views/custom_fields/fields/edit.blade.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index 504b556fa..fa869bc37 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -135,7 +135,7 @@ @if (!$field->id) -
+
- @endif @@ -302,11 +301,21 @@ $(this).find("option:selected").each(function(){ if (($(this).attr("value")!="text") && ($(this).attr("value")!="textarea")){ $("#field_values_text").show(); + if ($(this).attr("value") == "checkbox" || $(this).attr("value") == "radio") { + $("#encryption_section").hide(); + } } else{ + $("#encryption_section").show(); $("#field_values_text").hide(); } }); }).change(); + // $(".field_element").change(function(){ + // $(this).find("option:selected").each(function(){ + // if + // }) + // }) + }); From a251e61d73a11a853250934c17235fabb19dc2d4 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Mar 2024 13:40:44 -0600 Subject: [PATCH 20/30] rm commented code and add comment --- resources/views/custom_fields/fields/edit.blade.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index fa869bc37..e21e9fba4 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -297,6 +297,7 @@ }).change(); // Only display the field element if the type is not text + // and don't display encryption option for checkbox or radio $(".field_element").change(function(){ $(this).find("option:selected").each(function(){ if (($(this).attr("value")!="text") && ($(this).attr("value")!="textarea")){ @@ -310,12 +311,6 @@ } }); }).change(); - // $(".field_element").change(function(){ - // $(this).find("option:selected").each(function(){ - // if - // }) - // }) - }); From 3a0a13d06d377bc86695006885730f57cb641bc2 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Mar 2024 16:35:06 -0600 Subject: [PATCH 21/30] tests written but something not working... --- tests/Feature/Api/Assets/AssetStoreTest.php | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php index 92a58a500..f7a0aaf6d 100644 --- a/tests/Feature/Api/Assets/AssetStoreTest.php +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -438,4 +438,70 @@ class AssetStoreTest extends TestCase $json->has('messages.company_id')->etc(); }); } + + public function testCustomFieldCheckboxPassesValidationForValidOptionsWithString() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => 'One, Two, Three', + ]) + ->assertOk() + ->assertStatusMessageIs('success'); + } + + public function testCustomFieldCheckboxPassesValidationForValidOptionsWithArray() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => ['One', 'Two', 'Three'], + ]) + ->assertOk() + ->assertStatusMessageIs('success'); + } + + public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithString() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => "One, Two, Four, Five", + ]) + ->assertStatusMessageIs('error'); + } + + public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithArray() + { + $model = AssetModel::factory()->create(); + $status = Statuslabel::factory()->create(); + + $this->settings->enableAutoIncrement(); + + $this->actingAsForApi(User::factory()->createAssets()->create()) + ->postJson(route('api.assets.store'), [ + 'model_id' => $model->id, + 'status_id' => $status->id, + '_snipeit_test_checkbox_7' => ['One', 'Two', 'Four', 'Five'] + ]) + ->assertStatusMessageIs('error'); + } } From 04e0a9d4a560dfcdaa1f1a1b3b71af3c35e2da0c Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Fri, 8 Mar 2024 13:14:59 -0600 Subject: [PATCH 22/30] commented tests for now --- tests/Feature/Api/Assets/AssetStoreTest.php | 134 ++++++++++---------- 1 file changed, 69 insertions(+), 65 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php index f7a0aaf6d..cafd71f55 100644 --- a/tests/Feature/Api/Assets/AssetStoreTest.php +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -439,69 +439,73 @@ class AssetStoreTest extends TestCase }); } - public function testCustomFieldCheckboxPassesValidationForValidOptionsWithString() - { - $model = AssetModel::factory()->create(); - $status = Statuslabel::factory()->create(); - - $this->settings->enableAutoIncrement(); - - $this->actingAsForApi(User::factory()->createAssets()->create()) - ->postJson(route('api.assets.store'), [ - 'model_id' => $model->id, - 'status_id' => $status->id, - '_snipeit_test_checkbox_7' => 'One, Two, Three', - ]) - ->assertOk() - ->assertStatusMessageIs('success'); - } - - public function testCustomFieldCheckboxPassesValidationForValidOptionsWithArray() - { - $model = AssetModel::factory()->create(); - $status = Statuslabel::factory()->create(); - - $this->settings->enableAutoIncrement(); - - $this->actingAsForApi(User::factory()->createAssets()->create()) - ->postJson(route('api.assets.store'), [ - 'model_id' => $model->id, - 'status_id' => $status->id, - '_snipeit_test_checkbox_7' => ['One', 'Two', 'Three'], - ]) - ->assertOk() - ->assertStatusMessageIs('success'); - } - - public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithString() - { - $model = AssetModel::factory()->create(); - $status = Statuslabel::factory()->create(); - - $this->settings->enableAutoIncrement(); - - $this->actingAsForApi(User::factory()->createAssets()->create()) - ->postJson(route('api.assets.store'), [ - 'model_id' => $model->id, - 'status_id' => $status->id, - '_snipeit_test_checkbox_7' => "One, Two, Four, Five", - ]) - ->assertStatusMessageIs('error'); - } - - public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithArray() - { - $model = AssetModel::factory()->create(); - $status = Statuslabel::factory()->create(); - - $this->settings->enableAutoIncrement(); - - $this->actingAsForApi(User::factory()->createAssets()->create()) - ->postJson(route('api.assets.store'), [ - 'model_id' => $model->id, - 'status_id' => $status->id, - '_snipeit_test_checkbox_7' => ['One', 'Two', 'Four', 'Five'] - ]) - ->assertStatusMessageIs('error'); - } + // Commenting these tests because they should be good, but there's a factory problem with + // custom fields that's preventing them from working properly. Leaving them here for now + // so that we can uncomment once we figure out how to resolve that. + //public function testCustomFieldCheckboxPassesValidationForValidOptionsWithString() + //{ + // $model = AssetModel::factory()->create(); + // $status = Statuslabel::factory()->create(); + // + // + // $this->settings->enableAutoIncrement(); + // + // $this->actingAsForApi(User::factory()->createAssets()->create()) + // ->postJson(route('api.assets.store'), [ + // 'model_id' => $model->id, + // 'status_id' => $status->id, + // '_snipeit_test_checkbox_7' => 'One, Two, Three', + // ]) + // ->assertOk() + // ->assertStatusMessageIs('success'); + //} + // + //public function testCustomFieldCheckboxPassesValidationForValidOptionsWithArray() + //{ + // $model = AssetModel::factory()->create(); + // $status = Statuslabel::factory()->create(); + // + // $this->settings->enableAutoIncrement(); + // + // $this->actingAsForApi(User::factory()->createAssets()->create()) + // ->postJson(route('api.assets.store'), [ + // 'model_id' => $model->id, + // 'status_id' => $status->id, + // '_snipeit_test_checkbox_7' => ['One', 'Two', 'Three'], + // ]) + // ->assertOk() + // ->assertStatusMessageIs('success'); + //} + // + //public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithString() + //{ + // $model = AssetModel::factory()->mbp13Model()->create(); + // $status = Statuslabel::factory()->create(); + // + // $this->settings->enableAutoIncrement(); + // + // $this->actingAsForApi(User::factory()->createAssets()->create()) + // ->postJson(route('api.assets.store'), [ + // 'model_id' => $model->id, + // 'status_id' => $status->id, + // '_snipeit_test_checkbox_7' => "One, Two, Four, Five", + // ]) + // ->assertStatusMessageIs('error'); + //} + // + //public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithArray() + //{ + // $model = AssetModel::factory()->mbp13Model()->create(); + // $status = Statuslabel::factory()->create(); + // + // $this->settings->enableAutoIncrement(); + // + // $this->actingAsForApi(User::factory()->createAssets()->create()) + // ->postJson(route('api.assets.store'), [ + // 'model_id' => $model->id, + // 'status_id' => $status->id, + // '_snipeit_test_checkbox_7' => ['One', 'Two', 'Four', 'Five'] + // ]) + // ->assertStatusMessageIs('error'); + //} } From 7e4a0eedf0c5e062ca85618bb8e52fb39d93d4e5 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Mon, 25 Mar 2024 10:46:26 -0500 Subject: [PATCH 23/30] rm dumb note --- app/Http/Controllers/Api/AssetsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index 7b3db3090..ecd0ff7a0 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -556,7 +556,7 @@ class AssetsController extends Controller $model = AssetModel::find($request->input('model_id')); // Check that it's an object and not a collection - // (Sometimes people send arrays here and they shouldn't, unless it's a checkbox) + // (Sometimes people send arrays here and they shouldn't if (($model) && ($model instanceof AssetModel) && ($model->fieldset)) { foreach ($model->fieldset->fields as $field) { From 9b40c9788fc349972e6d45eb4a4a019c28000b97 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Mon, 25 Mar 2024 18:58:49 -0500 Subject: [PATCH 24/30] rm commented tests --- tests/Feature/Api/Assets/AssetStoreTest.php | 70 --------------------- 1 file changed, 70 deletions(-) diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php index cafd71f55..92a58a500 100644 --- a/tests/Feature/Api/Assets/AssetStoreTest.php +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -438,74 +438,4 @@ class AssetStoreTest extends TestCase $json->has('messages.company_id')->etc(); }); } - - // Commenting these tests because they should be good, but there's a factory problem with - // custom fields that's preventing them from working properly. Leaving them here for now - // so that we can uncomment once we figure out how to resolve that. - //public function testCustomFieldCheckboxPassesValidationForValidOptionsWithString() - //{ - // $model = AssetModel::factory()->create(); - // $status = Statuslabel::factory()->create(); - // - // - // $this->settings->enableAutoIncrement(); - // - // $this->actingAsForApi(User::factory()->createAssets()->create()) - // ->postJson(route('api.assets.store'), [ - // 'model_id' => $model->id, - // 'status_id' => $status->id, - // '_snipeit_test_checkbox_7' => 'One, Two, Three', - // ]) - // ->assertOk() - // ->assertStatusMessageIs('success'); - //} - // - //public function testCustomFieldCheckboxPassesValidationForValidOptionsWithArray() - //{ - // $model = AssetModel::factory()->create(); - // $status = Statuslabel::factory()->create(); - // - // $this->settings->enableAutoIncrement(); - // - // $this->actingAsForApi(User::factory()->createAssets()->create()) - // ->postJson(route('api.assets.store'), [ - // 'model_id' => $model->id, - // 'status_id' => $status->id, - // '_snipeit_test_checkbox_7' => ['One', 'Two', 'Three'], - // ]) - // ->assertOk() - // ->assertStatusMessageIs('success'); - //} - // - //public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithString() - //{ - // $model = AssetModel::factory()->mbp13Model()->create(); - // $status = Statuslabel::factory()->create(); - // - // $this->settings->enableAutoIncrement(); - // - // $this->actingAsForApi(User::factory()->createAssets()->create()) - // ->postJson(route('api.assets.store'), [ - // 'model_id' => $model->id, - // 'status_id' => $status->id, - // '_snipeit_test_checkbox_7' => "One, Two, Four, Five", - // ]) - // ->assertStatusMessageIs('error'); - //} - // - //public function testCustomFieldCheckboxFailsValidationForInvalidOptionsWithArray() - //{ - // $model = AssetModel::factory()->mbp13Model()->create(); - // $status = Statuslabel::factory()->create(); - // - // $this->settings->enableAutoIncrement(); - // - // $this->actingAsForApi(User::factory()->createAssets()->create()) - // ->postJson(route('api.assets.store'), [ - // 'model_id' => $model->id, - // 'status_id' => $status->id, - // '_snipeit_test_checkbox_7' => ['One', 'Two', 'Four', 'Five'] - // ]) - // ->assertStatusMessageIs('error'); - //} } From 581560792421a53fbb698716be4cd5d73cd57cce Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 25 Mar 2024 17:45:41 -0700 Subject: [PATCH 25/30] Add validation for pwd_secure_complexity --- app/Http/Controllers/SettingsController.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index b1cb620a8..dbb6f6622 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -20,6 +20,7 @@ use DB; use enshrined\svgSanitize\Sanitizer; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; +use Illuminate\Validation\Rule; use Image; use Input; use Redirect; @@ -499,6 +500,19 @@ class SettingsController extends Controller */ public function postSecurity(Request $request) { + $this->validate($request, [ + 'pwd_secure_complexity' => 'array', + 'pwd_secure_complexity.*' => [ + Rule::in([ + 'disallow_same_pwd_as_user_fields', + 'letters', + 'numbers', + 'symbols', + 'case_diff', + ]) + ] + ]); + if (is_null($setting = Setting::getSettings())) { return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error')); } From bd506820b7144da54cfcc1d1f26221773a602863 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 25 Mar 2024 17:59:39 -0700 Subject: [PATCH 26/30] Display error message --- resources/views/settings/security.blade.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/resources/views/settings/security.blade.php b/resources/views/settings/security.blade.php index a23b8cece..baacb4144 100644 --- a/resources/views/settings/security.blade.php +++ b/resources/views/settings/security.blade.php @@ -74,12 +74,11 @@ -
+
{{ Form::label('pwd_secure_complexity', trans('admin/settings/general.pwd_secure_complexity')) }}
- + @if ($errors->has('pwd_secure_complexity.*')) + Invalid value included in this field + @endif

{{ trans('admin/settings/general.pwd_secure_complexity_help') }}

From 5cf1a6c3006c4ca82c8251c751aa311c79cbdd4e Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Mon, 25 Mar 2024 21:03:13 -0500 Subject: [PATCH 27/30] new validator for radio buttons --- app/Models/CustomFieldset.php | 4 ++++ app/Providers/ValidationServiceProvider.php | 8 ++++++++ resources/lang/en-US/validation.php | 1 + 3 files changed, 13 insertions(+) diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index 4d960ede4..71be28e8a 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -103,6 +103,10 @@ class CustomFieldset extends Model if ($field->element == 'checkbox') { $rules[$field->db_column_name()][] = 'checkboxes'; } + + if ($field->element == 'radio') { + $rules[$field->db_column_name()][] = 'radio_buttons'; + } } return $rules; diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index d13898fb3..803d54086 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -322,6 +322,14 @@ class ValidationServiceProvider extends ServiceProvider return true; }); + + // Validates that a radio button option exists + Validator::extend('radio_buttons', function ($attribute, $value) { + $field = CustomField::where('db_column', $attribute)->first(); + $options = $field->formatFieldValuesAsArray(); + + return in_array($value, $options); + }); } /** diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 98084afcd..d027a93f8 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -106,6 +106,7 @@ return [ 'numeric' => 'Value cannot be negative' ], 'checkboxes' => ':attribute contains invalid options.', + 'radio_buttons' => ':attribute is invalid.', /* From b5b8777c9486d86832035b8c5d283d62121f0499 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 26 Mar 2024 12:23:57 -0700 Subject: [PATCH 28/30] Extract translation string --- resources/lang/en-US/validation.php | 6 ++++++ resources/views/settings/security.blade.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/lang/en-US/validation.php b/resources/lang/en-US/validation.php index 1c6ad8a14..9298bc106 100644 --- a/resources/lang/en-US/validation.php +++ b/resources/lang/en-US/validation.php @@ -151,4 +151,10 @@ return [ 'attributes' => [], + /* + |-------------------------------------------------------------------------- + | Generic Validation Messages + |-------------------------------------------------------------------------- + */ + 'invalid_value_in_field' => 'Invalid value included in this field', ]; diff --git a/resources/views/settings/security.blade.php b/resources/views/settings/security.blade.php index baacb4144..f108683dc 100644 --- a/resources/views/settings/security.blade.php +++ b/resources/views/settings/security.blade.php @@ -106,7 +106,7 @@ @if ($errors->has('pwd_secure_complexity.*')) - Invalid value included in this field + {{ trans('validation.invalid_value_in_field') }} @endif

{{ trans('admin/settings/general.pwd_secure_complexity_help') }} From 8bc9688d719d84a657cb7455dc88604be291fca2 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Mar 2024 16:04:00 +0000 Subject: [PATCH 29/30] =?UTF-8?q?Added=20ability=20to=20filter=20on=20cate?= =?UTF-8?q?gory=20ID=20and=20model=20ID=20from=20user=E2=80=99s=20asset=20?= =?UTF-8?q?API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 21 +++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index e9551d51a..5ef45ee4d 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -560,7 +560,26 @@ class UsersController extends Controller { $this->authorize('view', User::class); $this->authorize('view', Asset::class); - $assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model')->get(); + $assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model'); + + + // Filter on category ID + if ($request->filled('category_id')) { + $assets = $assets->InCategory($request->input('category_id')); + } + + + // Filter on model ID + if ($request->filled('model_id')) { + + $model_ids = $request->input('model_id'); + if (!is_array($model_ids)) { + $model_ids = array($model_ids); + } + $assets = $assets->InModelList($model_ids); + } + + $assets = $assets->get(); return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request); } From 60c678680ae50666168e6d9ede7f132c1c405146 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 27 Mar 2024 16:12:57 +0000 Subject: [PATCH 30/30] [Snyk] Upgrade alpinejs from 3.13.5 to 3.13.6 Signed-off-by: snipe --- package-lock.json | 6 +++--- package.json | 2 +- public/js/dist/all-defer.js | 40 ++++++++++++++++++++++--------------- public/mix-manifest.json | 2 +- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3a81578e6..37902c1ff 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2379,9 +2379,9 @@ } }, "alpinejs": { - "version": "3.13.5", - "resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-3.13.5.tgz", - "integrity": "sha512-1d2XeNGN+Zn7j4mUAKXtAgdc4/rLeadyTMWeJGXF5DzwawPBxwTiBhFFm6w/Ei8eJxUZeyNWWSD9zknfdz1kEw==", + "version": "3.13.7", + "resolved": "https://registry.npmjs.org/alpinejs/-/alpinejs-3.13.7.tgz", + "integrity": "sha512-rcTyjTANbsePq1hb7eSekt3qjI94HLGeO6JaRjCssCVbIIc+qBrc7pO5S/+2JB6oojIibjM6FA+xRI3zhGPZIg==", "requires": { "@vue/reactivity": "~3.1.1" } diff --git a/package.json b/package.json index f02b78db0..fab86d9d2 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "acorn-import-assertions": "^1.9.0", "admin-lte": "^2.4.18", "ajv": "^6.12.6", - "alpinejs": "^3.13.5", + "alpinejs": "^3.13.6", "blueimp-file-upload": "^9.34.0", "bootstrap": "^3.4.1", "bootstrap-colorpicker": "^2.5.3", diff --git a/public/js/dist/all-defer.js b/public/js/dist/all-defer.js index 50470c93f..5d43f61e3 100644 --- a/public/js/dist/all-defer.js +++ b/public/js/dist/all-defer.js @@ -211,8 +211,8 @@ }); }); } - function destroyTree(root) { - walk(root, (el) => { + function destroyTree(root, walker = walk) { + walker(root, (el) => { cleanupAttributes(el); cleanupElement(el); }); @@ -413,7 +413,7 @@ if (name == Symbol.unscopables) return false; return objects.some( - (obj) => Object.prototype.hasOwnProperty.call(obj, name) + (obj) => Object.prototype.hasOwnProperty.call(obj, name) || Reflect.has(obj, name) ); }, get({ objects }, name, thisProxy) { @@ -421,7 +421,7 @@ return collapseProxies; return Reflect.get( objects.find( - (obj) => Object.prototype.hasOwnProperty.call(obj, name) + (obj) => Reflect.has(obj, name) ) || {}, name, thisProxy @@ -452,6 +452,8 @@ Object.entries(Object.getOwnPropertyDescriptors(obj)).forEach(([key, { value, enumerable }]) => { if (enumerable === false || value === void 0) return; + if (typeof value === "object" && value !== null && value.__v_skip) + return; let path = basePath === "" ? key : `${basePath}.${key}`; if (typeof value === "object" && value !== null && value._x_interceptor) { obj[key] = value.initialize(data2, path, key); @@ -1619,7 +1621,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); get raw() { return raw; }, - version: "3.13.5", + version: "3.13.7", flushAndStopDeferringMutations, dontAutoEvaluateFunctions, disableEffectScheduling, @@ -2423,12 +2425,10 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); }); function getArrayOfRefObject(el) { let refObjects = []; - let currentEl = el; - while (currentEl) { - if (currentEl._x_refs) - refObjects.push(currentEl._x_refs); - currentEl = currentEl.parentNode; - } + findClosest(el, (i) => { + if (i._x_refs) + refObjects.push(i._x_refs); + }); return refObjects; } @@ -3088,13 +3088,21 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); if (isObject2(items)) { items = Object.entries(items).map(([key, value]) => { let scope2 = getIterationScopeVariables(iteratorNames, value, key, items); - evaluateKey((value2) => keys.push(value2), { scope: { index: key, ...scope2 } }); + evaluateKey((value2) => { + if (keys.includes(value2)) + warn("Duplicate key on x-for", el); + keys.push(value2); + }, { scope: { index: key, ...scope2 } }); scopes.push(scope2); }); } else { for (let i = 0; i < items.length; i++) { let scope2 = getIterationScopeVariables(iteratorNames, items[i], i, items); - evaluateKey((value) => keys.push(value), { scope: { index: i, ...scope2 } }); + evaluateKey((value) => { + if (keys.includes(value)) + warn("Duplicate key on x-for", el); + keys.push(value); + }, { scope: { index: i, ...scope2 } }); scopes.push(scope2); } } @@ -3142,7 +3150,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); let marker = document.createElement("div"); mutateDom(() => { if (!elForSpot) - warn(`x-for ":key" is undefined or invalid`, templateEl); + warn(`x-for ":key" is undefined or invalid`, templateEl, keyForSpot, lookup); elForSpot.after(marker); elInSpot.after(elForSpot); elForSpot._x_currentIfEl && elForSpot.after(elForSpot._x_currentIfEl); @@ -3169,7 +3177,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); }; mutateDom(() => { lastEl.after(clone2); - initTree(clone2); + skipDuringClone(() => initTree(clone2))(); }); if (typeof key === "object") { warn("x-for key cannot be an object, it must be a string or an integer", templateEl); @@ -3253,7 +3261,7 @@ ${expression ? 'Expression: "' + expression + '"\n\n' : ""}`, el); addScopeToNode(clone2, {}, el); mutateDom(() => { el.after(clone2); - initTree(clone2); + skipDuringClone(() => initTree(clone2))(); }); el._x_currentIfEl = clone2; el._x_undoIf = () => { diff --git a/public/mix-manifest.json b/public/mix-manifest.json index 68309ab7e..0c7d2c8a8 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -33,7 +33,7 @@ "/js/build/vendor.js": "/js/build/vendor.js?id=a2b971da417306a63385c8098acfe4af", "/js/dist/bootstrap-table.js": "/js/dist/bootstrap-table.js?id=857da5daffd13e0553510e5ccd410c79", "/js/dist/all.js": "/js/dist/all.js?id=13bdb521e0c745d7f81dae3fb110b650", - "/js/dist/all-defer.js": "/js/dist/all-defer.js?id=19ccc62a8f1ea103dede4808837384d4", + "/js/dist/all-defer.js": "/js/dist/all-defer.js?id=18d36546bdad8285c229008df799b343", "/css/dist/skins/skin-green.min.css": "/css/dist/skins/skin-green.min.css?id=0a82a6ae6bb4e58fe62d162c4fb50397", "/css/dist/skins/skin-green-dark.min.css": "/css/dist/skins/skin-green-dark.min.css?id=d419cb63a12dc175d71645c876bfc2ab", "/css/dist/skins/skin-black.min.css": "/css/dist/skins/skin-black.min.css?id=76482123f6c70e866d6b971ba91de7bb",