mirror of
https://github.com/overleaf/overleaf.git
synced 2025-02-17 01:32:12 +00:00
Merge pull request #2222 from overleaf/bg-invalidate-tokens
invalidate tokens GitOrigin-RevId: b8a65846d2b671f7f7b8a2ab75f76bb8255bd73b
This commit is contained in:
parent
625b4c9339
commit
d376047c20
1 changed files with 67 additions and 0 deletions
67
services/web/scripts/invalidate_tokens.js
Normal file
67
services/web/scripts/invalidate_tokens.js
Normal file
|
@ -0,0 +1,67 @@
|
|||
const { db, ObjectId } = require('../app/src/infrastructure/mongojs')
|
||||
const minimist = require('minimist')
|
||||
const _ = require('lodash')
|
||||
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')
|
||||
db.projects.find(
|
||||
{
|
||||
_id: { $in: projectIds }
|
||||
},
|
||||
(err, affectedProjects) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
console.log('Found ' + affectedProjects.length + ' affected projects')
|
||||
affectedProjects.forEach(x => {
|
||||
console.log(
|
||||
JSON.stringify(
|
||||
_.pick(x, [
|
||||
'_id',
|
||||
'owner_ref',
|
||||
'tokenAccessReadOnly_refs',
|
||||
'tokenAccessReadAndWrite_refs'
|
||||
])
|
||||
)
|
||||
)
|
||||
})
|
||||
if (!commit) {
|
||||
console.log('dry run, not updating')
|
||||
process.exit(0)
|
||||
} else {
|
||||
db.projects.update(
|
||||
{
|
||||
_id: {
|
||||
$in: affectedProjects.map(x => {
|
||||
return x._id
|
||||
})
|
||||
}
|
||||
},
|
||||
{
|
||||
$set: {
|
||||
publicAccesLevel: 'private', // note the spelling in the db is publicAccesLevel (with one 's')
|
||||
tokenAccessReadOnly_refs: [],
|
||||
tokenAccessReadAndWrite_refs: []
|
||||
}
|
||||
},
|
||||
{
|
||||
multi: true
|
||||
},
|
||||
(err, result) => {
|
||||
console.log('err', err, 'result', result)
|
||||
db.close()
|
||||
setTimeout(() => {
|
||||
process.exit(0)
|
||||
}, 5000)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
Loading…
Reference in a new issue