From d88194b9bd2fb69c45d0e26cb2501c6b5c10575f Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 1 Sep 2025 21:28:56 +0100 Subject: [PATCH] accounts: invalidate user cache in more/all places using app.userSummary as a source of relevant storage places and things to look for. --- api-invites.go | 1 + api-messages.go | 7 +++++++ api-userpage.go | 1 + api-users.go | 7 +++++++ user-d.go | 2 ++ users.go | 1 + 6 files changed, 19 insertions(+) diff --git a/api-invites.go b/api-invites.go index 4a47d28..feb54cb 100644 --- a/api-invites.go +++ b/api-invites.go @@ -104,6 +104,7 @@ func (app *appContext) deleteExpiredInvite(data Invite) { if ok { user.ReferralTemplateKey = "" app.storage.SetEmailsKey(data.ReferrerJellyfinID, user) + app.InvalidateWebUserCache() } } wait := app.sendAdminExpiryNotification(data) diff --git a/api-messages.go b/api-messages.go index c3378d1..5be2af3 100644 --- a/api-messages.go +++ b/api-messages.go @@ -271,6 +271,7 @@ func (app *appContext) TelegramAddUser(gc *gin.Context) { } linkExistingOmbiDiscordTelegram(app) + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -336,6 +337,7 @@ func (app *appContext) setContactMethods(req SetContactMethodsDTO, gc *gin.Conte app.err.Printf(lm.FailedSyncContactMethods, lm.Jellyseerr, err) } } + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -564,6 +566,7 @@ func (app *appContext) MatrixConnect(gc *gin.Context) { Lang: "en-us", Contact: true, }) + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -635,6 +638,7 @@ func (app *appContext) DiscordConnect(gc *gin.Context) { }, gc, false) linkExistingOmbiDiscordTelegram(app) + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -672,6 +676,7 @@ func (app *appContext) UnlinkDiscord(gc *gin.Context) { Time: time.Now(), }, gc, false) + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -708,6 +713,7 @@ func (app *appContext) UnlinkTelegram(gc *gin.Context) { Time: time.Now(), }, gc, false) + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -737,5 +743,6 @@ func (app *appContext) UnlinkMatrix(gc *gin.Context) { Time: time.Now(), }, gc, false) + app.InvalidateWebUserCache() respondBool(200, true, gc) } diff --git a/api-userpage.go b/api-userpage.go index dbdc525..10da341 100644 --- a/api-userpage.go +++ b/api-userpage.go @@ -796,6 +796,7 @@ func (app *appContext) GetMyReferral(gc *gin.Context) { inv.ValidTill = inv.Created.Add(REFERRAL_EXPIRY_DAYS * 24 * time.Hour) app.storage.SetInvitesKey(inv.Code, inv) } + app.InvalidateWebUserCache() gc.JSON(200, GetMyReferralRespDTO{ Code: inv.Code, RemainingUses: inv.RemainingUses, diff --git a/api-users.go b/api-users.go index dc89f23..2b3f894 100644 --- a/api-users.go +++ b/api-users.go @@ -625,6 +625,7 @@ func (app *appContext) EnableReferralForUsers(gc *gin.Context) { inv.UseReferralExpiry = useExpiry app.storage.SetInvitesKey(inv.Code, inv) } + app.InvalidateWebUserCache() } // @Summary Disable referrals for the given user(s). @@ -648,6 +649,7 @@ func (app *appContext) DisableReferralForUsers(gc *gin.Context) { user.ReferralTemplateKey = "" app.storage.SetEmailsKey(u, user) } + app.InvalidateWebUserCache() respondBool(200, true, gc) } @@ -848,6 +850,8 @@ func (app *appContext) AdminPasswordReset(gc *gin.Context) { respondBool(204, true, gc) } +// userSummary generates a respUser for to be displayed to the user, or sorted/filtered. +// also, consider it a source of which data fields/struct modifications need to trigger a cache invalidation. func (app *appContext) userSummary(jfUser mediabrowser.User) respUser { adminOnly := app.config.Section("ui").Key("admin_only").MustBool(true) allowAll := app.config.Section("ui").Key("allow_all").MustBool(false) @@ -1016,6 +1020,7 @@ func (app *appContext) SetAccountsAdmin(gc *gin.Context) { app.info.Printf(lm.UserAdminAdjusted, id, admin) } } + app.InvalidateWebUserCache() respondBool(204, true, gc) } @@ -1048,6 +1053,7 @@ func (app *appContext) ModifyLabels(gc *gin.Context) { app.storage.SetEmailsKey(id, emailStore) } } + app.InvalidateWebUserCache() respondBool(204, true, gc) } @@ -1087,6 +1093,7 @@ func (app *appContext) modifyEmail(jfID string, addr string) { } } } + app.InvalidateWebUserCache() } // @Summary Modify user's email addresses. diff --git a/user-d.go b/user-d.go index d4aca9c..c1fd102 100644 --- a/user-d.go +++ b/user-d.go @@ -131,6 +131,7 @@ func (app *appContext) checkUsers(remindBeforeExpiry *DayTimerSet) { activity.Type = ActivityDeletion // Store the user name, since there's no longer a user ID to reference back to activity.Value = user.Name + app.InvalidateUserCaches() } else { app.info.Printf(lm.DisableExpiredUser, user.Name) // Admins can't be disabled @@ -138,6 +139,7 @@ func (app *appContext) checkUsers(remindBeforeExpiry *DayTimerSet) { user.Policy.IsAdministrator = false err, _, _ = app.SetUserDisabled(user, true) activity.Type = ActivityDisabled + app.InvalidateUserCaches() } if err != nil { app.err.Printf(lm.FailedDeleteOrDisableExpiredUser, user.ID, err) diff --git a/users.go b/users.go index 4fa9822..e641ba4 100644 --- a/users.go +++ b/users.go @@ -155,6 +155,7 @@ func (app *appContext) NewUserPostVerification(p NewUserParams) (out NewUserData out.Status = 200 out.Success = true + app.InvalidateWebUserCache() return }