mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-28 23:43:46 -05:00
6ca86168b1
Bugfix for script to fix lowercase emails in group invites GitOrigin-RevId: f8581376fa5dde2fe057f0e988e5921de7446612
70 lines
1.6 KiB
JavaScript
70 lines
1.6 KiB
JavaScript
const DRY_RUN = process.env.DRY_RUN !== 'false'
|
|
|
|
const { db, waitForDb } = require('../app/src/infrastructure/mongodb')
|
|
const { batchedUpdate } = require('./helpers/batchedUpdate')
|
|
|
|
console.log({
|
|
DRY_RUN,
|
|
})
|
|
|
|
function anyInviteEmailHasUppercaseChars(subscription) {
|
|
return subscription.teamInvites.some(invite => {
|
|
return /[A-Z]/.test(invite.email)
|
|
})
|
|
}
|
|
|
|
async function processBatch(_, subscriptions) {
|
|
for (const subscription of subscriptions) {
|
|
if (anyInviteEmailHasUppercaseChars(subscription)) {
|
|
console.log('fixing emails in group invites for', subscription._id)
|
|
if (!DRY_RUN) {
|
|
await db.subscriptions.updateOne({ _id: subscription._id }, [
|
|
{
|
|
$set: {
|
|
teamInvites: {
|
|
$map: {
|
|
input: '$teamInvites',
|
|
in: {
|
|
$mergeObjects: [
|
|
'$$this',
|
|
{
|
|
email: {
|
|
$toLower: '$$this.email',
|
|
},
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
await waitForDb()
|
|
|
|
const projection = {
|
|
_id: 1,
|
|
teamInvites: 1,
|
|
}
|
|
const query = {
|
|
'teamInvites.0': {
|
|
$exists: true,
|
|
},
|
|
}
|
|
await batchedUpdate('subscriptions', query, processBatch, projection)
|
|
}
|
|
|
|
main()
|
|
.then(() => {
|
|
console.error('Done.')
|
|
process.exit(0)
|
|
})
|
|
.catch(error => {
|
|
console.error({ error })
|
|
process.exit(1)
|
|
})
|