mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-27 11:01:56 +02: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:
@@ -1,5 +1,5 @@
|
||||
const minimist = require('minimist')
|
||||
const { db, ObjectId } = require('../../../app/src/infrastructure/mongodb')
|
||||
import minimist from 'minimist'
|
||||
import { db, ObjectId } from '../../../app/src/infrastructure/mongodb.js'
|
||||
|
||||
async function main() {
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
@@ -15,7 +15,7 @@ async function main() {
|
||||
Number.isNaN(compileTimeout)
|
||||
) {
|
||||
console.error(
|
||||
`Usage: node ${__filename} --user-id=5a9414f259776c7900b300e6 --timeout=90`
|
||||
`Usage: node ${import.meta.filename} --user-id=5a9414f259776c7900b300e6 --timeout=90`
|
||||
)
|
||||
process.exit(101)
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
const { ObjectId } = require('mongodb-legacy')
|
||||
const {
|
||||
import mongodb from 'mongodb-legacy'
|
||||
import {
|
||||
connectionPromise,
|
||||
db,
|
||||
} = require('../../../app/src/infrastructure/mongodb')
|
||||
} from '../../../app/src/infrastructure/mongodb.js'
|
||||
|
||||
const { ObjectId } = mongodb
|
||||
|
||||
const MIN_MONGO_VERSION = [5, 0]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const RedisWrapper = require('../../../app/src/infrastructure/RedisWrapper')
|
||||
import RedisWrapper from '../../../app/src/infrastructure/RedisWrapper.js'
|
||||
const rclient = RedisWrapper.client('health_check')
|
||||
rclient.on('error', err => {
|
||||
console.error('Cannot connect to redis.')
|
||||
@@ -1,4 +1,4 @@
|
||||
const { db } = require('../../../app/src/infrastructure/mongodb')
|
||||
import { db } from '../../../app/src/infrastructure/mongodb.js'
|
||||
|
||||
async function readImagesInUse() {
|
||||
const projectCount = await db.projects.countDocuments()
|
||||
@@ -1,49 +1,13 @@
|
||||
const minimist = require('minimist')
|
||||
const { db } = require('../../../app/src/infrastructure/mongodb')
|
||||
const UserRegistrationHandler = require('../../../app/src/Features/User/UserRegistrationHandler')
|
||||
/**
|
||||
* WARNING
|
||||
* This file has been replaced by create-user.mjs. It is left in place for backwards compatibility with previous versions of Overleaf.
|
||||
* This will be used by the e2e tests that check the upgrade from the older versions, if these tests are updated or removed,
|
||||
* this file can be removed as well.
|
||||
*/
|
||||
|
||||
async function main() {
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
string: ['email'],
|
||||
boolean: ['admin'],
|
||||
})
|
||||
|
||||
const { admin, email } = argv
|
||||
if (!email) {
|
||||
console.error(`Usage: node ${__filename} [--admin] --email=joe@example.com`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
UserRegistrationHandler.registerNewUserAndSendActivationEmail(
|
||||
email,
|
||||
(error, user, setNewPasswordUrl) => {
|
||||
if (error) {
|
||||
return reject(error)
|
||||
}
|
||||
db.users.updateOne(
|
||||
{ _id: user._id },
|
||||
{ $set: { isAdmin: admin } },
|
||||
error => {
|
||||
if (error) {
|
||||
return reject(error)
|
||||
}
|
||||
|
||||
console.log('')
|
||||
console.log(`\
|
||||
Successfully created ${email} as ${admin ? 'an admin' : 'a'} user.
|
||||
|
||||
Please visit the following URL to set a password for ${email} and log in:
|
||||
|
||||
${setNewPasswordUrl}
|
||||
|
||||
`)
|
||||
resolve()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
const { default: createUser } = await import('./create-user.mjs')
|
||||
await createUser()
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import minimist from 'minimist'
|
||||
import { db } from '../../../app/src/infrastructure/mongodb.js'
|
||||
import UserRegistrationHandler from '../../../app/src/Features/User/UserRegistrationHandler.js'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
|
||||
export default async function main() {
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
string: ['email'],
|
||||
boolean: ['admin'],
|
||||
})
|
||||
|
||||
const { admin, email } = argv
|
||||
if (!email) {
|
||||
console.error(`Usage: node ${filename} [--admin] --email=joe@example.com`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
await new Promise((resolve, reject) => {
|
||||
UserRegistrationHandler.registerNewUserAndSendActivationEmail(
|
||||
email,
|
||||
(error, user, setNewPasswordUrl) => {
|
||||
if (error) {
|
||||
return reject(error)
|
||||
}
|
||||
db.users.updateOne(
|
||||
{ _id: user._id },
|
||||
{ $set: { isAdmin: admin } },
|
||||
error => {
|
||||
if (error) {
|
||||
return reject(error)
|
||||
}
|
||||
|
||||
console.log('')
|
||||
console.log(`\
|
||||
Successfully created ${email} as ${admin ? 'an admin' : 'a'} user.
|
||||
|
||||
Please visit the following URL to set a password for ${email} and log in:
|
||||
|
||||
${setNewPasswordUrl}
|
||||
|
||||
`)
|
||||
resolve()
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
const UserGetter = require('../../../app/src/Features/User/UserGetter')
|
||||
const UserDeleter = require('../../../app/src/Features/User/UserDeleter')
|
||||
import UserGetter from '../../../app/src/Features/User/UserGetter.js'
|
||||
import UserDeleter from '../../../app/src/Features/User/UserDeleter.js'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
|
||||
async function main() {
|
||||
const email = (process.argv.slice(2).pop() || '').replace(/^--email=/, '')
|
||||
if (!email) {
|
||||
console.error(`Usage: node ${__filename} --email=joe@example.com`)
|
||||
console.error(`Usage: node ${filename} --email=joe@example.com`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
// Intended for Server Pro customers migrating user emails from one domain to
|
||||
// another.
|
||||
|
||||
const minimist = require('minimist')
|
||||
import minimist from 'minimist'
|
||||
|
||||
const os = require('os')
|
||||
const fs = require('fs')
|
||||
const csv = require('csv/sync')
|
||||
const { parseEmail } = require('../../../app/src/Features/Helpers/EmailHelper')
|
||||
const UserGetter = require('../../../app/src/Features/User/UserGetter')
|
||||
const UserUpdater = require('../../../app/src/Features/User/UserUpdater')
|
||||
const UserSessionsManager = require('../../../app/src/Features/User/UserSessionsManager')
|
||||
import os from 'os'
|
||||
import fs from 'fs'
|
||||
import * as csv from 'csv/sync'
|
||||
import { parseEmail } from '../../../app/src/Features/Helpers/EmailHelper.js'
|
||||
import UserGetter from '../../../app/src/Features/User/UserGetter.js'
|
||||
import UserUpdater from '../../../app/src/Features/User/UserUpdater.js'
|
||||
import UserSessionsManager from '../../../app/src/Features/User/UserSessionsManager.js'
|
||||
|
||||
const hostname = os.hostname()
|
||||
const scriptTimestamp = new Date().toISOString()
|
||||
@@ -39,7 +39,7 @@ const argv = minimist(process.argv.slice(2), {
|
||||
// display usage if no CSV file is provided
|
||||
if (argv._.length === 0) {
|
||||
console.log(
|
||||
'Usage: node migrate_user_emails.js [--commit] [--continue|--ignore-missing] [--admin-id=ADMIN_USER_ID] <csv_file>'
|
||||
'Usage: node migrate_user_emails.mjs [--commit] [--continue|--ignore-missing] [--admin-id=ADMIN_USER_ID] <csv_file>'
|
||||
)
|
||||
console.log(' --commit: actually do the migration (default: false)')
|
||||
console.log(
|
||||
@@ -1,5 +1,8 @@
|
||||
const minimist = require('minimist')
|
||||
const { db } = require('../../../app/src/infrastructure/mongodb')
|
||||
import minimist from 'minimist'
|
||||
import { db } from '../../../app/src/infrastructure/mongodb.js'
|
||||
import { fileURLToPath } from 'url'
|
||||
|
||||
const filename = fileURLToPath(import.meta.url)
|
||||
|
||||
async function main() {
|
||||
const argv = minimist(process.argv.slice(2), {
|
||||
@@ -9,7 +12,7 @@ async function main() {
|
||||
const { 'user-id': userId, 'old-name': oldName, 'new-name': newName } = argv
|
||||
if (!userId || !oldName || !newName) {
|
||||
console.error(
|
||||
`Usage: node ${__filename} --user-id=5a9414f259776c7900b300e6 --old-name=my-folder --new-name=my-folder-renamed`
|
||||
`Usage: node ${filename} --user-id=5a9414f259776c7900b300e6 --old-name=my-folder --new-name=my-folder-renamed`
|
||||
)
|
||||
process.exit(101)
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
const Settings = require('@overleaf/settings')
|
||||
const logger = require('@overleaf/logger')
|
||||
const { db } = require('../../../app/src/infrastructure/mongodb')
|
||||
const {
|
||||
import Settings from '@overleaf/settings'
|
||||
import logger from '@overleaf/logger'
|
||||
import { db } from '../../../app/src/infrastructure/mongodb.js'
|
||||
import {
|
||||
mergeFeatures,
|
||||
compareFeatures,
|
||||
} = require('../../../app/src/Features/Subscription/FeaturesHelper')
|
||||
} 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) {
|
||||
@@ -38,9 +39,11 @@ async function main(DRY_RUN, defaultFeatures) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = main
|
||||
export default main
|
||||
|
||||
if (require.main === module) {
|
||||
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')
|
||||
Reference in New Issue
Block a user