mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-13 13:43:41 +01:00
Merge pull request #22580 from overleaf/ar-migrate-server-ce-scripts
Convert server-ce-scripts module to ES modules GitOrigin-RevId: 516247b25b5bdbfd89fee4b99a88431097c827de
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import Settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger'
|
||||
import { db } from '../../../app/src/infrastructure/mongodb.js'
|
||||
import {
|
||||
mergeFeatures,
|
||||
compareFeatures,
|
||||
} from '../../../app/src/Features/Subscription/FeaturesHelper.js'
|
||||
import { fileURLToPath } from 'url'
|
||||
const DRY_RUN = !process.argv.includes('--dry-run=false')
|
||||
|
||||
async function main(DRY_RUN, defaultFeatures) {
|
||||
logger.info({ defaultFeatures }, 'default features')
|
||||
|
||||
const cursor = db.users.find(
|
||||
{},
|
||||
{ projection: { _id: 1, email: 1, features: 1 } }
|
||||
)
|
||||
for await (const user of cursor) {
|
||||
const newFeatures = mergeFeatures(user.features, defaultFeatures)
|
||||
const diff = compareFeatures(newFeatures, user.features)
|
||||
if (Object.keys(diff).length > 0) {
|
||||
logger.warn(
|
||||
{
|
||||
userId: user._id,
|
||||
email: user.email,
|
||||
oldFeatures: user.features,
|
||||
newFeatures,
|
||||
},
|
||||
'user features upgraded'
|
||||
)
|
||||
|
||||
if (!DRY_RUN) {
|
||||
await db.users.updateOne(
|
||||
{ _id: user._id },
|
||||
{ $set: { features: newFeatures } }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default main
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
|
||||
if (filename === process.argv[1]) {
|
||||
if (DRY_RUN) {
|
||||
console.error('---')
|
||||
console.error('Dry-run enabled, use --dry-run=false to commit changes')
|
||||
console.error('---')
|
||||
}
|
||||
main(DRY_RUN, Settings.defaultFeatures)
|
||||
.then(() => {
|
||||
console.log('Done.')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error({ error })
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user