A free open source IT asset/license management system
Save User ID when checking out a license. Also buff up importing tests to confirm license can be checked out.
Daniel Meltzere4888b23e20e
diff --git a/app/Importer/ItemImporter.php b/app/Importer/ItemImporter.phpindex 0fa94b2f2f..b68d9d5e8c 100644--- a/app/Importer/ItemImporter.php+++ b/app/Importer/ItemImporter.php@@ -85,7 +85,6 @@ class ItemImporter extends Importerif(get_class($this) !== UserImporter::class) {// $this->item["user"] = $this->createOrFetchUser($row);$this->item["checkout_target"] = $this->determineCheckout($row);-}}diff --git a/app/Importer/LicenseImporter.php b/app/Importer/LicenseImporter.phpindex 8009735bb7..f9bc1d825b 100644--- a/app/Importer/LicenseImporter.php+++ b/app/Importer/LicenseImporter.php@@ -4,6 +4,7 @@ namespace App\Importer;use App\Models\Asset;use App\Models\License;+use Illuminate\Support\Facades\Auth;class LicenseImporter extends ItemImporter{@@ -70,14 +71,16 @@ class LicenseImporter extends ItemImporterif ($license->seats > 0) {$checkout_target = $this->item['checkout_target'];$asset = Asset::where('asset_tag', $asset_tag)->first();- $targetLicense = $license->licenseSeats()->first();+ $targetLicense = $license->freeSeat();if ($checkout_target) {$targetLicense->assigned_to = $checkout_target->id;+ $targetLicense->user_id = Auth::id();if ($asset) {$targetLicense->asset_id = $asset->id;}$targetLicense->save();} elseif ($asset) {+ $targetLicense->user_id = Auth::id();$targetLicense->asset_id = $asset->id;$targetLicense->save();}diff --git a/tests/unit/ImporterTest.php b/tests/unit/ImporterTest.phpindex 8fdaaf9256..db2aef4d5c 100644--- a/tests/unit/ImporterTest.php+++ b/tests/unit/ImporterTest.php@@ -541,12 +541,27 @@ EOT;{$this->signIn();$csv = <<<'EOT'-Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes-Helen Anderson,[email protected],cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,[email protected],01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.+Full Name,Email,Username,Item name,serial,manufacturer,purchase date,purchase cost,purchase order,order number,Licensed To Name,Licensed to Email,expiration date,maintained,reassignable,seats,company,supplier,category,notes,asset tag+Helen Anderson,[email protected],cspencer0,Argentum Malachite Athletes Foot Relief,1aa5b0eb-79c5-40b2-8943-5472a6893c3c,"Beer, Leannon and Lubowitz",07/13/2012,$79.66,53008,386436062-5,Cynthia Spencer,[email protected],01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.,test 1EOT;++ // Force create an asset to match the checkout+ $testAsset = $this->createValidAsset(['asset_tag' => 'test 1']);$this->import(new LicenseImporter($csv));// dd($this->tester->grabRecord('licenses'));+ // Did we create a user?+ $this->tester->seeRecord('users', [+ 'first_name' => 'Helen',+ 'last_name' => 'Anderson',+ 'email' => '[email protected]',+ ]);+ // Grab the user record for use in asserting assigned_to+ $createdUser = $this->tester->grabRecord('users', [+ 'first_name' => 'Helen',+ 'last_name' => 'Anderson',+ 'email' => '[email protected]',+ ]);$this->tester->seeRecord('licenses', ['name' => 'Argentum Malachite Athletes Foot Relief','purchase_date' => '2012-07-13 00:00:01',@@ -562,7 +577,6 @@ EOT;'reassignable' => 0,'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',]);-$this->tester->seeRecord('manufacturers', ['name' => 'Beer, Leannon and Lubowitz']);@@ -580,6 +594,11 @@ EOT;]);$this->tester->seeNumRecords(80, 'license_seats');+ $this->tester->seeRecord('license_seats', [+ 'assigned_to' => $createdUser['id'],+ 'license_id' => \App\Models\License::where('serial','1aa5b0eb-79c5-40b2-8943-5472a6893c3c')->first()->id,+ 'asset_id' => $testAsset->id+ ]);}public function testDefaultLicenseUpdate()