diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php index 9c501aaf63..b1c6c79141 100644 --- a/app/Models/CheckoutAcceptance.php +++ b/app/Models/CheckoutAcceptance.php @@ -70,7 +70,7 @@ class CheckoutAcceptance extends Model */ public function isCheckedOutTo(User $user) { - return $this->assignedTo->is($user); + return $this->assignedTo?->is($user); } /** diff --git a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php index 83ec916cb4..2390b16808 100644 --- a/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php +++ b/tests/Feature/CheckoutAcceptances/Ui/AccessoryAcceptanceTest.php @@ -3,7 +3,9 @@ namespace Tests\Feature\CheckoutAcceptances\Ui; use App\Models\Accessory; +use App\Models\Asset; use App\Models\CheckoutAcceptance; +use App\Models\User; use App\Notifications\AcceptanceAssetAcceptedNotification; use App\Notifications\AcceptanceAssetDeclinedNotification; use Notification; @@ -76,4 +78,22 @@ class AccessoryAcceptanceTest extends TestCase } ); } + + public function testUserIsNotAbleToAcceptAnAssetAssignedToADifferentUser() + { + Notification::fake(); + + $otherUser = User::factory()->create(); + + $acceptance = CheckoutAcceptance::factory() + ->pending() + ->for(Asset::factory()->laptopMbp(), 'checkoutable') + ->create(); + + $this->actingAs($otherUser) + ->post(route('account.store-acceptance', $acceptance), ['asset_acceptance' => 'accepted']) + ->assertSessionHas(['error' => trans('admin/users/message.error.incorrect_user_accepted')]); + + $this->assertNull($acceptance->fresh()->accepted_at); + } }