Merge pull request #16527 from Godmartinz/license_seat_notes_fix

add notes as fillable to license seat model
This commit is contained in:
snipe 2025-04-08 06:49:26 +01:00 committed by GitHub
commit fe65ffc384
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 89 additions and 2 deletions

View file

@ -136,13 +136,13 @@ class LicenseSeatsController extends Controller
if ($licenseSeat->save()) {
if ($is_checkin) {
$licenseSeat->logCheckin($target, $request->input('note'));
$licenseSeat->logCheckin($target, $request->input('notes'));
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
}
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
$licenseSeat->logCheckout($request->input('note'), $target);
$licenseSeat->logCheckout($request->input('notes'), $target);
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
}

View file

@ -30,6 +30,7 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild
protected $fillable = [
'assigned_to',
'asset_id',
'notes',
];
use Acceptable;

View file

@ -0,0 +1,45 @@
<?php
namespace Tests\Feature\Checkins\Api;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
use Tests\TestCase;
class LicenseCheckInTest extends TestCase {
public function testLicenseCheckin()
{
$authUser = User::factory()->superuser()->create();
$this->actingAsForApi($authUser);
$license = License::factory()->create();
$oldUser = User::factory()->create();
$licenseSeat = LicenseSeat::factory()->for($license)->create([
'assigned_to' => $oldUser->id,
'notes' => 'Previously checked out',
]);
$payload = [
'assigned_to' => null,
'asset_id' => null,
'notes' => 'Checking in the seat',
];
$response = $this->patchJson(
route('api.licenses.seats.update', [$license->id, $licenseSeat->id]),
$payload);
$response->assertStatus(200)
->assertJsonFragment([
'status' => 'success',
]);
$licenseSeat->refresh();
$this->assertNull($licenseSeat->assigned_to);
$this->assertNull($licenseSeat->asset_id);
$this->assertEquals('Checking in the seat', $licenseSeat->notes);
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Tests\Feature\Checkouts\Api;
use App\Models\License;
use App\Models\LicenseSeat;
use App\Models\User;
use Tests\TestCase;
class LicenseCheckOutTest extends TestCase {
public function testLicenseCheckout()
{
$authUser = User::factory()->superuser()->create();
$this->actingAsForApi($authUser);
$license = License::factory()->create();
$licenseSeat = LicenseSeat::factory()->for($license)->create([
'assigned_to' => null,
]);
$targetUser = User::factory()->create();
$payload = [
'assigned_to' => $targetUser->id,
'notes' => 'Checking out the seat to a user',
];
$response = $this->patchJson(
route('api.licenses.seats.update', [$license->id, $licenseSeat->id]),
$payload);
$response->assertStatus(200)
->assertJsonFragment([
'status' => 'success',
]);
$licenseSeat->refresh();
$this->assertEquals($targetUser->id, $licenseSeat->assigned_to);
$this->assertEquals('Checking out the seat to a user', $licenseSeat->notes);
}
}