Have legacy locations updated upon api asset checkin

This commit is contained in:
Marcus Moore 2024-02-22 13:14:30 -08:00
parent 2df026bcb5
commit 714fc63050
No known key found for this signature in database
2 changed files with 29 additions and 1 deletions

View file

@ -886,6 +886,25 @@ class AssetsController extends Controller
$asset->name = $request->input('name');
}
// This is just meant to correct legacy issues where some user data would have 0
// as a location ID, which isn't valid. Later versions of Snipe-IT have stricter validation
// rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
// people (and their data) in the long run
if ($asset->rtd_location_id == '0') {
\Log::debug('Manually override the RTD location IDs');
\Log::debug('Original RTD Location ID: '.$asset->rtd_location_id);
$asset->rtd_location_id = '';
\Log::debug('New RTD Location ID: '.$asset->rtd_location_id);
}
if ($asset->location_id == '0') {
\Log::debug('Manually override the location IDs');
\Log::debug('Original Location ID: '.$asset->location_id);
$asset->location_id = '';
\Log::debug('New Location ID: '.$asset->location_id);
}
$asset->location_id = $asset->rtd_location_id;
if ($request->filled('location_id')) {

View file

@ -116,7 +116,16 @@ class AssetCheckinTest extends TestCase
public function testLegacyLocationValuesSetToZeroAreUpdated()
{
$this->markTestIncomplete('Not currently in controller');
$asset = Asset::factory()->canBeInvalidUponCreation()->assignedToUser()->create([
'rtd_location_id' => 0,
'location_id' => 0,
]);
$this->actingAsForApi(User::factory()->checkinAssets()->create())
->postJson(route('api.asset.checkin', $asset));
$this->assertNull($asset->refresh()->rtd_location_id);
$this->assertEquals($asset->location_id, $asset->rtd_location_id);
}
public function testPendingCheckoutAcceptancesAreClearedUponCheckin()