Repository navigation
enhance: serialize user update methods - #1042
eternal-flame-AD wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1042 +/- ##
==========================================
+ Coverage 76.66% 76.79% +0.13%
==========================================
Files 68 68
Lines 3724 3771 +47
==========================================
+ Hits 2855 2896 +41
- Misses 657 660 +3
- Partials 212 215 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ddfa0cc to
08f571c
Compare
c031b29 to
e787139
Compare
d486c1b to
6e4f37c
Compare
3421a40 to
6445b84
Compare
1728f14 to
d7f2d0b
Compare
| // $ref: "#/definitions/Error" | ||
| func (a *UserAPI) DeleteUserByID(ctx *gin.Context) { | ||
| withID(ctx, "id", func(id uint) { | ||
| user, err := a.DB.GetUserByID(id) |
There was a problem hiding this comment.
(optional) Can we move this into the transaction too? Otherwise they can still be some race here. Similar for the UpdateUser api.
There was a problem hiding this comment.
I think this is fine as is, it's just an early filter making sure the ID exists. The risk would be someone deleted the user right before the check and your transaction runs, in such case returning a success instead of "user does not exist" is probably acceptable.
There was a problem hiding this comment.
For the update endpoint it caches oidc_id before the transaction and then set's it inside the transaction. There probably could be a race condition where a user is linked to an oidc identity & maybe updates the admin permissions, and at the same time the update method is called, this could unset the oidc_id and the change of permission.
For the delete endpoint it could be that at the same time another admin changes the admin flag of the user, so it's the last admin. The admin flag is false on the read outside of the transaction, but before the transaction is called, it was actually updated, and then the admin check isn't done correctly.
But yeah, it's optional, but it seems like a similar problem we are trying to fix here.
01169b4 to
60ec466
Compare
58c4bf8 to
ef973fb
Compare
ef973fb to
2bf405a
Compare
Serializes user update actions to prevent race conditions leading to unexpected results.
I removed the 'Test_UpdateUserByID_EmptyPassword_Expect400' test as it seemed to be a mistake - it should return 200, it returned 400 in the test because there wasn't a second admin.