Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not store modified email when deduping email list #4232

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions forge/routes/api/teamInvitations.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,17 @@ module.exports = async function (app) {
const namesOnlyDeduplicated = [...new Set(namesOnly.map(u => u.trim().toLowerCase()))].map(u => namesOnly.find(n => n.trim().toLowerCase() === u))
// use a regex to determine if the user is an email address
const emailsOnly = userDetails.filter(u => u.match(/^[^@]+@[^@]+$/))
const emailsOnlyDeduplicated = [...new Set(emailsOnly.map(u => getCanonicalEmail(u)))]
// Deduplicate the list based on the canonical email, but keep the as-provided
// email in the list
const emailsOnlyDeduplicated = {}
emailsOnly.forEach(email => {
const canonicalEmail = getCanonicalEmail(email)
if (!emailsOnlyDeduplicated[canonicalEmail]) {
emailsOnlyDeduplicated[canonicalEmail] = email
}
})
// recombine the deduplicated lists
const userDetailsDeduplicated = [...namesOnlyDeduplicated, ...emailsOnlyDeduplicated]
const userDetailsDeduplicated = [...namesOnlyDeduplicated, ...Object.values(emailsOnlyDeduplicated)]

// limit to 5 invites at a time
if (userDetailsDeduplicated.length > 5) {
Expand Down
Loading