From 758d3aadb4c3e23709e2c70714879452f2774f57 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 10 Oct 2023 11:52:35 +0100 Subject: [PATCH 1/4] Added trim to import values Signed-off-by: snipe --- app/Importer/AccessoryImporter.php | 2 +- app/Importer/AssetImporter.php | 10 +++--- app/Importer/ComponentImporter.php | 4 +-- app/Importer/ConsumableImporter.php | 8 ++--- app/Importer/ItemImporter.php | 6 ++-- app/Importer/LicenseImporter.php | 18 +++++------ app/Importer/LocationImporter.php | 24 +++++++-------- app/Importer/UserImporter.php | 48 ++++++++++++++--------------- 8 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/Importer/AccessoryImporter.php b/app/Importer/AccessoryImporter.php index 417075ef31..9901fb70d7 100644 --- a/app/Importer/AccessoryImporter.php +++ b/app/Importer/AccessoryImporter.php @@ -34,7 +34,7 @@ class AccessoryImporter extends ItemImporter } $this->log('Updating Accessory'); - $this->item['model_number'] = $this->findCsvMatch($row, "model_number"); + $this->item['model_number'] = trim($this->findCsvMatch($row, "model_number")); $accessory->update($this->sanitizeItemForUpdating($accessory)); $accessory->save(); diff --git a/app/Importer/AssetImporter.php b/app/Importer/AssetImporter.php index 76eae0739a..a7719aa663 100644 --- a/app/Importer/AssetImporter.php +++ b/app/Importer/AssetImporter.php @@ -80,13 +80,13 @@ class AssetImporter extends ItemImporter $this->log('No Matching Asset, Creating a new one'); $asset = new Asset; } - $this->item['notes'] = $this->findCsvMatch($row, 'asset_notes'); - $this->item['image'] = $this->findCsvMatch($row, 'image'); - $this->item['requestable'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'requestable')) == 1) ? '1' : 0; + $this->item['notes'] = trim($this->findCsvMatch($row, 'asset_notes')); + $this->item['image'] = trim($this->findCsvMatch($row, 'image')); + $this->item['requestable'] = trim(($this->fetchHumanBoolean($this->findCsvMatch($row, 'requestable'))) == 1) ? '1' : 0; $asset->requestable = $this->item['requestable']; - $this->item['warranty_months'] = intval($this->findCsvMatch($row, 'warranty_months')); + $this->item['warranty_months'] = intval(trim($this->findCsvMatch($row, 'warranty_months'))); $this->item['model_id'] = $this->createOrFetchAssetModel($row); - $this->item['byod'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'byod')) == 1) ? '1' : 0; + $this->item['byod'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'byod'))) == 1) ? '1' : 0; // If no status ID is found diff --git a/app/Importer/ComponentImporter.php b/app/Importer/ComponentImporter.php index de3ee14d1c..71ded1b0e5 100644 --- a/app/Importer/ComponentImporter.php +++ b/app/Importer/ComponentImporter.php @@ -28,8 +28,8 @@ class ComponentImporter extends ItemImporter { $component = null; $this->log('Creating Component'); - $component = Component::where('name', $this->item['name']) - ->where('serial', $this->item['serial']) + $component = Component::where('name', trim($this->item['name'])) + ->where('serial', trim($this->item['serial'])) ->first(); if ($component) { diff --git a/app/Importer/ConsumableImporter.php b/app/Importer/ConsumableImporter.php index b0dea1f514..5a65514deb 100644 --- a/app/Importer/ConsumableImporter.php +++ b/app/Importer/ConsumableImporter.php @@ -26,7 +26,7 @@ class ConsumableImporter extends ItemImporter */ public function createConsumableIfNotExists($row) { - $consumable = Consumable::where('name', $this->item['name'])->first(); + $consumable = Consumable::where('name', trim($this->item['name']))->first(); if ($consumable) { if (! $this->updating) { $this->log('A matching Consumable '.$this->item['name'].' already exists. '); @@ -41,9 +41,9 @@ class ConsumableImporter extends ItemImporter } $this->log('No matching consumable, creating one'); $consumable = new Consumable(); - $this->item['model_number'] = $this->findCsvMatch($row, 'model_number'); - $this->item['item_no'] = $this->findCsvMatch($row, 'item_number'); - $this->item['min_amt'] = $this->findCsvMatch($row, "min_amt"); + $this->item['model_number'] = trim($this->findCsvMatch($row, 'model_number')); + $this->item['item_no'] = trim($this->findCsvMatch($row, 'item_number')); + $this->item['min_amt'] = trim($this->findCsvMatch($row, "min_amt")); $consumable->fill($this->sanitizeItemForStoring($consumable)); //FIXME: this disables model validation. Need to find a way to avoid double-logs without breaking everything. $consumable->unsetEventDispatcher(); diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 4e53ef60b7..98590c9ff1 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -372,7 +372,7 @@ class ItemImporter extends Importer if (empty($asset_statuslabel_name)) { return null; } - $status = Statuslabel::where(['name' => $asset_statuslabel_name])->first(); + $status = Statuslabel::where(['name' => trim($asset_statuslabel_name]))->first(); if ($status) { $this->log('A matching Status '.$asset_statuslabel_name.' already exists'); @@ -381,7 +381,7 @@ class ItemImporter extends Importer } $this->log('Creating a new status'); $status = new Statuslabel(); - $status->name = $asset_statuslabel_name; + $status->name = trim($asset_statuslabel_name); $status->deployable = 1; $status->pending = 0; @@ -420,7 +420,7 @@ class ItemImporter extends Importer //Otherwise create a manufacturer. $manufacturer = new Manufacturer(); - $manufacturer->name = $item_manufacturer; + $manufacturer->name = trim($item_manufacturer); $manufacturer->user_id = $this->user_id; if ($manufacturer->save()) { diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.php index 6c43734b9b..393d00367d 100644 --- a/app/Importer/LicenseImporter.php +++ b/app/Importer/LicenseImporter.php @@ -55,19 +55,19 @@ class LicenseImporter extends ItemImporter $this->log('No Matching License, Creating a new one'); $license = new License; } - $asset_tag = $this->item['asset_tag'] = $this->findCsvMatch($row, 'asset_tag'); // used for checkout out to an asset. + $asset_tag = $this->item['asset_tag'] = trim($this->findCsvMatch($row, 'asset_tag')); // used for checkout out to an asset. $this->item["expiration_date"] = null; if ($this->findCsvMatch($row, "expiration_date")!='') { - $this->item["expiration_date"] = date("Y-m-d 00:00:01", strtotime($this->findCsvMatch($row, "expiration_date"))); + $this->item["expiration_date"] = date("Y-m-d 00:00:01", strtotime(trim($this->findCsvMatch($row, "expiration_date")))); } - $this->item['license_email'] = $this->findCsvMatch($row, 'license_email'); - $this->item['license_name'] = $this->findCsvMatch($row, 'license_name'); - $this->item['maintained'] = $this->findCsvMatch($row, 'maintained'); - $this->item['purchase_order'] = $this->findCsvMatch($row, 'purchase_order'); - $this->item['order_number'] = $this->findCsvMatch($row, 'order_number'); - $this->item['reassignable'] = $this->findCsvMatch($row, 'reassignable'); - $this->item['manufacturer'] = $this->createOrFetchManufacturer($this->findCsvMatch($row, 'manufacturer')); + $this->item['license_email'] = trim($this->findCsvMatch($row, 'license_email')); + $this->item['license_name'] = trim($this->findCsvMatch($row, 'license_name')); + $this->item['maintained'] = trim($this->findCsvMatch($row, 'maintained')); + $this->item['purchase_order'] = trim($this->findCsvMatch($row, 'purchase_order')); + $this->item['order_number'] = trim($this->findCsvMatch($row, 'order_number')); + $this->item['reassignable'] = trim($this->findCsvMatch($row, 'reassignable')); + $this->item['manufacturer'] = $this->createOrFetchManufacturer(trim($this->findCsvMatch($row, 'manufacturer'))); if($this->item['reassignable'] == "") { diff --git a/app/Importer/LocationImporter.php b/app/Importer/LocationImporter.php index 25140abe00..47a157aa7f 100644 --- a/app/Importer/LocationImporter.php +++ b/app/Importer/LocationImporter.php @@ -53,21 +53,21 @@ class LocationImporter extends ItemImporter } // Pull the records from the CSV to determine their values - $this->item['name'] = $this->findCsvMatch($row, 'name'); - $this->item['address'] = $this->findCsvMatch($row, 'address'); - $this->item['address2'] = $this->findCsvMatch($row, 'address2'); - $this->item['city'] = $this->findCsvMatch($row, 'city'); - $this->item['state'] = $this->findCsvMatch($row, 'state'); - $this->item['country'] = $this->findCsvMatch($row, 'country'); - $this->item['zip'] = $this->findCsvMatch($row, 'zip'); - $this->item['currency'] = $this->findCsvMatch($row, 'currency'); - $this->item['ldap_ou'] = $this->findCsvMatch($row, 'ldap_ou'); - $this->item['manager'] = $this->findCsvMatch($row, 'manager'); - $this->item['manager_username'] = $this->findCsvMatch($row, 'manager_username'); + $this->item['name'] = trim($this->findCsvMatch($row, 'name')); + $this->item['address'] = trim($this->findCsvMatch($row, 'address')); + $this->item['address2'] = trim($this->findCsvMatch($row, 'address2')); + $this->item['city'] = trim($this->findCsvMatch($row, 'city')); + $this->item['state'] = trim($this->findCsvMatch($row, 'state')); + $this->item['country'] = trim($this->findCsvMatch($row, 'country')); + $this->item['zip'] = trim($this->findCsvMatch($row, 'zip')); + $this->item['currency'] = trim($this->findCsvMatch($row, 'currency')); + $this->item['ldap_ou'] = trim($this->findCsvMatch($row, 'ldap_ou')); + $this->item['manager'] = trim($this->findCsvMatch($row, 'manager')); + $this->item['manager_username'] = trim($this->findCsvMatch($row, 'manager_username')); $this->item['user_id'] = \Auth::user()->id; if ($this->findCsvMatch($row, 'parent_location')) { - $this->item['parent_id'] = $this->createOrFetchLocation($this->findCsvMatch($row, 'parent_location')); + $this->item['parent_id'] = $this->createOrFetchLocation(trim($this->findCsvMatch($row, 'parent_location'))); } if (!empty($this->item['manager'])) { diff --git a/app/Importer/UserImporter.php b/app/Importer/UserImporter.php index e13d4c4cce..7e23708e78 100644 --- a/app/Importer/UserImporter.php +++ b/app/Importer/UserImporter.php @@ -42,32 +42,32 @@ class UserImporter extends ItemImporter public function createUserIfNotExists(array $row) { // Pull the records from the CSV to determine their values - $this->item['id'] = $this->findCsvMatch($row, 'id'); - $this->item['username'] = $this->findCsvMatch($row, 'username'); - $this->item['first_name'] = $this->findCsvMatch($row, 'first_name'); - $this->item['last_name'] = $this->findCsvMatch($row, 'last_name'); - $this->item['email'] = $this->findCsvMatch($row, 'email'); - $this->item['gravatar'] = $this->findCsvMatch($row, 'gravatar'); - $this->item['phone'] = $this->findCsvMatch($row, 'phone_number'); - $this->item['website'] = $this->findCsvMatch($row, 'website'); - $this->item['jobtitle'] = $this->findCsvMatch($row, 'jobtitle'); - $this->item['address'] = $this->findCsvMatch($row, 'address'); - $this->item['city'] = $this->findCsvMatch($row, 'city'); - $this->item['state'] = $this->findCsvMatch($row, 'state'); - $this->item['country'] = $this->findCsvMatch($row, 'country'); - $this->item['start_date'] = $this->findCsvMatch($row, 'start_date'); - $this->item['end_date'] = $this->findCsvMatch($row, 'end_date'); - $this->item['zip'] = $this->findCsvMatch($row, 'zip'); - $this->item['activated'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'activated')) == 1) ? '1' : 0; - $this->item['employee_num'] = $this->findCsvMatch($row, 'employee_num'); - $this->item['department_id'] = $this->createOrFetchDepartment($this->findCsvMatch($row, 'department')); - $this->item['manager_id'] = $this->fetchManager($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')); - $this->item['remote'] =($this->fetchHumanBoolean($this->findCsvMatch($row, 'remote')) ==1 ) ? '1' : 0; - $this->item['vip'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'vip')) ==1 ) ? '1' : 0; - $this->item['autoassign_licenses'] = ($this->fetchHumanBoolean($this->findCsvMatch($row, 'autoassign_licenses')) ==1 ) ? '1' : 0; + $this->item['id'] = trim($this->findCsvMatch($row, 'id')); + $this->item['username'] = trim($this->findCsvMatch($row, 'username')); + $this->item['first_name'] = trim($this->findCsvMatch($row, 'first_name')); + $this->item['last_name'] = trim($this->findCsvMatch($row, 'last_name')); + $this->item['email'] = trim($this->findCsvMatch($row, 'email')); + $this->item['gravatar'] = trim($this->findCsvMatch($row, 'gravatar')); + $this->item['phone'] = trim($this->findCsvMatch($row, 'phone_number')); + $this->item['website'] = trim($this->findCsvMatch($row, 'website')); + $this->item['jobtitle'] = trim($this->findCsvMatch($row, 'jobtitle')); + $this->item['address'] = trim($this->findCsvMatch($row, 'address')); + $this->item['city'] = trim($this->findCsvMatch($row, 'city')); + $this->item['state'] = trim($this->findCsvMatch($row, 'state')); + $this->item['country'] = trim($this->findCsvMatch($row, 'country')); + $this->item['start_date'] = trim($this->findCsvMatch($row, 'start_date')); + $this->item['end_date'] = trim($this->findCsvMatch($row, 'end_date')); + $this->item['zip'] = trim($this->findCsvMatch($row, 'zip')); + $this->item['activated'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'activated'))) == 1) ? '1' : 0; + $this->item['employee_num'] = trim($this->findCsvMatch($row, 'employee_num')); + $this->item['department_id'] = trim($this->createOrFetchDepartment(trim($this->findCsvMatch($row, 'department')))); + $this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name'))); + $this->item['remote'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'remote'))) == 1 ) ? '1' : 0; + $this->item['vip'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'vip'))) ==1 ) ? '1' : 0; + $this->item['autoassign_licenses'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'autoassign_licenses'))) ==1 ) ? '1' : 0; - $user_department = $this->findCsvMatch($row, 'department'); + $user_department = trim($this->findCsvMatch($row, 'department')); if ($this->shouldUpdateField($user_department)) { $this->item['department_id'] = $this->createOrFetchDepartment($user_department); } From 316c90c14404370c4e5b3c1af79eefa5e14b71c9 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 14:17:27 +0000 Subject: [PATCH 2/4] Update app/Importer/ItemImporter.php Co-authored-by: Marcus Moore --- app/Importer/ItemImporter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.php index 98590c9ff1..e1b0f1c289 100644 --- a/app/Importer/ItemImporter.php +++ b/app/Importer/ItemImporter.php @@ -372,7 +372,7 @@ class ItemImporter extends Importer if (empty($asset_statuslabel_name)) { return null; } - $status = Statuslabel::where(['name' => trim($asset_statuslabel_name]))->first(); + $status = Statuslabel::where(['name' => trim($asset_statuslabel_name)])->first(); if ($status) { $this->log('A matching Status '.$asset_statuslabel_name.' already exists'); From 97953ae0827b26a64f7dae9a9b4b423440e60f82 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 30 Oct 2023 12:17:55 -0700 Subject: [PATCH 3/4] add missing translation string --- resources/lang/en/admin/users/message.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lang/en/admin/users/message.php b/resources/lang/en/admin/users/message.php index a3f936dcbb..b7c0a29f14 100644 --- a/resources/lang/en/admin/users/message.php +++ b/resources/lang/en/admin/users/message.php @@ -8,6 +8,7 @@ return array( 'user_exists' => 'User already exists!', 'user_not_found' => 'User does not exist.', 'user_login_required' => 'The login field is required', + 'user_has_no_assets_assigned' => 'No assets currently assigned to user.', 'user_password_required' => 'The password is required.', 'insufficient_permissions' => 'Insufficient Permissions.', 'user_deleted_warning' => 'This user has been deleted. You will have to restore this user to edit them or assign them new assets.', From e554a80589e7af56b7fb0e47cb3c276a3e2619e5 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 30 Oct 2023 20:01:01 +0000 Subject: [PATCH 4/4] Handle redirect from after POST request from backup restore Signed-off-by: snipe --- routes/web.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/routes/web.php b/routes/web.php index 0aacf85135..635cdbcb94 100644 --- a/routes/web.php +++ b/routes/web.php @@ -224,6 +224,11 @@ Route::group(['prefix' => 'admin', 'middleware' => ['auth', 'authorize:superuser [SettingsController::class, 'postUploadBackup'] )->name('settings.backups.upload'); + // Handle redirect from after POST request from backup restore + Route::get('/restore/{filename?}', function () { + return redirect(route('settings.backups.index')); + }); + Route::get('/', [SettingsController::class, 'getBackups'])->name('settings.backups.index'); });