[web] Update revokeAllUserSessions and rename it to removeSessionsFromRedis (#18360)

* Fix `revokeAllUserSessions` call in `_cleanupUser`

The user object should be passed, not the _id

* Change `revokeAllUserSessions` signature, take `req` and `stayLoggedIn` arguments

* Update uses of `revokeAllUserSessions`

* Fix promisified `revokeAllUserSessions` args

* Update tests

* Destroy or Regenerate the session in the end of `revokeAllUserSessions`

Per https://github.com/overleaf/internal/issues/17036#issuecomment-1938398570

* Revert "Destroy or Regenerate the session in the end of `revokeAllUserSessions`"

This reverts commit fe30734dbe45b27d2931d2e43a711d591bb85787.

* Rename `revokeAllUserSessions` to `removeSessionsFromRedis`

* Fixup tests

* Fix: add optional chaining in `req.sessionID` (!!)

GitOrigin-RevId: d41676bf00f463230af495e09c65fb9ee521f49f
This commit is contained in:
Antoine Clausse
2024-05-17 12:15:14 +02:00
committed by Copybot
parent 2f80db1299
commit 7fae1cbb2c
15 changed files with 79 additions and 61 deletions
@@ -77,7 +77,7 @@ async function main() {
{ $set: { staffAccess: FULL_STAFF_ACCESS } }
)
if (!KEEP_SESSIONS) {
await UserSessionsManager.promises.revokeAllUserSessions(user, [])
await UserSessionsManager.promises.removeSessionsFromRedis(user)
}
}
} else {
@@ -37,15 +37,20 @@ function _handleUser(userId, callback) {
processLogger.failedSet.push(userId)
return callback()
} else {
UserSessionsManager.revokeAllUserSessions({ _id: userId }, [], error => {
if (error) {
console.log(`Failed to clear sessions for ${userId}`, error)
processLogger.failedClear.push(userId)
} else {
processLogger.success.push(userId)
UserSessionsManager.removeSessionsFromRedis(
{ _id: userId },
null,
null,
error => {
if (error) {
console.log(`Failed to clear sessions for ${userId}`, error)
processLogger.failedClear.push(userId)
} else {
processLogger.success.push(userId)
}
return callback()
}
return callback()
})
)
}
})
}