Fix: group membership changes didn't invalidate the User cache
routes/group.js's add/removeMember never called User.clearCache(), unlike the isServiceAccount handling in routes/user.js (which does this deliberately, with a comment explaining exactly why). isServiceAccount is derived at User.get() time from app_sso_service_account membership and cached for 5 minutes -- so adding or removing a user from ANY group via this route left group-derived state (isServiceAccount, and by extension anything else that reads memberOf off a cached User) stale for up to 5 minutes. In production this manifested as a real user's account appearing to "vanish": users.ejs's People tab filters out anything with isServiceAccount truthy, so once that user's membership in app_sso_service_account changed, they'd disappear from the tab anyone actually looks at for up to 5 minutes -- looking exactly like data loss, though the account was never touched. Found by investigating a live "lost users" report: the account had isServiceAccount: 'yes' and was in fact still fully present, just hidden. This does not explain how the account came to be a member of app_sso_service_account in the first place (unresolved -- possibly a manual/accidental group-membership change via the Groups UI, which has no guardrail against adding a real person to what's meant to be a marker group for non-person accounts). It does fix a real correctness gap: any admin group-membership change now takes effect immediately instead of on a timer. Verified against a real LDAP+Redis harness: the new test fails on the unfixed code (stale isServiceAccount immediately after the PUT) and passes with the fix. Full suite: 189/191 passing (2 pre-existing skips). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -82,8 +82,13 @@ router.put('/:group/:uid', async function(req, res, next){
|
||||
|
||||
var group = await Group.get(req.params.group);
|
||||
var user = await User.get(req.params.uid);
|
||||
const results = await group.addMember(user);
|
||||
// Group membership feeds directly into cached-User-derived state
|
||||
// (isServiceAccount, isAdmin, group-gated nav/UI) -- without this,
|
||||
// a membership change here is invisible for up to the cache's TTL.
|
||||
User.clearCache();
|
||||
return res.json({
|
||||
results: await group.addMember(user),
|
||||
results,
|
||||
message: `Added user ${req.params.uid} to ${req.params.group} group.`
|
||||
});
|
||||
}catch(error){
|
||||
@@ -98,8 +103,10 @@ router.delete('/:group/:uid', async function(req, res, next){
|
||||
|
||||
var group = await Group.get(req.params.group);
|
||||
var user = await User.get(req.params.uid);
|
||||
const results = await group.removeMember(user);
|
||||
User.clearCache();
|
||||
return res.json({
|
||||
results: await group.removeMember(user),
|
||||
results,
|
||||
message: `Removed user ${req.params.uid} from ${req.params.group} group.`
|
||||
});
|
||||
}catch(error){
|
||||
|
||||
Reference in New Issue
Block a user