From e73b16846e79284751c39c101aa5d4f701d13e73 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 11 Sep 2023 11:21:56 -0700 Subject: [PATCH 001/172] adds an option to bulk edit actual location for bulk edit and fixes update issue --- app/Http/Controllers/Assets/BulkAssetsController.php | 8 +++++++- resources/lang/en/admin/hardware/form.php | 1 + resources/views/hardware/bulk.blade.php | 8 ++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index a744db5788..c3c7e21ab0 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -189,9 +189,15 @@ class BulkAssetsController extends Controller } if ($request->filled('rtd_location_id')) { - $this->update_array['rtd_location_id'] = $request->input('rtd_location_id'); + if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '0')) { + $this->update_array['rtd_location_id'] = $request->input('rtd_location_id'); + } if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '1')) { $this->update_array['location_id'] = $request->input('rtd_location_id'); + $this->update_array['rtd_location_id'] = $request->input('rtd_location_id'); + } + if (($request->filled('update_real_loc')) && (($request->input('update_real_loc')) == '2')) { + $this->update_array['location_id'] = $request->input('rtd_location_id'); } } diff --git a/resources/lang/en/admin/hardware/form.php b/resources/lang/en/admin/hardware/form.php index ef877c8377..ee3fa20fb0 100644 --- a/resources/lang/en/admin/hardware/form.php +++ b/resources/lang/en/admin/hardware/form.php @@ -49,6 +49,7 @@ return [ 'asset_location' => 'Update Asset Location', 'asset_location_update_default_current' => 'Update default location AND actual location', 'asset_location_update_default' => 'Update only default location', + 'asset_location_update_actual' => 'Update only actual location', 'asset_not_deployable' => 'That asset status is not deployable. This asset cannot be checked out.', 'asset_deployable' => 'That status is deployable. This asset can be checked out.', 'processing_spinner' => 'Processing... (This might take a bit of time on large files)', diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index 667126ec99..e26b957057 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -92,9 +92,13 @@ {{ Form::radio('update_real_loc', '1', old('update_real_loc'), ['checked'=> 'checked', 'aria-label'=>'update_real_loc']) }} {{ trans('admin/hardware/form.asset_location_update_default_current') }} + From 74a891afbb2d86bdbca6baa824a710c4a8dcd168 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 27 Sep 2023 15:58:01 -0700 Subject: [PATCH 002/172] WIP: Render select box for field options in label engine --- .../label2-field-definitions.blade.php | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index 6522b951d8..5bc473418f 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -304,7 +304,52 @@ - + {{----}} + @@ -331,4 +376,4 @@ > - \ No newline at end of file + From 518ae28a374aef744327b5b5fe7a26b9340adb24 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 27 Sep 2023 16:20:26 -0700 Subject: [PATCH 003/172] Improve option display values --- .../label2-field-definitions.blade.php | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index 5bc473418f..fcdc97bc56 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -305,49 +305,49 @@ {{----}} - - - - - - - - - + + + + + + + + - - - - + + + + - + - + - + - - + + - - - + + + - - + + From a4a25ab9d0e1e3257d25e4974f3c0237d3d73281 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 27 Sep 2023 16:35:44 -0700 Subject: [PATCH 004/172] Remove a couple fields --- resources/views/partials/label2-field-definitions.blade.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index fcdc97bc56..73ee3935b6 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -304,13 +304,10 @@ - {{----}} diff --git a/resources/views/settings/labels.blade.php b/resources/views/settings/labels.blade.php index 46ce4fe610..a6edd29154 100644 --- a/resources/views/settings/labels.blade.php +++ b/resources/views/settings/labels.blade.php @@ -216,7 +216,7 @@ {{ Form::label('label2_fields', trans('admin/settings/general.label2_fields')) }}
- @include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields) ]) + @include('partials.label2-field-definitions', [ 'name' => 'label2_fields', 'value' => old('label2_fields', $setting->label2_fields), 'customFields' => $customFields ]) {!! $errors->first('label2_fields', '') !!}

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

From 4675f02349bd6bdadc02a43e256ec083e6302bb3 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 28 Sep 2023 11:35:20 -0700 Subject: [PATCH 006/172] Format assigned to field --- app/Models/Labels/FieldOption.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/Models/Labels/FieldOption.php b/app/Models/Labels/FieldOption.php index 76427accaf..2f874ec389 100644 --- a/app/Models/Labels/FieldOption.php +++ b/app/Models/Labels/FieldOption.php @@ -14,6 +14,14 @@ class FieldOption { public function getValue(Asset $asset) { $dataPath = collect(explode('.', $this->dataSource)); + + // assignedTo directly on the asset is a special case where + // we want to avoid returning the property directly + // and instead return the entity's presented name. + if ($dataPath[0] === 'assignedTo'){ + return $asset->assignedTo->present()->fullName(); + } + return $dataPath->reduce(function ($myValue, $path) { try { return $myValue ? $myValue->{$path} : ${$myValue}; } catch (\Exception $e) { return $myValue; } @@ -46,4 +54,4 @@ class FieldOption { return $option; } } -} \ No newline at end of file +} From 36638feac4619745d53229a88616d861fffe59a7 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 28 Sep 2023 11:37:02 -0700 Subject: [PATCH 007/172] Add assigned to as option --- resources/views/partials/label2-field-definitions.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index 710edda621..9ca4f191de 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -313,6 +313,7 @@ + From 3aa256ec021d7351fd07b472a927a1b432d96799 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 28 Sep 2023 12:33:20 -0700 Subject: [PATCH 008/172] Ensure non-checked out items can be displayed --- app/Models/Labels/FieldOption.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Labels/FieldOption.php b/app/Models/Labels/FieldOption.php index 2f874ec389..7e45cc0ce7 100644 --- a/app/Models/Labels/FieldOption.php +++ b/app/Models/Labels/FieldOption.php @@ -19,7 +19,7 @@ class FieldOption { // we want to avoid returning the property directly // and instead return the entity's presented name. if ($dataPath[0] === 'assignedTo'){ - return $asset->assignedTo->present()->fullName(); + return $asset->assignedTo ? $asset->assignedTo->present()->fullName() : null; } return $dataPath->reduce(function ($myValue, $path) { From ed77e8768c7cc17c0292cce2ca448340876c9d41 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 28 Sep 2023 12:33:27 -0700 Subject: [PATCH 009/172] Re-order options --- .../partials/label2-field-definitions.blade.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/resources/views/partials/label2-field-definitions.blade.php b/resources/views/partials/label2-field-definitions.blade.php index 9ca4f191de..21aa7a0cf9 100644 --- a/resources/views/partials/label2-field-definitions.blade.php +++ b/resources/views/partials/label2-field-definitions.blade.php @@ -307,17 +307,16 @@ -
+
-
- +
+ to - +
+ + @if ($errors->has('purchase_start') || $errors->has('purchase_end')) +
+ {!! $errors->first('purchase_start', '') !!} + {!! $errors->first('purchase_end', '') !!} +
+ @endif +
-
+
-
- +
+ to - +
+ + @if ($errors->has('created_start') || $errors->has('created_end')) +
+ {!! $errors->first('created_start', '') !!} + {!! $errors->first('created_end', '') !!} +
+ @endif
-
+
-
- +
+ to - +
+ + @if ($errors->has('checkout_date_start') || $errors->has('checkout_date_end')) +
+ {!! $errors->first('checkout_date_start', '') !!} + {!! $errors->first('checkout_date_end', '') !!} +
+ @endif +
-
+
-
- +
+ {{ strtolower(trans('general.to')) }} - +
+ + @if ($errors->has('checkin_date_start') || $errors->has('checkin_date_end')) +
+ {!! $errors->first('checkin_date_start', '') !!} + {!! $errors->first('checkin_date_end', '') !!} +
+ @endif
-
+
-
- +
+ to - +
+ + @if ($errors->has('expected_checkin_start') || $errors->has('expected_checkin_end')) +
+ {!! $errors->first('expected_checkin_start', '') !!} + {!! $errors->first('expected_checkin_end', '') !!} +
+ @endif +
-
+
-
- +
+ to - +
+ + @if ($errors->has('last_audit_start') || $errors->has('last_audit_end')) +
+ {!! $errors->first('last_audit_start', '') !!} + {!! $errors->first('last_audit_end', '') !!} +
+ @endif
-
+
-
- +
+ to - +
+ + @if ($errors->has('next_audit_start') || $errors->has('next_audit_end')) +
+ {!! $errors->first('next_audit_start', '') !!} + {!! $errors->first('next_audit_end', '') !!} +
+ @endif
From 1be503b21a4c7ccd945ab42247be118f3660a65d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 18 Oct 2023 14:36:16 +0100 Subject: [PATCH 022/172] Make sure order number is not an array Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 2 +- resources/views/hardware/index.blade.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index e49edc4db4..c838da15e5 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -295,7 +295,7 @@ class AssetsController extends Controller } if ($request->filled('order_number')) { - $assets->where('assets.order_number', '=', $request->get('order_number')); + $assets->where('assets.order_number', '=', strval($request->get('order_number'))); } // This is kinda gross, but we need to do this because the Bootstrap Tables diff --git a/resources/views/hardware/index.blade.php b/resources/views/hardware/index.blade.php index a9a0dba580..d30a1c012a 100755 --- a/resources/views/hardware/index.blade.php +++ b/resources/views/hardware/index.blade.php @@ -34,7 +34,7 @@ {{ trans('general.assets') }} @if (Request::has('order_number')) - : Order #{{ Request::get('order_number') }} + : Order #{{ strval(Request::get('order_number')) }} @endif @stop @@ -88,7 +88,7 @@ class="table table-striped snipe-table" data-url="{{ route('api.assets.index', array('status' => e(Request::get('status')), - 'order_number'=>e(Request::get('order_number')), + 'order_number'=>e(strval(Request::get('order_number'))), 'company_id'=>e(Request::get('company_id')), 'status_id'=>e(Request::get('status_id')))) }}" data-export-options='{ From 38de69b3da8829ab6deb8cdd540eec8b0e0f09d5 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 18 Oct 2023 12:41:24 -0500 Subject: [PATCH 023/172] new validation rule --- app/Http/Controllers/Api/AssetsController.php | 5 ----- app/Models/CustomFieldset.php | 2 ++ app/Providers/ValidationServiceProvider.php | 4 ++++ resources/lang/en/validation.php | 1 + 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bce5354b72..e42c82841e 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -582,11 +582,6 @@ class AssetsController extends Controller // Set the field value based on what was sent in the request $field_val = $request->input($field->db_column, null); - //reduce "array to string conversion" exceptions - ideally we'd handle this in a form request, but this works for now - if(is_array($field_val)) { - return response()->json(Helper::formatStandardApiResponse('error', null, 'This custom field can not be an array', 200)); - } - // If input value is null, use custom field's default value if ($field_val == null) { \Log::debug('Field value for '.$field->db_column.' is null'); diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index a2698d818c..a62f96d631 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -92,6 +92,8 @@ 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'; } return $rules; diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index d7a3c03778..70fa64702e 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -232,6 +232,10 @@ class ValidationServiceProvider extends ServiceProvider return true; } }); + + Validator::extend('not_array', function ($attribute, $value, $parameters, $validator) { + return !is_array($value); + }); } /** diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index df514da6f9..7720fda79d 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -95,6 +95,7 @@ return [ 'url' => 'The :attribute format is invalid.', 'unique_undeleted' => 'The :attribute must be unique.', 'non_circular' => 'The :attribute must not create a circular reference.', + 'not_array' => 'The :attribute field can not be an array.', 'disallow_same_pwd_as_user_fields' => 'Password cannot be the same as the username.', 'letters' => 'Password must contain at least one letter.', 'numbers' => 'Password must contain at least one number.', From 6b745930b5dcc8b0eba5e146a3c8df0849000765 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 18 Oct 2023 13:00:13 -0500 Subject: [PATCH 024/172] what typo? --- resources/lang/en/validation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index 7720fda79d..bb35515fdb 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -95,7 +95,7 @@ return [ 'url' => 'The :attribute format is invalid.', 'unique_undeleted' => 'The :attribute must be unique.', 'non_circular' => 'The :attribute must not create a circular reference.', - 'not_array' => 'The :attribute field can not be an array.', + 'not_array' => 'The :attribute field cannot be an array.', 'disallow_same_pwd_as_user_fields' => 'Password cannot be the same as the username.', 'letters' => 'Password must contain at least one letter.', 'numbers' => 'Password must contain at least one number.', From b98c1a0627af046851375092743e9d2b72461d22 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 18 Oct 2023 13:25:34 -0700 Subject: [PATCH 025/172] fixes getExpiringLicenses query --- app/Models/License.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/License.php b/app/Models/License.php index 44f1f45b70..0cec4a7cd4 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -668,7 +668,7 @@ class License extends Depreciable return self::whereNotNull('expiration_date') ->whereNull('deleted_at') - ->whereRaw(DB::raw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) ')) + ->whereRaw('DATE_SUB(`expiration_date`,INTERVAL '.$days.' DAY) <= DATE(NOW()) ') ->where('expiration_date', '>', date('Y-m-d')) ->orderBy('expiration_date', 'ASC') ->get(); From e0a4387b10863df54d8dab28f12952e2fcad9f17 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 19 Oct 2023 10:01:08 -0700 Subject: [PATCH 026/172] clarifies an address column under locations --- app/Presenters/LocationPresenter.php | 2 +- resources/lang/en/admin/locations/table.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Presenters/LocationPresenter.php b/app/Presenters/LocationPresenter.php index bf4ee27bba..86e82c1220 100644 --- a/app/Presenters/LocationPresenter.php +++ b/app/Presenters/LocationPresenter.php @@ -106,7 +106,7 @@ class LocationPresenter extends Presenter 'searchable' => true, 'sortable' => true, 'switchable' => true, - 'title' => trans('admin/locations/table.address'), + 'title' => trans('admin/locations/table.address2'), 'visible' => false, ], [ diff --git a/resources/lang/en/admin/locations/table.php b/resources/lang/en/admin/locations/table.php index 29edf0f565..0cfaa4fdc3 100644 --- a/resources/lang/en/admin/locations/table.php +++ b/resources/lang/en/admin/locations/table.php @@ -15,6 +15,7 @@ return [ 'print_all_assigned' => 'Print All Assigned', 'name' => 'Location Name', 'address' => 'Address', + 'address2' => 'Address Line 2', 'zip' => 'Postal Code', 'locations' => 'Locations', 'parent' => 'Parent', From 47186b0abe7940d843eb9f12fa8bc0bf355b44e0 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 16:28:44 +0200 Subject: [PATCH 027/172] [FIX] Custom report - date fields error Custom report in v6.2.3 give Error if selected are fields: Purchase Date, Checkout Date, Last Checkin Date, Expected Checkin Date Reason is: date field format --- app/Http/Requests/CustomAssetReportRequest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/Http/Requests/CustomAssetReportRequest.php b/app/Http/Requests/CustomAssetReportRequest.php index a34d1b8ae8..2a8fbe7fab 100644 --- a/app/Http/Requests/CustomAssetReportRequest.php +++ b/app/Http/Requests/CustomAssetReportRequest.php @@ -22,9 +22,6 @@ class CustomAssetReportRequest extends Request public function rules() { return [ - 'purchase_date' => 'date|date_format:Y-m-d|nullable', - 'checkout_date' => 'date|date_format:Y-m-d|nullable', - 'checkin_date' => 'date|date_format:Y-m-d|nullable', 'purchase_start' => 'date|date_format:Y-m-d|nullable', 'purchase_end' => 'date|date_format:Y-m-d|nullable', 'created_start' => 'date|date_format:Y-m-d|nullable', From 7571d45d44a8053950692d158996a02e3d7c0ce7 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:41:33 +0200 Subject: [PATCH 028/172] [Improvement[ Dashboard If multicompany option is enabled much more important for admin is to see on dashboard list of companies instead of locations. In other way if multicompanies option is disabled then locations are displayed. --- resources/views/dashboard.blade.php | 183 +++++++++++++++++++--------- 1 file changed, 128 insertions(+), 55 deletions(-) diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 296a940b3f..2744946871 100755 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -274,63 +274,136 @@
- -
-
-

{{ trans('general.asset') }} {{ trans('general.locations') }}

-
- -
-
- -
-
-
-
- - - - - - - - - - - -
{{ trans('general.name') }} - - {{ trans('general.asset_count') }} - - - {{ trans('general.assigned') }} - - - {{ trans('general.people') }} - -
-
-
- -
+ @if ($snipeSettings->full_multiple_companies_support=='1') + +
+
+

{{ trans('general.companies') }}

+
+ +
+
+ +
+
+
+
+ - - + + + + + + + + + + + +
{{ trans('general.name') }} + + {{ trans('general.people') }} + + + {{ trans('general.asset_count') }} + + + {{ trans('general.accessories_count') }} + + + {{ trans('general.consumables_count') }} + + + {{ trans('general.components_count') }} + + + {{ trans('general.licenses_count') }} +
+
+
+ +
+ +
+
+ + @else + +
+
+

{{ trans('general.locations') }}

+
+ +
+
+ +
+
+
+
+ + + + + + + + + + + + +
{{ trans('general.name') }} + + {{ trans('general.asset_count') }} + + + {{ trans('general.assigned') }} + + + {{ trans('general.people') }} + +
+
+
+ +
+ +
+
+ + @endif +
From 58062ff9f502008c9d8ce964654b872e02e37688 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:56:38 +0200 Subject: [PATCH 029/172] Update AssetModelsController.php if EOL of model has been changed and value is >0 assets will be updates with new EOL rate, date if EOL of model has been changes and value is null or 0 then assets will be updates by null EOL rate, date *asset with set expilicity market will not be updated --- app/Http/Controllers/AssetModelsController.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index d7a135dd76..1783b33921 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -179,9 +179,14 @@ class AssetModelsController extends Controller if ($model->save()) { if ($model->wasChanged('eol')) { - $newEol = $model->eol; - $model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false) - ->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]); + if ($model->eol > 0) { + $newEol = $model->eol; + $model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false) + ->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]); + } elseif ($model->eol == 0) { + $model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false) + ->update(['asset_eol_date' => DB::raw('null')]); + } } return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success')); } From bd195a691161932941e8a4258e9b3a137c498bf2 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:11:19 +0200 Subject: [PATCH 030/172] Update AssetsController.php when asset is updated control EOL date change sand set explicit marker depends to setup of model EOL rate --- app/Http/Controllers/Assets/AssetsController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 92922c4cdf..8a12d744ae 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -137,7 +137,7 @@ class AssetsController extends Controller $asset->warranty_months = request('warranty_months', null); $asset->purchase_cost = request('purchase_cost'); $asset->purchase_date = request('purchase_date', null); - $asset->asset_eol_date = request('asset_eol_date', $asset->present()->eol_date()); + $asset->asset_eol_date = request('asset_eol_date', null); $asset->assigned_to = request('assigned_to', null); $asset->supplier_id = request('supplier_id', null); $asset->requestable = request('requestable', 0); @@ -309,14 +309,15 @@ class AssetsController extends Controller $asset->warranty_months = $request->input('warranty_months', null); $asset->purchase_cost = $request->input('purchase_cost', null); $asset->purchase_date = $request->input('purchase_date', null); - if ($request->filled('purchase_date') && !$request->filled('asset_eol_date') && $asset->model->eol) { + if ($request->filled('purchase_date') && !$request->filled('asset_eol_date') && ($asset->model->eol > 0)) { $asset->purchase_date = $request->input('purchase_date', null); $asset->asset_eol_date = Carbon::parse($request->input('purchase_date'))->addMonths($asset->model->eol)->format('Y-m-d'); + $asset->eol_explicit = false; } elseif ($request->filled('asset_eol_date')) { $asset->asset_eol_date = $request->input('asset_eol_date', null); $months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date); if($asset->model->eol) { - if($months != $asset->model->eol) { + if($months != $asset->model->eol > 0) { $asset->eol_explicit = true; } else { $asset->eol_explicit = false; @@ -324,6 +325,9 @@ class AssetsController extends Controller } else { $asset->eol_explicit = true; } + } elseif (!$request->filled('asset_eol_date') && (($asset->model->eol) == 0)) { + $asset->asset_eol_date = null; + $asset->eol_explicit = false; } $asset->supplier_id = $request->input('supplier_id', null); $asset->expected_checkin = $request->input('expected_checkin', null); From 5ae09b791f32896bd7a91b5c4a897b332873db7d Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:16:49 +0200 Subject: [PATCH 031/172] Update AssetsTransformer.php on list of assets display EOL rate in months if purchase date and eol date are set, otherwise null (not display anything) --- app/Http/Transformers/AssetsTransformer.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 68dc731f07..70b0cfe8d2 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -7,6 +7,7 @@ use App\Models\Asset; use App\Models\Setting; use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; +use Carbon\Carbon; class AssetsTransformer @@ -38,7 +39,7 @@ class AssetsTransformer 'byod' => ($asset->byod ? true : false), 'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null, - 'eol' => (($asset->model) && ($asset->model->eol != '')) ? $asset->model->eol : null, + 'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date).' months' : null, 'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null, 'status_label' => ($asset->assetstatus) ? [ 'id' => (int) $asset->assetstatus->id, From 30cc498a163ca869717c72de9a6b42b337aeef9e Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:23:30 +0200 Subject: [PATCH 032/172] Update AssetObserver.php update exlicit marker depends if model EOL > 0 , EOL = 0 --- app/Observers/AssetObserver.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index c15c54a568..a440dbf4ff 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -137,14 +137,14 @@ class AssetObserver public function saving(Asset $asset) { // determine if calculated eol and then calculate it - this should only happen on a new asset - if (is_null($asset->asset_eol_date) && !is_null($asset->purchase_date) && !is_null($asset->model->eol)){ + if (is_null($asset->asset_eol_date) && !is_null($asset->purchase_date) && ($asset->model->eol > 0)){ $asset->asset_eol_date = $asset->purchase_date->addMonths($asset->model->eol)->format('Y-m-d'); $asset->eol_explicit = false; } // determine if explicit and set eol_explicit to true if (!is_null($asset->asset_eol_date) && !is_null($asset->purchase_date)) { - if($asset->model->eol) { + if($asset->model->eol > 0) { $months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date); if($months != $asset->model->eol) { $asset->eol_explicit = true; @@ -153,7 +153,7 @@ class AssetObserver } elseif (!is_null($asset->asset_eol_date) && is_null($asset->purchase_date)) { $asset->eol_explicit = true; } - if ((!is_null($asset->asset_eol_date)) && (!is_null($asset->purchase_date)) && (is_null($asset->model->eol))) { + if ((!is_null($asset->asset_eol_date)) && (!is_null($asset->purchase_date)) && (is_null($asset->model->eol) || ($asset->model->eol == 0))) { $asset->eol_explicit = true; } From 4e20a241ceb41c5910af4382573712dc58240894 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:26:19 +0200 Subject: [PATCH 033/172] Update AssetPresenter.php display name 'EOL rate' instead of 'EOL' --- app/Presenters/AssetPresenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Presenters/AssetPresenter.php b/app/Presenters/AssetPresenter.php index c570c568da..de7c2c7709 100644 --- a/app/Presenters/AssetPresenter.php +++ b/app/Presenters/AssetPresenter.php @@ -173,7 +173,7 @@ class AssetPresenter extends Presenter 'searchable' => false, 'sortable' => true, 'visible' => false, - 'title' => trans('general.eol'), + 'title' => trans('admin/hardware/form.eol_rate'), ], [ 'field' => 'asset_eol_date', From e62636b3a550dbd528795d26451821beb255e9be Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:27:53 +0200 Subject: [PATCH 034/172] Update AssetModelPresenter.php display name 'EOL rate' instead of 'EOL' --- app/Presenters/AssetModelPresenter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Presenters/AssetModelPresenter.php b/app/Presenters/AssetModelPresenter.php index e661b1ab80..85a0fa58ec 100644 --- a/app/Presenters/AssetModelPresenter.php +++ b/app/Presenters/AssetModelPresenter.php @@ -104,7 +104,7 @@ class AssetModelPresenter extends Presenter 'searchable' => false, 'sortable' => true, 'switchable' => true, - 'title' => trans('general.eol'), + 'title' => trans('admin/hardware/form.eol_rate'), 'visible' => true, ], [ From 04a867d12b81e80211e7280b63a4562c6979d64d Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:32:20 +0200 Subject: [PATCH 035/172] Update eol_date.blade.php read EOL date from database instead calculate on the base model EOL rate --- resources/views/partials/forms/edit/eol_date.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/partials/forms/edit/eol_date.blade.php b/resources/views/partials/forms/edit/eol_date.blade.php index 88055cfc0e..fb461cf44e 100644 --- a/resources/views/partials/forms/edit/eol_date.blade.php +++ b/resources/views/partials/forms/edit/eol_date.blade.php @@ -1,9 +1,9 @@ - +
- +
{!! $errors->first('asset_eol_date', '') !!} From 309f30f630218f4901ca8d8529c2dfd050513e75 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Sun, 22 Oct 2023 18:38:59 +0200 Subject: [PATCH 036/172] Update view.blade.php display marker if date of EOL is expired and show real EOL rate as diff between purchase date and eol date --- resources/views/hardware/view.blade.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index 7609feb35f..5a043ffc40 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -631,7 +631,7 @@
@endif - @if (($asset->model) && ($asset->model->eol)) + @if (($asset->asset_eol_date) && ($asset->purchase_date))
@@ -639,7 +639,7 @@
- {{ $asset->model->eol }} + {{ Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date) }} {{ trans('admin/hardware/form.months') }}
@@ -650,6 +650,9 @@
{{ trans('admin/hardware/form.eol_date') }} + @if ($asset->purchase_date) + {!! $asset->asset_eol_date < date("Y-m-d") ? '' : '' !!} + @endif
From 8f8e5cb7235d41fc7b0542720c0a22a0c76b67b9 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 23 Oct 2023 21:47:10 -0600 Subject: [PATCH 037/172] Adds condition to only process CSV if is not empty --- resources/views/livewire/importer.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 297dcc7b87..6a7e02e617 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -235,9 +235,11 @@ ]) }}
+ @if ($activeFile->first_row)

{{ str_limit($activeFile->first_row[$index], 50, '...') }}

+ @endif
@endforeach @else From 49f6eef9df43bc28f046b09772ceabb7b5dc934c Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 23 Oct 2023 21:57:35 -0600 Subject: [PATCH 038/172] Places a text indicating that the file is empty and display it as an info text --- resources/views/livewire/importer.blade.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 6a7e02e617..c134718429 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -239,6 +239,11 @@

{{ str_limit($activeFile->first_row[$index], 50, '...') }}

+ @else + @php + $statusText = trans('general.empty_file'); + $statusType = 'info'; + @endphp @endif
@endforeach From 0c5d54dfdead1897ea2f1738bf1e23bb8558ca5a Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 23 Oct 2023 22:09:17 -0600 Subject: [PATCH 039/172] Create the language string to show in the importer GUI indicating the file is empty --- resources/lang/en/help.php | 3 ++- resources/views/livewire/importer.blade.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/help.php b/resources/lang/en/help.php index a3a2ddd762..a59e0056be 100644 --- a/resources/lang/en/help.php +++ b/resources/lang/en/help.php @@ -30,5 +30,6 @@ return [ 'consumables' => 'Consumables are anything purchased that will be used up over time. For example, printer ink or copier paper.', 'depreciations' => 'You can set up asset depreciations to depreciate assets based on straight-line depreciation.', - + + 'empty_file' => 'The importer detects that this file is empty.' ]; diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index c134718429..48c1a2938c 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -241,7 +241,7 @@
@else @php - $statusText = trans('general.empty_file'); + $statusText = trans('help.empty_file'); $statusType = 'info'; @endphp @endif From c756849497d23a9cc921c04f1c87a14125deacc3 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Oct 2023 17:01:51 +0100 Subject: [PATCH 040/172] Removed debug line Signed-off-by: snipe --- app/Notifications/CheckinAccessoryNotification.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Notifications/CheckinAccessoryNotification.php b/app/Notifications/CheckinAccessoryNotification.php index 53be68f58f..7735f7dc11 100644 --- a/app/Notifications/CheckinAccessoryNotification.php +++ b/app/Notifications/CheckinAccessoryNotification.php @@ -26,7 +26,6 @@ class CheckinAccessoryNotification extends Notification $this->admin = $checkedInby; $this->note = $note; $this->settings = Setting::getSettings(); - \Log::debug('Constructor for notification fired'); } /** From aae289e150eeda09948d766ab86bd5d8c22ef9ef Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Oct 2023 17:02:07 +0100 Subject: [PATCH 041/172] Added missing string Signed-off-by: snipe --- resources/lang/en/admin/accessories/message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/accessories/message.php b/resources/lang/en/admin/accessories/message.php index 542f71f03c..c688d5e03d 100644 --- a/resources/lang/en/admin/accessories/message.php +++ b/resources/lang/en/admin/accessories/message.php @@ -3,6 +3,7 @@ return array( 'does_not_exist' => 'The accessory [:id] does not exist.', + 'not_found' => 'That accessory was not found.', 'assoc_users' => 'This accessory currently has :count items checked out to users. Please check in the accessories and and try again. ', 'create' => array( From 944520bc5de380d3b8ea3d76e22c2d74844f3944 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 24 Oct 2023 17:02:16 +0100 Subject: [PATCH 042/172] Fixed notification formatting Signed-off-by: snipe --- resources/views/notifications.blade.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 1811b3cdd7..eca773e219 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -41,7 +41,7 @@
- {{ trans('general.asset_information') }} + {{ trans('general.asset_information') }}:
    @isset ($asset->model->name)
  • {{ trans('general.model_name') }} {{ $asset->model->name }}
  • @@ -67,7 +67,7 @@
    - {{ trans('general.consumable_information') }} + {{ trans('general.consumable_information') }}:
    • {{ trans('general.consumable_name') }} {{ $consumable->name }}
@@ -81,7 +81,7 @@
- {{ trans('general.accessory_information') }} + {{ trans('general.accessory_information') }}:
  • {{ trans('general.accessory_name') }} {{ $accessory->name }}
@@ -94,7 +94,7 @@
- {{ trans('general.error') }} + {{ trans('general.error') }}: {{ $message }}
@@ -107,7 +107,7 @@
- {{ trans('general.notification_error') }} + {{ trans('general.notification_error') }}: {{ $message }}
From c919cd31fafebe92190cd6f40cd7bf61c7a8c4c8 Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Tue, 24 Oct 2023 11:30:24 -0500 Subject: [PATCH 043/172] Map Snipe-IT logs to storage logs folder For docker-compose.yml usage to prevent error messages. --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 101c15d3b5..15272ce5c5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: ports: - "8000:80" volumes: - - ./logs:/var/www/html/storage/logs + - ./storage/logs:/var/www/html/storage/logs depends_on: - mariadb - redis From f2f3931fa9251a66f2740fdee9d6593979e6607c Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 24 Oct 2023 11:26:37 -0600 Subject: [PATCH 044/172] Formatting correctly --- resources/views/livewire/importer.blade.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/resources/views/livewire/importer.blade.php b/resources/views/livewire/importer.blade.php index 48c1a2938c..0134cfe7f2 100644 --- a/resources/views/livewire/importer.blade.php +++ b/resources/views/livewire/importer.blade.php @@ -235,16 +235,16 @@ ]) }}
- @if ($activeFile->first_row) + @if ($activeFile->first_row)

{{ str_limit($activeFile->first_row[$index], 50, '...') }}

- @else - @php - $statusText = trans('help.empty_file'); - $statusType = 'info'; - @endphp - @endif + @else + @php + $statusText = trans('help.empty_file'); + $statusType = 'info'; + @endphp + @endif
@endforeach @else From 96f7f49b68079d50f5ecbacf207b363b57359959 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 16:40:49 +0100 Subject: [PATCH 045/172] Fixed response docblock Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index ca3e6400f4..a8f4285b36 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -48,7 +48,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function index(Request $request, $audit = null) { @@ -443,7 +443,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function show(Request $request, $id) { @@ -474,7 +474,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @since [v4.0.16] * @see \App\Http\Transformers\SelectlistTransformer - * + * @return \Illuminate\Http\JsonResponse */ public function selectlist(Request $request) { @@ -530,6 +530,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param \App\Http\Requests\ImageUploadRequest $request * @since [v4.0] + * @return \Illuminate\Http\JsonResponse */ public function store(ImageUploadRequest $request) { @@ -638,7 +639,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param \App\Http\Requests\ImageUploadRequest $request * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function update(ImageUploadRequest $request, $id) { @@ -719,7 +720,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function destroy($id) { @@ -748,7 +749,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v5.1.18] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function restore(Request $request, $assetId = null) { @@ -788,7 +789,7 @@ class AssetsController extends Controller * @author [N. Butler] * @param string $tag * @since [v6.0.5] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function checkoutByTag(AssetCheckoutRequest $request, $tag) { @@ -804,7 +805,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function checkout(AssetCheckoutRequest $request, $asset_id) { @@ -888,7 +889,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $assetId * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function checkin(Request $request, $asset_id) { @@ -944,7 +945,7 @@ class AssetsController extends Controller * * @author [A. Janes] [] * @since [v6.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function checkinByTag(Request $request, $tag = null) { @@ -970,7 +971,7 @@ class AssetsController extends Controller * @author [A. Gianotto] [] * @param int $id * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function audit(Request $request) From c4adc3ccc8d113b34d2c4f137c9854a9480e4df8 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:18:37 +0100 Subject: [PATCH 046/172] Migration to add show_in_requestable_list boolean Signed-off-by: snipe --- ...d_show_in_requestable_to_custom_fields.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php diff --git a/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php b/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php new file mode 100644 index 0000000000..ed667590f8 --- /dev/null +++ b/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php @@ -0,0 +1,34 @@ +boolean('show_in_requestable_list')->after('show_in_email')->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fields', function (Blueprint $table) { + if (Schema::hasColumn('custom_fields', 'show_in_requestable_list')) { + $table->dropColumn('show_in_requestable_list'); + } + }); + } +} From e7ef7f04f0636c4319bf80157aa247cc7ab9d8d1 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:21:48 +0100 Subject: [PATCH 047/172] Removed periods for consistency Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index cb4ab3730a..5481c8ecfb 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -34,7 +34,8 @@ return [ 'create_field' => 'New Custom Field', 'create_field_title' => 'Create a new custom field', 'value_encrypted' => 'The value of this field is encrypted in the database. Only admin users will be able to view the decrypted value', - 'show_in_email' => 'Include the value of this field in checkout emails sent to the user? Encrypted fields cannot be included in emails.', + 'show_in_email' => 'Include the value of this field in checkout emails sent to the user? Encrypted fields cannot be included in emails', + 'show_in_email_short' => 'Include in emails.', 'help_text' => 'Help Text', 'help_text_description' => 'This is optional text that will appear below the form elements while editing an asset to provide context on the field.', 'about_custom_fields_title' => 'About Custom Fields', From 3a37b802513538da461ee2ba08ec5da73221faef Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:21:58 +0100 Subject: [PATCH 048/172] Added translations Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 5481c8ecfb..d6a3db343f 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -52,7 +52,8 @@ return [ 'display_in_user_view_table' => 'Visible to User', 'auto_add_to_fieldsets' => 'Automatically add this to every new fieldset', 'add_to_preexisting_fieldsets' => 'Add to any existing fieldsets', - 'show_in_listview' => 'Show in list views by default. Authorized users will still be able to show/hide via the column selector.', + 'show_in_listview' => 'Show in list views by default. Authorized users will still be able to show/hide via the column selector', 'show_in_listview_short' => 'Show in lists', + 'show_in_requestable_list' => 'Show value in requestable assets list', ]; From 08693f09b0c37c66c3a877c8bf7c8fc45d505df3 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:22:12 +0100 Subject: [PATCH 049/172] Added requests() method on Assets Signed-off-by: snipe --- app/Models/Asset.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 7bce0df242..ed72313aa4 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -786,7 +786,17 @@ class Asset extends Depreciable return $this->belongsTo(\App\Models\Location::class, 'location_id'); } - + /** + * Establishes the asset -> checkout_requests relationship + * + * @author [A. Gianotto] [] + * @since [v6.2.4] + * @return \Illuminate\Database\Eloquent\Relations\Relation + */ + public function requests() + { + return $this->belongsToMany(\App\Models\Asset::class, 'checkout_requests', 'requestable_id', 'user_id')->where('requestable_type','=',\App\Models\Asset::class); + } /** * Get the next autoincremented asset tag From 88661a58a77db995b634e60a6b60e76b1bb00f1d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:26:31 +0100 Subject: [PATCH 050/172] Make field nullable Signed-off-by: snipe --- ...23_10_25_064324_add_show_in_requestable_to_custom_fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php b/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php index ed667590f8..710a56e819 100644 --- a/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php +++ b/database/migrations/2023_10_25_064324_add_show_in_requestable_to_custom_fields.php @@ -14,7 +14,7 @@ class AddShowInRequestableToCustomFields extends Migration public function up() { Schema::table('custom_fields', function (Blueprint $table) { - $table->boolean('show_in_requestable_list')->after('show_in_email')->default(0); + $table->boolean('show_in_requestable_list')->after('show_in_email')->nullable()->default(0); }); } From 933ce61efd6017d8f9ed676f5c01ba76d7a1b12e Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:26:51 +0100 Subject: [PATCH 051/172] Removed eager loading for defaultLoc, added requests loading, sorting Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 57 ++++++++++++++----- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index a8f4285b36..ea916c5182 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -1032,24 +1032,54 @@ class AssetsController extends Controller * * @author [A. Gianotto] [] * @since [v4.0] - * @return JsonResponse + * @return \Illuminate\Http\JsonResponse */ public function requestable(Request $request) { $this->authorize('viewRequestable', Asset::class); + $allowed_columns = [ + 'name', + 'asset_tag', + 'serial', + 'model_number', + 'image', + 'purchase_cost', + 'expected_checkin', + ]; + + $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load + + foreach ($all_custom_fields as $field) { + $allowed_columns[] = $field->db_column_name(); + } + $assets = Asset::select('assets.*') - ->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo', - 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier') + ->with('location', 'assetstatus', 'assetlog', 'company','assignedTo', + 'model.category', 'model.manufacturer', 'model.fieldset', 'supplier', 'requests') ->requestableAssets(); - $offset = request('offset', 0); - $limit = $request->input('limit', 50); - $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; + + + if ($request->filled('search')) { $assets->TextSearch($request->input('search')); } + // Search custom fields by column name + foreach ($all_custom_fields as $field) { + if ($request->filled($field->db_column_name())) { + $assets->where($field->db_column_name(), '=', $request->input($field->db_column_name())); + } + } + + $order = $request->input('order') === 'asc' ? 'asc' : 'desc'; + $sort_override = str_replace('custom_fields.', '', $request->input('sort')); + + // This handles all the pivot sorting (versus the assets.* fields + // in the allowed_columns array) + $column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'assets.created_at'; + switch ($request->input('sort')) { case 'model': $assets->OrderModels($order); @@ -1057,17 +1087,18 @@ class AssetsController extends Controller case 'model_number': $assets->OrderModelNumber($order); break; - case 'category': - $assets->OrderCategory($order); - break; - case 'manufacturer': - $assets->OrderManufacturer($order); - break; + case 'location': + $assets->OrderLocation($order); default: - $assets->orderBy('assets.created_at', $order); + $assets->orderBy($column_sort, $order); break; } + + // Make sure the offset and limit are actually integers and do not exceed system limits + $offset = ($request->input('offset') > $assets->count()) ? $assets->count() : app('api_offset_value'); + $limit = app('api_limit_value'); + $total = $assets->count(); $assets = $assets->skip($offset)->take($limit)->get(); From 63a86c56220cbc94d16995c62708d7e9b0ca1fe0 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:27:36 +0100 Subject: [PATCH 052/172] Added field to controller Signed-off-by: snipe --- app/Http/Controllers/CustomFieldsController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index c9579ae7ef..ffe5eceec2 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -110,6 +110,7 @@ class CustomFieldsController extends Controller "display_in_user_view" => $display_in_user_view, "auto_add_to_fieldsets" => $request->get("auto_add_to_fieldsets", 0), "show_in_listview" => $request->get("show_in_listview", 0), + "show_in_requestable_list" => $request->get("show_in_requestable_list", 0), "user_id" => Auth::id() ]); @@ -267,6 +268,7 @@ class CustomFieldsController extends Controller $field->display_in_user_view = $display_in_user_view; $field->auto_add_to_fieldsets = $request->get("auto_add_to_fieldsets", 0); $field->show_in_listview = $request->get("show_in_listview", 0); + $field->show_in_requestable_list = $request->get("show_in_requestable_list", 0); if ($request->get('format') == 'CUSTOM REGEX') { $field->format = e($request->get('custom_format')); From 23a6547adaec30bbbd8f0056900feaccfe5ace32 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:28:14 +0100 Subject: [PATCH 053/172] Added custom fields, fixed n+1 Signed-off-by: snipe --- app/Http/Transformers/AssetsTransformer.php | 29 ++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index 68dc731f07..b1232d4f3e 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -7,7 +7,7 @@ use App\Models\Asset; use App\Models\Setting; use Illuminate\Support\Facades\Gate; use Illuminate\Database\Eloquent\Collection; - +use Auth; class AssetsTransformer { @@ -231,9 +231,32 @@ class AssetsTransformer 'assigned_to_self' => ($asset->assigned_to == \Auth::user()->id), ]; + if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields->count() > 0)) { + $fields_array = []; + + foreach ($asset->model->fieldset->fields as $field) { + + // Only display this if it's allowed via the custom field setting + if ($field->show_in_requestable_list == '1') { + + $value = $asset->{$field->db_column}; + if (($field->format == 'DATE') && (!is_null($value)) && ($value != '')) { + $value = Helper::getFormattedDateObject($value, 'date', false); + } + + $fields_array[$field->db_column] = e($value); + } + + $array['custom_fields'] = $fields_array; + } + } else { + $array['custom_fields'] = new \stdClass; // HACK to force generation of empty object instead of empty list + } + + $permissions_array['available_actions'] = [ - 'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false, - 'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true, + 'cancel' => ($asset->requests->find(Auth::user()->id)) ? true : false, + 'request' => ($asset->requests->find(Auth::user()->id)) ? false : true, ]; $array += $permissions_array; From e5bd78a7221c2d249d499e8f61b7b69b4dde2dad Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:28:35 +0100 Subject: [PATCH 054/172] Added show_in_requestable_list validation, casting Signed-off-by: snipe --- app/Models/CustomField.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index c98dbe637c..1dd04c017e 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -53,6 +53,12 @@ class CustomField extends Model 'field_encrypted' => 'nullable|boolean', 'auto_add_to_fieldsets' => 'boolean', 'show_in_listview' => 'boolean', + 'show_in_requestable_list' => 'boolean', + 'show_in_email' => 'boolean', + ]; + + protected $casts = [ + 'show_in_requestable_list' => 'boolean', ]; /** @@ -72,7 +78,8 @@ class CustomField extends Model 'display_in_user_view', 'auto_add_to_fieldsets', 'show_in_listview', - + 'show_in_email', + 'show_in_requestable_list', ]; /** From 3c6b79e80769a3b9ce42f1acd25b6d3303ce4227 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 17:28:55 +0100 Subject: [PATCH 055/172] Added new fields to blades Signed-off-by: snipe --- .../account/requestable-assets.blade.php | 6 ++++++ .../views/custom_fields/fields/edit.blade.php | 7 +++++++ resources/views/custom_fields/index.blade.php | 20 ++++++++++--------- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/resources/views/account/requestable-assets.blade.php b/resources/views/account/requestable-assets.blade.php index adec7a100a..752c8d64fb 100644 --- a/resources/views/account/requestable-assets.blade.php +++ b/resources/views/account/requestable-assets.blade.php @@ -65,6 +65,12 @@ {{ trans('admin/hardware/table.location') }} {{ trans('admin/hardware/table.status') }} {{ trans('admin/hardware/form.expected_checkin') }} + + @foreach(\App\Models\CustomField::get() as $field) + @if ($field->show_in_requestable_list=='1') + {{ $field->name }} + @endif + @endforeach {{ trans('table.actions') }} diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index ac945d8597..6a2bbd7ede 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -136,6 +136,13 @@
+
+ +
+ @if (!$field->id)
diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 141d715344..781f253f95 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -145,12 +145,13 @@ - + - - - {{ trans('admin/custom_fields/general.field_element_short') }} + + + + {{ trans('admin/custom_fields/general.field_element_short') }} {{ trans('admin/custom_fields/general.fieldsets') }} {{ trans('button.actions') }} @@ -161,7 +162,7 @@ {{ $field->name }} {{ $field->help_text }} - {!! ($field->is_unique=='1') ? '' : '' !!} + {!! ($field->is_unique=='1') ? '' : '' !!} {{ $field->convertUnicodeDbSlug() }} @if ($field->convertUnicodeDbSlug()!=$field->db_column) @@ -170,10 +171,11 @@ @endif {{ $field->format }} - {!! ($field->field_encrypted=='1' ? '' : '') !!} - {!! ($field->show_in_listview=='1' ? '' : '') !!} - {!! ($field->display_in_user_view=='1' ? '' : '') !!} - {!! ($field->show_in_email=='1') ? '' : '' !!} + {!! ($field->field_encrypted=='1' ? '' : '') !!} + {!! ($field->show_in_listview=='1' ? '' : '') !!} + {!! ($field->display_in_user_view=='1' ? '' : '') !!} + {!! ($field->show_in_email=='1') ? '' : '' !!} + {!! ($field->show_in_requestable_list=='1') ? '' : '' !!} {{ $field->element }} @foreach($field->fieldset as $fieldset) From 307f84dff8e43d0300d61a475cb1163001bc2316 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:41:53 +0100 Subject: [PATCH 056/172] Removed extraneous method Signed-off-by: snipe --- app/Models/Asset.php | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index ed72313aa4..f8ae67f9ec 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -786,17 +786,6 @@ class Asset extends Depreciable return $this->belongsTo(\App\Models\Location::class, 'location_id'); } - /** - * Establishes the asset -> checkout_requests relationship - * - * @author [A. Gianotto] [] - * @since [v6.2.4] - * @return \Illuminate\Database\Eloquent\Relations\Relation - */ - public function requests() - { - return $this->belongsToMany(\App\Models\Asset::class, 'checkout_requests', 'requestable_id', 'user_id')->where('requestable_type','=',\App\Models\Asset::class); - } /** * Get the next autoincremented asset tag From 8b9b46c562bea8a412569586ec2947587d350549 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:41:59 +0100 Subject: [PATCH 057/172] Removed comment Signed-off-by: snipe --- app/Models/CustomField.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 1dd04c017e..c1826a94d8 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -250,8 +250,6 @@ class CustomField extends Model /** * Gets the DB column name. * - * @todo figure out if this is still needed? I don't know WTF it's for. - * * @author [A. Gianotto] [] * @since [v3.0] * @return string From eb82bc290db237d3722f1b15d0f4a33ab893ff96 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:42:07 +0100 Subject: [PATCH 058/172] Clarified translation Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index d6a3db343f..39917dd77d 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -54,6 +54,7 @@ return [ 'add_to_preexisting_fieldsets' => 'Add to any existing fieldsets', 'show_in_listview' => 'Show in list views by default. Authorized users will still be able to show/hide via the column selector', 'show_in_listview_short' => 'Show in lists', - 'show_in_requestable_list' => 'Show value in requestable assets list', + 'show_in_requestable_list_short' => 'Show in requestable assets list.', + 'show_in_requestable_list' => 'Show value in requestable assets list. Encrypted fields will not be shown.', ]; From 887d013a3947771e513056cf06f011f0fd2a1078 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:42:33 +0100 Subject: [PATCH 059/172] Added listable fields in profile -> requested assets Signed-off-by: snipe --- .../Controllers/Api/ProfileController.php | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/ProfileController.php b/app/Http/Controllers/Api/ProfileController.php index 4f5e3b1bdf..ef56ed5370 100644 --- a/app/Http/Controllers/Api/ProfileController.php +++ b/app/Http/Controllers/Api/ProfileController.php @@ -11,6 +11,7 @@ use Illuminate\Http\Request; use Laravel\Passport\TokenRepository; use Illuminate\Contracts\Validation\Factory as ValidationFactory; use Illuminate\Support\Facades\Gate; +use App\Models\CustomField; use DB; class ProfileController extends Controller @@ -48,14 +49,23 @@ class ProfileController extends Controller { $checkoutRequests = CheckoutRequest::where('user_id', '=', Auth::user()->id)->get(); - $results = []; + $results = array(); + $show_field = array(); + $showable_fields = array(); $results['total'] = $checkoutRequests->count(); + $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load + foreach ($all_custom_fields as $field) { + if (($field->field_encrypted=='0') && ($field->show_in_requestable_list=='1')) { + $showable_fields[] = $field->db_column_name(); + } + } + foreach ($checkoutRequests as $checkoutRequest) { // Make sure the asset and request still exist if ($checkoutRequest && $checkoutRequest->itemRequested()) { - $results['rows'][] = [ + $assets = [ 'image' => e($checkoutRequest->itemRequested()->present()->getImageUrl()), 'name' => e($checkoutRequest->itemRequested()->present()->name()), 'type' => e($checkoutRequest->itemType()), @@ -64,7 +74,16 @@ class ProfileController extends Controller 'expected_checkin' => Helper::getFormattedDateObject($checkoutRequest->itemRequested()->expected_checkin, 'datetime'), 'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'), ]; + + foreach ($showable_fields as $showable_field_name) { + $show_field['custom_fields.'.$showable_field_name] = $checkoutRequest->itemRequested()->{$showable_field_name}; + } + + // Merge the plain asset data and the custom fields data + $results['rows'][] = array_merge($assets, $show_field); } + + } return $results; From ab3edae0b68a8cf2c15a2cc8177c58cc6b58ae5c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:43:09 +0100 Subject: [PATCH 060/172] Reverted buttons (this re-introduces the n+1 problem.) Signed-off-by: snipe --- app/Http/Transformers/AssetsTransformer.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Transformers/AssetsTransformer.php b/app/Http/Transformers/AssetsTransformer.php index b1232d4f3e..e1d98a5200 100644 --- a/app/Http/Transformers/AssetsTransformer.php +++ b/app/Http/Transformers/AssetsTransformer.php @@ -237,7 +237,7 @@ class AssetsTransformer foreach ($asset->model->fieldset->fields as $field) { // Only display this if it's allowed via the custom field setting - if ($field->show_in_requestable_list == '1') { + if (($field->field_encrypted=='0') && ($field->show_in_requestable_list=='1')) { $value = $asset->{$field->db_column}; if (($field->format == 'DATE') && (!is_null($value)) && ($value != '')) { @@ -255,8 +255,8 @@ class AssetsTransformer $permissions_array['available_actions'] = [ - 'cancel' => ($asset->requests->find(Auth::user()->id)) ? true : false, - 'request' => ($asset->requests->find(Auth::user()->id)) ? false : true, + 'cancel' => ($asset->isRequestedBy(\Auth::user())) ? true : false, + 'request' => ($asset->isRequestedBy(\Auth::user())) ? false : true, ]; $array += $permissions_array; From 43da292d6058e62c830969c48fa21eb3541e092d Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:43:34 +0100 Subject: [PATCH 061/172] Used short translation for sr-only text Signed-off-by: snipe --- resources/views/custom_fields/index.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 781f253f95..7b0c4965d8 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -150,7 +150,7 @@ - + {{ trans('admin/custom_fields/general.field_element_short') }} {{ trans('admin/custom_fields/general.fieldsets') }} {{ trans('button.actions') }} From a202bf81fa870998654aad6922eeb070a8e7b77c Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:44:02 +0100 Subject: [PATCH 062/172] Removed column widths, check for encryption and showable Signed-off-by: snipe --- resources/views/account/requested.blade.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resources/views/account/requested.blade.php b/resources/views/account/requested.blade.php index e3d80edf69..e2e1db2e51 100644 --- a/resources/views/account/requested.blade.php +++ b/resources/views/account/requested.blade.php @@ -32,13 +32,19 @@ }'> - {{ trans('general.image') }} - {{ trans('general.item_name') }} - {{ trans('general.type') }} - {{ trans('general.qty') }} - {{ trans('admin/hardware/table.location') }} - {{ trans('admin/hardware/form.expected_checkin') }} - {{ trans('general.requested_date') }} + {{ trans('general.image') }} + {{ trans('general.item_name') }} + {{ trans('general.type') }} + {{ trans('general.qty') }} + {{ trans('admin/hardware/table.location') }} + {{ trans('admin/hardware/form.expected_checkin') }} + {{ trans('general.requested_date') }} + + @foreach(\App\Models\CustomField::get() as $field) + @if (($field->field_encrypted=='0') && ($field->show_in_requestable_list=='1')) + {{ $field->name }} + @endif + @endforeach From 57d3b2d2ef2b14654ed0f08a5351be3b3753cc71 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:44:10 +0100 Subject: [PATCH 063/172] Check for encryption Signed-off-by: snipe --- resources/views/account/requestable-assets.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/requestable-assets.blade.php b/resources/views/account/requestable-assets.blade.php index 752c8d64fb..8e3c08fd57 100644 --- a/resources/views/account/requestable-assets.blade.php +++ b/resources/views/account/requestable-assets.blade.php @@ -67,7 +67,7 @@ {{ trans('admin/hardware/form.expected_checkin') }} @foreach(\App\Models\CustomField::get() as $field) - @if ($field->show_in_requestable_list=='1') + @if (($field->field_encrypted=='0') && ($field->show_in_requestable_list=='1')) {{ $field->name }} @endif @endforeach From 6264d9045915dff6d57270e4fffbcb5e5aa4ed97 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 19:45:11 +0100 Subject: [PATCH 064/172] Removed ending period for consistency Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 39917dd77d..57d8ffa949 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -55,6 +55,6 @@ return [ 'show_in_listview' => 'Show in list views by default. Authorized users will still be able to show/hide via the column selector', 'show_in_listview_short' => 'Show in lists', 'show_in_requestable_list_short' => 'Show in requestable assets list.', - 'show_in_requestable_list' => 'Show value in requestable assets list. Encrypted fields will not be shown.', + 'show_in_requestable_list' => 'Show value in requestable assets list. Encrypted fields will not be shown', ]; From 3916bac95f860b8a2c7e4938875de72ae1537d16 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 20:10:46 +0100 Subject: [PATCH 065/172] Added warning translation for encrypted fields Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 57d8ffa949..67b1718cbe 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -56,5 +56,6 @@ return [ 'show_in_listview_short' => 'Show in lists', 'show_in_requestable_list_short' => 'Show in requestable assets list.', 'show_in_requestable_list' => 'Show value in requestable assets list. Encrypted fields will not be shown', + 'encrypted_options' => 'This field is encrypted, so some display options will not be available.', ]; From 0f97c0601b5fc586ac028dcb9abc9e959e3a4b06 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 20:11:06 +0100 Subject: [PATCH 066/172] Nicer show/hide if encrypted, warn if already encrypted Signed-off-by: snipe --- .../views/custom_fields/fields/edit.blade.php | 78 ++++++++++++------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index 6a2bbd7ede..227fb08378 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -118,10 +118,40 @@
+ +
+ + + @if (($field->id) && ($field->field_encrypted=='1')) +
+
+ + {{ trans('general.notification_warning') }}: + {{ trans('admin/custom_fields/general.encrypted_options') }} +
+ +
+ @endif + + @if (!$field->id) + +
+ +
+ + + @endif + -
+
-
+ + @if ((!$field->id) || ($field->field_encrypted=='0')) + + +
- @if (!$field->id) - -
- -
- - - @endif - -
+
+ +
+ +
+ @endif + -
+
- -
- -
+
@@ -294,11 +316,13 @@ $("#show_in_email").hide(); $("#display_in_user_view").hide(); $("#is_unique").hide(); + $("#show_in_requestable_list").hide(); } else { $("#encrypt_warning").hide(); $("#show_in_email").show(); $("#display_in_user_view").show(); $("#is_unique").show(); + $("#show_in_requestable_list").show(); } }); From a0cae77278b3fdac3dbbc4fb39b02852b10d965f Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 20:21:07 +0100 Subject: [PATCH 067/172] Fixed weird layout quirk on smaller screens Signed-off-by: snipe --- resources/views/custom_fields/fields/edit.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index 227fb08378..504b556faa 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -88,7 +88,7 @@ } @endphp
- {{ Form::select("format",Helper::predefined_formats(), ($field_format == '') ? $field->format : $field_format, array('class'=>'format select2 form-control', 'aria-label'=>'format')) }} + {{ Form::select("format",Helper::predefined_formats(), ($field_format == '') ? $field->format : $field_format, array('class'=>'format select2 form-control', 'aria-label'=>'format', 'style' => 'width:100%;')) }} {!! $errors->first('format', '') !!}
From 0feb56d931dfd2065df6a6bf8232f032966fd294 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 25 Oct 2023 20:39:15 +0100 Subject: [PATCH 068/172] Removed period Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 67b1718cbe..e3c21d1f0c 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -54,7 +54,7 @@ return [ 'add_to_preexisting_fieldsets' => 'Add to any existing fieldsets', 'show_in_listview' => 'Show in list views by default. Authorized users will still be able to show/hide via the column selector', 'show_in_listview_short' => 'Show in lists', - 'show_in_requestable_list_short' => 'Show in requestable assets list.', + 'show_in_requestable_list_short' => 'Show in requestable assets list', 'show_in_requestable_list' => 'Show value in requestable assets list. Encrypted fields will not be shown', 'encrypted_options' => 'This field is encrypted, so some display options will not be available.', From 33b45898b177a49155949516beddab3847ff6f9d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 25 Oct 2023 12:59:58 -0700 Subject: [PATCH 069/172] adds to advancedsearch --- app/Models/Asset.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 7bce0df242..0479e40df6 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -950,6 +950,7 @@ class Asset extends Depreciable ->orWhere('assets_users.first_name', 'LIKE', '%'.$term.'%') ->orWhere('assets_users.last_name', 'LIKE', '%'.$term.'%') ->orWhere('assets_users.username', 'LIKE', '%'.$term.'%') + ->orWhere('assets_users.employee_num', 'LIKE', '%'.$term.'%') ->orWhereMultipleColumns([ 'assets_users.first_name', 'assets_users.last_name', @@ -1359,7 +1360,8 @@ class Asset extends Depreciable ->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%') ->orWhere('assets.serial', 'LIKE', '%'.$search.'%') ->orWhere('assets.order_number', 'LIKE', '%'.$search.'%') - ->orWhere('assets.notes', 'LIKE', '%'.$search.'%'); + ->orWhere('assets.notes', 'LIKE', '%'.$search.'%') + ->orWhere('assets_users.employee_num', 'LIKE', '%'.$search.'%'); } })->withTrashed()->whereNull('assets.deleted_at'); //workaround for laravel bug From 56fd41eee424175d7c90842d3fc25ebae24a2df8 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 25 Oct 2023 13:03:12 -0700 Subject: [PATCH 070/172] removed erroneous code --- app/Models/Asset.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 0479e40df6..83522d3862 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1361,7 +1361,6 @@ class Asset extends Depreciable ->orWhere('assets.serial', 'LIKE', '%'.$search.'%') ->orWhere('assets.order_number', 'LIKE', '%'.$search.'%') ->orWhere('assets.notes', 'LIKE', '%'.$search.'%') - ->orWhere('assets_users.employee_num', 'LIKE', '%'.$search.'%'); } })->withTrashed()->whereNull('assets.deleted_at'); //workaround for laravel bug From 1b614c13fb69856b4b55e74a6e99e28ed22200bf Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 25 Oct 2023 13:03:42 -0700 Subject: [PATCH 071/172] ugh --- app/Models/Asset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 83522d3862..2b055c196e 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -1360,7 +1360,7 @@ class Asset extends Depreciable ->orWhere('assets.asset_tag', 'LIKE', '%'.$search.'%') ->orWhere('assets.serial', 'LIKE', '%'.$search.'%') ->orWhere('assets.order_number', 'LIKE', '%'.$search.'%') - ->orWhere('assets.notes', 'LIKE', '%'.$search.'%') + ->orWhere('assets.notes', 'LIKE', '%'.$search.'%'); } })->withTrashed()->whereNull('assets.deleted_at'); //workaround for laravel bug From 7ed58a177b0361c73e74ae18ba19792bc55603bd Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 25 Oct 2023 16:31:23 -0600 Subject: [PATCH 072/172] Evaluate if the asset was assigned to a different user than current target to log a checkin event --- app/Importer/AssetImporter.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 76eae0739a..61cdd3c7b7 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -5,6 +5,9 @@ namespace App\Importer; use App\Models\Asset; use App\Models\AssetModel; use App\Models\Statuslabel; +use App\Models\User; +use App\Events\CheckoutableCheckedIn; +use Illuminate\Support\Facades\Auth; use Carbon\Carbon; class AssetImporter extends ItemImporter @@ -142,6 +145,10 @@ class AssetImporter extends ItemImporter //-- user_id is a property of the abstract class Importer, which this class inherits from and it's setted by //-- the class that needs to use it (command importer or GUI importer inside the project). if (isset($target)) { + if ($asset->assigned_to != $target->id){ + event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), Auth::user(), $asset->notes, date('Y-m-d H:i:s'))); + } + $asset->fresh()->checkOut($target, $this->user_id, date('Y-m-d H:i:s'), null, $asset->notes, $asset->name); } From ca1845efd777d3eb23bb474309a17607253d024e Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 25 Oct 2023 16:41:31 -0600 Subject: [PATCH 073/172] Only log checkin event if the assigned_to property is not empty --- app/Importer/AssetImporter.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 61cdd3c7b7..5014efac12 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -145,8 +145,10 @@ class AssetImporter extends ItemImporter //-- user_id is a property of the abstract class Importer, which this class inherits from and it's setted by //-- the class that needs to use it (command importer or GUI importer inside the project). if (isset($target)) { - if ($asset->assigned_to != $target->id){ - event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), Auth::user(), $asset->notes, date('Y-m-d H:i:s'))); + if (!is_null($asset->assigned_to)){ + if ($asset->assigned_to != $target->id){ + event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), Auth::user(), $asset->notes, date('Y-m-d H:i:s'))); + } } $asset->fresh()->checkOut($target, $this->user_id, date('Y-m-d H:i:s'), null, $asset->notes, $asset->name); From 4a759f0a204dceb596b305d15b4485601572c15c Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 01:49:01 +0100 Subject: [PATCH 074/172] Added fingerprint icon for unique Signed-off-by: snipe --- resources/views/custom_fields/index.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 7b0c4965d8..08f2fb3845 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -151,6 +151,7 @@ + {{ trans('admin/custom_fields/general.unique') }} {{ trans('admin/custom_fields/general.field_element_short') }} {{ trans('admin/custom_fields/general.fieldsets') }} {{ trans('button.actions') }} @@ -176,6 +177,7 @@ {!! ($field->display_in_user_view=='1' ? '' : '') !!} {!! ($field->show_in_email=='1') ? '' : '' !!} {!! ($field->show_in_requestable_list=='1') ? '' : '' !!} + {!! ($field->is_unique=='1') ? '' : '' !!} {{ $field->element }} @foreach($field->fieldset as $fieldset) From 4b6b36c6397f789978c5c2bff870f4fd5fbfdf39 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 01:49:14 +0100 Subject: [PATCH 075/172] Removed semicolon Signed-off-by: snipe --- resources/lang/en/general.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index e1a5cc0e7a..fba828839f 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -368,7 +368,7 @@ return [ 'consumables_count' => 'Consumables Count', 'components_count' => 'Components Count', 'licenses_count' => 'Licenses Count', - 'notification_error' => 'Error:', + 'notification_error' => 'Error', 'notification_error_hint' => 'Please check the form below for errors', 'notification_bulk_error_hint' => 'The following fields had validation errors and were not edited:', 'notification_success' => 'Success', From 6ebc01ca50c65a8fe6d6621dca80fb7be2f3dd5e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 01:49:23 +0100 Subject: [PATCH 076/172] Bulk edit refactor Signed-off-by: snipe --- .../Assets/BulkAssetsController.php | 140 ++++++++++++------ 1 file changed, 92 insertions(+), 48 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index bd234cb9a6..fe151b4278 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -120,8 +120,9 @@ class BulkAssetsController extends Controller $bulk_back_url = $request->session()->pull('bulk_back_url'); } + \Log::debug(print_r($request->all(), true)); - $custom_field_columns = CustomField::all()->pluck('db_column')->toArray(); + $custom_field_columns = CustomField::all()->pluck('db_column')->toArray(); if(Session::exists('ids')) { $assets = Session::get('ids'); @@ -156,13 +157,14 @@ class BulkAssetsController extends Controller ) { foreach ($assets as $assetId) { + \Log::debug('Asset ID is: '.$assetId); $this->update_array = []; $this->conditionallyAddItem('purchase_date') ->conditionallyAddItem('expected_checkin') - ->conditionallyAddItem('model_id') ->conditionallyAddItem('order_number') ->conditionallyAddItem('requestable') + ->conditionallyAddItem('model_id') ->conditionallyAddItem('status_id') ->conditionallyAddItem('supplier_id') ->conditionallyAddItem('warranty_months') @@ -187,6 +189,7 @@ class BulkAssetsController extends Controller $this->update_array['purchase_cost'] = $request->input('purchase_cost'); } + if ($request->filled('company_id')) { $this->update_array['company_id'] = $request->input('company_id'); if ($request->input('company_id') == 'clear') { @@ -208,61 +211,101 @@ class BulkAssetsController extends Controller } $changed = []; - $assetCollection = Asset::where('id' ,$assetId)->get(); + $asset = Asset::find($assetId); + + //dd($this->update_array); foreach ($this->update_array as $key => $value) { - if ($this->update_array[$key] != $assetCollection->toArray()[0][$key]) { - $changed[$key]['old'] = $assetCollection->toArray()[0][$key]; + if ($this->update_array[$key] != $asset->{$key}) { + $changed[$key]['old'] = $asset->{$key}; $changed[$key]['new'] = $this->update_array[$key]; } } + \Log::debug('$this->update_array:'); + \Log::debug(print_r($this->update_array, true)); - $logAction = new Actionlog(); - $logAction->item_type = Asset::class; - $logAction->item_id = $assetId; - $logAction->created_at = date("Y-m-d H:i:s"); - $logAction->user_id = Auth::id(); - $logAction->log_meta = json_encode($changed); - $logAction->logaction('update'); + \Log::debug('$changed'); + \Log::debug(print_r($changed, true)); - if($custom_fields_present) { - $asset = Asset::find($assetId); - $assetCustomFields = $asset->model()->first()->fieldset; - if($assetCustomFields && $assetCustomFields->fields) { - foreach ($assetCustomFields->fields as $field) { - if (array_key_exists($field->db_column, $this->update_array)) { - $asset->{$field->db_column} = $this->update_array[$field->db_column]; - $saved = $asset->save(); - if(!$saved) { - $error_bag[] = $asset->getErrors(); - } - continue; - } else { - $array = $this->update_array; - array_except($array, $field->db_column); - $asset->save($array); - } - if (!$asset->save()) { - $error_bag[] = $asset->getErrors(); - } - } - } - } else { - Asset::find($assetId)->update($this->update_array); - } - } - if(!empty($error_bag)) { - $errors = []; - //find the customfield name from the name of the messagebag items - foreach ($error_bag as $key => $bag) { - foreach($bag->keys() as $key => $value) { - CustomField::where('db_column', $value)->get()->map(function($item) use (&$errors) { - $errors[] = $item->name; - }); + if ($custom_fields_present) { + \Log::debug('Custom fields are present'); + + $model = $asset->model()->first(); + // Make sure this model is valid + $assetCustomFields = ($model) ? $asset->model()->first()->fieldset : null; + + if ($assetCustomFields && $assetCustomFields->fields) { + + \Log::debug('There are custom fields on '.$assetCustomFields->name); + + foreach ($assetCustomFields->fields as $field) { + + if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) { + \Log::debug('The custom field is encrypted!'); + $decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column}); + + // Check if the decrypted existing value is different than one we just submitted + // and if not, pull it out of the object + if ($decrypted_old != $this->update_array[$field->db_column]) { + \Log::debug('The decrypted existing value is different than the one submitted'); + $asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]); + } else { + \Log::debug('The decrypted existing value is the same as the one submitted - unset it'); + unset($this->update_array[$field->db_column]); + unset($asset->{$field->db_column}); + } + + // These fields aren't encrypted, just carry on as usual + } else { + if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) { + \Log::debug('The custom field value is different than the original one'); + $asset->{$field->db_column} = $this->update_array[$field->db_column]; + } + } + + } // endforeach + } // end custom field check + } // end custom fields handler + + + // Check if it passes validation, and then try to save + $has_errors = 0; + $error_array = array(); + + if ($asset->isValid()) { + if ($asset->update($this->update_array)) { + $logAction = new Actionlog(); + $logAction->item_type = Asset::class; + $logAction->item_id = $assetId; + $logAction->created_at = date("Y-m-d H:i:s"); + $logAction->user_id = Auth::id(); + $logAction->log_meta = json_encode($changed); + $logAction->logaction('update'); + } + + \Log::debug('New asset info:'); + \Log::debug('Model name: '.$asset->model->name); + \Log::debug('Asset ID '.$asset->id.' with custom fields bulk edited successfully'); + + } else { + $has_errors++; + \Log::debug(print_r($asset->getErrors(), true)); + // Build the error array + foreach ($asset->getErrors()->toArray() as $key => $message) { + for ($x = 0; $x < count($message); $x++) { + $error_array[][] = trans('general.asset').' '.$asset->id.': '.$message[$x]; + } } } - return redirect($bulk_back_url)->with('bulk_errors', array_unique($errors)); - } + + } // end asset foreach + + if ($has_errors > 0) { + \Log::debug('Ooops!'); + dd($error_array); + return redirect($bulk_back_url)->with('bulk_errors', array_unique($error_array)); + } + return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); } // no values given, nothing to update @@ -284,6 +327,7 @@ class BulkAssetsController extends Controller { if (request()->filled($field)) { $this->update_array[$field] = request()->input($field); + \Log::debug('Conditionally adding '.$field); } return $this; From 60e0e899bc0a203bbc1439e1afcff3e8d4c6fcaf Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 02:35:33 +0100 Subject: [PATCH 077/172] Added show_in_requestable_list to factory Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index 2dfa07d61a..937c66fb0b 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -26,6 +26,7 @@ class CustomFieldFactory extends Factory 'format' => '', 'element' => 'text', 'auto_add_to_fieldsets' => '0', + 'show_in_requestable_list' => '0', ]; } @@ -66,6 +67,7 @@ class CustomFieldFactory extends Factory return [ 'name' => 'CPU', 'help_text' => 'The speed of the processor on this device.', + 'show_in_requestable_list' => '1', ]; }); } From b87879f8e7f4f074fdca7a22b8eb05322d292616 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 02:35:53 +0100 Subject: [PATCH 078/172] Removed debugging Signed-off-by: snipe --- .../Assets/BulkAssetsController.php | 66 ++++++++----------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index fe151b4278..02119edf6e 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -112,7 +112,8 @@ class BulkAssetsController extends Controller public function update(Request $request) { $this->authorize('update', Asset::class); - $error_bag = []; + $has_errors = 0; + $error_array = array(); // Get the back url from the session and then destroy the session $bulk_back_url = route('hardware.index'); @@ -120,11 +121,9 @@ class BulkAssetsController extends Controller $bulk_back_url = $request->session()->pull('bulk_back_url'); } - \Log::debug(print_r($request->all(), true)); - $custom_field_columns = CustomField::all()->pluck('db_column')->toArray(); - if(Session::exists('ids')) { + if (Session::exists('ids')) { $assets = Session::get('ids'); } elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) { return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected')); @@ -157,7 +156,6 @@ class BulkAssetsController extends Controller ) { foreach ($assets as $assetId) { - \Log::debug('Asset ID is: '.$assetId); $this->update_array = []; $this->conditionallyAddItem('purchase_date') @@ -221,14 +219,13 @@ class BulkAssetsController extends Controller $changed[$key]['new'] = $this->update_array[$key]; } } - \Log::debug('$this->update_array:'); - \Log::debug(print_r($this->update_array, true)); - - \Log::debug('$changed'); - \Log::debug(print_r($changed, true)); +// \Log::debug('$this->update_array:'); +// \Log::debug(print_r($this->update_array, true)); +// +// \Log::debug('$changed'); +// \Log::debug(print_r($changed, true)); if ($custom_fields_present) { - \Log::debug('Custom fields are present'); $model = $asset->model()->first(); // Make sure this model is valid @@ -236,18 +233,15 @@ class BulkAssetsController extends Controller if ($assetCustomFields && $assetCustomFields->fields) { - \Log::debug('There are custom fields on '.$assetCustomFields->name); foreach ($assetCustomFields->fields as $field) { if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) { - \Log::debug('The custom field is encrypted!'); $decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column}); // Check if the decrypted existing value is different than one we just submitted // and if not, pull it out of the object if ($decrypted_old != $this->update_array[$field->db_column]) { - \Log::debug('The decrypted existing value is different than the one submitted'); $asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]); } else { \Log::debug('The decrypted existing value is the same as the one submitted - unset it'); @@ -258,7 +252,6 @@ class BulkAssetsController extends Controller // These fields aren't encrypted, just carry on as usual } else { if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) { - \Log::debug('The custom field value is different than the original one'); $asset->{$field->db_column} = $this->update_array[$field->db_column]; } } @@ -269,41 +262,37 @@ class BulkAssetsController extends Controller // Check if it passes validation, and then try to save - $has_errors = 0; - $error_array = array(); - - if ($asset->isValid()) { - if ($asset->update($this->update_array)) { - $logAction = new Actionlog(); - $logAction->item_type = Asset::class; - $logAction->item_id = $assetId; - $logAction->created_at = date("Y-m-d H:i:s"); - $logAction->user_id = Auth::id(); - $logAction->log_meta = json_encode($changed); - $logAction->logaction('update'); - } - - \Log::debug('New asset info:'); - \Log::debug('Model name: '.$asset->model->name); - \Log::debug('Asset ID '.$asset->id.' with custom fields bulk edited successfully'); + if ($asset->update($this->update_array)) { + $logAction = new Actionlog(); + $logAction->item_type = Asset::class; + $logAction->item_id = $assetId; + $logAction->created_at = date("Y-m-d H:i:s"); + $logAction->user_id = Auth::id(); + $logAction->log_meta = json_encode($changed); + $logAction->logaction('update'); } else { - $has_errors++; + + \Log::debug('Error bag:'); \Log::debug(print_r($asset->getErrors(), true)); // Build the error array foreach ($asset->getErrors()->toArray() as $key => $message) { for ($x = 0; $x < count($message); $x++) { - $error_array[][] = trans('general.asset').' '.$asset->id.': '.$message[$x]; + $error_array[$key][] = trans('general.asset') . ' ' . $asset->id . ': ' . $message[$x]; + $has_errors++; } } - } + + } // end if saved } // end asset foreach + \Log::debug($has_errors.' errors'); if ($has_errors > 0) { - \Log::debug('Ooops!'); - dd($error_array); - return redirect($bulk_back_url)->with('bulk_errors', array_unique($error_array)); + \Log::debug('Error array:'); + \Log::debug(print_r($error_array, true)); + //dd($error_array); + return redirect($bulk_back_url)->with('bulk_asset_errors', $error_array); } return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success')); @@ -327,7 +316,6 @@ class BulkAssetsController extends Controller { if (request()->filled($field)) { $this->update_array[$field] = request()->input($field); - \Log::debug('Conditionally adding '.$field); } return $this; From 522aa96fcc016a50c70f14c1c5e6c428d5f50a88 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 02:36:18 +0100 Subject: [PATCH 079/172] Changed error variable name Signed-off-by: snipe --- resources/views/notifications.blade.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index eca773e219..9dbb547515 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -115,17 +115,19 @@ @endif -@if ($messages = Session::get('bulk_errors')) +@if ($messages = Session::get('bulk_asset_errors'))
{{ trans('general.notification_error') }}: {{ trans('general.notification_bulk_error_hint') }} - @foreach($messages as $message) + @foreach($messages as $key => $message) + @for ($x = 0; $x < count($message); $x++)
    -
  • {{ $message }}
  • -
+
  • {{ $message[$x] }}
  • + + @endfor @endforeach
    From 436192b8362ddedf84da1a91d4db09b048cf8b5f Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 02:56:34 +0100 Subject: [PATCH 080/172] Fixed seeder Signed-off-by: snipe --- database/factories/ActionlogFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/ActionlogFactory.php b/database/factories/ActionlogFactory.php index c25fdcc70a..1a4007888c 100644 --- a/database/factories/ActionlogFactory.php +++ b/database/factories/ActionlogFactory.php @@ -38,7 +38,7 @@ class ActionlogFactory extends Factory { return $this->state(function () { $target = User::inRandomOrder()->first(); - $asset = Asset::RTD()->inRandomOrder()->first(); + $asset = Asset::inRandomOrder()->RTD()->first(); $asset->update( [ From 77d141d19c005c3a1487a8b10e3847568bceb35b Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 03:56:02 +0100 Subject: [PATCH 081/172] =?UTF-8?q?Don=E2=80=99t=20check=20the=20delete=20?= =?UTF-8?q?expected=20checkin=20by=20detault?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/views/hardware/bulk.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/hardware/bulk.blade.php b/resources/views/hardware/bulk.blade.php index e26b957057..a7e52dfa56 100755 --- a/resources/views/hardware/bulk.blade.php +++ b/resources/views/hardware/bulk.blade.php @@ -62,7 +62,7 @@
    From 541ba0c0ba406caa58e137e2a09385acf0e0a5a2 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 04:20:52 +0100 Subject: [PATCH 082/172] Removed conditional add for model_id Signed-off-by: snipe --- app/Http/Controllers/Assets/BulkAssetsController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 02119edf6e..1ec73e5390 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -162,7 +162,6 @@ class BulkAssetsController extends Controller ->conditionallyAddItem('expected_checkin') ->conditionallyAddItem('order_number') ->conditionallyAddItem('requestable') - ->conditionallyAddItem('model_id') ->conditionallyAddItem('status_id') ->conditionallyAddItem('supplier_id') ->conditionallyAddItem('warranty_months') From f25ddee8571b53e11a6a6e06c9c530d0d53e3e92 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 04:21:14 +0100 Subject: [PATCH 083/172] Removed debugging, use new model rules if model has changed Signed-off-by: snipe --- .../Assets/BulkAssetsController.php | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 1ec73e5390..44d2498edf 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -210,35 +210,35 @@ class BulkAssetsController extends Controller $changed = []; $asset = Asset::find($assetId); - //dd($this->update_array); - foreach ($this->update_array as $key => $value) { if ($this->update_array[$key] != $asset->{$key}) { $changed[$key]['old'] = $asset->{$key}; $changed[$key]['new'] = $this->update_array[$key]; } } -// \Log::debug('$this->update_array:'); -// \Log::debug(print_r($this->update_array, true)); -// -// \Log::debug('$changed'); -// \Log::debug(print_r($changed, true)); if ($custom_fields_present) { $model = $asset->model()->first(); + + // Use the rules of the new model fieldsets if the model changed + if ($request->filled('model_id')) { + $this->update_array['model_id'] = $request->input('model_id'); + $model = \App\Models\AssetModel::find($request->input('model_id')); + } + + // Make sure this model is valid - $assetCustomFields = ($model) ? $asset->model()->first()->fieldset : null; + $assetCustomFields = ($model) ? $model->fieldset : null; if ($assetCustomFields && $assetCustomFields->fields) { - foreach ($assetCustomFields->fields as $field) { if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) { $decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column}); - // Check if the decrypted existing value is different than one we just submitted + // Check if the decrypted existing value is different from one we just submitted // and if not, pull it out of the object if ($decrypted_old != $this->update_array[$field->db_column]) { $asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]); @@ -252,6 +252,10 @@ class BulkAssetsController extends Controller } else { if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) { $asset->{$field->db_column} = $this->update_array[$field->db_column]; + if (is_array($this->update_array[$field->db_column])) { + $asset->{$field->db_column} = implode(', ', $this->update_array[$field->db_column]); + } + } } From 269557696879fa958aedeec822436d43bdc15ef7 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 04:21:20 +0100 Subject: [PATCH 084/172] Removed debugging Signed-off-by: snipe --- app/Http/Controllers/Assets/BulkAssetsController.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 44d2498edf..bd41c7582f 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -290,11 +290,7 @@ class BulkAssetsController extends Controller } // end asset foreach - \Log::debug($has_errors.' errors'); if ($has_errors > 0) { - \Log::debug('Error array:'); - \Log::debug(print_r($error_array, true)); - //dd($error_array); return redirect($bulk_back_url)->with('bulk_asset_errors', $error_array); } From 7042260871927f3a24c11c2b0f771e8df00e824b Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 04:23:11 +0100 Subject: [PATCH 085/172] More style polishing on custom fields in bulk edit Signed-off-by: snipe --- .../custom_fields_form_bulk_edit.blade.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/resources/views/models/custom_fields_form_bulk_edit.blade.php b/resources/views/models/custom_fields_form_bulk_edit.blade.php index e974c3f6eb..f30c60d331 100644 --- a/resources/views/models/custom_fields_form_bulk_edit.blade.php +++ b/resources/views/models/custom_fields_form_bulk_edit.blade.php @@ -37,21 +37,20 @@ @elseif ($field->element=='checkbox') @foreach ($field->formatFieldValuesAsArray() as $key => $value) -
    - -
    + + @endforeach @elseif ($field->element=='radio') @foreach ($field->formatFieldValuesAsArray() as $value) -
    -
    + @endforeach @endif From 6c996ac8faeddf1c8bdd182345b32ef8da89348d Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 05:03:59 +0100 Subject: [PATCH 086/172] Changed the seeder order to accomodate actionlog factory Signed-off-by: snipe --- database/seeders/DatabaseSeeder.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 1429604139..5e26a9a257 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -38,12 +38,13 @@ class DatabaseSeeder extends Seeder $this->call(DepreciationSeeder::class); $this->call(StatuslabelSeeder::class); $this->call(AccessorySeeder::class); + $this->call(CustomFieldSeeder::class); $this->call(AssetSeeder::class); $this->call(LicenseSeeder::class); $this->call(ComponentSeeder::class); $this->call(ConsumableSeeder::class); $this->call(ActionlogSeeder::class); - $this->call(CustomFieldSeeder::class); + Artisan::call('snipeit:sync-asset-locations', ['--output' => 'all']); $output = Artisan::output(); From 3717d60170640e201a85b2d272f7aa48789ec9cf Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 05:04:30 +0100 Subject: [PATCH 087/172] Added two more custom fields/fieldsets to seeder Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 22 +++++++++++++++++ database/seeders/CustomFieldSeeder.php | 30 +++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index 937c66fb0b..53f23a205f 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -81,4 +81,26 @@ class CustomFieldFactory extends Factory ]; }); } + + public function testEncrypted() + { + return $this->state(function () { + return [ + 'name' => 'Test Encrypted', + 'help_text' => 'This is a test encrypted field.', + ]; + }); + } + + public function testCheckbox() + { + return $this->state(function () { + return [ + 'name' => 'Test Checkbox', + 'help_text' => 'This is a test checkbox.', + 'field_values' => "One\nTwo\nThree", + 'element' => 'checkbox', + ]; + }); + } } diff --git a/database/seeders/CustomFieldSeeder.php b/database/seeders/CustomFieldSeeder.php index 551e05f40f..e51ca510f9 100644 --- a/database/seeders/CustomFieldSeeder.php +++ b/database/seeders/CustomFieldSeeder.php @@ -33,6 +33,9 @@ class CustomFieldSeeder extends Seeder CustomField::factory()->count(1)->ram()->create(); CustomField::factory()->count(1)->cpu()->create(); CustomField::factory()->count(1)->macAddress()->create(); + CustomField::factory()->count(1)->testEncrypted()->create(); + CustomField::factory()->count(1)->testCheckbox()->create(); + DB::table('custom_field_custom_fieldset')->insert([ [ @@ -66,6 +69,33 @@ class CustomFieldSeeder extends Seeder 'required' => 0, ], + [ + 'custom_field_id' => '6', + 'custom_fieldset_id' => '2', + 'order' => 0, + 'required' => 0, + ], + + [ + 'custom_field_id' => '6', + 'custom_fieldset_id' => '1', + 'order' => 0, + 'required' => 0, + ], + + [ + 'custom_field_id' => '7', + 'custom_fieldset_id' => '2', + 'order' => 0, + 'required' => 0, + ], + [ + 'custom_field_id' => '7', + 'custom_fieldset_id' => '1', + 'order' => 0, + 'required' => 0, + ], + ]); } } From c3b3aa4de630dfd1e7d3c83d9966734c3ec0cd30 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 06:25:51 +0100 Subject: [PATCH 088/172] Set one field to encrypted in the seeder Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 1 + 1 file changed, 1 insertion(+) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index 53f23a205f..142adacdcf 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -87,6 +87,7 @@ class CustomFieldFactory extends Factory return $this->state(function () { return [ 'name' => 'Test Encrypted', + 'field_encrypted' => '1', 'help_text' => 'This is a test encrypted field.', ]; }); From 0cebccac95ee04689cf992acfc49b8a768ac0c6c Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 06:51:07 +0100 Subject: [PATCH 089/172] Removed extra logging Signed-off-by: snipe --- .../Assets/BulkAssetsController.php | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index bd41c7582f..d17dbcb3bb 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -250,12 +250,16 @@ class BulkAssetsController extends Controller // These fields aren't encrypted, just carry on as usual } else { + + if ((array_key_exists($field->db_column, $this->update_array)) && ($asset->{$field->db_column} != $this->update_array[$field->db_column])) { - $asset->{$field->db_column} = $this->update_array[$field->db_column]; + + // Check if this is an array, and if so, flatten it if (is_array($this->update_array[$field->db_column])) { $asset->{$field->db_column} = implode(', ', $this->update_array[$field->db_column]); + } else { + $asset->{$field->db_column} = $this->update_array[$field->db_column]; } - } } @@ -264,20 +268,10 @@ class BulkAssetsController extends Controller } // end custom fields handler + // Check if it passes validation, and then try to save - if ($asset->update($this->update_array)) { - $logAction = new Actionlog(); - $logAction->item_type = Asset::class; - $logAction->item_id = $assetId; - $logAction->created_at = date("Y-m-d H:i:s"); - $logAction->user_id = Auth::id(); - $logAction->log_meta = json_encode($changed); - $logAction->logaction('update'); + if (!$asset->update($this->update_array)) { - } else { - - \Log::debug('Error bag:'); - \Log::debug(print_r($asset->getErrors(), true)); // Build the error array foreach ($asset->getErrors()->toArray() as $key => $message) { for ($x = 0; $x < count($message); $x++) { @@ -286,7 +280,7 @@ class BulkAssetsController extends Controller } } - } // end if saved + } // end if saved } // end asset foreach From c4c47f2e8d3f8e7f61064bb8871875a783b5bb0b Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 06:51:14 +0100 Subject: [PATCH 090/172] Updated comment Signed-off-by: snipe --- app/Observers/AssetObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index c15c54a568..1e137d34c4 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -11,7 +11,7 @@ use Carbon\Carbon; class AssetObserver { /** - * Listen to the User created event. + * Listen to the User updating event. This fires automatically every time an asset is saved. * * @param Asset $asset * @return void From 9d887484c8c40faad442b0b163c0adb93b935a18 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 07:41:25 +0100 Subject: [PATCH 091/172] Added encrypted custom field to seeder Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 14 ++++++++++++-- database/seeders/CustomFieldSeeder.php | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index 142adacdcf..7cbc2210c9 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -88,7 +88,7 @@ class CustomFieldFactory extends Factory return [ 'name' => 'Test Encrypted', 'field_encrypted' => '1', - 'help_text' => 'This is a test encrypted field.', + 'help_text' => 'This is a sample encrypted field.', ]; }); } @@ -98,10 +98,20 @@ class CustomFieldFactory extends Factory return $this->state(function () { return [ 'name' => 'Test Checkbox', - 'help_text' => 'This is a test checkbox.', + 'help_text' => 'This is a sample checkbox.', 'field_values' => "One\nTwo\nThree", 'element' => 'checkbox', ]; }); } + + public function testRequired() + { + return $this->state(function () { + return [ + 'name' => 'Test Required', + 'help_text' => 'This is a sample required field.', + ]; + }); + } } diff --git a/database/seeders/CustomFieldSeeder.php b/database/seeders/CustomFieldSeeder.php index e51ca510f9..5d8d44e4b8 100644 --- a/database/seeders/CustomFieldSeeder.php +++ b/database/seeders/CustomFieldSeeder.php @@ -35,6 +35,7 @@ class CustomFieldSeeder extends Seeder CustomField::factory()->count(1)->macAddress()->create(); CustomField::factory()->count(1)->testEncrypted()->create(); CustomField::factory()->count(1)->testCheckbox()->create(); + CustomField::factory()->count(1)->testRequired()->create(); DB::table('custom_field_custom_fieldset')->insert([ @@ -96,6 +97,13 @@ class CustomFieldSeeder extends Seeder 'required' => 0, ], + [ + 'custom_field_id' => '8', + 'custom_fieldset_id' => '1', + 'order' => 0, + 'required' => 1, + ], + ]); } } From ff72c4fbaa510f71846eaf35e4795a3375449aa5 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 09:17:28 +0100 Subject: [PATCH 092/172] Added nicer formatting for fields in log meta Signed-off-by: snipe --- .../Transformers/ActionlogsTransformer.php | 8 +++++ .../views/partials/bootstrap-table.blade.php | 29 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index d3af3bb753..61ae1af9a2 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -3,6 +3,7 @@ namespace App\Http\Transformers; use App\Helpers\Helper; use App\Models\Actionlog; +use App\Models\Asset; use App\Models\CustomField; use App\Models\Setting; use App\Models\Company; @@ -12,6 +13,7 @@ use App\Models\AssetModel; use Illuminate\Database\Eloquent\Collection; use Illuminate\Contracts\Encryption\DecryptException; use Illuminate\Support\Facades\Crypt; +use Illuminate\Support\Facades\Gate; class ActionlogsTransformer { @@ -98,6 +100,12 @@ class ActionlogsTransformer \Log::debug('custom fields do not match'); $clean_meta[$fieldname]['old'] = "************"; $clean_meta[$fieldname]['new'] = "************"; + + if (Gate::allows('admin')) { + $clean_meta[$fieldname]['old'] = unserialize($enc_old); + $clean_meta[$fieldname]['new'] = unserialize($enc_new); + } + } diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index 78f3d152d2..a7c2084adb 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -530,15 +530,42 @@ function changeLogFormatter(value) { + + console.dir(value); var result = ''; + var pretty_index = ''; + + console.error('first the formatter'); + for (var index in value) { - result += index + ': ' + value[index].old + ' ' + value[index].new + '
    ' + + + // Check if it's a custom field + if (index.startsWith('_snipeit_')) { + console.error('It is a custom field'); + pretty_index = index.replace("_snipeit_", "Custom:_"); + } else { + console.error('Not a custom field'); + pretty_index = index; + } + + extra_pretty_index = prettyLog(pretty_index); + + result += extra_pretty_index + ': ' + value[index].old + ' ' + value[index].new + '
    ' } return result; } + function prettyLog(str) { + let frags = str.split('_'); + for (let i = 0; i < frags.length; i++) { + frags[i] = frags[i].charAt(0).toUpperCase() + frags[i].slice(1); + } + return frags.join(' '); + } + // Create a linked phone number in the table list function phoneFormatter(value) { From 05de8a5731d7d67ac536652fba3c542ff98721ea Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 09:21:27 +0100 Subject: [PATCH 093/172] Re-added missing break Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index ea916c5182..bbdc982599 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -1089,6 +1089,7 @@ class AssetsController extends Controller break; case 'location': $assets->OrderLocation($order); + break; default: $assets->orderBy($column_sort, $order); break; From c1213e0abc364a981d4f89c87d4ba6bc9ae80f9c Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 09:41:44 +0100 Subject: [PATCH 094/172] Nicer handling for empty custom fields Signed-off-by: snipe --- app/Http/Transformers/ActionlogsTransformer.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index 61ae1af9a2..db7105fc9a 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -101,9 +101,10 @@ class ActionlogsTransformer $clean_meta[$fieldname]['old'] = "************"; $clean_meta[$fieldname]['new'] = "************"; + // Display the changes if the user is an admin or superadmin if (Gate::allows('admin')) { - $clean_meta[$fieldname]['old'] = unserialize($enc_old); - $clean_meta[$fieldname]['new'] = unserialize($enc_new); + $clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): '(blank)'; + $clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): '(blank)'; } } From 9c90f031423461dfba22bba2aa33f06b74494fb8 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 14:34:18 +0100 Subject: [PATCH 095/172] Updated comment Signed-off-by: snipe --- app/Observers/AssetObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Observers/AssetObserver.php b/app/Observers/AssetObserver.php index 1e137d34c4..5117f74d3c 100644 --- a/app/Observers/AssetObserver.php +++ b/app/Observers/AssetObserver.php @@ -11,7 +11,7 @@ use Carbon\Carbon; class AssetObserver { /** - * Listen to the User updating event. This fires automatically every time an asset is saved. + * Listen to the Asset updating event. This fires automatically every time an existing asset is saved. * * @param Asset $asset * @return void From 1ce95b6eac52a394b996def1a3177116d4688c44 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 14:34:27 +0100 Subject: [PATCH 096/172] Removed debugging Signed-off-by: snipe --- resources/views/partials/bootstrap-table.blade.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/resources/views/partials/bootstrap-table.blade.php b/resources/views/partials/bootstrap-table.blade.php index a7c2084adb..0122096f80 100644 --- a/resources/views/partials/bootstrap-table.blade.php +++ b/resources/views/partials/bootstrap-table.blade.php @@ -531,21 +531,16 @@ function changeLogFormatter(value) { - console.dir(value); var result = ''; var pretty_index = ''; - console.error('first the formatter'); - for (var index in value) { // Check if it's a custom field if (index.startsWith('_snipeit_')) { - console.error('It is a custom field'); pretty_index = index.replace("_snipeit_", "Custom:_"); } else { - console.error('Not a custom field'); pretty_index = index; } From 9bba0b764ab25fe154be5097e4961a145c2bf267 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 14:38:39 +0100 Subject: [PATCH 097/172] Added clearer comments Signed-off-by: snipe --- .../Controllers/Assets/BulkAssetsController.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index d17dbcb3bb..45ca5bab7c 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -238,17 +238,26 @@ class BulkAssetsController extends Controller if ((array_key_exists($field->db_column, $this->update_array)) && ($field->field_encrypted=='1')) { $decrypted_old = Helper::gracefulDecrypt($field, $asset->{$field->db_column}); - // Check if the decrypted existing value is different from one we just submitted - // and if not, pull it out of the object + /* + * Check if the decrypted existing value is different from one we just submitted + * and if not, pull it out of the object since it shouldn't really be updating at all. + * If we don't do this, it will try to re-encrypt it, and the same value encrypted two + * different times will have different values, so it will *look* like it was updated + * but it wasn't. + */ if ($decrypted_old != $this->update_array[$field->db_column]) { $asset->{$field->db_column} = \Crypt::encrypt($this->update_array[$field->db_column]); } else { - \Log::debug('The decrypted existing value is the same as the one submitted - unset it'); + /* + * Remove the encrypted custom field from the update_array, since nothing changed + */ unset($this->update_array[$field->db_column]); unset($asset->{$field->db_column}); } - // These fields aren't encrypted, just carry on as usual + /* + * These custom fields aren't encrypted, just carry on as usual + */ } else { From 305cd9b0b81d35d3eb10edfec263394f6880053d Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 14:42:49 +0100 Subject: [PATCH 098/172] Use null instead of blank Signed-off-by: snipe --- app/Http/Transformers/ActionlogsTransformer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index db7105fc9a..e5837666ac 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -103,8 +103,8 @@ class ActionlogsTransformer // Display the changes if the user is an admin or superadmin if (Gate::allows('admin')) { - $clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): '(blank)'; - $clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): '(blank)'; + $clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): 'null'; + $clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): 'null'; } } From 7b2f49644ee86947021ece76d6036fb2442cc386 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 14:44:17 +0100 Subject: [PATCH 099/172] Use nothing instead of null to make it consistent Signed-off-by: snipe --- app/Http/Transformers/ActionlogsTransformer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Transformers/ActionlogsTransformer.php b/app/Http/Transformers/ActionlogsTransformer.php index e5837666ac..1de9143329 100644 --- a/app/Http/Transformers/ActionlogsTransformer.php +++ b/app/Http/Transformers/ActionlogsTransformer.php @@ -103,8 +103,8 @@ class ActionlogsTransformer // Display the changes if the user is an admin or superadmin if (Gate::allows('admin')) { - $clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): 'null'; - $clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): 'null'; + $clean_meta[$fieldname]['old'] = ($enc_old) ? unserialize($enc_old): ''; + $clean_meta[$fieldname]['new'] = ($enc_new) ? unserialize($enc_new): ''; } } From a2ba39c837307b0d7f87d6e1b128d5a4a5689861 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 26 Oct 2023 17:57:05 +0100 Subject: [PATCH 100/172] Removed required custom field from seeder Signed-off-by: snipe --- database/factories/CustomFieldFactory.php | 9 --------- database/seeders/CustomFieldSeeder.php | 8 -------- 2 files changed, 17 deletions(-) diff --git a/database/factories/CustomFieldFactory.php b/database/factories/CustomFieldFactory.php index 7cbc2210c9..9407f16b0a 100644 --- a/database/factories/CustomFieldFactory.php +++ b/database/factories/CustomFieldFactory.php @@ -105,13 +105,4 @@ class CustomFieldFactory extends Factory }); } - public function testRequired() - { - return $this->state(function () { - return [ - 'name' => 'Test Required', - 'help_text' => 'This is a sample required field.', - ]; - }); - } } diff --git a/database/seeders/CustomFieldSeeder.php b/database/seeders/CustomFieldSeeder.php index 5d8d44e4b8..e51ca510f9 100644 --- a/database/seeders/CustomFieldSeeder.php +++ b/database/seeders/CustomFieldSeeder.php @@ -35,7 +35,6 @@ class CustomFieldSeeder extends Seeder CustomField::factory()->count(1)->macAddress()->create(); CustomField::factory()->count(1)->testEncrypted()->create(); CustomField::factory()->count(1)->testCheckbox()->create(); - CustomField::factory()->count(1)->testRequired()->create(); DB::table('custom_field_custom_fieldset')->insert([ @@ -97,13 +96,6 @@ class CustomFieldSeeder extends Seeder 'required' => 0, ], - [ - 'custom_field_id' => '8', - 'custom_fieldset_id' => '1', - 'order' => 0, - 'required' => 1, - ], - ]); } } From 91b53bffa1f606484c922534ffba0a36c41959d3 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 26 Oct 2023 14:23:31 -0500 Subject: [PATCH 101/172] resolved --- app/Http/Controllers/ReportsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index bfa7d98b24..f89ae029db 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -744,7 +744,7 @@ class ReportsController extends Controller } if ($request->filled('eol')) { - $row[] = ($asset->purchase_date != '') ? $asset->present()->eol_date() : ''; + $row[] = ($asset->eol_explicit) ? $asset->asset_eol_date : $asset->present()->eol_date(); } if ($request->filled('order')) { From f12d44509e8100ca82274f1aef1ee54dd68f5b92 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 26 Oct 2023 14:39:02 -0500 Subject: [PATCH 102/172] asset_eol_date should always be filled now --- app/Http/Controllers/ReportsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index f89ae029db..d449d3c444 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -744,7 +744,7 @@ class ReportsController extends Controller } if ($request->filled('eol')) { - $row[] = ($asset->eol_explicit) ? $asset->asset_eol_date : $asset->present()->eol_date(); + $row[] = ($asset->asset_eol_date) ? $asset->asset_eol_date : ''; } if ($request->filled('order')) { From 90eb3b86cf75486adcb784abbff9629357cdd5d9 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Thu, 26 Oct 2023 19:10:53 -0500 Subject: [PATCH 103/172] added user phone & address fields --- app/Http/Controllers/ReportsController.php | 72 ++++++++++++++++++++++ resources/views/reports/custom.blade.php | 32 ++++++++++ 2 files changed, 104 insertions(+) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index d449d3c444..ebd5bc3c4f 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -528,6 +528,30 @@ class ReportsController extends Controller $header[] = trans('admin/users/table.title'); } + if ($request->filled('phone')) { + $header[] = trans('admin/users/table.phone'); + } + + if ($request->filled('user_address')) { + $header[] = trans('general.user') .' '. trans('general.address'); + } + + if ($request->filled('user_city')) { + $header[] = trans('general.user') .' '. trans('general.city'); + } + + if ($request->filled('user_state')) { + $header[] = trans('general.user') .' '. trans('general.state'); + } + + if ($request->filled('user_country')) { + $header[] = trans('general.user') .' '. trans('general.country'); + } + + if ($request->filled('user_zip')) { + $header[] = trans('general.user') .' '. trans('general.zip'); + } + if ($request->filled('status')) { $header[] = trans('general.status'); } @@ -828,6 +852,54 @@ class ReportsController extends Controller } } + if ($request->filled('phone')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->phone : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + + if ($request->filled('user_address')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->address : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + + if ($request->filled('user_city')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->city : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + + if ($request->filled('user_state')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->state : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + + if ($request->filled('user_country')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->country : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + + if ($request->filled('user_zip')) { + if ($asset->checkedOutToUser()) { + $row[] = ($asset->assignedto) ? $asset->assignedto->zip : ''; + } else { + $row[] = ''; // Empty string if unassigned + } + } + if ($request->filled('status')) { $row[] = ($asset->assetstatus) ? $asset->assetstatus->name.' ('.$asset->present()->statusMeta.')' : ''; } diff --git a/resources/views/reports/custom.blade.php b/resources/views/reports/custom.blade.php index 959be57c9c..cc0ec158af 100644 --- a/resources/views/reports/custom.blade.php +++ b/resources/views/reports/custom.blade.php @@ -221,6 +221,38 @@ {{ trans('admin/users/table.title') }} + + + + + + + + + + + + + + @if ($customfields->count() > 0) From 8c46f4ef69b215331516f3597f7d463bd2a2da98 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 13:19:59 +0000 Subject: [PATCH 104/172] Added min_amt value to model detaul page Signed-off-by: snipe --- resources/views/models/view.blade.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index 99a22b00e6..29cfd99c11 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -236,6 +236,12 @@ @endif + @if ($model->min_amt) +
  • {{ trans('general.min_amt') }}: + {{$model->min_amt }} +
  • + @endif + @if ($model->manufacturer)
  • {{ trans('general.manufacturer') }}: From bd894677ef76a65288a8ad95e969805cf8025b1a Mon Sep 17 00:00:00 2001 From: Matthew Manjos Date: Mon, 30 Oct 2023 10:09:44 -0400 Subject: [PATCH 105/172] add missing variable APP_FORCE_TLS to .env.docker --- .env.docker | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.docker b/.env.docker index 8c47c801e2..87897b10db 100644 --- a/.env.docker +++ b/.env.docker @@ -159,6 +159,7 @@ LOG_CHANNEL=stderr LOG_MAX_DAYS=10 APP_LOCKED=false APP_CIPHER=AES-256-CBC +APP_FORCE_TLS=false GOOGLE_MAPS_API= LDAP_MEM_LIM=500M LDAP_TIME_LIM=600 From a6b713ae21bf73401204333fbc2bd28a704866ec Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 14:12:23 +0000 Subject: [PATCH 106/172] Add @mmanjos as a contributor --- .all-contributorsrc | 9 +++++++++ README.md | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index c10b080181..3684e2e26e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -2970,6 +2970,15 @@ "contributions": [ "code" ] + }, + { + "login": "mmanjos", + "name": "mmanjos", + "avatar_url": "https://avatars.githubusercontent.com/u/3483684?v=4", + "profile": "https://github.com/mmanjos", + "contributions": [ + "code" + ] } ] } diff --git a/README.md b/README.md index 3a74120b3d..71aba22b59 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![Crowdin](https://d322cqt584bo4o.cloudfront.net/snipe-it/localized.svg)](https://crowdin.com/project/snipe-it) [![Docker Pulls](https://img.shields.io/docker/pulls/snipe/snipe-it.svg)](https://hub.docker.com/r/snipe/snipe-it/) [![Twitter Follow](https://img.shields.io/twitter/follow/snipeitapp.svg?style=social)](https://twitter.com/snipeitapp) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/553ce52037fc43ea99149785afcfe641)](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade) -[![All Contributors](https://img.shields.io/badge/all_contributors-327-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev) +[![All Contributors](https://img.shields.io/badge/all_contributors-328-orange.svg?style=flat-square)](#contributors) [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/yZFtShAcKk) [![huntr](https://cdn.huntr.dev/huntr_security_badge_mono.svg)](https://huntr.dev) ## Snipe-IT - Open Source Asset Management System @@ -145,7 +145,7 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken | [
    Chris Hartjes](http://www.littlehart.net/atthekeyboard)
    [💻](https://github.com/snipe/snipe-it/commits?author=chartjes "Code") | [
    geo-chen](https://github.com/geo-chen)
    [💻](https://github.com/snipe/snipe-it/commits?author=geo-chen "Code") | [
    Phan Nguyen](https://github.com/nh314)
    [💻](https://github.com/snipe/snipe-it/commits?author=nh314 "Code") | [
    Iisakki Jaakkola](https://github.com/StarlessNights)
    [💻](https://github.com/snipe/snipe-it/commits?author=StarlessNights "Code") | [
    Ikko Ashimine](https://bandism.net/)
    [💻](https://github.com/snipe/snipe-it/commits?author=eltociear "Code") | [
    Lukas Fehling](https://github.com/lukasfehling)
    [💻](https://github.com/snipe/snipe-it/commits?author=lukasfehling "Code") | [
    Fernando Almeida](https://github.com/fernando-almeida)
    [💻](https://github.com/snipe/snipe-it/commits?author=fernando-almeida "Code") | | [
    akemidx](https://github.com/akemidx)
    [💻](https://github.com/snipe/snipe-it/commits?author=akemidx "Code") | [
    Oguz Bilgic](http://oguz.site)
    [💻](https://github.com/snipe/snipe-it/commits?author=oguzbilgic "Code") | [
    Scooter Crawford](https://github.com/scoo73r)
    [💻](https://github.com/snipe/snipe-it/commits?author=scoo73r "Code") | [
    subdriven](https://github.com/subdriven)
    [💻](https://github.com/snipe/snipe-it/commits?author=subdriven "Code") | [
    Andrew Savinykh](https://github.com/AndrewSav)
    [💻](https://github.com/snipe/snipe-it/commits?author=AndrewSav "Code") | [
    Tadayuki Onishi](https://kenchan0130.github.io)
    [💻](https://github.com/snipe/snipe-it/commits?author=kenchan0130 "Code") | [
    Florian](https://github.com/floschoepfer)
    [💻](https://github.com/snipe/snipe-it/commits?author=floschoepfer "Code") | | [
    Spencer Long](http://spencerlong.com)
    [💻](https://github.com/snipe/snipe-it/commits?author=spencerrlongg "Code") | [
    Marcus Moore](https://github.com/marcusmoore)
    [💻](https://github.com/snipe/snipe-it/commits?author=marcusmoore "Code") | [
    Martin Meredith](https://github.com/Mezzle)
    | [
    dboth](http://dboth.de)
    [💻](https://github.com/snipe/snipe-it/commits?author=dboth "Code") | [
    Zachary Fleck](https://github.com/zacharyfleck)
    [💻](https://github.com/snipe/snipe-it/commits?author=zacharyfleck "Code") | [
    VIKAAS-A](https://github.com/vikaas-cyper)
    [💻](https://github.com/snipe/snipe-it/commits?author=vikaas-cyper "Code") | [
    Abdul Kareem](https://github.com/ak-piracha)
    [💻](https://github.com/snipe/snipe-it/commits?author=ak-piracha "Code") | -| [
    NojoudAlshehri](https://github.com/NojoudAlshehri)
    [💻](https://github.com/snipe/snipe-it/commits?author=NojoudAlshehri "Code") | [
    Stefan Stidl](https://github.com/stefanstidlffg)
    [💻](https://github.com/snipe/snipe-it/commits?author=stefanstidlffg "Code") | [
    Quentin Aymard](https://github.com/qay21)
    [💻](https://github.com/snipe/snipe-it/commits?author=qay21 "Code") | [
    Grant Le Roux](https://github.com/cram42)
    [💻](https://github.com/snipe/snipe-it/commits?author=cram42 "Code") | [
    Bogdan](http://@singrity)
    [💻](https://github.com/snipe/snipe-it/commits?author=Singrity "Code") | +| [
    NojoudAlshehri](https://github.com/NojoudAlshehri)
    [💻](https://github.com/snipe/snipe-it/commits?author=NojoudAlshehri "Code") | [
    Stefan Stidl](https://github.com/stefanstidlffg)
    [💻](https://github.com/snipe/snipe-it/commits?author=stefanstidlffg "Code") | [
    Quentin Aymard](https://github.com/qay21)
    [💻](https://github.com/snipe/snipe-it/commits?author=qay21 "Code") | [
    Grant Le Roux](https://github.com/cram42)
    [💻](https://github.com/snipe/snipe-it/commits?author=cram42 "Code") | [
    Bogdan](http://@singrity)
    [💻](https://github.com/snipe/snipe-it/commits?author=Singrity "Code") | [
    mmanjos](https://github.com/mmanjos)
    [💻](https://github.com/snipe/snipe-it/commits?author=mmanjos "Code") | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! From 316c90c14404370c4e5b3c1af79eefa5e14b71c9 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 14:17:27 +0000 Subject: [PATCH 107/172] Update app/Importer/ItemImporter.php Co-authored-by: Marcus Moore --- app/Importer/ItemImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 98590c9ff1..e1b0f1c289 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -372,7 +372,7 @@ class ItemImporter extends Importer if (empty($asset_statuslabel_name)) { return null; } - $status = Statuslabel::where(['name' => trim($asset_statuslabel_name]))->first(); + $status = Statuslabel::where(['name' => trim($asset_statuslabel_name)])->first(); if ($status) { $this->log('A matching Status '.$asset_statuslabel_name.' already exists'); From 97953ae0827b26a64f7dae9a9b4b423440e60f82 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 30 Oct 2023 12:17:55 -0700 Subject: [PATCH 108/172] add missing translation string --- resources/lang/en/admin/users/message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/users/message.php b/resources/lang/en/admin/users/message.php index a3f936dcbb..b7c0a29f14 100644 --- a/resources/lang/en/admin/users/message.php +++ b/resources/lang/en/admin/users/message.php @@ -8,6 +8,7 @@ return array( 'user_exists' => 'User already exists!', 'user_not_found' => 'User does not exist.', 'user_login_required' => 'The login field is required', + 'user_has_no_assets_assigned' => 'No assets currently assigned to user.', 'user_password_required' => 'The password is required.', 'insufficient_permissions' => 'Insufficient Permissions.', 'user_deleted_warning' => 'This user has been deleted. You will have to restore this user to edit them or assign them new assets.', From e554a80589e7af56b7fb0e47cb3c276a3e2619e5 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 20:01:01 +0000 Subject: [PATCH 109/172] Handle redirect from after POST request from backup restore Signed-off-by: snipe --- routes/web.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routes/web.php b/routes/web.php index 0aacf85135..635cdbcb94 100644 --- a/routes/web.php +++ b/routes/web.php @@ -224,6 +224,11 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser [SettingsController::class, 'postUploadBackup'] )->name('settings.backups.upload'); + // Handle redirect from after POST request from backup restore + Route::get('/restore/{filename?}', function () { + return redirect(route('settings.backups.index')); + }); + Route::get('/', [SettingsController::class, 'getBackups'])->name('settings.backups.index'); }); From 79f380cbe7f94192ce67b9d24bf9353a56562182 Mon Sep 17 00:00:00 2001 From: Nathan Butler Date: Tue, 31 Oct 2023 10:28:54 +1100 Subject: [PATCH 110/172] Added asset history tab to locations view --- resources/views/locations/view.blade.php | 56 ++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index a1c3320194..e000ed5c28 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -104,6 +104,17 @@
  • + +
  • + + + + +
  • @@ -319,6 +330,51 @@
    +
    +

    {{ trans('general.history') }}

    + +
    +
    + + + + + + + + + + + + + + + +
    {{ trans('general.date') }}{{ trans('general.admin') }}{{ trans('general.action') }}{{ trans('general.item') }}{{ trans('general.target') }}{{ trans('general.notes') }}{{ trans('general.signature') }}{{ trans('general.download') }}{{ trans('admin/hardware/table.changed')}}
    +
    +
    +
    +
    From 96211cf73c2c4f4e52bdfb27a8b57ca1a1d9cbd2 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 09:43:47 +0000 Subject: [PATCH 111/172] Add additional fields to Download All in Activity Report Signed-off-by: snipe --- app/Http/Controllers/ReportsController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index ebd5bc3c4f..72e042db91 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -247,6 +247,9 @@ class ReportsController extends Controller trans('general.action'), trans('general.type'), trans('general.item'), + trans('general.license_serial'), + trans('general.model_name'), + trans('general.model_no'), 'To', trans('general.notes'), 'Changed', @@ -289,6 +292,9 @@ class ReportsController extends Controller $actionlog->present()->actionType(), e($actionlog->itemType()), ($actionlog->itemType() == 'user') ? $actionlog->filename : $item_name, + ($actionlog->item->serial) ? $actionlog->item->serial : null, + ($actionlog->item->model) ? htmlspecialchars($actionlog->item->model->name, ENT_NOQUOTES) : null, + ($actionlog->item->model) ? $actionlog->item->model->model_number : null, $target_name, ($actionlog->note) ? e($actionlog->note) : '', $actionlog->log_meta, From 9fc1cbd7aec9c6cf32a4e4716822c9fbe4915ab7 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 12:24:48 +0000 Subject: [PATCH 112/172] Change cast to include format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://laravel.com/docs/8.x/eloquent-mutators#date-casting - this doesn’t seem to work tho? Signed-off-by: snipe --- app/Models/License.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Models/License.php b/app/Models/License.php index 44f1f45b70..ba00b7d0d4 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -32,10 +32,11 @@ class License extends Depreciable protected $guarded = 'id'; protected $table = 'licenses'; + protected $casts = [ - 'purchase_date' => 'date', - 'expiration_date' => 'date', - 'termination_date' => 'date', + 'purchase_date' => 'date:Y-m-d', + 'expiration_date' => 'date:Y-m-d', + 'termination_date' => 'date:Y-m-d', 'category_id' => 'integer', 'company_id' => 'integer', ]; From 209627e2cc828eea439fed92d422b84a7e6ef877 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 12:25:00 +0000 Subject: [PATCH 113/172] Force format if dates are given Signed-off-by: snipe --- resources/views/licenses/edit.blade.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/licenses/edit.blade.php b/resources/views/licenses/edit.blade.php index cdbbc23e74..b0ff9063f2 100755 --- a/resources/views/licenses/edit.blade.php +++ b/resources/views/licenses/edit.blade.php @@ -79,7 +79,7 @@
    - +
    {!! $errors->first('expiration_date', '') !!} @@ -93,7 +93,7 @@
    - +
    {!! $errors->first('termination_date', '') !!} From 5779a632216b678ef86c6c5577fcf0cd44fd331c Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 12:28:57 +0000 Subject: [PATCH 114/172] Undoing that thing I just did :( Signed-off-by: snipe --- app/Models/License.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Models/License.php b/app/Models/License.php index ba00b7d0d4..2ea10939fa 100755 --- a/app/Models/License.php +++ b/app/Models/License.php @@ -34,9 +34,9 @@ class License extends Depreciable protected $casts = [ - 'purchase_date' => 'date:Y-m-d', - 'expiration_date' => 'date:Y-m-d', - 'termination_date' => 'date:Y-m-d', + 'purchase_date' => 'date', + 'expiration_date' => 'date', + 'termination_date' => 'date', 'category_id' => 'integer', 'company_id' => 'integer', ]; From 3495652827a92a0580f876b36bb0553d78d40b69 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 12:52:53 +0000 Subject: [PATCH 115/172] Added checkboxes to intentionally remove field values in bulk user edit Signed-off-by: snipe --- .../Controllers/Users/BulkUsersController.php | 16 ++++++++++ resources/views/users/bulk-edit.blade.php | 30 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index a2d3d496da..ca1e2a4897 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -125,10 +125,26 @@ class BulkUsersController extends Controller ]; } + /** + * Check to see if the user wants to actually blank out the values vs skip them + */ if ($request->input('null_location_id')=='1') { $this->update_array['location_id'] = null; } + if ($request->input('null_department_id')=='1') { + $this->update_array['department_id'] = null; + } + + if ($request->input('null_manager_id')=='1') { + $this->update_array['manager_id'] = null; + } + + if ($request->input('null_company_id')=='1') { + $this->update_array['company_id'] = null; + } + + if (! $manager_conflict) { $this->conditionallyAddItem('manager_id'); } diff --git a/resources/views/users/bulk-edit.blade.php b/resources/views/users/bulk-edit.blade.php index bdc1ad9289..b28eb602d2 100644 --- a/resources/views/users/bulk-edit.blade.php +++ b/resources/views/users/bulk-edit.blade.php @@ -39,6 +39,16 @@ @include ('partials.forms.edit.department-select', ['translated_name' => trans('general.department'), 'fieldname' => 'department_id']) +
    +
    + +
    +
    + + @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) @@ -55,11 +65,31 @@ @if (\App\Models\Company::canManageUsersCompanies()) @include ('partials.forms.edit.company-select', ['translated_name' => trans('general.select_company'), 'fieldname' => 'company_id']) + +
    +
    + +
    +
    + @endif @include ('partials.forms.edit.user-select', ['translated_name' => trans('admin/users/table.manager'), 'fieldname' => 'manager_id']) +
    +
    + +
    +
    + +
    From 57372fc82ab2f3c89ef1d6b372b76511de2738a0 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 15:30:38 +0000 Subject: [PATCH 116/172] Correctly call the validator in the response if it fails Signed-off-by: snipe --- app/Http/Controllers/SettingsController.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/SettingsController.php b/app/Http/Controllers/SettingsController.php index 7a7aa45b6e..b4acc4c5a0 100755 --- a/app/Http/Controllers/SettingsController.php +++ b/app/Http/Controllers/SettingsController.php @@ -26,7 +26,7 @@ use Response; use App\Http\Requests\SlackSettingsRequest; use Illuminate\Support\Str; use Illuminate\Support\Facades\Artisan; -use Validator; +use Illuminate\Support\Facades\Validator; /** * This controller handles all actions related to Settings for @@ -1248,13 +1248,11 @@ class SettingsController extends Controller if (!$request->hasFile('file')) { return redirect()->route('settings.backups.index')->with('error', 'No file uploaded'); } else { + $max_file_size = Helper::file_upload_max_size(); - - $rules = [ + $validator = Validator::make($request->all(), [ 'file' => 'required|mimes:zip|max:'.$max_file_size, - ]; - - $validator = \Validator::make($request->all(), $rules); + ]); if ($validator->passes()) { @@ -1265,7 +1263,7 @@ class SettingsController extends Controller return redirect()->route('settings.backups.index')->with('success', 'File uploaded'); } - return redirect()->route('settings.backups.index')->withErrors($request->getErrors()); + return redirect()->route('settings.backups.index')->withErrors($validator); } From aa2a25dc192e16b85e6150432b7234ff65593c2e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 15:30:49 +0000 Subject: [PATCH 117/172] Display the form errors correctly Signed-off-by: snipe --- resources/views/settings/backups.blade.php | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/resources/views/settings/backups.blade.php b/resources/views/settings/backups.blade.php index ea074d45af..67c1976541 100644 --- a/resources/views/settings/backups.blade.php +++ b/resources/views/settings/backups.blade.php @@ -137,7 +137,7 @@ @csrf -
    +
    @@ -145,26 +145,18 @@ - +
    - -

    -

    {{ trans_choice('general.filetypes_accepted_help', 1, ['size' => Helper::file_upload_max_size_readable(), 'types' => '.zip']) }}

    - {!! $errors->first('image', '') !!} - - + {!! $errors->first('file', '') !!} +
    From 28641493ca36924335fe28ce42064ae40b32e752 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 15:58:59 +0000 Subject: [PATCH 118/172] Check that the category exists Signed-off-by: snipe --- resources/views/users/print.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index 0f1e8a9097..3442285a9c 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -80,7 +80,7 @@ {{ $counter }} {{ $asset->asset_tag }} {{ $asset->name }} - {{ $asset->model->category->name }} + {{ (($asset->model) && ($asset->model->category)) ? $asset->model->category->name : trans('general.invalid_category') }} {{ $asset->model->name }} {{ $asset->serial }} From 9f9f8c173bfe14b0f8b7801d7627dddc2e0823f7 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Tue, 31 Oct 2023 10:00:36 -0600 Subject: [PATCH 119/172] Add condition to only run trough custom fields if a custom fieldset exist --- app/Models/Asset.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 63df483729..9f15101d33 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -212,9 +212,11 @@ class Asset extends Depreciable $this->rules += $model->fieldset->validation_rules(); - foreach ($this->model->fieldset->fields as $field){ - if($field->format == 'BOOLEAN'){ - $this->{$field->db_column} = filter_var($this->{$field->db_column}, FILTER_VALIDATE_BOOLEAN); + if ($this->model->fieldset){ + foreach ($this->model->fieldset->fields as $field){ + if($field->format == 'BOOLEAN'){ + $this->{$field->db_column} = filter_var($this->{$field->db_column}, FILTER_VALIDATE_BOOLEAN); + } } } } From 22996895d863e88942f2202152dc8509e8aa978a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 16:04:19 +0000 Subject: [PATCH 120/172] Check for valid model Signed-off-by: snipe --- resources/views/users/print.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index 3442285a9c..3be7923d88 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -81,7 +81,7 @@ {{ $asset->asset_tag }} {{ $asset->name }} {{ (($asset->model) && ($asset->model->category)) ? $asset->model->category->name : trans('general.invalid_category') }} - {{ $asset->model->name }} + {{ ($asset->model) ? $asset->model->name : trans('general.invalid_model') }} {{ $asset->serial }} {{ $asset->last_checkout }} From f822f8b1866b0c4fab345dcbe9db65053690f109 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 31 Oct 2023 17:09:18 +0000 Subject: [PATCH 121/172] =?UTF-8?q?More=20graceful=20failure=20if=20ldap?= =?UTF-8?q?=5Fresults=20JSON=20decode=20isn=E2=80=99t=20set?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- app/Http/Controllers/Users/LDAPImportController.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Http/Controllers/Users/LDAPImportController.php b/app/Http/Controllers/Users/LDAPImportController.php index 88a6b207df..b86be03d99 100644 --- a/app/Http/Controllers/Users/LDAPImportController.php +++ b/app/Http/Controllers/Users/LDAPImportController.php @@ -56,6 +56,10 @@ class LDAPImportController extends Controller $ldap_results_json = Artisan::output(); $ldap_results = json_decode($ldap_results_json, true); + if (!$ldap_results) { + return redirect()->back()->withInput()->with('error', trans('general.no_results')); + } + // Direct user to appropriate status page. if ($ldap_results['error']) { return redirect()->back()->withInput()->with('error', $ldap_results['error_message']); From d4b9f6a2a47a3a7e9dc6310c25062493764aaeda Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 31 Oct 2023 21:00:22 -0500 Subject: [PATCH 122/172] add not_array (not ready, doesn't catch for specific exception) --- app/Models/Asset.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 9f15101d33..7f4f691628 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -91,7 +91,7 @@ class Asset extends Depreciable protected $rules = [ 'name' => 'max:255|nullable', - 'model_id' => 'required|integer|exists:models,id,deleted_at,NULL', + 'model_id' => 'required|integer|exists:models,id,deleted_at,NULL|not_array', 'status_id' => 'required|integer|exists:status_labels,id', 'company_id' => 'integer|nullable', 'warranty_months' => 'numeric|nullable|digits_between:0,240', From b67b00dd82af6c32636d645d88990b5d5d19b9ab Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 31 Oct 2023 21:06:44 -0500 Subject: [PATCH 123/172] this is a start, something up with asset_tag unique rule --- app/Http/Controllers/Api/AssetsController.php | 4 +- app/Http/Requests/StoreAssetRequest.php | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 app/Http/Requests/StoreAssetRequest.php diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bbdc982599..c32c3c4429 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Events\CheckoutableCheckedIn; +use App\Http\Requests\StoreAssetRequest; use Illuminate\Support\Facades\Gate; use App\Helpers\Helper; use App\Http\Controllers\Controller; @@ -33,6 +34,7 @@ use TCPDF; use Validator; use Route; + /** * This class controls all actions related to assets for * the Snipe-IT Asset Management application. @@ -532,7 +534,7 @@ class AssetsController extends Controller * @since [v4.0] * @return \Illuminate\Http\JsonResponse */ - public function store(ImageUploadRequest $request) + public function store(StoreAssetRequest $request) { $this->authorize('create', Asset::class); diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php new file mode 100644 index 0000000000..992d67e25b --- /dev/null +++ b/app/Http/Requests/StoreAssetRequest.php @@ -0,0 +1,49 @@ +getRules(), + parent::rules(), + ); + + if(!$this->expectsJson()) { + //accepts an array for the gui form + $rules['asset_tags.*'] = $rules['asset_tag']; + unset($rules['asset_tag']); + $rules['serials.*'] = $rules['serial']; + unset($rules['serial']); + } + + return $rules; + } +} From 8f75bb8706a7474c40855689f8e9b33bb6c2ba83 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 31 Oct 2023 21:38:52 -0500 Subject: [PATCH 124/172] fix translation strings --- app/Http/Controllers/ReportsController.php | 10 +++++----- resources/lang/en/admin/reports/general.php | 9 ++++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ReportsController.php b/app/Http/Controllers/ReportsController.php index 72e042db91..04e3c434eb 100644 --- a/app/Http/Controllers/ReportsController.php +++ b/app/Http/Controllers/ReportsController.php @@ -539,23 +539,23 @@ class ReportsController extends Controller } if ($request->filled('user_address')) { - $header[] = trans('general.user') .' '. trans('general.address'); + $header[] = trans('admin/reports/general.custom_export.user_address'); } if ($request->filled('user_city')) { - $header[] = trans('general.user') .' '. trans('general.city'); + $header[] = trans('admin/reports/general.custom_export.user_city'); } if ($request->filled('user_state')) { - $header[] = trans('general.user') .' '. trans('general.state'); + $header[] = trans('admin/reports/general.custom_export.user_state'); } if ($request->filled('user_country')) { - $header[] = trans('general.user') .' '. trans('general.country'); + $header[] = trans('admin/reports/general.custom_export.user_country'); } if ($request->filled('user_zip')) { - $header[] = trans('general.user') .' '. trans('general.zip'); + $header[] = trans('admin/reports/general.custom_export.user_zip'); } if ($request->filled('status')) { diff --git a/resources/lang/en/admin/reports/general.php b/resources/lang/en/admin/reports/general.php index 344d5c8743..9b682f8ecd 100644 --- a/resources/lang/en/admin/reports/general.php +++ b/resources/lang/en/admin/reports/general.php @@ -6,5 +6,12 @@ return [ 'send_reminder' => 'Send reminder', 'reminder_sent' => 'Reminder sent', 'acceptance_deleted' => 'Acceptance request deleted', - 'acceptance_request' => 'Acceptance request' + 'acceptance_request' => 'Acceptance request', + 'custom_export' => [ + 'user_address' => 'User Address', + 'user_city' => 'User City', + 'user_state' => 'User State', + 'user_country' => 'User Country', + 'user_zip' => 'User Zip' + ] ]; \ No newline at end of file From 53bd5626c9e3fda94f0394993d8384941d9a7f20 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 11:33:29 -0500 Subject: [PATCH 125/172] this works, need to write up pr --- app/Exceptions/Handler.php | 6 ++++++ app/Http/Requests/StoreAssetRequest.php | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 3d4db93452..b3317ad2df 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,6 +4,7 @@ namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use App\Helpers\Helper; +use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; use Illuminate\Auth\AuthenticationException; use ArieTimmerman\Laravel\SCIMServer\Exceptions\SCIMException; @@ -150,6 +151,11 @@ class Handler extends ExceptionHandler return redirect()->guest('login'); } + protected function invalidJson($request, ValidationException $exception) + { + return response()->json(Helper::formatStandardApiResponse('error', null, $exception->errors()), 200); + } + /** * A list of the inputs that are never flashed for validation exceptions. diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index 992d67e25b..a9a06baed4 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -15,8 +15,8 @@ class StoreAssetRequest extends ImageUploadRequest */ public function authorize(): bool { - //TODO: make sure this works - //return Gate::allows('create', new Asset); + // TODO: make sure this works + return Gate::allows('create', new Asset); } public function prepareForValidation(): void @@ -36,13 +36,11 @@ class StoreAssetRequest extends ImageUploadRequest parent::rules(), ); - if(!$this->expectsJson()) { - //accepts an array for the gui form + // unsets unique check here, that check cannot run twice. $rules['asset_tags.*'] = $rules['asset_tag']; unset($rules['asset_tag']); $rules['serials.*'] = $rules['serial']; unset($rules['serial']); - } return $rules; } From d971172cf35ddd96cf2f8b3526341284c14193d5 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 11:34:15 -0500 Subject: [PATCH 126/172] rm unnecessary import --- app/Exceptions/Handler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index b3317ad2df..e76d8e5dae 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -4,7 +4,6 @@ namespace App\Exceptions; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use App\Helpers\Helper; -use Illuminate\Http\JsonResponse; use Illuminate\Validation\ValidationException; use Illuminate\Auth\AuthenticationException; use ArieTimmerman\Laravel\SCIMServer\Exceptions\SCIMException; From 3f834cb88fdc99cf7fe3b6a55a80f0f2da226aa7 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 11:43:53 -0500 Subject: [PATCH 127/172] authorization tested in request --- app/Http/Controllers/Api/AssetsController.php | 2 -- app/Http/Requests/StoreAssetRequest.php | 1 - 2 files changed, 3 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index c32c3c4429..eb2be64442 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -536,8 +536,6 @@ class AssetsController extends Controller */ public function store(StoreAssetRequest $request) { - $this->authorize('create', Asset::class); - $asset = new Asset(); $asset->model()->associate(AssetModel::find((int) $request->get('model_id'))); diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index a9a06baed4..d42ead35d5 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -15,7 +15,6 @@ class StoreAssetRequest extends ImageUploadRequest */ public function authorize(): bool { - // TODO: make sure this works return Gate::allows('create', new Asset); } From e05af5216e3c8474533e3e573e29db863876d23c Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 12:14:46 -0500 Subject: [PATCH 128/172] formatting --- app/Http/Requests/StoreAssetRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index d42ead35d5..2fb2544160 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -35,11 +35,11 @@ class StoreAssetRequest extends ImageUploadRequest parent::rules(), ); - // unsets unique check here, that check cannot run twice. - $rules['asset_tags.*'] = $rules['asset_tag']; - unset($rules['asset_tag']); - $rules['serials.*'] = $rules['serial']; - unset($rules['serial']); + // unsets unique check here, that check cannot run twice. + $rules['asset_tags.*'] = $rules['asset_tag']; + unset($rules['asset_tag']); + $rules['serials.*'] = $rules['serial']; + unset($rules['serial']); return $rules; } From d167ec6dc0ec8b87fbb7522c53ba37848d030e51 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 13:36:35 -0500 Subject: [PATCH 129/172] unique undeleted recreated with laravel rule --- app/Http/Requests/StoreAssetRequest.php | 6 ------ app/Models/Asset.php | 5 ++++- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/Http/Requests/StoreAssetRequest.php b/app/Http/Requests/StoreAssetRequest.php index 2fb2544160..254895f134 100644 --- a/app/Http/Requests/StoreAssetRequest.php +++ b/app/Http/Requests/StoreAssetRequest.php @@ -35,12 +35,6 @@ class StoreAssetRequest extends ImageUploadRequest parent::rules(), ); - // unsets unique check here, that check cannot run twice. - $rules['asset_tags.*'] = $rules['asset_tag']; - unset($rules['asset_tag']); - $rules['serials.*'] = $rules['serial']; - unset($rules['serial']); - return $rules; } } diff --git a/app/Models/Asset.php b/app/Models/Asset.php index 7f4f691628..fac914dcb0 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -100,7 +100,10 @@ class Asset extends Depreciable 'expected_checkin' => 'date|nullable', 'location_id' => 'exists:locations,id|nullable', 'rtd_location_id' => 'exists:locations,id|nullable', - 'asset_tag' => 'required|min:1|max:255|unique_undeleted', + // okay, i know this looks scary - but it's not. it checks to see if the asset tag is unique, but only if the asset is not deleted - `NULL,NULL` says to ignore the unique rule if following conditions are met + // https://laracasts.com/discuss/channels/laravel/unique-validation-with-soft-delete + // this is tested and verified + 'asset_tag' => 'required|min:1|max:255|unique:assets,asset_tag,NULL,NULL,deleted_at,NULL', 'purchase_date' => 'date|date_format:Y-m-d|nullable', 'serial' => 'unique_serial|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', From c9604b896a0c777cb180dfea55e731867e914932 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 13:46:32 -0500 Subject: [PATCH 130/172] nevermind --- app/Models/Asset.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/Models/Asset.php b/app/Models/Asset.php index fac914dcb0..a7d4d7442a 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -100,10 +100,7 @@ class Asset extends Depreciable 'expected_checkin' => 'date|nullable', 'location_id' => 'exists:locations,id|nullable', 'rtd_location_id' => 'exists:locations,id|nullable', - // okay, i know this looks scary - but it's not. it checks to see if the asset tag is unique, but only if the asset is not deleted - `NULL,NULL` says to ignore the unique rule if following conditions are met - // https://laracasts.com/discuss/channels/laravel/unique-validation-with-soft-delete - // this is tested and verified - 'asset_tag' => 'required|min:1|max:255|unique:assets,asset_tag,NULL,NULL,deleted_at,NULL', + 'asset_tag' => 'required|min:1|max:255|unique_undeleted:assets,asset_tag', 'purchase_date' => 'date|date_format:Y-m-d|nullable', 'serial' => 'unique_serial|nullable', 'purchase_cost' => 'numeric|nullable|gte:0', From 938ec75aa70b7e9da3c264b2a57e378283fce389 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 14:09:03 -0500 Subject: [PATCH 131/172] clarifying note --- app/Providers/ValidationServiceProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Providers/ValidationServiceProvider.php b/app/Providers/ValidationServiceProvider.php index 70fa64702e..30c5a0197e 100644 --- a/app/Providers/ValidationServiceProvider.php +++ b/app/Providers/ValidationServiceProvider.php @@ -48,6 +48,8 @@ class ValidationServiceProvider extends ServiceProvider // Unique only if undeleted // This works around the use case where multiple deleted items have the same unique attribute. // (I think this is a bug in Laravel's validator?) + // $parameters is the rule parameters, like `unique_undeleted:users,id` - $parameters[0] is users, $parameters[1] is id + // the UniqueUndeletedTrait prefills these so you can just use `unique_undeleted` in your rules (but this would only work directly in the model) Validator::extend('unique_undeleted', function ($attribute, $value, $parameters, $validator) { if (count($parameters)) { $count = DB::table($parameters[0])->select('id')->where($attribute, '=', $value)->whereNull('deleted_at')->where('id', '!=', $parameters[1])->count(); From 13d3f85c62074219a7401843c7a83cbbcb4ded45 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 1 Nov 2023 12:26:58 -0700 Subject: [PATCH 132/172] fixes ldap location sync --- app/Console/Commands/LdapSync.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index afe1070dd0..edb29614ee 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -83,7 +83,12 @@ class LdapSync extends Command $summary = []; try { - if ($this->option('base_dn') != '') { + if ( $this->option('location_id') != '') { + $location_ou= Location::where('id', '=', $this->option('location_id'))->value('ldap_ou'); + $search_base = $location_ou; + Log::debug('Importing users from specified location OU: \"'.$search_base.'\".'); + } + else if ($this->option('base_dn') != '') { $search_base = $this->option('base_dn'); Log::debug('Importing users from specified base DN: \"'.$search_base.'\".'); } else { From 75532d96622f77324be8fb6a3a3b4fac3ecb7130 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 1 Nov 2023 16:49:59 -0500 Subject: [PATCH 133/172] adds permission test --- tests/Feature/Api/Assets/AssetStoreTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/Feature/Api/Assets/AssetStoreTest.php diff --git a/tests/Feature/Api/Assets/AssetStoreTest.php b/tests/Feature/Api/Assets/AssetStoreTest.php new file mode 100644 index 0000000000..5a68aebccb --- /dev/null +++ b/tests/Feature/Api/Assets/AssetStoreTest.php @@ -0,0 +1,19 @@ +actingAsForApi(User::factory()->create()) + ->postJson(route('api.assets.store')) + ->assertForbidden(); + } +} From 4d65d0930637d32f8fbb2d76e957645b9c6cc34d Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 Nov 2023 14:50:40 +0000 Subject: [PATCH 134/172] Removed trim on manager ID Signed-off-by: snipe --- app/Importer/UserImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/UserImporter.php b/app/Importer/UserImporter.php index 7e23708e78..040f34f9ef 100644 --- a/app/Importer/UserImporter.php +++ b/app/Importer/UserImporter.php @@ -61,7 +61,7 @@ class UserImporter extends ItemImporter $this->item['activated'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'activated'))) == 1) ? '1' : 0; $this->item['employee_num'] = trim($this->findCsvMatch($row, 'employee_num')); $this->item['department_id'] = trim($this->createOrFetchDepartment(trim($this->findCsvMatch($row, 'department')))); - $this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name'))); + $this->item['manager_id'] = $this->fetchManager($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')); $this->item['remote'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'remote'))) == 1 ) ? '1' : 0; $this->item['vip'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'vip'))) ==1 ) ? '1' : 0; $this->item['autoassign_licenses'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'autoassign_licenses'))) ==1 ) ? '1' : 0; From 3b6a0d65250371bb895b447dd0552a114626c30b Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 2 Nov 2023 16:50:19 -0700 Subject: [PATCH 135/172] allows multi location sync for ldap --- app/Console/Commands/LdapSync.php | 37 ++++++++++--------- .../Users/LDAPImportController.php | 6 +-- resources/views/users/ldap.blade.php | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/LdapSync.php b/app/Console/Commands/LdapSync.php index edb29614ee..1a8521487b 100755 --- a/app/Console/Commands/LdapSync.php +++ b/app/Console/Commands/LdapSync.php @@ -18,7 +18,7 @@ class LdapSync extends Command * * @var string */ - protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=} {--base_dn=} {--filter=} {--summary} {--json_summary}'; + protected $signature = 'snipeit:ldap-sync {--location=} {--location_id=*} {--base_dn=} {--filter=} {--summary} {--json_summary}'; /** * The console command description. @@ -84,10 +84,13 @@ class LdapSync extends Command try { if ( $this->option('location_id') != '') { - $location_ou= Location::where('id', '=', $this->option('location_id'))->value('ldap_ou'); - $search_base = $location_ou; - Log::debug('Importing users from specified location OU: \"'.$search_base.'\".'); - } + + foreach($this->option('location_id') as $location_id){ + $location_ou= Location::where('id', '=', $location_id)->value('ldap_ou'); + $search_base = $location_ou; + Log::debug('Importing users from specified location OU: \"'.$search_base.'\".'); + } + } else if ($this->option('base_dn') != '') { $search_base = $this->option('base_dn'); Log::debug('Importing users from specified base DN: \"'.$search_base.'\".'); @@ -111,21 +114,21 @@ class LdapSync extends Command /* Determine which location to assign users to by default. */ $location = null; // TODO - this would be better called "$default_location", which is more explicit about its purpose + if ($this->option('location') != '') { + if ($location = Location::where('name', '=', $this->option('location'))->first()) { + Log::debug('Location name ' . $this->option('location') . ' passed'); + Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')'); + } + + } elseif ($this->option('location_id') != '') { + foreach($this->option('location_id') as $location_id) { + if ($location = Location::where('id', '=', $location_id)->first()) { + Log::debug('Location ID ' . $location_id . ' passed'); + Log::debug('Importing to ' . $location->name . ' (' . $location->id . ')'); + } - if ($this->option('location') != '') { - if ($location = Location::where('name', '=', $this->option('location'))->first()) { - Log::debug('Location name '.$this->option('location').' passed'); - Log::debug('Importing to '.$location->name.' ('.$location->id.')'); } - - } elseif ($this->option('location_id') != '') { - if ($location = Location::where('id', '=', $this->option('location_id'))->first()) { - Log::debug('Location ID '.$this->option('location_id').' passed'); - Log::debug('Importing to '.$location->name.' ('.$location->id.')'); - } - } - if (! isset($location)) { Log::debug('That location is invalid or a location was not provided, so no location will be assigned by default.'); } diff --git a/app/Http/Controllers/Users/LDAPImportController.php b/app/Http/Controllers/Users/LDAPImportController.php index b86be03d99..e535a171a0 100644 --- a/app/Http/Controllers/Users/LDAPImportController.php +++ b/app/Http/Controllers/Users/LDAPImportController.php @@ -49,19 +49,19 @@ class LDAPImportController extends Controller { $this->authorize('update', User::class); // Call Artisan LDAP import command. - $location_id = $request->input('location_id'); - Artisan::call('snipeit:ldap-sync', ['--location_id' => $location_id, '--json_summary' => true]); + + Artisan::call('snipeit:ldap-sync', ['--location_id' => $request->input('location_id'), '--json_summary' => true]); // Collect and parse JSON summary. $ldap_results_json = Artisan::output(); $ldap_results = json_decode($ldap_results_json, true); - if (!$ldap_results) { return redirect()->back()->withInput()->with('error', trans('general.no_results')); } // Direct user to appropriate status page. if ($ldap_results['error']) { + return redirect()->back()->withInput()->with('error', $ldap_results['error_message']); } diff --git a/resources/views/users/ldap.blade.php b/resources/views/users/ldap.blade.php index 0dbbbc2fa4..555dc65829 100644 --- a/resources/views/users/ldap.blade.php +++ b/resources/views/users/ldap.blade.php @@ -29,7 +29,7 @@
    - @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id']) + @include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'fieldname' => 'location_id[]', 'multiple' => true])
    From 7a638e4a658b7347ac0494ede6b192baab8b52ba Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Nov 2023 14:06:27 +0000 Subject: [PATCH 136/172] RB-17457 - Object of class Illuminate\Database\Eloquent\Collection could not be converted to int Signed-off-by: snipe --- app/Http/Controllers/Api/AssetsController.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index bbdc982599..6c343731ca 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -666,10 +666,11 @@ class AssetsController extends Controller $request->offsetSet('image', $request->offsetGet('image_source')); } - $asset = $request->handleImages($asset); + $asset = $request->handleImages($asset); + $model = AssetModel::find($asset->model_id); // Update custom fields - if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) { + if (($model) && (isset($model->fieldset))) { foreach ($model->fieldset->fields as $field) { if ($request->has($field->db_column)) { if ($field->field_encrypted == '1') { From 8c316e0bd311a3c7797aa80bd5a92f79b8b95230 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Nov 2023 14:07:15 +0000 Subject: [PATCH 137/172] Bumped hash Signed-off-by: snipe --- config/version.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/version.php b/config/version.php index b220a12558..311cfdb336 100644 --- a/config/version.php +++ b/config/version.php @@ -1,10 +1,10 @@ 'v6.2.3', - 'full_app_version' => 'v6.2.3 - build 11759-g8c4bf74f9', - 'build_version' => '11759', + 'full_app_version' => 'v6.2.3 - build 11936-gb47e734b3', + 'build_version' => '11936', 'prerelease_version' => '', - 'hash_version' => 'g8c4bf74f9', - 'full_hash' => 'v6.2.3-42-g8c4bf74f9', + 'hash_version' => 'gb47e734b3', + 'full_hash' => 'v6.2.3-175-gb47e734b3', 'branch' => 'develop', ); \ No newline at end of file From d0cc42a06895fd27388f471a60cc4008e2ab0393 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Nov 2023 20:09:11 +0000 Subject: [PATCH 138/172] Added employee number to user merge screeb Signed-off-by: snipe --- resources/views/users/confirm-merge.blade.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/resources/views/users/confirm-merge.blade.php b/resources/views/users/confirm-merge.blade.php index ce033acaed..45635dc4f4 100644 --- a/resources/views/users/confirm-merge.blade.php +++ b/resources/views/users/confirm-merge.blade.php @@ -48,6 +48,7 @@ {{ trans('general.name') }} {{ trans('general.email') }} {{ trans('general.username') }} + {{ trans('general.employee_number') }} {{ trans('general.groups') }} @@ -80,6 +81,9 @@ {{ $user->username }} + + {{ $user->employee_num }} + @foreach ($user->groups as $group) From a08e0bd547a1e1dad0d68d51d8930839684be5ac Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 12:20:13 -0800 Subject: [PATCH 139/172] Ensure notes are saved to the action log when licenses are checked in and out --- app/Http/Controllers/Licenses/LicenseCheckinController.php | 2 +- app/Http/Controllers/Licenses/LicenseCheckoutController.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Licenses/LicenseCheckinController.php b/app/Http/Controllers/Licenses/LicenseCheckinController.php index a78b548723..367ff3f1d9 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckinController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckinController.php @@ -101,7 +101,7 @@ class LicenseCheckinController extends Controller // Was the asset updated? if ($licenseSeat->save()) { - event(new CheckoutableCheckedIn($licenseSeat, $return_to, Auth::user(), $request->input('note'))); + event(new CheckoutableCheckedIn($licenseSeat, $return_to, Auth::user(), $request->input('notes'))); if ($backTo == 'user') { return redirect()->route('users.show', $return_to->id)->with('success', trans('admin/licenses/message.checkin.success')); diff --git a/app/Http/Controllers/Licenses/LicenseCheckoutController.php b/app/Http/Controllers/Licenses/LicenseCheckoutController.php index ec6b4bbac8..07ca8bbd58 100644 --- a/app/Http/Controllers/Licenses/LicenseCheckoutController.php +++ b/app/Http/Controllers/Licenses/LicenseCheckoutController.php @@ -105,7 +105,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = $target->assigned_to; } if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); return true; } @@ -122,7 +122,7 @@ class LicenseCheckoutController extends Controller $licenseSeat->assigned_to = request('assigned_to'); if ($licenseSeat->save()) { - event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('note'))); + event(new CheckoutableCheckedOut($licenseSeat, $target, Auth::user(), request('notes'))); return true; } From 4d2790c3f4178eaad631ef3a19e95f925f5351e2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 13:54:36 -0800 Subject: [PATCH 140/172] Add tests for license checkout notes --- .../Feature/Checkouts/LicenseCheckoutTest.php | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/Feature/Checkouts/LicenseCheckoutTest.php diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php new file mode 100644 index 0000000000..c1529355bf --- /dev/null +++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php @@ -0,0 +1,65 @@ +superuser()->create(); + $asset = Asset::factory()->create(); + $licenseSeat = LicenseSeat::factory()->create(); + + $this->actingAs($admin) + ->post("/licenses/{$licenseSeat->license->id}/checkout", [ + 'checkout_to_type' => 'asset', + 'assigned_to' => null, + 'asset_id' => $asset->id, + 'notes' => 'oh hi there', + ]) + ->assertRedirect(); + + $this->assertDatabaseHas('action_logs', [ + 'action_type' => 'checkout', + 'target_id' => $asset->id, + 'target_type' => Asset::class, + 'item_id' => $licenseSeat->license->id, + 'item_type' => License::class, + 'note' => 'oh hi there', + ]); + } + + public function testNotesAreStoredInActionLogOnCheckoutToUser() + { + $admin = User::factory()->superuser()->create(); + $licenseSeat = LicenseSeat::factory()->create(); + + $this->actingAs($admin) + ->post("/licenses/{$licenseSeat->license->id}/checkout", [ + 'checkout_to_type' => 'user', + 'assigned_to' => $admin->id, + 'asset_id' => null, + 'notes' => 'oh hi there', + ]) + ->assertRedirect(); + + $this->assertDatabaseHas('action_logs', [ + 'action_type' => 'checkout', + 'target_id' => $admin->id, + 'target_type' => User::class, + 'item_id' => $licenseSeat->license->id, + 'item_type' => License::class, + 'note' => 'oh hi there', + ]); + } +} From 4fb349e3269390c2a88478734b244e433957b927 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Mon, 6 Nov 2023 14:04:52 -0800 Subject: [PATCH 141/172] Remove extra assertions --- tests/Feature/Checkouts/LicenseCheckoutTest.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tests/Feature/Checkouts/LicenseCheckoutTest.php b/tests/Feature/Checkouts/LicenseCheckoutTest.php index c1529355bf..978fac28f2 100644 --- a/tests/Feature/Checkouts/LicenseCheckoutTest.php +++ b/tests/Feature/Checkouts/LicenseCheckoutTest.php @@ -2,7 +2,6 @@ namespace Tests\Feature\Checkouts; -use App\Models\Actionlog; use App\Models\Asset; use App\Models\License; use App\Models\LicenseSeat; @@ -26,8 +25,7 @@ class LicenseCheckoutTest extends TestCase 'assigned_to' => null, 'asset_id' => $asset->id, 'notes' => 'oh hi there', - ]) - ->assertRedirect(); + ]); $this->assertDatabaseHas('action_logs', [ 'action_type' => 'checkout', @@ -50,8 +48,7 @@ class LicenseCheckoutTest extends TestCase 'assigned_to' => $admin->id, 'asset_id' => null, 'notes' => 'oh hi there', - ]) - ->assertRedirect(); + ]); $this->assertDatabaseHas('action_logs', [ 'action_type' => 'checkout', From 93101d36b8440b6d3e10d61363b9854aa9349a8a Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 7 Nov 2023 15:07:24 -0600 Subject: [PATCH 142/172] removed refresh button on client tables --- resources/views/account/accept/index.blade.php | 2 +- resources/views/account/view-assets.blade.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/account/accept/index.blade.php b/resources/views/account/accept/index.blade.php index b627135a4d..77cf21664c 100755 --- a/resources/views/account/accept/index.blade.php +++ b/resources/views/account/accept/index.blade.php @@ -24,7 +24,7 @@ data-side-pagination="client" data-show-columns="true" data-show-export="true" - data-show-refresh="true" + data-show-refresh="false" data-sort-order="asc" id="pendingAcceptances" class="table table-striped snipe-table" diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index 10b09602ab..81011175a6 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -388,7 +388,7 @@ data-show-columns="true" data-show-export="true" data-show-footer="true" - data-show-refresh="true" + data-show-refresh="false" data-sort-order="asc" id="userAssets" class="table table-striped snipe-table" @@ -478,7 +478,7 @@ data-side-pagination="client" data-show-columns="true" data-show-export="true" - data-show-refresh="true" + data-show-refresh="false" data-sort-order="asc" id="userLicenses" class="table table-striped snipe-table" @@ -525,7 +525,7 @@ data-show-fullscreen="true" data-show-export="true" data-show-footer="true" - data-show-refresh="true" + data-show-refresh="false" data-sort-order="asc" data-sort-name="name" class="table table-striped snipe-table table-hover" @@ -576,7 +576,7 @@ data-show-fullscreen="true" data-show-export="true" data-show-footer="true" - data-show-refresh="true" + data-show-refresh="false" data-sort-order="asc" data-sort-name="name" class="table table-striped snipe-table table-hover" From 154e71de74792cb539dcbe24de0d492ecb8007b2 Mon Sep 17 00:00:00 2001 From: akemidx Date: Tue, 7 Nov 2023 17:43:51 -0500 Subject: [PATCH 143/172] shifting wrap around logic back into 0-265 --- app/Helpers/Helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index c2ccda6c84..98f40de5b8 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -349,7 +349,7 @@ class Helper $total_colors = count($colors); if ($index >= $total_colors) { - $index = $index - $total_colors; + $index = $index - $total_colors - 1; } return $colors[$index]; From eceb69122c09cf06cf8e7ab7b6c59576f9b21fd2 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Tue, 7 Nov 2023 16:03:28 -0800 Subject: [PATCH 144/172] Add missing import --- app/Notifications/CheckinAssetNotification.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 5389c8ddde..05e56a9619 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -2,6 +2,7 @@ namespace App\Notifications; +use App\Helpers\Helper; use App\Models\Asset; use App\Models\Setting; use App\Models\User; From 26311e46b88d6a616069b3b152471aadd3c47210 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 11:38:48 +0000 Subject: [PATCH 145/172] Fixed URL to favicon on default blade (used in 404 messages) Signed-off-by: snipe --- resources/views/layouts/basic.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/layouts/basic.blade.php b/resources/views/layouts/basic.blade.php index b921042b04..759ffd52a8 100644 --- a/resources/views/layouts/basic.blade.php +++ b/resources/views/layouts/basic.blade.php @@ -8,7 +8,7 @@ {{ ($snipeSettings) && ($snipeSettings->site_name) ? $snipeSettings->site_name : 'Snipe-IT' }} - + {{-- stylesheets --}} From 3f8b63e053b7ff0f7ec661c1b230b084c264127b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:02 +0000 Subject: [PATCH 146/172] Add linked text Signed-off-by: snipe --- resources/lang/en/admin/hardware/message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index 04be92a754..056692998e 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -11,6 +11,7 @@ return [ 'create' => [ 'error' => 'Asset was not created, please try again. :(', 'success' => 'Asset created successfully. :)', + 'success_linked' => 'Asset with tag :tag was created successfully. Click here to view.', ], 'update' => [ From 08153d418f89703501915a35ed1f6004262673ac Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:18 +0000 Subject: [PATCH 147/172] Use new alert box and linked string Signed-off-by: snipe --- app/Http/Controllers/Assets/AssetsController.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 8a12d744ae..28d7906cd7 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -204,12 +204,8 @@ class AssetsController extends Controller } if ($success) { - // Redirect to the asset listing page - $minutes = 518400; - // dd( $_POST['options']); - // Cookie::queue(Cookie::make('optional_info', json_decode($_POST['options']), $minutes)); return redirect()->route('hardware.index') - ->with('success', trans('admin/hardware/message.create.success')); + ->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', $asset->id), 'id', 'tag' => $asset->asset_tag])); } From ef10f2e50e862504180c5debb6b99854ef62689b Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:38 +0000 Subject: [PATCH 148/172] Use more correct route in redirect Signed-off-by: snipe --- .../Controllers/Components/ComponentCheckinController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Components/ComponentCheckinController.php b/app/Http/Controllers/Components/ComponentCheckinController.php index 49199aa6d2..9f4724e353 100644 --- a/app/Http/Controllers/Components/ComponentCheckinController.php +++ b/app/Http/Controllers/Components/ComponentCheckinController.php @@ -96,8 +96,8 @@ class ComponentCheckinController extends Controller $asset = Asset::find($component_assets->asset_id); event(new CheckoutableCheckedIn($component, $asset, Auth::user(), $request->input('note'), Carbon::now())); - if($backto == 'asset'){ - return redirect()->route('hardware.view', $asset->id)->with('success', + if ($backto == 'asset'){ + return redirect()->route('hardware.show', $asset->id)->with('success', trans('admin/components/message.checkin.success')); } From d2bf71327baaad8dd9831692e3fef28701bf01b6 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:40:56 +0000 Subject: [PATCH 149/172] Redirect /asset_tag/view to /asset_tag Signed-off-by: snipe --- routes/web/hardware.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 1643e5794e..934712d7e4 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -122,9 +122,9 @@ Route::group( [AssetCheckinController::class, 'store'] )->name('hardware.checkin.store'); - Route::get('{assetId}/view', - [AssetsController::class, 'show'] - )->name('hardware.view'); + Route::get('{assetId}/view', function ($assetId) { + return redirect()->route('hardware.show', ['hardware' => $assetId]); + }); Route::get('{assetId}/qr_code', [AssetsController::class, 'getQrCode'] @@ -178,13 +178,17 @@ Route::group( Route::post('bulkcheckout', [BulkAssetsController::class, 'storeCheckout'] )->name('hardware.bulkcheckout.store'); + }); Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id' + 'parameters' => ['asset' => 'asset_id', + 'names' => [ + 'show' => 'view', + ], ], ]); From a24d21e68390fee864d3bab0379230a02d93281a Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:41:05 +0000 Subject: [PATCH 150/172] Added new unescaped alert box Signed-off-by: snipe --- resources/views/notifications.blade.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 9dbb547515..0205e3e10f 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -35,6 +35,18 @@ @endif +@if ($message = Session::get('success-unescaped')) +
    +
    + + + {{ trans('general.notification_success') }}: + {!! $message !!} +
    +
    +@endif + + @if ($assets = Session::get('assets')) @foreach ($assets as $asset)
    From 6da0671143f3f83be6b0fc4e3d40a399cc9a7f51 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 8 Nov 2023 14:44:09 +0000 Subject: [PATCH 151/172] Added comment Signed-off-by: snipe --- routes/web/hardware.php | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index 934712d7e4..d29b2cd836 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -122,6 +122,7 @@ Route::group( [AssetCheckinController::class, 'store'] )->name('hardware.checkin.store'); + // Redirect old legacy /asset_id/view urls to the resource route version Route::get('{assetId}/view', function ($assetId) { return redirect()->route('hardware.show', ['hardware' => $assetId]); }); From 495521b70ebb5e4fbdcc3905a059fadcdfd08e20 Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 12:51:51 -0500 Subject: [PATCH 152/172] adjusting for less than 0 possibility --- app/Helpers/Helper.php | 4 ++++ tests/Feature/DefaultColorKeyTest.php | 21 +++++++++++++++++++++ tests/Feature/Reports/CustomReportTest.php | 1 + 3 files changed, 26 insertions(+) create mode 100644 tests/Feature/DefaultColorKeyTest.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 98f40de5b8..cd790ff40f 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -350,6 +350,10 @@ class Helper if ($index >= $total_colors) { $index = $index - $total_colors - 1; + + if($index < 0) { + $index = 0; + } } return $colors[$index]; diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php new file mode 100644 index 0000000000..fdabd0db14 --- /dev/null +++ b/tests/Feature/DefaultColorKeyTest.php @@ -0,0 +1,21 @@ +hasAssets(1)->count(255)->create(); + + $this->defaultChartColors($index); + + $this->assertArrayHasKey('index', ($index)[0]); + + + } +} diff --git a/tests/Feature/Reports/CustomReportTest.php b/tests/Feature/Reports/CustomReportTest.php index a1a269a4ab..dd3199212e 100644 --- a/tests/Feature/Reports/CustomReportTest.php +++ b/tests/Feature/Reports/CustomReportTest.php @@ -11,6 +11,7 @@ use PHPUnit\Framework\Assert; use Tests\Support\InteractsWithSettings; use Tests\TestCase; + class CustomReportTest extends TestCase { use InteractsWithSettings; From 9cc89911f7213b34ba78c1e7bb4dc6107fe86dff Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 13:29:32 -0500 Subject: [PATCH 153/172] possibilitieeeeeeeeessss --- app/Helpers/Helper.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index cd790ff40f..0fcee31575 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -354,6 +354,9 @@ class Helper if($index < 0) { $index = 0; } + elseif($index > 255) { + $index = 255; + } } return $colors[$index]; From 2051ac785d92dfcf2e7f7246771d102e5ee4fb8f Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 13:44:46 -0500 Subject: [PATCH 154/172] adding in error logging and code comments --- app/Helpers/Helper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 0fcee31575..3c5a0e9f11 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -349,13 +349,18 @@ class Helper $total_colors = count($colors); if ($index >= $total_colors) { + + \Log::error('Status label count is '.$index.' and exceeds the allowed count of 256.'); + //patch fix for array key overflow (color count starts at 1, array starts at 0) $index = $index - $total_colors - 1; + //constraints to keep result in 0-265 range. This should never be needed, but if something happens + //to create this many status labels and it DOES happen, this will keep it from failing at least. if($index < 0) { $index = 0; } - elseif($index > 255) { - $index = 255; + elseif($index > 265) { + $index = 265; } } From 4382adce85352516b09f957020ae5a7e3781cb62 Mon Sep 17 00:00:00 2001 From: akemidx Date: Wed, 8 Nov 2023 15:29:29 -0500 Subject: [PATCH 155/172] typo in error log message --- app/Helpers/Helper.php | 2 +- tests/Feature/DefaultColorKeyTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 3c5a0e9f11..6039457637 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -350,7 +350,7 @@ class Helper if ($index >= $total_colors) { - \Log::error('Status label count is '.$index.' and exceeds the allowed count of 256.'); + \Log::error('Status label count is '.$index.' and exceeds the allowed count of 266.'); //patch fix for array key overflow (color count starts at 1, array starts at 0) $index = $index - $total_colors - 1; diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php index fdabd0db14..3fab03b7f6 100644 --- a/tests/Feature/DefaultColorKeyTest.php +++ b/tests/Feature/DefaultColorKeyTest.php @@ -2,8 +2,8 @@ namespace Tests\Feature; -use Tests\TestCase; use App\Models\Statuslabel; +use Tests\TestCase; use App\Models\Asset; class DefaultColorKeyTest extends TestCase From 49136a4d67c9d0434ae51c3820b294f24590a864 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 8 Nov 2023 12:35:42 -0800 Subject: [PATCH 156/172] Add tests for color helper --- app/Helpers/Helper.php | 12 ++++++++---- tests/Feature/DefaultColorKeyTest.php | 21 --------------------- tests/Unit/Helpers/HelperTest.php | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+), 25 deletions(-) delete mode 100644 tests/Feature/DefaultColorKeyTest.php create mode 100644 tests/Unit/Helpers/HelperTest.php diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 6039457637..800a2491d4 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -73,10 +73,14 @@ class Helper * * @author [A. Gianotto] [] * @since [v3.3] - * @return array + * @return string */ - public static function defaultChartColors($index = 0) + public static function defaultChartColors(int $index = 0) { + if ($index < 0) { + $index = 0; + } + $colors = [ '#008941', '#FF4A46', @@ -359,8 +363,8 @@ class Helper if($index < 0) { $index = 0; } - elseif($index > 265) { - $index = 265; + elseif($index >($total_colors - 1)) { + $index = $total_colors - 1; } } diff --git a/tests/Feature/DefaultColorKeyTest.php b/tests/Feature/DefaultColorKeyTest.php deleted file mode 100644 index 3fab03b7f6..0000000000 --- a/tests/Feature/DefaultColorKeyTest.php +++ /dev/null @@ -1,21 +0,0 @@ -hasAssets(1)->count(255)->create(); - - $this->defaultChartColors($index); - - $this->assertArrayHasKey('index', ($index)[0]); - - - } -} diff --git a/tests/Unit/Helpers/HelperTest.php b/tests/Unit/Helpers/HelperTest.php new file mode 100644 index 0000000000..0b5fba986c --- /dev/null +++ b/tests/Unit/Helpers/HelperTest.php @@ -0,0 +1,19 @@ +assertIsString(Helper::defaultChartColors(1000)); + } + + public function testDefaultChartColorsMethodHandlesNegativeNumbers() + { + $this->assertIsString(Helper::defaultChartColors(-1)); + } +} From 7d30001ff803c84149571d53dde8c8fa81497724 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Wed, 8 Nov 2023 15:32:33 -0600 Subject: [PATCH 157/172] Ignore the importer checkout if user is not found --- app/Importer/AssetImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index cd2b29205f..cf762a8fd4 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -144,7 +144,7 @@ class AssetImporter extends ItemImporter // If we have a target to checkout to, lets do so. //-- user_id is a property of the abstract class Importer, which this class inherits from and it's setted by //-- the class that needs to use it (command importer or GUI importer inside the project). - if (isset($target)) { + if (isset($target) && ($target !== false)) { if (!is_null($asset->assigned_to)){ if ($asset->assigned_to != $target->id){ event(new CheckoutableCheckedIn($asset, User::find($asset->assigned_to), Auth::user(), $asset->notes, date('Y-m-d H:i:s'))); From 9bff2d0bbf62e06cbdf409f29c7987d06b256657 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 9 Nov 2023 21:47:29 +0000 Subject: [PATCH 158/172] Fixed indenting? Signed-off-by: snipe --- routes/web/hardware.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index d29b2cd836..dc0ba43fa0 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -186,11 +186,8 @@ Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id', - 'names' => [ - 'show' => 'view', - ], - ], + 'parameters' => ['asset' => 'asset_id'], + 'names' => ['show' => 'view'], ]); Route::get('ht/{any?}', From 042a15d294fb2823aca2182ea3099a44905e1965 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 14:41:13 -0800 Subject: [PATCH 159/172] Set minimum PHP version to 8.1 --- composer.json | 2 +- composer.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index b5c08777dd..f2a663d33c 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ } ], "require": { - "php": "8.0 - 8.2", + "php": "^8.1", "ext-curl": "*", "ext-fileinfo": "*", "ext-json": "*", diff --git a/composer.lock b/composer.lock index e1f6c3f7d6..179fb8495b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6a7666957fcf514f54340bf80ad18726", + "content-hash": "6f3c589a1c2a3a3dc24535abba26e1a6", "packages": [ { "name": "alek13/slack", @@ -15699,7 +15699,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "8.0 - 8.2", + "php": "^8.1", "ext-curl": "*", "ext-fileinfo": "*", "ext-json": "*", @@ -15707,5 +15707,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } From cc0653c68a05cd4f190f711d6a12ca80adcfe53c Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 14:42:47 -0800 Subject: [PATCH 160/172] Update GitHub test action to run on PHP 8.1 and 8.2 --- .github/workflows/tests.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a82946161d..24e5dc6e10 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,9 +25,8 @@ jobs: fail-fast: false matrix: php-version: - - "7.4" - - "8.0" - - "8.1.1" + - "8.1" + - "8.2" name: PHP ${{ matrix.php-version }} From 690a5119f45da29e980ea0362c86d4cdd3800793 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 14:49:56 -0800 Subject: [PATCH 161/172] Install Passport during test setup process --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24e5dc6e10..0461d4a728 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,6 +60,9 @@ jobs: - name: Generate key run: php artisan key:generate + - name: Install Passport + run: php artisan passport:install + - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache From 65e3696029dc295036e13734b2798afb9ac3755f Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 14:56:32 -0800 Subject: [PATCH 162/172] Add database migration step --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0461d4a728..51049e14f1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,6 +60,9 @@ jobs: - name: Generate key run: php artisan key:generate + - name: Migrate Database + run: php artisan migrate + - name: Install Passport run: php artisan passport:install From fd410c02813114aa9ab90967b72b1172d6bf73c6 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:20:41 -0800 Subject: [PATCH 163/172] Be explicit about database host --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 51049e14f1..0e17c60e53 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -73,6 +73,7 @@ jobs: env: DB_CONNECTION: mysql DB_DATABASE: snipeit + DB_HOST: 127.0.0.1 DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root run: php artisan test --parallel From 158c82ff5f544704f8947ae82cb78f9b96ae3ee1 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:26:50 -0800 Subject: [PATCH 164/172] Revert "Be explicit about database host" This reverts commit fd410c02813114aa9ab90967b72b1172d6bf73c6. --- .github/workflows/tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0e17c60e53..51049e14f1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -73,7 +73,6 @@ jobs: env: DB_CONNECTION: mysql DB_DATABASE: snipeit - DB_HOST: 127.0.0.1 DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root run: php artisan test --parallel From 62b557f82c544d2de5844fea32e83f757eb5758a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:29:19 -0800 Subject: [PATCH 165/172] Revert "Add database migration step" This reverts commit 65e3696029dc295036e13734b2798afb9ac3755f. --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 51049e14f1..0461d4a728 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,9 +60,6 @@ jobs: - name: Generate key run: php artisan key:generate - - name: Migrate Database - run: php artisan migrate - - name: Install Passport run: php artisan passport:install From 3d858b21faa5ba85b4bc2a8b5d122dffd5838780 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:29:31 -0800 Subject: [PATCH 166/172] Revert "Install Passport during test setup process" This reverts commit 690a5119f45da29e980ea0362c86d4cdd3800793. --- .github/workflows/tests.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0461d4a728..24e5dc6e10 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,9 +60,6 @@ jobs: - name: Generate key run: php artisan key:generate - - name: Install Passport - run: php artisan passport:install - - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache From a3306e4a814fc43ced736d0e3506ab50a1123f79 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:41:22 -0800 Subject: [PATCH 167/172] Install Passport during test setup process specifying the environment --- .github/workflows/tests.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 24e5dc6e10..e555620d6f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,6 +60,9 @@ jobs: - name: Generate key run: php artisan key:generate + - name: Install Passport + run: php artisan passport:install --env=testing + - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache From fbc54526ed5aa68e848a1c14a311fd43f2c4f587 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:47:52 -0800 Subject: [PATCH 168/172] Set variables for Passport install step --- .github/workflows/tests.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e555620d6f..d3ba6c9f91 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -61,7 +61,12 @@ jobs: run: php artisan key:generate - name: Install Passport - run: php artisan passport:install --env=testing + env: + DB_CONNECTION: mysql + DB_DATABASE: snipeit + DB_PORT: ${{ job.services.mysql.ports[3306] }} + DB_USERNAME: root + run: php artisan passport:install - name: Directory Permissions run: chmod -R 777 storage bootstrap/cache From 32fdd36802f397db57eaa19bbd0424d84f6cb862 Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:51:30 -0800 Subject: [PATCH 169/172] Run migrations --- .github/workflows/tests.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d3ba6c9f91..f232bf6fd7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -60,6 +60,14 @@ jobs: - name: Generate key run: php artisan key:generate + - name: Migrate Database + env: + DB_CONNECTION: mysql + DB_DATABASE: snipeit + DB_PORT: ${{ job.services.mysql.ports[3306] }} + DB_USERNAME: root + run: php artisan migrate --force + - name: Install Passport env: DB_CONNECTION: mysql From be6545a366e201e0ed86da151896cdfc0738f80a Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Thu, 9 Nov 2023 15:55:04 -0800 Subject: [PATCH 170/172] Merge Laravel setup steps --- .github/workflows/tests.yml | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f232bf6fd7..611c1171b6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -57,27 +57,17 @@ jobs: - name: Install Dependencies run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist - - name: Generate key - run: php artisan key:generate - - - name: Migrate Database + - name: Setup Laravel env: DB_CONNECTION: mysql DB_DATABASE: snipeit DB_PORT: ${{ job.services.mysql.ports[3306] }} DB_USERNAME: root - run: php artisan migrate --force - - - name: Install Passport - env: - DB_CONNECTION: mysql - DB_DATABASE: snipeit - DB_PORT: ${{ job.services.mysql.ports[3306] }} - DB_USERNAME: root - run: php artisan passport:install - - - name: Directory Permissions - run: chmod -R 777 storage bootstrap/cache + run: | + php artisan key:generate + php artisan migrate --force + php artisan passport:install + chmod -R 777 storage bootstrap/cache - name: Execute tests (Unit and Feature tests) via PHPUnit env: From 495df737fcfe66e233ca975469a4816958cf6501 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 13 Nov 2023 16:39:35 +0000 Subject: [PATCH 171/172] Unfixed indenting :( Signed-off-by: snipe --- routes/web/hardware.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routes/web/hardware.php b/routes/web/hardware.php index dc0ba43fa0..d4f2892281 100644 --- a/routes/web/hardware.php +++ b/routes/web/hardware.php @@ -186,8 +186,11 @@ Route::resource('hardware', AssetsController::class, [ 'middleware' => ['auth'], - 'parameters' => ['asset' => 'asset_id'], - 'names' => ['show' => 'view'], + 'parameters' => ['asset' => 'asset_id', + 'names' => [ + 'show' => 'view', + ], + ], ]); Route::get('ht/{any?}', From 73ebd9017fc26a8b597d249e76a110a0cdfd527a Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 14 Nov 2023 14:37:48 +0000 Subject: [PATCH 172/172] Added default map back to the importer Signed-off-by: snipe --- app/Importer/Importer.php | 58 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index 76703ae1f8..961f4af52c 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -19,22 +19,76 @@ abstract class Importer * Id of User performing import * @var */ + protected $user_id; /** * Are we updating items in the import * @var bool */ + protected $updating; + /** * Default Map of item fields->csv names * * This has been moved into app/Http/Livewire/Importer.php to be more granular. - * @todo - remove references to this property since we don't use it anymore. + * This private variable is ONLY used for the cli-importer. * + * @todo - find a way to make this less duplicative * @var array */ private $defaultFieldMap = [ - + 'asset_tag' => 'asset tag', + 'activated' => 'activated', + 'category' => 'category', + 'checkout_class' => 'checkout type', // Supports Location or User for assets. Using checkout_class instead of checkout_type because type exists on asset already. + 'checkout_location' => 'checkout location', + 'company' => 'company', + 'item_name' => 'item name', + 'item_number' => 'item number', + 'image' => 'image', + 'expiration_date' => 'expiration date', + 'location' => 'location', + 'notes' => 'notes', + 'license_email' => 'licensed to email', + 'license_name' => 'licensed to name', + 'maintained' => 'maintained', + 'manufacturer' => 'manufacturer', + 'asset_model' => 'model name', + 'model_number' => 'model number', + 'order_number' => 'order number', + 'purchase_cost' => 'purchase cost', + 'purchase_date' => 'purchase date', + 'purchase_order' => 'purchase order', + 'qty' => 'quantity', + 'reassignable' => 'reassignable', + 'requestable' => 'requestable', + 'seats' => 'seats', + 'serial' => 'serial number', + 'status' => 'status', + 'supplier' => 'supplier', + 'termination_date' => 'termination date', + 'warranty_months' => 'warranty', + 'full_name' => 'full name', + 'email' => 'email', + 'username' => 'username', + 'address' => 'address', + 'address2' => 'address2', + 'city' => 'city', + 'state' => 'state', + 'country' => 'country', + 'zip' => 'zip', + 'jobtitle' => 'job title', + 'employee_num' => 'employee number', + 'phone_number' => 'phone number', + 'first_name' => 'first name', + 'last_name' => 'last name', + 'department' => 'department', + 'manager_name' => 'manager full name', + 'manager_username' => 'manager username', + 'min_amt' => 'minimum quantity', + 'remote' => 'remote', + 'vip' => 'vip', ]; /** * Map of item fields->csv names