cht-core icon indicating copy to clipboard operation
cht-core copied to clipboard

Add client-side transition for offline user replace

Open jkuester opened this issue 3 years ago • 2 comments

Description

Overview of logic flow:

  • CLIENT (in webapp)
    • replace_user form submitted
    • Triggers client-side user-replace.transition to set replaced properties on user's current contact
      • replaced.by = _id of new contact
      • replaced.status = "PENDING"
    • Any additional reports submitted after the user is replaced (but before the client syncs) will be automatically re-parented by the client-side transition
    • Client syncs.
      • When syncing completes successfully, the syncStatusChanged function in the user-replace.service is triggered
        • If the user has been replaced, and the status is set to "PENDING", then we know everything has now synced successfully (since that is what triggered syncStatusChanged in the first place
        • Set the status on the original contact to "READY" and sync again
        • When the next sync completes, automatically log out the user
  • SERVER
    • Server's user_replace transition is triggered by updated contact with replaced.status=READY
      • Creates new user
      • Deletes existing user
      • Sets original contact replaced.status=COMPLETE

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

jkuester avatar Sep 21 '22 20:09 jkuester

If I understand correctly, any report submitted after the replace will automatically appear to be submitted by the new contact, that's neat! I love where this is going :star_struck:

m5r avatar Sep 22 '22 15:09 m5r

Yes, the re-parenting would happen immediately on the client side and the user should see any subsequent reports be added by the new contact (which I think is a good thing, though I am afraid it will make it a little more confusing later when they are suddenly logged out...)

jkuester avatar Sep 22 '22 15:09 jkuester

@jkuester I went ahead and added one more commit to simplify even more some return types, other than that it's looking very good!

m5r avatar Sep 27 '22 14:09 m5r