diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 8c02baf5db..0852a46240 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -336,7 +336,7 @@ class AssetsController extends Controller $status = Statuslabel::find($asset->status_id); - if($status->archived){ + if ($status && $status->archived) { $asset->assigned_to = null; } @@ -355,14 +355,26 @@ class AssetsController extends Controller } // Update the asset data - $asset_tag = $request->input('asset_tags'); + $serial = $request->input('serials'); + $asset->serial = $request->input('serials'); + + if (is_array($request->input('serials'))) { + $asset->serial = $serial[1]; + } + $asset->name = $request->input('name'); - $asset->serial = $serial[1]; $asset->company_id = Company::getIdForCurrentUser($request->input('company_id')); $asset->model_id = $request->input('model_id'); $asset->order_number = $request->input('order_number'); - $asset->asset_tag = $asset_tag[1]; + + $asset_tags = $request->input('asset_tags'); + $asset->asset_tag = $request->input('asset_tags'); + + if (is_array($request->input('asset_tags'))) { + $asset->asset_tag = $asset_tags[1]; + } + $asset->notes = $request->input('notes'); $asset = $request->handleImages($asset); @@ -374,6 +386,7 @@ class AssetsController extends Controller $model = AssetModel::find($request->get('model_id')); if (($model) && ($model->fieldset)) { foreach ($model->fieldset->fields as $field) { + if ($field->field_encrypted == '1') { if (Gate::allows('admin')) { if (is_array($request->input($field->db_column))) { diff --git a/tests/Feature/Assets/Ui/EditAssetTest.php b/tests/Feature/Assets/Ui/EditAssetTest.php index 9e58be2685..2c19e768b4 100644 --- a/tests/Feature/Assets/Ui/EditAssetTest.php +++ b/tests/Feature/Assets/Ui/EditAssetTest.php @@ -3,17 +3,65 @@ namespace Feature\Assets\Ui; use App\Models\Asset; +use App\Models\AssetModel; +use App\Models\StatusLabel; use App\Models\User; use Tests\TestCase; class EditAssetTest extends TestCase { + + public function testPermissionRequiredToViewLicense() + { + $asset = Asset::factory()->create(); + $this->actingAs(User::factory()->create()) + ->get(route('hardware.edit', $asset)) + ->assertForbidden(); + } + public function testPageCanBeAccessed(): void { $asset = Asset::factory()->create(); $user = User::factory()->editAssets()->create(); $response = $this->actingAs($user)->get(route('hardware.edit', $asset->id)); - $response->assertStatus(200); } + + public function testAssetEditPostIsRedirectedIfRedirectSelectionIsIndex() + { + $asset = Asset::factory()->assignedToUser()->create(); + + $this->actingAs(User::factory()->viewAssets()->editAssets()->create()) + ->from(route('hardware.edit', $asset)) + ->put(route('hardware.update', $asset), + [ + 'redirect_option' => 'index', + 'name' => 'New name', + 'asset_tags' => 'New Asset Tag', + 'status_id' => StatusLabel::factory()->create()->id, + 'model_id' => AssetModel::factory()->create()->id, + ]) + ->assertStatus(302) + ->assertRedirect(route('hardware.index')); + $this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']); + } + public function testAssetEditPostIsRedirectedIfRedirectSelectionIsItem() + { + $asset = Asset::factory()->create(); + + $this->actingAs(User::factory()->viewAssets()->editAssets()->create()) + ->from(route('hardware.edit', $asset)) + ->put(route('hardware.update', $asset), [ + 'redirect_option' => 'item', + 'name' => 'New name', + 'asset_tags' => 'New Asset Tag', + 'status_id' => StatusLabel::factory()->create()->id, + 'model_id' => AssetModel::factory()->create()->id, + ]) + ->assertStatus(302) + ->assertRedirect(route('hardware.show', ['hardware' => $asset->id])); + + $this->assertDatabaseHas('assets', ['asset_tag' => 'New Asset Tag']); + } + } diff --git a/tests/Feature/Checkins/Ui/AssetCheckinTest.php b/tests/Feature/Checkins/Ui/AssetCheckinTest.php index cebd5010f1..f412d4439e 100644 --- a/tests/Feature/Checkins/Ui/AssetCheckinTest.php +++ b/tests/Feature/Checkins/Ui/AssetCheckinTest.php @@ -196,4 +196,31 @@ class AssetCheckinTest extends TestCase ->assertSessionHas('error') ->assertRedirect(route('hardware.show', ['hardware' => $asset->id])); } + + public function testAssetCheckinPagePostIsRedirectedIfRedirectSelectionIsIndex() + { + $asset = Asset::factory()->assignedToUser()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('hardware.index')) + ->post(route('hardware.checkin.store', $asset), [ + 'redirect_option' => 'index', + ]) + ->assertStatus(302) + ->assertRedirect(route('hardware.index')); + } + + public function testAssetCheckinPagePostIsRedirectedIfRedirectSelectionIsItem() + { + $asset = Asset::factory()->assignedToUser()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('hardware.index')) + ->post(route('hardware.checkin.store', $asset), [ + 'redirect_option' => 'item', + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors() + ->assertRedirect(route('hardware.show', ['hardware' => $asset->id])); + } } diff --git a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php index a87b5c1609..1213d65252 100644 --- a/tests/Feature/Checkins/Ui/ComponentCheckinTest.php +++ b/tests/Feature/Checkins/Ui/ComponentCheckinTest.php @@ -17,7 +17,8 @@ class ComponentCheckinTest extends TestCase ->assertForbidden(); } - public function testAssetCheckinPagePostIsRedirectedIfModelIsInvalid() + + public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectionIsIndex() { $component = Component::factory()->checkedOutToAsset()->create(); @@ -31,7 +32,7 @@ class ComponentCheckinTest extends TestCase ->assertRedirect(route('components.index')); } - public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectioonGiven() + public function testComponentCheckinPagePostIsRedirectedIfRedirectSelectionIsItem() { $component = Component::factory()->checkedOutToAsset()->create(); @@ -42,6 +43,7 @@ class ComponentCheckinTest extends TestCase 'checkin_qty' => 1, ]) ->assertStatus(302) + ->assertSessionHasNoErrors() ->assertRedirect(route('components.show', ['component' => $component->id])); } diff --git a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php index e0af379db0..c06c780768 100644 --- a/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php +++ b/tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php @@ -140,4 +140,51 @@ class AccessoryCheckoutTest extends TestCase 'Log entry either does not exist or there are more than expected' ); } + + public function testAccessoryCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex() + { + $accessory = Accessory::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('accessories.index')) + ->post(route('accessories.checkout.store', $accessory), [ + 'assigned_to' => User::factory()->create()->id, + 'redirect_option' => 'index', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertRedirect(route('accessories.index')); + } + + public function testAccessoryCheckoutPagePostIsRedirectedIfRedirectSelectionIsItem() + { + $accessory = Accessory::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('accessories.index')) + ->post(route('accessories.checkout.store' , $accessory), [ + 'assigned_to' => User::factory()->create()->id, + 'redirect_option' => 'item', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertSessionHasNoErrors() + ->assertRedirect(route('accessories.show', ['accessory' => $accessory->id])); + } + + public function testAccessoryCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget() + { + $user = User::factory()->create(); + $accessory = Accessory::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('accessories.index')) + ->post(route('accessories.checkout.store' , $accessory), [ + 'assigned_to' => $user->id, + 'redirect_option' => 'target', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertRedirect(route('users.show', ['user' => $user])); + } } diff --git a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php index b595640493..90132fcedf 100644 --- a/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php +++ b/tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php @@ -3,6 +3,8 @@ namespace Tests\Feature\Checkouts\Ui; use App\Models\Actionlog; +use App\Models\Asset; +use App\Models\Component; use App\Models\Consumable; use App\Models\User; use App\Notifications\CheckoutConsumableNotification; @@ -90,4 +92,51 @@ class ConsumableCheckoutTest extends TestCase 'Log entry either does not exist or there are more than expected' ); } + + public function testConsumableCheckoutPagePostIsRedirectedIfRedirectSelectionIsIndex() + { + $consumable = Consumable::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('consumables.index')) + ->post(route('consumables.checkout.store', $consumable), [ + 'assigned_to' => User::factory()->create()->id, + 'redirect_option' => 'index', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertRedirect(route('consumables.index')); + } + + public function testConsumableCheckoutPagePostIsRedirectedIfRedirectSelectionIsItem() + { + $consumable = Consumable::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('consumables.index')) + ->post(route('consumables.checkout.store' , $consumable), [ + 'assigned_to' => User::factory()->create()->id, + 'redirect_option' => 'item', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertRedirect(route('consumables.show', ['consumable' => $consumable->id])); + } + + public function testConsumableCheckoutPagePostIsRedirectedIfRedirectSelectionIsTarget() + { + $user = User::factory()->create(); + $consumable = Consumable::factory()->create(); + + $this->actingAs(User::factory()->admin()->create()) + ->from(route('components.index')) + ->post(route('consumables.checkout.store' , $consumable), [ + 'assigned_to' => $user->id, + 'redirect_option' => 'target', + 'assigned_qty' => 1, + ]) + ->assertStatus(302) + ->assertRedirect(route('users.show', ['user' => $user])); + } + }