A free open source IT asset/license management system
Fix asset create (#3929)
Daniel Meltzerae0573b3dafc
diff --git a/app/Models/SnipeModel.php b/app/Models/SnipeModel.phpindex 8e2509ed06..43cf0cfc92 100644--- a/app/Models/SnipeModel.php+++ b/app/Models/SnipeModel.php@@ -82,8 +82,4 @@ class SnipeModel extends Model{return $this->name;}-- public function name() {- return $this->name;- }}diff --git a/app/Presenters/Presenter.php b/app/Presenters/Presenter.phpindex 821553e022..c47c2547d9 100644--- a/app/Presenters/Presenter.php+++ b/app/Presenters/Presenter.php@@ -65,6 +65,11 @@ abstract class Presenterreturn '';}+ public function name()+ {+ return $this->model->name;+ }+public function __get($property){if (method_exists($this, $property)) {diff --git a/resources/views/categories/view.blade.php b/resources/views/categories/view.blade.phpindex 0e2dbdb5df..9763b0ab8e 100644--- a/resources/views/categories/view.blade.php+++ b/resources/views/categories/view.blade.php@@ -32,7 +32,7 @@name="category_assets"class="snipe-table"id="table"- data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }}+ data-url="{{ route('api.'.$category_type_route.'.index',['category_id'=> $category->id]) }}"data-cookie="true"data-click-to-select="true"data-cookie-id-table="category{{ $category_type_route }}Table">diff --git a/resources/views/locations/view.blade.php b/resources/views/locations/view.blade.phpindex ce8c4ac96e..4628a58ca4 100644--- a/resources/views/locations/view.blade.php+++ b/resources/views/locations/view.blade.php@@ -21,6 +21,11 @@<div class="row"><div class="col-md-12"><div class="box box-default">+ <div class="box-header with-border">+ <div class="box-heading">+ <h3 class="box-title">{{ trans('general.users') }}</h3>+ </div>+ </div><div class="box-body"><div class="row"><div class="col-md-12">@@ -50,6 +55,11 @@<div class="row"><div class="col-md-12"><div class="box box-default">+ <div class="box-header with-border">+ <div class="box-heading">+ <h3 class="box-title">{{ trans('general.assets') }}</h3>+ </div>+ </div><div class="box-body"><div class="row"><div class="col-md-12">diff --git a/tests/unit/ImporterTest.php b/tests/unit/ImporterTest.phpindex ef5e65f233..a90963211d 100644--- a/tests/unit/ImporterTest.php+++ b/tests/unit/ImporterTest.php@@ -18,181 +18,181 @@ class ImporterTest extends BaseTest*/protected $tester;-// public function testDefaultImportAsset()-// {-// $csv = <<<'EOT'-// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier-// Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan-// EOT;-// $this->import(new AssetImporter($csv));-// // Did we create a user?--// $this->tester->seeRecord('users', [-// 'first_name' => 'Bonnie',-// 'last_name' => 'Nelson',-// 'email' => '[email protected]',-// ]);-// $this->tester->seeRecord('categories', [-// 'name' => 'quam'-// ]);--// $this->tester->seeRecord('models', [-// 'name' => 'massa id',-// 'model_number' => 6377018600094472-// ]);--// $this->tester->seeRecord('manufacturers', [-// 'name' => 'Linkbridge'-// ]);--// $this->tester->seeRecord('locations', [-// 'name' => 'Daping'-// ]);--// $this->tester->seeRecord('companies', [-// 'name' => 'Alpha'-// ]);--// $this->tester->seeRecord('status_labels', [-// 'name' => 'Undeployable'-// ]);--// $this->tester->seeRecord('suppliers', [-// 'name' => 'Blogspan'-// ]);-// $this->tester->seeRecord('assets', [-// 'name' => 'eget nunc donec quis',-// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',-// 'asset_tag' => '970882174-8',-// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",-// 'purchase_date' => '2016-04-05 00:00:01',-// 'purchase_cost' => 133289.59,-// 'warranty_months' => 14-// ]);-// }--// public function testUpdateAsset()-// {-// $csv = <<<'EOT'-// Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier-// Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan-// EOT;-// $this->import(new AssetImporter($csv));-// $updatedCSV = <<<'EOT'-// item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier-// A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative-// EOT;-// $importer = new AssetImporter($updatedCSV);-// $importer->setUserId(1)-// ->setUpdating(true)-// ->setUsernameFormat('firstname.lastname')-// ->import();--// $this->tester->seeRecord('categories', [-// 'name' => 'some other category'-// ]);--// $this->tester->seeRecord('models', [-// 'name' => 'Another Model',-// 'model_number' => 356-// ]);--// $this->tester->seeRecord('manufacturers', [-// 'name' => 'Linkbridge 32'-// ]);--// $this->tester->seeRecord('locations', [-// 'name' => 'New Location'-// ]);--// $this->tester->seeRecord('companies', [-// 'name' => 'Another Company'-// ]);--// $this->tester->seeRecord('status_labels', [-// 'name' => 'Ready To Go'-// ]);--// $this->tester->seeRecord('suppliers', [-// 'name' => 'Not Creative'-// ]);--// $this->tester->seeRecord('assets', [-// 'name' => 'A new name',-// 'serial' => '67433477',-// 'asset_tag' => '970882174-8',-// 'notes' => "I have no notes",-// 'purchase_date' => '2018-04-05 00:00:01',-// 'purchase_cost' => 25.59,-// 'warranty_months' => 18-// ]);-// }--// public function testCustomMappingImport()-// {-// $csv = <<<'EOT'-// Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier-// Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan-// EOT;--// $customFieldMap = [-// 'asset_tag' => 'Asset',-// 'category' => 'Cat',-// 'company' => 'comp',-// 'item_name' => 'object name',-// 'expiration_date' => 'expiration date',-// 'location' => 'loc',-// 'notes' => 'Some Notes',-// 'asset_model' => "model name",-// ];--// $this->import(new AssetImporter($csv), $customFieldMap);-// // Did we create a user?--// $this->tester->seeRecord('users', [-// 'first_name' => 'Bonnie',-// 'last_name' => 'Nelson',-// 'email' => '[email protected]',-// ]);--// $this->tester->seeRecord('categories', [-// 'name' => 'quam'-// ]);--// $this->tester->seeRecord('models', [-// 'name' => 'massa id',-// 'model_number' => 6377018600094472-// ]);--// $this->tester->seeRecord('manufacturers', [-// 'name' => 'Linkbridge'-// ]);--// $this->tester->seeRecord('locations', [-// 'name' => 'Daping'-// ]);--// $this->tester->seeRecord('companies', [-// 'name' => 'Alpha'-// ]);--// $this->tester->seeRecord('status_labels', [-// 'name' => 'Undeployable'-// ]);--// $this->tester->seeRecord('suppliers', [-// 'name' => 'Blogspan'-// ]);-// $this->tester->seeRecord('assets', [-// 'name' => 'eget nunc donec quis',-// 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',-// 'asset_tag' => '970882174-8',-// 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",-// 'purchase_date' => '2016-04-05 00:00:01',-// 'purchase_cost' => 133289.59,-// 'warranty_months' => 14-// ]);-// }+ public function testDefaultImportAsset()+ {+ $csv = <<<'EOT'+Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier+Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan+EOT;+ $this->import(new AssetImporter($csv));+ // Did we create a user?++ $this->tester->seeRecord('users', [+ 'first_name' => 'Bonnie',+ 'last_name' => 'Nelson',+ 'email' => '[email protected]',+ ]);+ $this->tester->seeRecord('categories', [+ 'name' => 'quam'+ ]);++ $this->tester->seeRecord('models', [+ 'name' => 'massa id',+ 'model_number' => 6377018600094472+ ]);++ $this->tester->seeRecord('manufacturers', [+ 'name' => 'Linkbridge'+ ]);++ $this->tester->seeRecord('locations', [+ 'name' => 'Daping'+ ]);++ $this->tester->seeRecord('companies', [+ 'name' => 'Alpha'+ ]);++ $this->tester->seeRecord('status_labels', [+ 'name' => 'Undeployable'+ ]);++ $this->tester->seeRecord('suppliers', [+ 'name' => 'Blogspan'+ ]);+ $this->tester->seeRecord('assets', [+ 'name' => 'eget nunc donec quis',+ 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',+ 'asset_tag' => '970882174-8',+ 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",+ 'purchase_date' => '2016-04-05 00:00:01',+ 'purchase_cost' => 133289.59,+ 'warranty_months' => 14+ ]);+ }++ public function testUpdateAsset()+ {+ $csv = <<<'EOT'+Name,Email,Username,item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier+Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan+EOT;+ $this->import(new AssetImporter($csv));+ $updatedCSV = <<<'EOT'+item Name,Category,Model name,Manufacturer,Model Number,Serial number,Asset Tag,Location,Notes,Purchase Date,Purchase Cost,Company,Status,Warranty,Supplier+A new name,some other category,Another Model,Linkbridge 32,356,67433477,970882174-8,New Location,I have no notes,2018-04-05,25.59,Another Company,Ready To Go,18,Not Creative+EOT;+ $importer = new AssetImporter($updatedCSV);+ $importer->setUserId(1)+ ->setUpdating(true)+ ->setUsernameFormat('firstname.lastname')+ ->import();++ $this->tester->seeRecord('categories', [+ 'name' => 'some other category'+ ]);++ $this->tester->seeRecord('models', [+ 'name' => 'Another Model',+ 'model_number' => 356+ ]);++ $this->tester->seeRecord('manufacturers', [+ 'name' => 'Linkbridge 32'+ ]);++ $this->tester->seeRecord('locations', [+ 'name' => 'New Location'+ ]);++ $this->tester->seeRecord('companies', [+ 'name' => 'Another Company'+ ]);++ $this->tester->seeRecord('status_labels', [+ 'name' => 'Ready To Go'+ ]);++ $this->tester->seeRecord('suppliers', [+ 'name' => 'Not Creative'+ ]);++ $this->tester->seeRecord('assets', [+ 'name' => 'A new name',+ 'serial' => '67433477',+ 'asset_tag' => '970882174-8',+ 'notes' => "I have no notes",+ 'purchase_date' => '2018-04-05 00:00:01',+ 'purchase_cost' => 25.59,+ 'warranty_months' => 18+ ]);+ }++ public function testCustomMappingImport()+ {+ $csv = <<<'EOT'+Name,Email,Username,object name,Cat,Model name,Manufacturer,Model Number,Serial number,Asset,Loc,Some Notes,Purchase Date,Purchase Cost,comp,Status,Warranty,Supplier+Bonnie Nelson,[email protected],bnelson0,eget nunc donec quis,quam,massa id,Linkbridge,6377018600094472,27aa8378-b0f4-4289-84a4-405da95c6147,970882174-8,Daping,"Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",2016-04-05,133289.59,Alpha,Undeployable,14,Blogspan+EOT;++ $customFieldMap = [+ 'asset_tag' => 'Asset',+ 'category' => 'Cat',+ 'company' => 'comp',+ 'item_name' => 'object name',+ 'expiration_date' => 'expiration date',+ 'location' => 'loc',+ 'notes' => 'Some Notes',+ 'asset_model' => "model name",+ ];++ $this->import(new AssetImporter($csv), $customFieldMap);+ // Did we create a user?++ $this->tester->seeRecord('users', [+ 'first_name' => 'Bonnie',+ 'last_name' => 'Nelson',+ 'email' => '[email protected]',+ ]);++ $this->tester->seeRecord('categories', [+ 'name' => 'quam'+ ]);++ $this->tester->seeRecord('models', [+ 'name' => 'massa id',+ 'model_number' => 6377018600094472+ ]);++ $this->tester->seeRecord('manufacturers', [+ 'name' => 'Linkbridge'+ ]);++ $this->tester->seeRecord('locations', [+ 'name' => 'Daping'+ ]);++ $this->tester->seeRecord('companies', [+ 'name' => 'Alpha'+ ]);++ $this->tester->seeRecord('status_labels', [+ 'name' => 'Undeployable'+ ]);++ $this->tester->seeRecord('suppliers', [+ 'name' => 'Blogspan'+ ]);+ $this->tester->seeRecord('assets', [+ 'name' => 'eget nunc donec quis',+ 'serial' => '27aa8378-b0f4-4289-84a4-405da95c6147',+ 'asset_tag' => '970882174-8',+ 'notes' => "Curabitur in libero ut massa volutpat convallis. Morbi odio odio, elementum eu, interdum eu, tincidunt in, leo. Maecenas pulvinar lobortis est.",+ 'purchase_date' => '2016-04-05 00:00:01',+ 'purchase_cost' => 133289.59,+ 'warranty_months' => 14+ ]);+ }public function testDefaultAccessoryImport(){@@ -546,8 +546,6 @@ EOT;if ($mappings) {$importer->setFieldMappings($mappings);}- dd($this);-$importer->setUserId(1)->setUpdating(false)->setUsernameFormat('firstname.lastname')