mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Save User ID when checking out a license. Also buff up importing tests to confirm license can be checked out.
This commit is contained in:
parent
274f82893f
commit
e4888b23e2
|
@ -85,7 +85,6 @@ class ItemImporter extends Importer
|
||||||
if(get_class($this) !== UserImporter::class) {
|
if(get_class($this) !== UserImporter::class) {
|
||||||
// $this->item["user"] = $this->createOrFetchUser($row);
|
// $this->item["user"] = $this->createOrFetchUser($row);
|
||||||
$this->item["checkout_target"] = $this->determineCheckout($row);
|
$this->item["checkout_target"] = $this->determineCheckout($row);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Importer;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class LicenseImporter extends ItemImporter
|
class LicenseImporter extends ItemImporter
|
||||||
{
|
{
|
||||||
|
@ -70,14 +71,16 @@ class LicenseImporter extends ItemImporter
|
||||||
if ($license->seats > 0) {
|
if ($license->seats > 0) {
|
||||||
$checkout_target = $this->item['checkout_target'];
|
$checkout_target = $this->item['checkout_target'];
|
||||||
$asset = Asset::where('asset_tag', $asset_tag)->first();
|
$asset = Asset::where('asset_tag', $asset_tag)->first();
|
||||||
$targetLicense = $license->licenseSeats()->first();
|
$targetLicense = $license->freeSeat();
|
||||||
if ($checkout_target) {
|
if ($checkout_target) {
|
||||||
$targetLicense->assigned_to = $checkout_target->id;
|
$targetLicense->assigned_to = $checkout_target->id;
|
||||||
|
$targetLicense->user_id = Auth::id();
|
||||||
if ($asset) {
|
if ($asset) {
|
||||||
$targetLicense->asset_id = $asset->id;
|
$targetLicense->asset_id = $asset->id;
|
||||||
}
|
}
|
||||||
$targetLicense->save();
|
$targetLicense->save();
|
||||||
} elseif ($asset) {
|
} elseif ($asset) {
|
||||||
|
$targetLicense->user_id = Auth::id();
|
||||||
$targetLicense->asset_id = $asset->id;
|
$targetLicense->asset_id = $asset->id;
|
||||||
$targetLicense->save();
|
$targetLicense->save();
|
||||||
}
|
}
|
||||||
|
|
|
@ -541,12 +541,27 @@ EOT;
|
||||||
{
|
{
|
||||||
$this->signIn();
|
$this->signIn();
|
||||||
$csv = <<<'EOT'
|
$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
|
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,cspencer0@privacy.gov.au,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,cspencer0@gov.uk,01/27/2016,false,no,80,"Haag, Schmidt and Farrell","Hegmann, Mohr and Cremin",Graphics Software,Sed ante. Vivamus tortor. Duis mattis egestas metus.
|
Helen Anderson,cspencer0@privacy.gov.au,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,cspencer0@gov.uk,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 1
|
||||||
EOT;
|
EOT;
|
||||||
|
|
||||||
|
// Force create an asset to match the checkout
|
||||||
|
$testAsset = $this->createValidAsset(['asset_tag' => 'test 1']);
|
||||||
$this->import(new LicenseImporter($csv));
|
$this->import(new LicenseImporter($csv));
|
||||||
// dd($this->tester->grabRecord('licenses'));
|
// dd($this->tester->grabRecord('licenses'));
|
||||||
|
|
||||||
|
// Did we create a user?
|
||||||
|
$this->tester->seeRecord('users', [
|
||||||
|
'first_name' => 'Helen',
|
||||||
|
'last_name' => 'Anderson',
|
||||||
|
'email' => 'cspencer0@privacy.gov.au',
|
||||||
|
]);
|
||||||
|
// Grab the user record for use in asserting assigned_to
|
||||||
|
$createdUser = $this->tester->grabRecord('users', [
|
||||||
|
'first_name' => 'Helen',
|
||||||
|
'last_name' => 'Anderson',
|
||||||
|
'email' => 'cspencer0@privacy.gov.au',
|
||||||
|
]);
|
||||||
$this->tester->seeRecord('licenses', [
|
$this->tester->seeRecord('licenses', [
|
||||||
'name' => 'Argentum Malachite Athletes Foot Relief',
|
'name' => 'Argentum Malachite Athletes Foot Relief',
|
||||||
'purchase_date' => '2012-07-13 00:00:01',
|
'purchase_date' => '2012-07-13 00:00:01',
|
||||||
|
@ -562,7 +577,6 @@ EOT;
|
||||||
'reassignable' => 0,
|
'reassignable' => 0,
|
||||||
'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',
|
'serial' => '1aa5b0eb-79c5-40b2-8943-5472a6893c3c',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->tester->seeRecord('manufacturers', [
|
$this->tester->seeRecord('manufacturers', [
|
||||||
'name' => 'Beer, Leannon and Lubowitz'
|
'name' => 'Beer, Leannon and Lubowitz'
|
||||||
]);
|
]);
|
||||||
|
@ -580,6 +594,11 @@ EOT;
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->tester->seeNumRecords(80, 'license_seats');
|
$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()
|
public function testDefaultLicenseUpdate()
|
||||||
|
|
Loading…
Reference in a new issue