forked from NodeBB/NodeBB
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…1260) when admin is changing users emails check if its avaiable and remove old email of user first upgrade script to cleanup email:uid, email:sorted, will remove entries if user doesn't exist or doesn't have email or if entry in user hash doesn't match entry in email:uid fix missing ! in email interstitial fix missing await in canSendValidation, fix broken tests dont pass sessionId to email.remove if admin is changing/removing email
- Loading branch information
1 parent
7a5bcc2
commit 845c801
Showing
4 changed files
with
72 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
|
||
const db = require('../../database'); | ||
const batch = require('../../batch'); | ||
|
||
|
||
module.exports = { | ||
name: 'Fix user email sorted sets', | ||
timestamp: Date.UTC(2023, 1, 4), | ||
method: async function () { | ||
const { progress } = this; | ||
const bulkRemove = []; | ||
await batch.processSortedSet('email:uid', async (data) => { | ||
progress.incr(data.length); | ||
const usersData = await db.getObjects(data.map(d => `user:${d.score}`)); | ||
data.forEach((emailData, index) => { | ||
const { score: uid, value: email } = emailData; | ||
const userData = usersData[index]; | ||
// user no longer exists or doesn't have email set in user hash | ||
// remove the email/uid pair from email:uid, email:sorted | ||
if (!userData || !userData.email) { | ||
bulkRemove.push(['email:uid', email]); | ||
bulkRemove.push(['email:sorted', `${email.toLowerCase()}:${uid}`]); | ||
return; | ||
} | ||
|
||
// user has email but doesn't match whats stored in user hash, gh#11259 | ||
if (userData.email && userData.email.toLowerCase() !== email.toLowerCase()) { | ||
bulkRemove.push(['email:uid', email]); | ||
bulkRemove.push(['email:sorted', `${email.toLowerCase()}:${uid}`]); | ||
} | ||
}); | ||
}, { | ||
batch: 500, | ||
withScores: true, | ||
progress: progress, | ||
}); | ||
|
||
await batch.processArray(bulkRemove, async (bulk) => { | ||
await db.sortedSetRemoveBulk(bulk); | ||
}, { | ||
batch: 500, | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters