mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-11 13:57:41 -08:00
Merge pull request #15057 from spencerrlongg/bug/sc-23212-2
Fixes Potential Exception
This commit is contained in:
commit
fb10c1439a
|
@ -70,7 +70,7 @@ class CheckoutAcceptance extends Model
|
|||
*/
|
||||
public function isCheckedOutTo(User $user)
|
||||
{
|
||||
return $this->assignedTo->is($user);
|
||||
return $this->assignedTo?->is($user);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue