diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 84033c2317..a096f16678 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -92,7 +92,6 @@ class AssetCheckoutController extends Controller $settings = \App\Models\Setting::getSettings(); // We have to check whether $target->company_id is null here since locations don't have a company yet - // @todo: test this if (($settings->full_multiple_companies_support) && ((!is_null($target->company_id)) && (!is_null($asset->company_id)))) { if ($target->company_id != $asset->company_id){ return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company')); diff --git a/tests/Feature/Checkouts/AssetCheckoutTest.php b/tests/Feature/Checkouts/AssetCheckoutTest.php index 6f2460e551..8577f638e5 100644 --- a/tests/Feature/Checkouts/AssetCheckoutTest.php +++ b/tests/Feature/Checkouts/AssetCheckoutTest.php @@ -4,6 +4,7 @@ namespace Tests\Feature\Checkouts; use App\Events\CheckoutableCheckedOut; use App\Models\Asset; +use App\Models\Company; use App\Models\LicenseSeat; use App\Models\Location; use App\Models\Statuslabel; @@ -169,6 +170,28 @@ class AssetCheckoutTest extends TestCase }); } + public function testCannotCheckoutAcrossCompaniesWhenFullCompanySupportEnabled() + { + Event::fake([CheckoutableCheckedOut::class]); + + $this->settings->enableMultipleFullCompanySupport(); + + $assetCompany = Company::factory()->create(); + $userCompany = Company::factory()->create(); + + $user = User::factory()->for($userCompany)->create(); + $asset = Asset::factory()->for($assetCompany)->create(); + + $this->actingAs(User::factory()->superuser()->create()) + ->post(route('hardware.checkout.store', $asset), [ + 'checkout_to_type' => 'user', + 'assigned_user' => $user->id, + ]) + ->assertRedirect(route('hardware.checkout.store', $asset)); + + Event::assertNotDispatched(CheckoutableCheckedOut::class); + } + public function testLicenseSeatsAreAssignedToUserUponCheckout() { $asset = Asset::factory()->create();