A free open source IT asset/license management system
Have legacy locations updated upon api asset checkin
Marcus Moore714fc630506a
diff --git a/app/Http/Controllers/Api/AssetsController.php b/app/Http/Controllers/Api/AssetsController.phpindex 2967471501..3d223248ab 100644--- a/app/Http/Controllers/Api/AssetsController.php+++ b/app/Http/Controllers/Api/AssetsController.php@@ -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')) {diff --git a/tests/Feature/Api/Assets/AssetCheckinTest.php b/tests/Feature/Api/Assets/AssetCheckinTest.phpindex b7dda0d4b8..befac2e4ce 100644--- a/tests/Feature/Api/Assets/AssetCheckinTest.php+++ b/tests/Feature/Api/Assets/AssetCheckinTest.php@@ -116,7 +116,16 @@ class AssetCheckinTest extends TestCasepublic 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()