Repository navigation
fix(accounts): create managed users in the sandbox database for test keys - #378
Merged
Merged
Conversation
…keys Users and companies are pinned to the live connection while company_users follows a test key onto the sandbox connection, so POST /v1/drivers and /v1/contacts failed on company_users_user_uuid_foreign and left an orphan live user. Copy the account (and its company) into the sandbox before adding the membership, and delete a newly created account if adding the membership fails. Fixes #359
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #359
With a
flb_test_key,POST /v1/driversandPOST /v1/contactsfailed with1452 ... company_users_user_uuid_foreign.core-api pins
Userto the livemysqlconnection, whileCompanyUserfollows the request ontosandbox.ProfileAccountManager::createManagedAccount()therefore saved the user in the live database, then inserted the membership intofleetbase_sandbox.company_users, whose foreign key couldn't find that user. Each attempt also left an orphan user in liveusers. A later retry could succeed after the hourlysandbox:sync, which made the failure look intermittent.Changes
ProfileAccountManager::copyAccountToSandbox(). On sandbox requests only, it upserts the user row, and the company row it belongs to, from the live connection intosandboxbefore the membership is written. This mirrors core-api'sApiCredentialController::upsertModelToSandbox()and is idempotent. It's called fromattachToCompany()and from the contact account path inContact.createManagedAccount()force-deletes the new user, and removes its sandbox copy, if attaching it to the company fails, then rethrows. No more orphan users.is_sandboxisn't set.This is done in fleetops only, so it doesn't wait on a core-api release. The two copy helpers could later move into core-api and be shared with
ApiCredentialController.Tests
server/tests/Unit/Support/ProfileAccountManagerTest.phpcovers the sandbox copy, live-mode no-op, idempotency and cleanup on a failed attach.DriverControllerCreateRecordTest.phpis updated for the new path.Both pass under
pest-runner.