A free open source IT asset/license management system
More improvements (#3116)
Daniel Meltzer3a6bbcc615d4
diff --git a/app/Models/Actionlog.php b/app/Models/Actionlog.phpindex a85f5fcde4..3aa0307eb8 100755--- a/app/Models/Actionlog.php+++ b/app/Models/Actionlog.php@@ -119,7 +119,7 @@ class Actionlog extends SnipeModelpublic function target(){- return $this->morphTo('target');+ return $this->morphTo('target')->withTrashed();}public function childlogs()diff --git a/app/Presenters/ActionlogPresenter.php b/app/Presenters/ActionlogPresenter.phpindex cceb683a42..1d3635c541 100644--- a/app/Presenters/ActionlogPresenter.php+++ b/app/Presenters/ActionlogPresenter.php@@ -19,7 +19,7 @@ class ActionlogPresenter extends Presenter'icon' => '<i class="'.$this->parseItemIcon().'"></i>','created_at' => date("M d, Y g:iA", strtotime($this->created_at)),'action_type' => strtolower(trans('general.'.str_replace(' ', '_', $this->action_type))),- 'admin' => $this->model->user ? $this->model->user->present()->nameUrl() : '',+ 'admin' => $this->admin(),'target' => $this->target(),'item' => $this->item(),'item_type' => $this->itemType(),@@ -30,6 +30,15 @@ class ActionlogPresenter extends Presenterpublic function admin(){+ if ($user = $this->model->user) {+ if(empty($user->deleted_at)) {+ return $user->present()->nameUrl();+ }+ // The user was deleted+ return '<del>'.$user->present()->name()."</del> (deleted)";+ }++ return '';}public function item()@@ -38,32 +47,42 @@ class ActionlogPresenter extends Presenterif($this->action_type=='uploaded') {return (string) link_to_route('show/userfile', $this->model->filename, [$this->model->item->id, $this->model->id]);}- if ($this->model->item) {- return $this->model->item->present()->nameUrl();+ if ($item = $this->model->item) {+ if (empty($item->deleted_at)) {+ return $this->model->item->present()->nameUrl();+ }+ // The item was deleted+ return '<del>'.$item->present()->name().'</del> (deleted)';}return '';}public function target(){+ $target = null;// Target is messy.// On an upload, the target is the item we are uploading to, stored as the "item" in the log.if ($this->action_type=='uploaded') {- return $this->model->item->present()->nameUrl();- }+ $target = $this->model->item;+ } elseif (($this->action_type=='accepted') || ($this->action_type=='declined')) {// If we are logging an accept/reject, the target is not stored directly,// so we access it through who the item is assigned to.// FIXME: On a reject it's not assigned to anyone.- if (($this->action_type=='accepted') || ($this->action_type=='declined')) {- return $this->model->item->assignedTo->nameUrl();+ $target = $this->model->item->assignedTo;} elseif ($this->action_type=='requested') {if ($this->model->user) {- return $this->model->user->present()->nameUrl();+ $target = $this->model->user;}+ } elseif ($this->model->target) {+ // Otherwise, we'll just take the target of the log.+ $target = $this->model->target;}- // Otherwise, we'll just take the target of the log.- if ($this->model->target) {- return $this->model->target->present()->nameUrl();++ if($target) {+ if (empty($target->deleted_at)) {+ return $target->present()->nameUrl();+ }+ return '<del>'.$target->present()->name().'</del>';}return '';}diff --git a/app/Presenters/ConsumablePresenter.php b/app/Presenters/ConsumablePresenter.phpindex 2346d40ace..7c2be419c9 100644--- a/app/Presenters/ConsumablePresenter.php+++ b/app/Presenters/ConsumablePresenter.php@@ -58,9 +58,15 @@ class ConsumablePresenter extends Presenter}/**- * Link to this consumables name+ * Displayable name of consumable* @return string*/++ public function name()+ {+ return $this->model->name;+ }+public function nameUrl(){return (string)link_to_route('consumables.show', $this->name, $this->id);diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.phpindex aa929d56b3..ef5d97f105 100644--- a/database/factories/ModelFactory.php+++ b/database/factories/ModelFactory.php@@ -30,7 +30,6 @@ $factory->defineAs(App\Models\Asset::class, 'asset', function (Faker\Generator $'purchase_cost' => $faker->randomFloat(2),'order_number' => $faker->numberBetween(1000000, 50000000),'supplier_id' => $faker->numberBetween(1, 5),- 'requestable' => $faker->numberBetween(0, 1),'company_id' => Company::inRandomOrder()->first()->id,'requestable' => $faker->boolean()];diff --git a/tests/functional/AssetsCest.php b/tests/functional/AssetsCest.phpindex c1b22ea060..b1a99fd137 100644--- a/tests/functional/AssetsCest.php+++ b/tests/functional/AssetsCest.php@@ -34,12 +34,13 @@ class AssetsCestpublic function passesCreateAndCheckout(FunctionalTester $I){$asset = factory(App\Models\Asset::class,'asset')->make();+ $userId = $I->getUserId();$values = ['company_id' => $asset->company_id,'asset_tag' => $asset->asset_tag,'model_id' => $asset->model_id,'status_id' => $asset->status_id,- 'assigned_user' => $I->getUserId(),+ 'assigned_user' => $userId,'serial' => $asset->serial,'name' => $asset->name,'purchase_date' => '2016-01-01',@@ -57,7 +58,7 @@ class AssetsCest'asset_tag' => $asset->asset_tag,'model_id' => $asset->model_id,'status_id' => $asset->status_id,- 'assigned_to' => $I->getUserId(),+ 'assigned_to' => $userId,'assigned_type' => 'App\\Models\\User','serial' => $asset->serial,'name' => $asset->name,