From e73b16846e79284751c39c101aa5d4f701d13e73 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 11 Sep 2023 11:21:56 -0700 Subject: [PATCH 01/30] 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 8f8e5cb7235d41fc7b0542720c0a22a0c76b67b9 Mon Sep 17 00:00:00 2001 From: Ivan Nieto Vivanco Date: Mon, 23 Oct 2023 21:47:10 -0600 Subject: [PATCH 02/30] 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 03/30] 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 04/30] 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 c919cd31fafebe92190cd6f40cd7bf61c7a8c4c8 Mon Sep 17 00:00:00 2001 From: Joe Ferguson Date: Tue, 24 Oct 2023 11:30:24 -0500 Subject: [PATCH 05/30] 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 06/30] 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 07/30] 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 08/30] 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 09/30] 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 10/30] 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 11/30] 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 12/30] 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 13/30] 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 14/30] 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 15/30] 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 16/30] 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 17/30] 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 18/30] 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 19/30] 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 20/30] 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 21/30] 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 22/30] 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 23/30] 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 24/30] 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 25/30] 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 26/30] 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 27/30] 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 28/30] 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 29/30] 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 30/30] 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.',