overleaf/services/web/scripts/beta-users/set_rich_text_beta_users.js
Simon Detheridge db162cfe0a Merge pull request #1656 from sharelatex/cmg-reintroduce-beta-fix-path
Use path.join() in reintroduce beta script to pass linting

GitOrigin-RevId: 4936de04b389571e73de3ddcae8ee611634efcaf
2019-03-22 13:02:21 +00:00

50 lines
1.1 KiB
JavaScript

const fs = require('fs')
const path = require('path')
const mongojs = require('../../app/js/infrastructure/mongojs')
const { db, ObjectId } = mongojs
const async = require('async')
console.log('Finding users for ids specified')
const text = fs.readFileSync(path.join(__dirname, 'beta-users.txt'))
const textByLine = text
.toString()
.split('\n')
.map(function(stringId) {
return ObjectId(stringId)
})
db.users.find({ _id: { $in: textByLine } }, function(err, users) {
if (err) throw err
if (users.length) {
console.log('Found ' + users.length + ' users')
async.each(
users,
function(user, callback) {
console.log('setting betaProgram==true for: ' + user._id)
db.users.update(
{
_id: user._id
},
{
$set: {
betaProgram: true
}
},
callback
)
},
function(result, err) {
if (err) {
console.log(err)
}
process.exit(0)
}
)
} else {
console.log('No users found matching those ids')
process.exit(0)
}
})