From 52dc5aa4ba750426600543a8ab46eca98bd1efcc Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:26:59 +0000 Subject: [PATCH 01/16] Added field to controller and tranformer Signed-off-by: snipe --- app/Http/Controllers/CustomFieldsController.php | 2 ++ app/Http/Transformers/CustomFieldsTransformer.php | 1 + 2 files changed, 3 insertions(+) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 43540ed421..529e8abbec 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -94,6 +94,7 @@ class CustomFieldsController extends Controller "field_encrypted" => $request->get("field_encrypted", 0), "show_in_email" => $request->get("show_in_email", 0), "is_unique" => $request->get("is_unique", 0), + "display_in_user_view" => $request->get("display_in_user_view", 0), "user_id" => Auth::id() ]); @@ -228,6 +229,7 @@ class CustomFieldsController extends Controller $field->help_text = $request->get("help_text"); $field->show_in_email = $request->get("show_in_email", 0); $field->is_unique = $request->get("is_unique", 0); + $field->display_in_user_view = $request->get("display_in_user_view", 0); if ($request->get('format') == 'CUSTOM REGEX') { $field->format = e($request->get('custom_format')); diff --git a/app/Http/Transformers/CustomFieldsTransformer.php b/app/Http/Transformers/CustomFieldsTransformer.php index 472a000002..9ada5183ab 100644 --- a/app/Http/Transformers/CustomFieldsTransformer.php +++ b/app/Http/Transformers/CustomFieldsTransformer.php @@ -47,6 +47,7 @@ class CustomFieldsTransformer 'field_values_array' => ($field->field_values) ? explode("\r\n", e($field->field_values)) : null, 'type' => e($field->element), 'required' => (($field->pivot) && ($field->pivot->required=='1')) ? true : false, + 'display_in_user_view' => ($field->display_in_user_view =='1') ? true : false, 'created_at' => Helper::getFormattedDateObject($field->created_at, 'datetime'), 'updated_at' => Helper::getFormattedDateObject($field->updated_at, 'datetime'), ]; From 7c37c70164c4b4d5201ea18e71fb69bc2c136564 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:27:22 +0000 Subject: [PATCH 02/16] Added new field to allowed_fields so that the API can change them if needed Signed-off-by: snipe --- app/Models/CustomField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Models/CustomField.php b/app/Models/CustomField.php index 0f19ccb446..e94b3fcc2f 100644 --- a/app/Models/CustomField.php +++ b/app/Models/CustomField.php @@ -64,6 +64,7 @@ class CustomField extends Model 'help_text', 'show_in_email', 'is_unique', + 'display_in_user_view', ]; /** From f91e1d58ad529344c5f11b30d54ce654863f5af5 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:27:34 +0000 Subject: [PATCH 03/16] Migration to add the field to the custom_fields table Signed-off-by: snipe --- ...8_add_display_to_user_in_custom_fields.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2022_11_07_134348_add_display_to_user_in_custom_fields.php diff --git a/database/migrations/2022_11_07_134348_add_display_to_user_in_custom_fields.php b/database/migrations/2022_11_07_134348_add_display_to_user_in_custom_fields.php new file mode 100644 index 0000000000..a29b223df7 --- /dev/null +++ b/database/migrations/2022_11_07_134348_add_display_to_user_in_custom_fields.php @@ -0,0 +1,32 @@ +boolean('display_in_user_view')->nullable()->default(0); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('custom_fields', function (Blueprint $table) { + $table->dropColumn('display_in_user_view'); + }); + } +} From b95d24b5eb2ca6d98fdc02fb998be13b01ab844d Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:27:44 +0000 Subject: [PATCH 04/16] Additional translations Signed-off-by: snipe --- resources/lang/en/admin/custom_fields/general.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lang/en/admin/custom_fields/general.php b/resources/lang/en/admin/custom_fields/general.php index 7434117830..92bf240a76 100644 --- a/resources/lang/en/admin/custom_fields/general.php +++ b/resources/lang/en/admin/custom_fields/general.php @@ -44,4 +44,6 @@ return [ 'db_convert_warning' => 'WARNING. This field is in the custom fields table as :db_column but should be :expected.', 'is_unique' => 'This value must be unique across all assets', 'unique' => 'Unique', + 'display_in_user_view' => 'Allow the checked out user to view these values in their View Assigned Assets page', + 'display_in_user_view_table' => 'Visible to User', ]; From 2e56c9b521e10b399a0fa1c65f59599df621597e Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:27:59 +0000 Subject: [PATCH 05/16] Added new general.display_in_user_view field to form Signed-off-by: snipe --- resources/views/custom_fields/fields/edit.blade.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index ba2fd0c6e0..0934a2daa8 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -116,6 +116,17 @@ + +
+
+ +
+ +
+
From 097821b818bdcc52595fbf9e8de978a41eea182d Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 8 Nov 2022 15:28:19 +0000 Subject: [PATCH 06/16] Slight revamping of column layouts and also added new general.display_in_user_view column Signed-off-by: snipe --- resources/views/custom_fields/index.blade.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/resources/views/custom_fields/index.blade.php b/resources/views/custom_fields/index.blade.php index 4638f615cb..08c43cdd7b 100644 --- a/resources/views/custom_fields/index.blade.php +++ b/resources/views/custom_fields/index.blade.php @@ -126,16 +126,17 @@ }'> - {{ trans('general.name') }} - {{ trans('admin/custom_fields/general.help_text')}} - {{ trans('general.email') }} - {{ trans('admin/custom_fields/general.unique') }} - {{ trans('admin/custom_fields/general.db_field') }} - {{ trans('admin/custom_fields/general.field_format') }} - + {{ trans('general.name') }} + {{ trans('admin/custom_fields/general.help_text')}} + {{ trans('admin/custom_fields/general.unique') }} + {{ trans('admin/custom_fields/general.db_field') }} + {{ trans('admin/custom_fields/general.field_format') }} + - {{ 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') }} @@ -145,7 +146,7 @@ {{ $field->name }} {{ $field->help_text }} - {!! ($field->show_in_email=='1') ? '' : '' !!} + {!! ($field->is_unique=='1') ? '' : '' !!} {{ $field->convertUnicodeDbSlug() }} @@ -156,6 +157,8 @@ {{ $field->format }} {!! ($field->field_encrypted=='1' ? '' : '') !!} + {!! ($field->display_in_user_view=='1' ? '' : '') !!} + {!! ($field->show_in_email=='1') ? '' : '' !!} {{ $field->element }} @foreach($field->fieldset as $fieldset) From 1fa624420e36cd3789a320f1098d57b1b4598473 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 16:46:49 +0000 Subject: [PATCH 07/16] Removed unneeded relationships Signed-off-by: snipe --- app/Http/Controllers/ViewAssetsController.php | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index 63267cbd05..edd1671ecf 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -8,6 +8,7 @@ use App\Models\AssetModel; use App\Models\Company; use App\Models\Setting; use App\Models\User; +use App\Models\CustomField; use App\Notifications\RequestAssetCancelation; use App\Notifications\RequestAssetNotification; use Illuminate\Http\Request; @@ -29,23 +30,28 @@ class ViewAssetsController extends Controller public function getIndex() { $user = User::with( + 'assets', 'assets.model', + 'assets.model.fieldset.fields', 'consumables', 'accessories', 'licenses', - 'userloc', - 'userlog' - )->withTrashed()->find(Auth::user()->id); + )->find(Auth::user()->id); - $userlog = $user->userlog->load('item', 'user', 'target'); + + foreach ($user->assets as $asset) { + foreach ($asset->model->fieldset->fields as $field) { + $field_array[$field->db_column] = $field->name; + } + } + + array_unique($field_array); if (isset($user->id)) { - return view('account/view-assets', compact('user', 'userlog')) + return view('account/view-assets', compact('user', 'field_array' )) ->with('settings', Setting::getSettings()); - } else { - // Redirect to the user management page - return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id'))); } + // Redirect to the user management page return redirect()->route('users.index') ->with('error', trans('admin/users/message.user_not_found', $user->id)); From 7a5fcfb87a5ca662efd92d93c6290f3e5e096d8c Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 16:46:59 +0000 Subject: [PATCH 08/16] Loop through fields array Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index 6081091c23..26b9a5b308 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -129,7 +129,7 @@
- @if(!empty($user->email)) + @if (!empty($user->email))
{{ csrf_field() }} @@ -404,6 +404,11 @@ {{ trans('general.name') }} {{ trans('admin/hardware/table.asset_model') }} {{ trans('admin/hardware/table.serial') }} + + @foreach ($field_array as $db_column => $field_name) + {{ $field_name }} + @endforeach + @@ -459,6 +464,11 @@ @endif + + @foreach ($field_array as $db_column => $field_value) + {{ $asset->{$db_column} }} skjgh + @endforeach + @php $assignedCounter++ @@ -551,7 +561,7 @@ @foreach ($user->accessories as $accessory) - {!! $accessory->name !!} + {{ $accessory->name }} {!! Helper::formatCurrencyOutput($accessory->purchase_cost) !!} @@ -599,7 +609,7 @@ @foreach ($user->consumables as $consumable) - {!! $consumable->name !!} + {{ $consumable->name }} {!! Helper::formatCurrencyOutput($consumable->purchase_cost) !!} From 1e34398c9957a66f7bc05ca95015cf2cd62a6767 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 17:19:12 +0000 Subject: [PATCH 09/16] Permissions check on the field itself Signed-off-by: snipe --- app/Http/Controllers/ViewAssetsController.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ViewAssetsController.php b/app/Http/Controllers/ViewAssetsController.php index edd1671ecf..55499ab22b 100755 --- a/app/Http/Controllers/ViewAssetsController.php +++ b/app/Http/Controllers/ViewAssetsController.php @@ -38,13 +38,17 @@ class ViewAssetsController extends Controller 'licenses', )->find(Auth::user()->id); - + // Loop through all the custom fields that are applied to any model the user has assigned foreach ($user->assets as $asset) { foreach ($asset->model->fieldset->fields as $field) { - $field_array[$field->db_column] = $field->name; + // check and make sure they're allowed to see the value of the custom field + if ($field->display_in_user_view == '1') { + $field_array[$field->db_column] = $field->name; + } } } + // Since some models may re-use the same fieldsets/fields, let's make the array unique so we don't repeat columns array_unique($field_array); if (isset($user->id)) { From ede16ad2c241448df4309fd4a37e931a9469798e Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 17:19:35 +0000 Subject: [PATCH 10/16] Removed unused block Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 41 ++++--------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index 26b9a5b308..dba84f3dfc 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -439,42 +439,15 @@ @endif {{ $asset->serial }} - - @if($settings->show_assigned_assets) - @php - $assignedCounter = 1 - @endphp - @foreach ($asset->assignedAssets as $asset) - - {{ $counter }}.{{ $assignedCounter }} - {{ $asset->model->category->name }} - {{ $asset->asset_tag }} - {{ $asset->name }} - - @if ($asset->physical=='1') - {{ $asset->model->name }} - @endif - - {{ $asset->serial }} - - @if (($asset->image) && ($asset->image!='')) - - @elseif (($asset->model) && ($asset->model->image!='')) - - @endif - - - @foreach ($field_array as $db_column => $field_value) - {{ $asset->{$db_column} }} skjgh - @endforeach - - - @php - $assignedCounter++ - @endphp + @foreach ($field_array as $db_column => $field_value) + + {{ $asset->{$db_column} }} + @endforeach - @endif + + + @php $counter++ @endphp From 2ac558494d934a31b61d36b09889066fe6db1bc4 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 17:21:07 +0000 Subject: [PATCH 11/16] Set column width instead of letting BS tables guess Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index dba84f3dfc..bdad9c337f 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -397,7 +397,7 @@ }'> - # + # {{ trans('general.image') }} {{ trans('general.category') }} {{ trans('admin/hardware/table.asset_tag') }} From ae95ee49f159e8a0a4a12baf28b39ab5e2cd5085 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 10 Nov 2022 17:56:50 +0000 Subject: [PATCH 12/16] Hide the option if the field is encrypted Signed-off-by: snipe --- resources/views/custom_fields/fields/edit.blade.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/views/custom_fields/fields/edit.blade.php b/resources/views/custom_fields/fields/edit.blade.php index 0934a2daa8..b9b9715a2e 100644 --- a/resources/views/custom_fields/fields/edit.blade.php +++ b/resources/views/custom_fields/fields/edit.blade.php @@ -217,11 +217,13 @@ $('#field_encrypted').on('ifChecked', function(event){ $("#encrypt_warning").show(); $("#show_in_email").hide(); + $("#display_in_user_view").hide(); }); $('#field_encrypted').on('ifUnchecked', function(event){ $("#encrypt_warning").hide(); $("#show_in_email").show(); + $("#display_in_user_view").show(); }); From 4aded5e117d44ddd3ca72c5f06cf923e7809552c Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 14 Nov 2022 22:01:33 +0000 Subject: [PATCH 13/16] FIxed 500 error if model files are missing Signed-off-by: snipe --- resources/views/models/view.blade.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index fe6ab3d0cf..445b90b7e8 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -145,17 +145,21 @@ - @if ( Helper::checkUploadIsImage($file->get_src('assetmodels'))) + @if ((Storage::exists('private_uploads/assetmodels/'.$file->filename)) && ( Helper::checkUploadIsImage($file->get_src('assetmodels')))) @endif - {{ $file->filename }} + @if (Storage::exists('private_uploads/assetmodels/'.$file->filename)) + {{ $file->filename }} + @else + {{ $file->filename }} + @endif - - {{ Helper::formatFilesizeUnits(Storage::size('private_uploads/assetmodels/'.$file->filename)) }} + + {{ (Storage::exists('private_uploads/assetmodels/'.$file->filename)) ? Helper::formatFilesizeUnits(Storage::size('private_uploads/assetmodels/'.$file->filename)) : '' }} @if ($file->note) From d4ac7530b634ce58c0023ee025988ccef5b935ca Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 14 Nov 2022 22:04:06 +0000 Subject: [PATCH 14/16] =?UTF-8?q?Removed=20download=20button=20for=20files?= =?UTF-8?q?=20that=20don=E2=80=99t=20exist=20on=20the=20server?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: snipe --- resources/views/models/view.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/models/view.blade.php b/resources/views/models/view.blade.php index 445b90b7e8..3b9078d29c 100755 --- a/resources/views/models/view.blade.php +++ b/resources/views/models/view.blade.php @@ -167,7 +167,7 @@ @endif - @if ($file->filename) + @if (($file->filename) && (Storage::exists('private_uploads/assetmodels/'.$file->filename))) From 602c2698d23caea7302adc98bca4ef450af76521 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 14 Nov 2022 22:06:23 +0000 Subject: [PATCH 15/16] Fixed broken table header tag Signed-off-by: snipe --- resources/views/account/view-assets.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/account/view-assets.blade.php b/resources/views/account/view-assets.blade.php index bdad9c337f..c1a391e453 100755 --- a/resources/views/account/view-assets.blade.php +++ b/resources/views/account/view-assets.blade.php @@ -397,7 +397,7 @@ }'> - # + # {{ trans('general.image') }} {{ trans('general.category') }} {{ trans('admin/hardware/table.asset_tag') }} From 56c4fa7c2712dea0e10af202d3f811f9df4e4326 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 14 Nov 2022 22:41:31 +0000 Subject: [PATCH 16/16] Override display settings if field is encrypted Signed-off-by: snipe --- .../Controllers/CustomFieldsController.php | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 529e8abbec..4eb31450ee 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -86,15 +86,24 @@ class CustomFieldsController extends Controller { $this->authorize('create', CustomField::class); + $show_in_email = $request->get("show_in_email", 0); + $display_in_user_view = $request->get("display_in_user_view", 0); + + // Override the display settings if the field is encrypted + if ($request->get("field_encrypted") == '1') { + $show_in_email = '0'; + $display_in_user_view = '0'; + } + $field = new CustomField([ "name" => trim($request->get("name")), "element" => $request->get("element"), "help_text" => $request->get("help_text"), "field_values" => $request->get("field_values"), "field_encrypted" => $request->get("field_encrypted", 0), - "show_in_email" => $request->get("show_in_email", 0), + "show_in_email" => $show_in_email, "is_unique" => $request->get("is_unique", 0), - "display_in_user_view" => $request->get("display_in_user_view", 0), + "display_in_user_view" => $display_in_user_view, "user_id" => Auth::id() ]); @@ -222,14 +231,24 @@ class CustomFieldsController extends Controller $this->authorize('update', $field); + + $show_in_email = $request->get("show_in_email", 0); + $display_in_user_view = $request->get("display_in_user_view", 0); + + // Override the display settings if the field is encrypted + if ($request->get("field_encrypted") == '1') { + $show_in_email = '0'; + $display_in_user_view = '0'; + } + $field->name = trim(e($request->get("name"))); $field->element = e($request->get("element")); $field->field_values = e($request->get("field_values")); $field->user_id = Auth::id(); $field->help_text = $request->get("help_text"); - $field->show_in_email = $request->get("show_in_email", 0); + $field->show_in_email = $show_in_email; $field->is_unique = $request->get("is_unique", 0); - $field->display_in_user_view = $request->get("display_in_user_view", 0); + $field->display_in_user_view = $display_in_user_view; if ($request->get('format') == 'CUSTOM REGEX') { $field->format = e($request->get('custom_format'));