mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-21 03:15:45 -08:00
Have legacy locations updated upon api asset checkin
This commit is contained in:
parent
2df026bcb5
commit
714fc63050
|
@ -886,6 +886,25 @@ class AssetsController extends Controller
|
||||||
$asset->name = $request->input('name');
|
$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;
|
$asset->location_id = $asset->rtd_location_id;
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
|
|
|
@ -116,7 +116,16 @@ class AssetCheckinTest extends TestCase
|
||||||
|
|
||||||
public function testLegacyLocationValuesSetToZeroAreUpdated()
|
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()
|
public function testPendingCheckoutAcceptancesAreClearedUponCheckin()
|
||||||
|
|
Loading…
Reference in a new issue