From 99741db645c22612e64c738140527f2aeaa43cc4 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 24 Jul 2024 11:24:30 -0700 Subject: [PATCH 01/26] adds status labels to confirmation emails --- app/Http/Controllers/Account/AcceptanceController.php | 2 ++ app/Notifications/AcceptanceAssetAcceptedNotification.php | 2 ++ app/Notifications/AcceptanceAssetDeclinedNotification.php | 2 ++ app/Notifications/CheckoutAssetNotification.php | 1 + .../views/notifications/markdown/asset-acceptance.blade.php | 3 +++ .../views/notifications/markdown/checkout-asset.blade.php | 3 +++ 6 files changed, 13 insertions(+) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 2c9d29fc16..cabd056332 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -218,6 +218,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, + 'item_status' => $item->assetstatus->name ?: '', 'eula' => $item->getEula(), 'note' => $request->input('note'), 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'), @@ -308,6 +309,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, + 'item_status' => $item->assetstatus->name ?: '', 'note' => $request->input('note'), 'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'), 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, diff --git a/app/Notifications/AcceptanceAssetAcceptedNotification.php b/app/Notifications/AcceptanceAssetAcceptedNotification.php index db1555b574..7798dbc0d5 100644 --- a/app/Notifications/AcceptanceAssetAcceptedNotification.php +++ b/app/Notifications/AcceptanceAssetAcceptedNotification.php @@ -24,6 +24,7 @@ class AcceptanceAssetAcceptedNotification extends Notification $this->item_tag = $params['item_tag']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; + $this->item_status = $params['item_status']; $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false); $this->assigned_to = $params['assigned_to']; $this->note = $params['note']; @@ -65,6 +66,7 @@ class AcceptanceAssetAcceptedNotification extends Notification 'item_tag' => $this->item_tag, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, + 'item_status' => $this->item_status, 'note' => $this->note, 'accepted_date' => $this->accepted_date, 'assigned_to' => $this->assigned_to, diff --git a/app/Notifications/AcceptanceAssetDeclinedNotification.php b/app/Notifications/AcceptanceAssetDeclinedNotification.php index abdfbbf0c0..0a9d6c211f 100644 --- a/app/Notifications/AcceptanceAssetDeclinedNotification.php +++ b/app/Notifications/AcceptanceAssetDeclinedNotification.php @@ -24,6 +24,7 @@ class AcceptanceAssetDeclinedNotification extends Notification $this->item_tag = $params['item_tag']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; + $this->item_status = $params['item_status']; $this->declined_date = Helper::getFormattedDateObject($params['declined_date'], 'date', false); $this->note = $params['note']; $this->assigned_to = $params['assigned_to']; @@ -63,6 +64,7 @@ class AcceptanceAssetDeclinedNotification extends Notification 'item_tag' => $this->item_tag, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, + 'item_status' => $this->item_status, 'note' => $this->note, 'declined_date' => $this->declined_date, 'assigned_to' => $this->assigned_to, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 1c8c901b52..7c9b6b2a8e 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,6 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, + 'status' => $this->item->assetstatus(), 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php index 93292375a5..037e24c139 100644 --- a/resources/views/notifications/markdown/asset-acceptance.blade.php +++ b/resources/views/notifications/markdown/asset-acceptance.blade.php @@ -16,6 +16,9 @@ @if (isset($note)) | **{{ trans('general.notes') }}** | {{ $note }} | @endif +@if (isset($item_status)) + | **{{ trans('general.status') }}** | {{ $item_status }} | +@endif @if ((isset($item_tag)) && ($item_tag!='')) | **{{ trans('mail.asset_tag') }}** | {{ $item_tag }} | @endif diff --git a/resources/views/notifications/markdown/checkout-asset.blade.php b/resources/views/notifications/markdown/checkout-asset.blade.php index 4646cef482..b76e3e66a3 100644 --- a/resources/views/notifications/markdown/checkout-asset.blade.php +++ b/resources/views/notifications/markdown/checkout-asset.blade.php @@ -31,6 +31,9 @@ @if (isset($last_checkout)) | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif +@if (isset($status)) + | **{{ trans('general.status') }}** | {{ $status }} | +@endif @if ((isset($expected_checkin)) && ($expected_checkin!='')) | **{{ trans('mail.expecting_checkin_date') }}** | {{ $expected_checkin }} | @endif From eb6f330e672429d9b40a168c493557048bd35aac Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Tue, 30 Jul 2024 09:38:39 -0700 Subject: [PATCH 02/26] adds status to check in and out --- app/Notifications/CheckinAssetNotification.php | 1 + app/Notifications/CheckoutAssetNotification.php | 2 +- resources/views/notifications/markdown/checkin-asset.blade.php | 3 +++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 54b96777fe..50745b1b27 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -162,6 +162,7 @@ class CheckinAssetNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.checkin-asset', [ 'item' => $this->item, + 'status' => $this->item->assetstatus->name ?: '', 'admin' => $this->admin, 'note' => $this->note, 'target' => $this->target, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 7c9b6b2a8e..352b088dba 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,7 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, - 'status' => $this->item->assetstatus(), + 'status' => $this->item->assetstatus->name ?: '', 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, diff --git a/resources/views/notifications/markdown/checkin-asset.blade.php b/resources/views/notifications/markdown/checkin-asset.blade.php index 74a4381707..fd9afbd286 100644 --- a/resources/views/notifications/markdown/checkin-asset.blade.php +++ b/resources/views/notifications/markdown/checkin-asset.blade.php @@ -31,6 +31,9 @@ @if (isset($last_checkout)) | **{{ trans('mail.checkout_date') }}** | {{ $last_checkout }} | @endif +@if (isset($status)) + | **{{ trans('general.status') }}** | {{ $status }} | +@endif @foreach($fields as $field) @if (($item->{ $field->db_column_name() }!='') && ($field->show_in_email) && ($field->field_encrypted=='0')) | **{{ $field->name }}** | {{ $item->{ $field->db_column_name() } }} | From 8684a3efc3da03ce1f8dfc3ab014e5e2e90c89a7 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 30 Jul 2024 21:22:46 -0500 Subject: [PATCH 03/26] delete note, add trait to other request --- app/Http/Requests/Traits/MayContainCustomFields.php | 1 - app/Http/Requests/UpdateAssetRequest.php | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Traits/MayContainCustomFields.php b/app/Http/Requests/Traits/MayContainCustomFields.php index 50b239b60e..1dd25dbe03 100644 --- a/app/Http/Requests/Traits/MayContainCustomFields.php +++ b/app/Http/Requests/Traits/MayContainCustomFields.php @@ -15,7 +15,6 @@ trait MayContainCustomFields $asset_model = AssetModel::find($this->model_id); } if ($this->method() == 'PATCH' || $this->method() == 'PUT') { - // this is dependent on the asset update request PR $asset_model = $this->asset; } // collect the custom fields in the request diff --git a/app/Http/Requests/UpdateAssetRequest.php b/app/Http/Requests/UpdateAssetRequest.php index cc23a65c40..a749e5816b 100644 --- a/app/Http/Requests/UpdateAssetRequest.php +++ b/app/Http/Requests/UpdateAssetRequest.php @@ -2,12 +2,14 @@ namespace App\Http\Requests; +use App\Http\Requests\Traits\MayContainCustomFields; use App\Models\Asset; use Illuminate\Support\Facades\Gate; use Illuminate\Validation\Rule; class UpdateAssetRequest extends ImageUploadRequest { + use MayContainCustomFields; /** * Determine if the user is authorized to make this request. * From 9b80843c7759bd145ca2f516499af36648607ca4 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 30 Jul 2024 21:44:22 -0500 Subject: [PATCH 04/26] tests a little broken, added some nullchecks --- app/Http/Requests/Traits/MayContainCustomFields.php | 2 +- tests/Feature/Assets/Api/UpdateAssetTest.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Traits/MayContainCustomFields.php b/app/Http/Requests/Traits/MayContainCustomFields.php index 1dd25dbe03..2feada1774 100644 --- a/app/Http/Requests/Traits/MayContainCustomFields.php +++ b/app/Http/Requests/Traits/MayContainCustomFields.php @@ -24,7 +24,7 @@ trait MayContainCustomFields }); // if there are custom fields, find the one's that don't exist on the model's fieldset and add an error to the validator's error bag if (count($request_fields) > 0) { - $request_fields->diff($asset_model->fieldset->fields->pluck('db_column')) + $request_fields->diff($asset_model?->fieldset?->fields?->pluck('db_column')) ->each(function ($request_field_name) use ($request_fields, $validator) { if (CustomField::where('db_column', $request_field_name)->exists()) { $validator->errors()->add($request_field_name, trans('validation.custom.custom_field_not_found_on_model')); diff --git a/tests/Feature/Assets/Api/UpdateAssetTest.php b/tests/Feature/Assets/Api/UpdateAssetTest.php index db5893b4dc..2a57d38391 100644 --- a/tests/Feature/Assets/Api/UpdateAssetTest.php +++ b/tests/Feature/Assets/Api/UpdateAssetTest.php @@ -269,6 +269,8 @@ class UpdateAssetTest extends TestCase { $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); + // hmm, for some reason this customfield isn't attached to a fieldset + // need to check out these factory methods... $field = CustomField::factory()->testEncrypted()->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $superuser = User::factory()->superuser()->create(); From 0941c0944a68f1043b43325f47cd51bd88fa6111 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 30 Jul 2024 22:55:15 -0500 Subject: [PATCH 05/26] ok, found issue, but need to test some things now... --- app/Http/Requests/Traits/MayContainCustomFields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Requests/Traits/MayContainCustomFields.php b/app/Http/Requests/Traits/MayContainCustomFields.php index 2feada1774..9a7f85e3a2 100644 --- a/app/Http/Requests/Traits/MayContainCustomFields.php +++ b/app/Http/Requests/Traits/MayContainCustomFields.php @@ -15,7 +15,7 @@ trait MayContainCustomFields $asset_model = AssetModel::find($this->model_id); } if ($this->method() == 'PATCH' || $this->method() == 'PUT') { - $asset_model = $this->asset; + $asset_model = $this->asset->model; } // collect the custom fields in the request $validator->after(function ($validator) use ($asset_model) { From b0063b1d4a0af2f78c3b7c4334256a89cfa661b0 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 31 Jul 2024 11:57:35 -0500 Subject: [PATCH 06/26] test written --- tests/Feature/Assets/Api/UpdateAssetTest.php | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tests/Feature/Assets/Api/UpdateAssetTest.php b/tests/Feature/Assets/Api/UpdateAssetTest.php index 2a57d38391..499ea61f28 100644 --- a/tests/Feature/Assets/Api/UpdateAssetTest.php +++ b/tests/Feature/Assets/Api/UpdateAssetTest.php @@ -269,8 +269,6 @@ class UpdateAssetTest extends TestCase { $this->markIncompleteIfMySQL('Custom Fields tests do not work on MySQL'); - // hmm, for some reason this customfield isn't attached to a fieldset - // need to check out these factory methods... $field = CustomField::factory()->testEncrypted()->create(); $asset = Asset::factory()->hasEncryptedCustomField($field)->create(); $superuser = User::factory()->superuser()->create(); @@ -456,4 +454,27 @@ class UpdateAssetTest extends TestCase ]) ->assertStatusMessageIs('success'); } + + public function testCustomFieldCannotBeUpdatedIfNotOnCurrentAssetModel() + { + $customField = CustomField::factory()->create(); + $customField2 = CustomField::factory()->create(); + $asset = Asset::factory()->hasMultipleCustomFields([$customField])->create(); + $user = User::factory()->editAssets()->create(); + + // successful + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + $customField->db_column_name() => 'test attribute', + ])->assertStatusMessageIs('success'); + + // custom field exists, but not on this asset model + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + $customField2->db_column_name() => 'test attribute', + ])->assertStatusMessageIs('error'); + + // custom field does not exist + $this->actingAsForApi($user)->patchJson(route('api.assets.update', $asset->id), [ + '_snipeit_non_existent_custom_field_50' => 'test attribute', + ])->assertStatusMessageIs('error'); + } } From 61312c2eecf92951e63ea76a474b12e9b0ff2de5 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Wed, 31 Jul 2024 12:07:50 -0500 Subject: [PATCH 07/26] oops, mysql --- tests/Feature/Assets/Api/UpdateAssetTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Feature/Assets/Api/UpdateAssetTest.php b/tests/Feature/Assets/Api/UpdateAssetTest.php index 499ea61f28..300d06ae50 100644 --- a/tests/Feature/Assets/Api/UpdateAssetTest.php +++ b/tests/Feature/Assets/Api/UpdateAssetTest.php @@ -457,6 +457,8 @@ class UpdateAssetTest extends TestCase public function testCustomFieldCannotBeUpdatedIfNotOnCurrentAssetModel() { + $this->markIncompleteIfMySQL('Custom Field Tests do not work in MySQL'); + $customField = CustomField::factory()->create(); $customField2 = CustomField::factory()->create(); $asset = Asset::factory()->hasMultipleCustomFields([$customField])->create(); From b6cac4baaef3f52be8c18f6068f3f1cf70caec9d Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 31 Jul 2024 12:03:36 -0700 Subject: [PATCH 08/26] corrects ? usage --- app/Http/Controllers/Account/AcceptanceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index cabd056332..207932556c 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -309,7 +309,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, - 'item_status' => $item->assetstatus->name ?: '', + 'item_status' => $item->assetstatus?->name, 'note' => $request->input('note'), 'declined_date' => Carbon::parse($acceptance->declined_at)->format('Y-m-d'), 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, From 854903805b54fb4d0d283f7de50c908b7e71386a Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Wed, 31 Jul 2024 12:16:41 -0700 Subject: [PATCH 09/26] one more spot --- app/Http/Controllers/Account/AcceptanceController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index 207932556c..6d84861fb0 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -218,7 +218,7 @@ class AcceptanceController extends Controller 'item_tag' => $item->asset_tag, 'item_model' => $display_model, 'item_serial' => $item->serial, - 'item_status' => $item->assetstatus->name ?: '', + 'item_status' => $item->assetstatus?->name, 'eula' => $item->getEula(), 'note' => $request->input('note'), 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d'), From ae4f278df15b1edf366f48dde11c6436e4777bd2 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 1 Aug 2024 11:13:20 -0700 Subject: [PATCH 10/26] edited terenaries on notifs --- app/Notifications/CheckinAssetNotification.php | 2 +- app/Notifications/CheckoutAssetNotification.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Notifications/CheckinAssetNotification.php b/app/Notifications/CheckinAssetNotification.php index 50745b1b27..77cd6d9b5a 100644 --- a/app/Notifications/CheckinAssetNotification.php +++ b/app/Notifications/CheckinAssetNotification.php @@ -162,7 +162,7 @@ class CheckinAssetNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.checkin-asset', [ 'item' => $this->item, - 'status' => $this->item->assetstatus->name ?: '', + 'status' => $this->item->assetstatus?->name, 'admin' => $this->admin, 'note' => $this->note, 'target' => $this->target, diff --git a/app/Notifications/CheckoutAssetNotification.php b/app/Notifications/CheckoutAssetNotification.php index 352b088dba..5ebde7e4f7 100644 --- a/app/Notifications/CheckoutAssetNotification.php +++ b/app/Notifications/CheckoutAssetNotification.php @@ -209,7 +209,7 @@ public function toGoogleChat() [ 'item' => $this->item, 'admin' => $this->admin, - 'status' => $this->item->assetstatus->name ?: '', + 'status' => $this->item->assetstatus?->name, 'note' => $this->note, 'target' => $this->target, 'fields' => $fields, From 1b2094f4e2ecd97a7f8eb91107c396d1b4e12324 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 13 Aug 2024 13:49:13 +0100 Subject: [PATCH 11/26] Added tooltips to top nav shortcuts Signed-off-by: snipe --- resources/views/layouts/default.blade.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index 78fd26dfdf..2c38e59111 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -144,7 +144,7 @@ dir="{{ Helper::determineLanguageDirection() }}">