Merge pull request #23820 from overleaf/jdt-transition-wf-accounts-script

Script to transition WF users from auto-load to auto-create

GitOrigin-RevId: 538ff04dece52e4c46a4a592cb5089d20eb5aa7a
This commit is contained in:
Jimmy Domagala-Tang
2025-02-27 08:41:50 -06:00
committed by Copybot
parent 18c2b4108d
commit 8a81b0777a
5 changed files with 107 additions and 13 deletions
@@ -0,0 +1,45 @@
import { db } from '../../app/src/infrastructure/mongodb.js'
import mongodb from 'mongodb-legacy'
import fs from 'node:fs'
import { fileURLToPath } from 'node:url'
const { ObjectId } = mongodb
async function main() {
// search for file of users to force into auto load
const userIdsPath = process.argv[2]
const userIdsFile = fs.readFileSync(userIdsPath, 'utf8')
let userIdsList = userIdsFile
userIdsList = userIdsList
.split('\n')
.filter(id => id?.length)
.map(id => new ObjectId(id))
console.log(
`enabling writefull with autoCreatedAccount:false for ${userIdsList.length} users`
)
// set them to writefull.enabled true, and autoCreatedAccount false which is the same state an auto-load account is placed in after their first load
// not this does NOT call writefull's first load function for the user's account
await db.users.updateMany(
{ _id: { $in: userIdsList } },
{
$set: {
'writefull.enabled': true,
'writefull.autoCreatedAccount': false,
},
}
)
}
export default main
if (fileURLToPath(import.meta.url) === process.argv[1]) {
try {
await main()
process.exit(0)
} catch (error) {
console.error({ error })
process.exit(1)
}
}