From 53f9e2bc7a47aa60c28aac854cef217009612fe9 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 15:25:39 -0700 Subject: [PATCH 1/8] Wrap the Carbon method in a try/catch to prevent crashing on bad data Signed-off-by: snipe --- app/Helpers/Helper.php | 54 ++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 227ec6e20..32d896a31 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -841,6 +841,15 @@ class Helper return preg_replace('/\s+/u', '_', trim($string)); } + /** + * Return an array (or null) of the the raw and formatted date object for easy use in + * the API and the bootstrap table listings. + * + * @param $date + * @param $type + * @param $array + * @return array|string|null + */ public static function getFormattedDateObject($date, $type = 'datetime', $array = true) { if ($date == '') { @@ -848,21 +857,42 @@ class Helper } $settings = Setting::getSettings(); - $tmp_date = new \Carbon($date); - if ($type == 'datetime') { - $dt['datetime'] = $tmp_date->format('Y-m-d H:i:s'); - $dt['formatted'] = $tmp_date->format($settings->date_display_format.' '.$settings->time_display_format); - } else { - $dt['date'] = $tmp_date->format('Y-m-d'); - $dt['formatted'] = $tmp_date->format($settings->date_display_format); + /** + * Wrap this in a try/catch so that if Carbon crashes, for example if the $date value + * isn't actually valid, we don't crash out completely. + * + * While this *shouldn't* typically happen since we validate dates before entering them + * into the database (and we use date/datetime fields for native fields in the system), + * It is a possible scenario that a custom field could be created as an "ANY" field, data gets + * added, and then the custom field format gets edited later. If someone put bad data in the + * database before then - or if they manually edited the field's value - it will crash. + * + */ += + + try { + $tmp_date = new \Carbon($date); + + if ($type == 'datetime') { + $dt['datetime'] = $tmp_date->format('Y-m-d H:i:s'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format.' '.$settings->time_display_format); + } else { + $dt['date'] = $tmp_date->format('Y-m-d'); + $dt['formatted'] = $tmp_date->format($settings->date_display_format); + } + + if ($array == 'true') { + return $dt; + } + + return $dt['formatted']; + + } catch (\Exception $e) { + \Log::warning($e); + return 'ERROR: Date value is invalid'; } - if ($array == 'true') { - return $dt; - } - - return $dt['formatted']; } // Nicked from Drupal :) From f033aeda83179096bb9d5847f7788249e687183c Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 15:28:00 -0700 Subject: [PATCH 2/8] Fixed typo in comments Signed-off-by: snipe --- 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 32d896a31..ea6ac63e0 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -864,7 +864,7 @@ class Helper * * While this *shouldn't* typically happen since we validate dates before entering them * into the database (and we use date/datetime fields for native fields in the system), - * It is a possible scenario that a custom field could be created as an "ANY" field, data gets + * it is a possible scenario that a custom field could be created as an "ANY" field, data gets * added, and then the custom field format gets edited later. If someone put bad data in the * database before then - or if they manually edited the field's value - it will crash. * From 59011828858d40d185f19827f825a02d6cec341b Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 15:30:34 -0700 Subject: [PATCH 3/8] Removed stray character Signed-off-by: snipe --- app/Helpers/Helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index ea6ac63e0..4fdd21385 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -850,6 +850,7 @@ class Helper * @param $array * @return array|string|null */ + public static function getFormattedDateObject($date, $type = 'datetime', $array = true) { if ($date == '') { @@ -869,7 +870,7 @@ class Helper * database before then - or if they manually edited the field's value - it will crash. * */ -= + try { $tmp_date = new \Carbon($date); From d31f185cce013f10c5aa4cd70305c87ab29ccc6d Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 15:36:52 -0700 Subject: [PATCH 4/8] Display the actual value Signed-off-by: snipe --- 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 4fdd21385..b47d4d6ad 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -891,7 +891,7 @@ class Helper } catch (\Exception $e) { \Log::warning($e); - return 'ERROR: Date value is invalid'; + return $date.' (Invalid '.$type.' value.)'; } } From 07b1062fb283fe2beffae70d9502b9f173a1c615 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 16:55:23 -0700 Subject: [PATCH 5/8] Better handle API calls to nonexistent users Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 26a998007..2dd323a10 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -519,10 +519,14 @@ class UsersController extends Controller { $this->authorize('view', User::class); $this->authorize('view', License::class); - $user = User::where('id', $id)->withTrashed()->first(); - $licenses = $user->licenses()->get(); + + if ($user = User::where('id', $id)->withTrashed()->first()) { + $licenses = $user->licenses()->get(); + return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); + } + + return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id')))); - return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count()); } /** From dba06a3a9e613e108db455fe34b61c580174d098 Mon Sep 17 00:00:00 2001 From: snipe Date: Fri, 3 Jun 2022 16:56:15 -0700 Subject: [PATCH 6/8] Check for valid location before trying to print Signed-off-by: snipe --- app/Http/Controllers/LocationsController.php | 36 +++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/LocationsController.php b/app/Http/Controllers/LocationsController.php index 668b8190b..9524abf6e 100755 --- a/app/Http/Controllers/LocationsController.php +++ b/app/Http/Controllers/LocationsController.php @@ -211,23 +211,35 @@ class LocationsController extends Controller public function print_assigned($id) { - $location = Location::where('id', $id)->first(); - $parent = Location::where('id', $location->parent_id)->first(); - $manager = User::where('id', $location->manager_id)->first(); - $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); - $assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get(); - return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + if ($location = Location::where('id', $id)->first()) { + $parent = Location::where('id', $location->parent_id)->first(); + $manager = User::where('id', $location->manager_id)->first(); + $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); + $assets = Asset::where('assigned_to', $id)->where('assigned_type', Location::class)->with('model', 'model.category')->get(); + return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + + } + + return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); + + + } public function print_all_assigned($id) { - $location = Location::where('id', $id)->first(); - $parent = Location::where('id', $location->parent_id)->first(); - $manager = User::where('id', $location->manager_id)->first(); - $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); - $assets = Asset::where('location_id', $id)->with('model', 'model.category')->get(); + if ($location = Location::where('id', $id)->first()) { + $parent = Location::where('id', $location->parent_id)->first(); + $manager = User::where('id', $location->manager_id)->first(); + $users = User::where('location_id', $id)->with('company', 'department', 'location')->get(); + $assets = Asset::where('location_id', $id)->with('model', 'model.category')->get(); + return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); + + } + return redirect()->route('locations.index')->with('error', trans('admin/locations/message.does_not_exist')); + + - return view('locations/print')->with('assets', $assets)->with('users', $users)->with('location', $location)->with('parent', $parent)->with('manager', $manager); } } From c3698053ea90b890418b006cb02317a2cc98fdf3 Mon Sep 17 00:00:00 2001 From: Raden Farid Nugraha Date: Mon, 6 Jun 2022 06:58:07 +0700 Subject: [PATCH 7/8] Fixed ( #10910 ) : Add php redis extension --- Dockerfile | 1 + Dockerfile.alpine | 1 + 2 files changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 30a6935cd..fa08f4d85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ php7.4-xml \ php7.4-mbstring \ php7.4-zip \ php7.4-bcmath \ +php7.4-redis \ patch \ curl \ wget \ diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 702b2f555..b96a0c70c 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -27,6 +27,7 @@ RUN apk add --no-cache \ php7-xmlwriter \ php7-xmlreader \ php7-sodium \ + php7-redis \ curl \ wget \ vim \ From 985e683896c7e55a751fe0270dcff9ae1e655bba Mon Sep 17 00:00:00 2001 From: snipe Date: Sun, 5 Jun 2022 16:59:53 -0700 Subject: [PATCH 8/8] Small display improvements Signed-off-by: snipe --- resources/lang/en/admin/locations/general.php | 9 +++++++ resources/views/locations/print.blade.php | 27 ++++++------------- resources/views/locations/view.blade.php | 25 +++++++++-------- 3 files changed, 31 insertions(+), 30 deletions(-) create mode 100644 resources/lang/en/admin/locations/general.php diff --git a/resources/lang/en/admin/locations/general.php b/resources/lang/en/admin/locations/general.php new file mode 100644 index 000000000..822fd66c8 --- /dev/null +++ b/resources/lang/en/admin/locations/general.php @@ -0,0 +1,9 @@ + 'Assigned to :location Location', + 'asset_management_system' => 'Asset Management System', + 'assigned_to' => 'Assigned To:', + 'manager' => 'Manager', + 'date' => 'Current Date:', +); \ No newline at end of file diff --git a/resources/views/locations/print.blade.php b/resources/views/locations/print.blade.php index b9c664e65..7fc02ea6e 100644 --- a/resources/views/locations/print.blade.php +++ b/resources/views/locations/print.blade.php @@ -156,34 +156,23 @@ - - + - + -
{{ trans('admin/locations/table.signed_by_asset_auditor') }}___________________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
-
-
-
- + - - + - + -
{{ trans('admin/locations/table.signed_by_finance_auditor') }}____________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
-
-
-
- + - - + - +
{{ trans('admin/locations/table.signed_by_location_manager') }}_______________________
------------------------------------------------------    
{{ trans('admin/locations/table.date') }}____________________
------------------------------    
diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.php index 87eaf7c1a..771538df5 100644 --- a/resources/views/locations/view.blade.php +++ b/resources/views/locations/view.blade.php @@ -191,9 +191,20 @@
+ + + + + @if ($location->image!='')
- {{ $location->name }} + {{ $location->name }}
@endif
@@ -220,21 +231,13 @@ @if (($location->state!='') && ($location->country!='') && (config('services.google.maps_api_key')))
- Map + Map
@endif
- - - +