diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.php index a843aa09db..ac9287b53e 100644 --- a/app/Http/Controllers/Api/AssetsController.php +++ b/app/Http/Controllers/Api/AssetsController.php @@ -857,7 +857,8 @@ class AssetsController extends Controller $checkout_at = request('checkout_at', date('Y-m-d H:i:s')); $expected_checkin = request('expected_checkin', null); $note = request('note', null); - $asset_name = request('name', null); + // Using `->has` preserves the asset name if the name parameter was not included in request. + $asset_name = request()->has('name') ? request('name') : $asset->name; // Set the location ID to the RTD location id if there is one // Wait, why are we doing this? This overrides the stuff we set further up, which makes no sense. diff --git a/app/Http/Controllers/Api/ImportController.php b/app/Http/Controllers/Api/ImportController.php index 9742cc1644..2426a49bed 100644 --- a/app/Http/Controllers/Api/ImportController.php +++ b/app/Http/Controllers/Api/ImportController.php @@ -10,6 +10,7 @@ use App\Models\Asset; use App\Models\Company; use App\Models\Import; use Artisan; +use Illuminate\Database\Eloquent\JsonEncodingException; use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Storage; @@ -35,7 +36,7 @@ class ImportController extends Controller * Process and store a CSV upload file. * * @param \Illuminate\Http\Request $request - * @return \Illuminate\Http\Response + * @return \Illuminate\Http\JsonResponse */ public function store() { @@ -56,7 +57,7 @@ class ImportController extends Controller 'text/tsv', ])) { $results['error'] = 'File type must be CSV. Uploaded file is '.$file->getMimeType(); - return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500); + return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 422); } //TODO: is there a lighter way to do this? @@ -64,7 +65,19 @@ class ImportController extends Controller ini_set('auto_detect_line_endings', '1'); } $reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak? - $import->header_row = $reader->fetchOne(0); + + try { + $import->header_row = $reader->fetchOne(0); + } catch (JsonEncodingException $e) { + return response()->json( + Helper::formatStandardApiResponse( + 'error', + null, + trans('admin/hardware/message.import.header_row_has_malformed_characters') + ), + 422 + ); + } //duplicate headers check $duplicate_headers = []; @@ -82,11 +95,22 @@ class ImportController extends Controller } } if (count($duplicate_headers) > 0) { - return response()->json(Helper::formatStandardApiResponse('error', null, implode('; ', $duplicate_headers)), 500); //should this be '4xx'? + return response()->json(Helper::formatStandardApiResponse('error', null, implode('; ', $duplicate_headers)),422); } - // Grab the first row to display via ajax as the user picks fields - $import->first_row = $reader->fetchOne(1); + try { + // Grab the first row to display via ajax as the user picks fields + $import->first_row = $reader->fetchOne(1); + } catch (JsonEncodingException $e) { + return response()->json( + Helper::formatStandardApiResponse( + 'error', + null, + trans('admin/hardware/message.import.content_row_has_malformed_characters') + ), + 422 + ); + } $date = date('Y-m-d-his'); $fixed_filename = str_slug($file->getClientOriginalName()); @@ -108,12 +132,12 @@ class ImportController extends Controller } $results = (new ImportsTransformer)->transformImports($results); - return [ + return response()->json([ 'files' => $results, - ]; + ]); } - return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.feature_disabled')), 500); + return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.feature_disabled')), 422); } /** diff --git a/app/Http/Controllers/CustomFieldsController.php b/app/Http/Controllers/CustomFieldsController.php index 4eb31450ee..e29cbaa3fc 100644 --- a/app/Http/Controllers/CustomFieldsController.php +++ b/app/Http/Controllers/CustomFieldsController.php @@ -109,9 +109,9 @@ class CustomFieldsController extends Controller if ($request->filled('custom_format')) { - $field->format = e($request->get('custom_format')); + $field->format = $request->get('custom_format'); } else { - $field->format = e($request->get('format')); + $field->format = $request->get('format'); } if ($field->save()) { diff --git a/database/migrations/2023_02_12_224353_fix_unescaped_customfields_format.php b/database/migrations/2023_02_12_224353_fix_unescaped_customfields_format.php new file mode 100644 index 0000000000..f1779e996a --- /dev/null +++ b/database/migrations/2023_02_12_224353_fix_unescaped_customfields_format.php @@ -0,0 +1,33 @@ +get(); + + foreach($customfields as $customfield){ + $customfield->update(['format' => html_entity_decode($customfield->format)]); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/resources/lang/en/admin/hardware/message.php b/resources/lang/en/admin/hardware/message.php index d2214ce00c..fabbb63243 100644 --- a/resources/lang/en/admin/hardware/message.php +++ b/resources/lang/en/admin/hardware/message.php @@ -49,6 +49,8 @@ return [ 'success' => 'Your file has been imported', 'file_delete_success' => 'Your file has been been successfully deleted', 'file_delete_error' => 'The file was unable to be deleted', + 'header_row_has_malformed_characters' => 'One or more attributes in the header row contain malformed UTF-8 characters', + 'content_row_has_malformed_characters' => 'One or more attributes in the first row of content contain malformed UTF-8 characters', ], diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index 9c8a0853f1..bd023979cc 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -399,6 +399,12 @@ return [ 'preview_not_available' => '(no preview)', 'display_username' => 'Display Username', 'display_username_help_text' => 'Checking this box will cause listings to display the username in addition to the first and last name for users on listing pages.', + 'setup' => 'Setup', + 'pre_flight' => 'Pre-Flight', + 'skip_to_main_content' => 'Skip to main content', + 'toggle_navigation' => 'Toggle navigation', + 'alerts' => 'Alerts', + 'tasks_view_all' => 'View all tasks', diff --git a/resources/views/hardware/view.blade.php b/resources/views/hardware/view.blade.php index b4cd6d4988..5b480a2446 100755 --- a/resources/views/hardware/view.blade.php +++ b/resources/views/hardware/view.blade.php @@ -243,7 +243,7 @@ @elseif (($asset->assetstatus) && ($asset->assetstatus->pending=='1')) - @elseif (($asset->assetstatus) && ($asset->assetstatus->archived=='1')) + @else @endif @@ -595,10 +595,12 @@ {{ $asset->warranty_months }} {{ trans('admin/hardware/form.months') }} - @if (($asset->serial && $asset->model->manufacturer) && $asset->model->manufacturer->name == 'Apple') + @if ($asset->serial && $asset->model->manufacturer) + @if ((strtolower($asset->model->manufacturer->name) == "apple") || (str_starts_with(str_replace(' ','',strtolower($asset->model->manufacturer->name)),"appleinc"))) Applecare Status Lookup + @endif @endif diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index ceabe13553..2bb9bc8cf9 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -88,7 +88,7 @@
@endif - Skip to main content + {{ trans('general.skip_to_main_content') }}