mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-11 07:00:47 +02:00
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:
committed by
Copybot
parent
aedb835067
commit
1c199e85aa
@@ -0,0 +1,50 @@
|
||||
import { db } from '../../app/src/infrastructure/mongodb.js'
|
||||
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
|
||||
import mongodb from 'mongodb-legacy'
|
||||
import fs from 'node:fs'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { chunkArray } from '../helpers/chunkArray.mjs'
|
||||
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
async function main() {
|
||||
// search for file of users who already explicitly opted out first
|
||||
const optOutPath = process.argv[2]
|
||||
const optedOutFile = fs.readFileSync(optOutPath, 'utf8')
|
||||
let optedOutList = optedOutFile
|
||||
|
||||
optedOutList = optedOutFile.split('\n').map(id => new ObjectId(id))
|
||||
|
||||
console.log(`preserving opt-outs of ${optedOutList.length} users`)
|
||||
// update all applicable user models
|
||||
await batchedUpdate(
|
||||
db.users,
|
||||
{ 'writefull.enabled': false }, // and is false
|
||||
{ $set: { 'writefull.enabled': null } }
|
||||
)
|
||||
|
||||
const chunks = chunkArray(optedOutList)
|
||||
|
||||
// then reset any explicit false back to being false
|
||||
// Iterate over each chunk and perform the query
|
||||
for (const chunkedIds of chunks) {
|
||||
console.log('batch update started')
|
||||
await db.users.updateMany(
|
||||
{ _id: { $in: chunkedIds } },
|
||||
{ $set: { 'writefull.enabled': false } }
|
||||
)
|
||||
console.log('batch completed')
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user