mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-15 14:43:46 +01:00
Merge pull request #19922 from overleaf/msm-fix-reversedHostname-launchpad
[web] Add missing `reversedHostname` for admins in CE/SP GitOrigin-RevId: 2ce273e963a7471c514289cc042890bd1a14d4d2
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
exports.tags = ['server-ce', 'server-pro']
|
||||
|
||||
exports.migrate = async client => {
|
||||
const { db } = client
|
||||
|
||||
const adminsWithEmails = await db.users
|
||||
.find(
|
||||
{
|
||||
isAdmin: true,
|
||||
emails: { $exists: true },
|
||||
},
|
||||
{ _id: 1, emails: 1 }
|
||||
)
|
||||
.toArray()
|
||||
|
||||
for (const { _id, emails } of adminsWithEmails) {
|
||||
let shouldUpdateEmails = false
|
||||
for (const emailObj of emails) {
|
||||
if (!emailObj.reversedHostname) {
|
||||
shouldUpdateEmails = true
|
||||
emailObj.reversedHostname = emailObj.email
|
||||
.split('@')[1]
|
||||
.split('')
|
||||
.reverse()
|
||||
.join('')
|
||||
}
|
||||
}
|
||||
if (shouldUpdateEmails) {
|
||||
await db.users.updateOne({ _id }, { $set: { emails } })
|
||||
}
|
||||
}
|
||||
|
||||
const adminsNoEmails = await db.users
|
||||
.find(
|
||||
{
|
||||
isAdmin: true,
|
||||
emails: { $exists: false },
|
||||
},
|
||||
{ _id: 1, email: 1 }
|
||||
)
|
||||
.toArray()
|
||||
|
||||
for (const { _id, email } of adminsNoEmails) {
|
||||
const reversedHostname = email.split('@')[1].split('').reverse().join('')
|
||||
await db.users.updateOne(
|
||||
{ _id },
|
||||
{
|
||||
emails: [
|
||||
{
|
||||
email,
|
||||
reversedHostname,
|
||||
createdAt: new Date(),
|
||||
},
|
||||
],
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
exports.rollback = async () => {}
|
||||
Reference in New Issue
Block a user