2020-10-07 13:17:49 +00:00
|
|
|
const { db, ObjectId, waitForDb } = require('../app/src/infrastructure/mongodb')
|
2019-10-10 11:25:27 +00:00
|
|
|
const minimist = require('minimist')
|
|
|
|
const argv = minimist(process.argv.slice(2))
|
|
|
|
const commit = argv.commit !== undefined
|
|
|
|
const projectIds = argv._.map(x => {
|
|
|
|
return ObjectId(x)
|
|
|
|
})
|
|
|
|
|
|
|
|
if (!commit) {
|
|
|
|
console.log('Doing dry run without --commit')
|
|
|
|
}
|
|
|
|
console.log('checking', projectIds.length, 'projects')
|
2020-10-07 13:17:49 +00:00
|
|
|
waitForDb().then(async () => {
|
|
|
|
const affectedProjects = await db.projects
|
|
|
|
.find(
|
|
|
|
{ _id: { $in: projectIds } },
|
|
|
|
{
|
|
|
|
projection: {
|
|
|
|
_id: 1,
|
|
|
|
owner_ref: 1,
|
|
|
|
tokenAccessReadOnly_refs: 1,
|
2021-04-27 07:52:58 +00:00
|
|
|
tokenAccessReadAndWrite_refs: 1,
|
|
|
|
},
|
2020-10-07 13:17:49 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
.toArray()
|
|
|
|
console.log('Found ' + affectedProjects.length + ' affected projects')
|
|
|
|
affectedProjects.forEach(project => {
|
|
|
|
console.log(JSON.stringify(project))
|
|
|
|
})
|
|
|
|
if (!commit) {
|
|
|
|
console.log('dry run, not updating')
|
|
|
|
process.exit(0)
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
const result = await db.projects.updateMany(
|
|
|
|
{ _id: { $in: affectedProjects.map(project => project._id) } },
|
2019-10-10 11:25:27 +00:00
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
publicAccesLevel: 'private', // note the spelling in the db is publicAccesLevel (with one 's')
|
|
|
|
tokenAccessReadOnly_refs: [],
|
2021-04-27 07:52:58 +00:00
|
|
|
tokenAccessReadAndWrite_refs: [],
|
|
|
|
},
|
2019-10-10 11:25:27 +00:00
|
|
|
}
|
|
|
|
)
|
2020-10-07 13:17:49 +00:00
|
|
|
console.log('result', JSON.stringify(result))
|
|
|
|
process.exit(0)
|
|
|
|
} catch (err) {
|
|
|
|
console.error('err', err)
|
|
|
|
process.exit(1)
|
2019-10-10 11:25:27 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 13:17:49 +00:00
|
|
|
})
|