More improvements (#3116)

* Restore display of deleted items in the logs

* Fix functional tests.
This commit is contained in:
Daniel Meltzer 2016-12-30 14:44:47 -05:00 committed by snipe
parent 8a782bf34a
commit 3a6bbcc615
5 changed files with 41 additions and 16 deletions

View file

@ -119,7 +119,7 @@ class Actionlog extends SnipeModel
public function target() public function target()
{ {
return $this->morphTo('target'); return $this->morphTo('target')->withTrashed();
} }
public function childlogs() public function childlogs()

View file

@ -19,7 +19,7 @@ class ActionlogPresenter extends Presenter
'icon' => '<i class="'.$this->parseItemIcon().'"></i>', 'icon' => '<i class="'.$this->parseItemIcon().'"></i>',
'created_at' => date("M d, Y g:iA", strtotime($this->created_at)), 'created_at' => date("M d, Y g:iA", strtotime($this->created_at)),
'action_type' => strtolower(trans('general.'.str_replace(' ', '_', $this->action_type))), '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(), 'target' => $this->target(),
'item' => $this->item(), 'item' => $this->item(),
'item_type' => $this->itemType(), 'item_type' => $this->itemType(),
@ -30,6 +30,15 @@ class ActionlogPresenter extends Presenter
public function admin() public 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() public function item()
@ -38,32 +47,42 @@ class ActionlogPresenter extends Presenter
if($this->action_type=='uploaded') { if($this->action_type=='uploaded') {
return (string) link_to_route('show/userfile', $this->model->filename, [$this->model->item->id, $this->model->id]); return (string) link_to_route('show/userfile', $this->model->filename, [$this->model->item->id, $this->model->id]);
} }
if ($this->model->item) { if ($item = $this->model->item) {
if (empty($item->deleted_at)) {
return $this->model->item->present()->nameUrl(); return $this->model->item->present()->nameUrl();
} }
// The item was deleted
return '<del>'.$item->present()->name().'</del> (deleted)';
}
return ''; return '';
} }
public function target() public function target()
{ {
$target = null;
// Target is messy. // Target is messy.
// On an upload, the target is the item we are uploading to, stored as the "item" in the log. // On an upload, the target is the item we are uploading to, stored as the "item" in the log.
if ($this->action_type=='uploaded') { 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, // If we are logging an accept/reject, the target is not stored directly,
// so we access it through who the item is assigned to. // so we access it through who the item is assigned to.
// FIXME: On a reject it's not assigned to anyone. // FIXME: On a reject it's not assigned to anyone.
if (($this->action_type=='accepted') || ($this->action_type=='declined')) { $target = $this->model->item->assignedTo;
return $this->model->item->assignedTo->nameUrl();
} elseif ($this->action_type=='requested') { } elseif ($this->action_type=='requested') {
if ($this->model->user) { 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. // Otherwise, we'll just take the target of the log.
if ($this->model->target) { $target = $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 ''; return '';
} }

View file

@ -58,9 +58,15 @@ class ConsumablePresenter extends Presenter
} }
/** /**
* Link to this consumables name * Displayable name of consumable
* @return string * @return string
*/ */
public function name()
{
return $this->model->name;
}
public function nameUrl() public function nameUrl()
{ {
return (string)link_to_route('consumables.show', $this->name, $this->id); return (string)link_to_route('consumables.show', $this->name, $this->id);

View file

@ -30,7 +30,6 @@ $factory->defineAs(App\Models\Asset::class, 'asset', function (Faker\Generator $
'purchase_cost' => $faker->randomFloat(2), 'purchase_cost' => $faker->randomFloat(2),
'order_number' => $faker->numberBetween(1000000, 50000000), 'order_number' => $faker->numberBetween(1000000, 50000000),
'supplier_id' => $faker->numberBetween(1, 5), 'supplier_id' => $faker->numberBetween(1, 5),
'requestable' => $faker->numberBetween(0, 1),
'company_id' => Company::inRandomOrder()->first()->id, 'company_id' => Company::inRandomOrder()->first()->id,
'requestable' => $faker->boolean() 'requestable' => $faker->boolean()
]; ];

View file

@ -34,12 +34,13 @@ class AssetsCest
public function passesCreateAndCheckout(FunctionalTester $I) public function passesCreateAndCheckout(FunctionalTester $I)
{ {
$asset = factory(App\Models\Asset::class,'asset')->make(); $asset = factory(App\Models\Asset::class,'asset')->make();
$userId = $I->getUserId();
$values = [ $values = [
'company_id' => $asset->company_id, 'company_id' => $asset->company_id,
'asset_tag' => $asset->asset_tag, 'asset_tag' => $asset->asset_tag,
'model_id' => $asset->model_id, 'model_id' => $asset->model_id,
'status_id' => $asset->status_id, 'status_id' => $asset->status_id,
'assigned_user' => $I->getUserId(), 'assigned_user' => $userId,
'serial' => $asset->serial, 'serial' => $asset->serial,
'name' => $asset->name, 'name' => $asset->name,
'purchase_date' => '2016-01-01', 'purchase_date' => '2016-01-01',
@ -57,7 +58,7 @@ class AssetsCest
'asset_tag' => $asset->asset_tag, 'asset_tag' => $asset->asset_tag,
'model_id' => $asset->model_id, 'model_id' => $asset->model_id,
'status_id' => $asset->status_id, 'status_id' => $asset->status_id,
'assigned_to' => $I->getUserId(), 'assigned_to' => $userId,
'assigned_type' => 'App\\Models\\User', 'assigned_type' => 'App\\Models\\User',
'serial' => $asset->serial, 'serial' => $asset->serial,
'name' => $asset->name, 'name' => $asset->name,