Merge pull request #1780 from overleaf/sk-script-remove-password-fields

Add a script to remove `hashedPassword` fields from non-sl user records

GitOrigin-RevId: d7c6fdbc138d4c5452e6e3a7f2ad639f049f122f
This commit is contained in:
Simon Detheridge 2019-05-20 13:07:19 +01:00 committed by sharelatex
parent 3486f61b5b
commit 02c4edcb1c

View file

@ -0,0 +1,40 @@
const { db } = require('../app/js/infrastructure/mongojs')
const minimist = require('minimist')
const argv = minimist(process.argv.slice(2))
const commit = argv.commit !== undefined
if (!commit) {
console.log('DOING DRY RUN. TO SAVE CHANGES PASS --commit')
}
function main(callback) {
const query = { 'overleaf.id': { $exists: true } }
db.users.count(query, (err, result) => {
if (err) {
return callback(err)
}
console.log(`>> Count: ${result}`)
if (!commit) {
return callback()
}
db.users.update(query, { $unset: { hashedPassword: 1 } }, (err, result) => {
if (err) {
return callback(err)
}
console.log(`>> Updated users: ${JSON.stringify(result)}`)
return callback()
})
})
}
if (require.main === module) {
main(err => {
if (err) {
console.error(err)
return process.exit(1)
}
console.log('>> done')
process.exit(0)
})
}