mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-26 13:52:07 +00:00
* Remove promises object from CollaboratorsInviteController.mjs * Define functions at root * Remove mentions of undefined `revokeInviteForUser` * Remove unused `doLogout` * Remove promises object from UserController.js * Remove unused `makeChangePreview` * Remove promises object from SubscriptionController.js (`getRecommendedCurrency` and `getLatamCountryBannerDetails`) * Remove promises object from CollabratecController.mjs * Remove promises object from SSOController.mjs * Remove promises object from ReferencesApiController.mjs * Remove promises object from MetricsEmailController.mjs * Remove promises object from InstitutionHubsController.mjs * Remove promises object from DocumentUpdaterController.mjs * Remove promises object from SubscriptionAdminController.mjs * Fixup unit tests * Add expects that controllers don't error * Promisify `ensureAffiliationMiddleware` GitOrigin-RevId: 311c8afa7d5c8e4f051408d305b6b4147a020edc
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
import { User } from '../app/src/models/User.js'
|
|
import UserController from '../app/src/Features/User/UserController.js'
|
|
import Logger from '@overleaf/logger'
|
|
import pLimit from 'p-limit'
|
|
|
|
Logger.logger.level('error')
|
|
const CONCURRENCY = 10
|
|
const failure = []
|
|
const success = []
|
|
console.log('Starting ensure affiliations')
|
|
|
|
const query = {
|
|
'emails.affiliationUnchecked': true,
|
|
}
|
|
|
|
async function _handleEnsureAffiliation(user) {
|
|
try {
|
|
await UserController.ensureAffiliation(user)
|
|
console.log(`✔ ${user._id}`)
|
|
success.push(user._id)
|
|
} catch (error) {
|
|
failure.push(user._id)
|
|
console.log(`ERROR: ${user._id}`, error)
|
|
}
|
|
}
|
|
|
|
async function getUsers() {
|
|
return User.find(query, { emails: 1 }).exec()
|
|
}
|
|
|
|
async function run() {
|
|
const limit = pLimit(CONCURRENCY)
|
|
const users = await getUsers()
|
|
console.log(`Found ${users.length} users`)
|
|
await Promise.all(
|
|
users.map(user => limit(() => _handleEnsureAffiliation(user)))
|
|
)
|
|
|
|
console.log(`${success.length} successes`)
|
|
console.log(`${failure.length} failures`)
|
|
if (failure.length > 0) {
|
|
console.log('Failed to update:', failure)
|
|
}
|
|
}
|
|
|
|
try {
|
|
await run()
|
|
process.exit()
|
|
} catch (error) {
|
|
console.log(error)
|
|
process.exit(1)
|
|
}
|