Fix for legacy location_id=0 issue that can cause failure to checkout/checkin #8605
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a smallish PR that tries to correct the issue of folks not being able to checkin/checkout because they have
0
as a value for eitherlocation_id
orrtd_location_id
.In previous versions of Snipe-IT, we weren't as strict about validating location selections, so it would allow you to save an asset or a user with an invalid
location_id
. This doesn't exactly fix that, but rather just tries to correct a zero value forlocation_id
, since that would never be valid in our system. It doesn't try to check whether the location is actually valid (as in, there is a record for it in the database that's not been deleted/purged), but it at least tries to correct the 0 issue for legacy systems.It includes a migration to do a one-time sweep of the assets and users tables, and also adds a little bit of logic to override that at the checkout/checkin layer, and pass at least slightly more helpful error messages. (Before you would just get "Asset was not checked in", which doesn't really help anyone figure out what's happening.)
The migration is basically the equivalent of running: