mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 02:51:57 +02:00
Merge pull request #16012 from overleaf/jpa-purge-legacy-pw
[web] purge legacy passwords GitOrigin-RevId: db779de632e1ac96cce341d79ff251908640ea72
This commit is contained in:
40
services/web/scripts/purge_legacy_passwords.js
Normal file
40
services/web/scripts/purge_legacy_passwords.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const { db, waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||
const { batchedUpdateWithResultHandling } = require('./helpers/batchedUpdate')
|
||||
const { UserAuditLogEntry } = require('../app/src/models/UserAuditLogEntry')
|
||||
const DRY_RUN = process.env.DRY_RUN !== 'false'
|
||||
|
||||
const VARIANTS = [
|
||||
{
|
||||
query: { sharelatexHashedPassword: { $exists: true } },
|
||||
update: { $unset: { sharelatexHashedPassword: true } },
|
||||
},
|
||||
{
|
||||
query: { hashedPassword: { $regex: /^[0-9a-f]{64}$/ } },
|
||||
update: { $unset: { hashedPassword: true } },
|
||||
},
|
||||
]
|
||||
|
||||
if (require.main === module) {
|
||||
batchedUpdateWithResultHandling(
|
||||
'users',
|
||||
{ $or: VARIANTS.map(variant => variant.query) },
|
||||
async users => {
|
||||
const userIds = users.map(user => user._id)
|
||||
if (DRY_RUN) {
|
||||
console.warn(`Running in dry-run mode. Skipping updates for ${userIds}`)
|
||||
return
|
||||
}
|
||||
for (const userId of userIds) {
|
||||
await UserAuditLogEntry.create({
|
||||
userId,
|
||||
operation: 'purge-legacy-password',
|
||||
info: { script: true },
|
||||
})
|
||||
}
|
||||
await waitForDb()
|
||||
for (const { query, update } of VARIANTS) {
|
||||
await db.users.updateMany({ _id: { $in: userIds }, ...query }, update)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user