Skip to content

Commit

Permalink
fix: Ensure emailUsers sync with delta.users using a map
Browse files Browse the repository at this point in the history
  • Loading branch information
hexaltation committed Oct 15, 2024
1 parent af7fb91 commit 2279bd9
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions app/gen-server/lib/homedb/UsersManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ export class UsersManager {
* One for creation
* the other for retrieving users in order to make it more maintainable
*/
public async createUser(email: string, options: GetUserOptions = {}): Promise<User|undefined> {
public async createUser(email: string, options: GetUserOptions = {}): Promise<User> {
return await this.getUserByLogin(email, options);
}

Expand Down Expand Up @@ -632,15 +632,13 @@ export class UsersManager {
const existingUsers = await this.getExistingUsersByLogin(emails, transaction);
const emailsExistingUsers = existingUsers.map(user => user.loginEmail);
const emailsUsersToCreate = emails.filter(email => !emailsExistingUsers.includes(email));
const emailUsers = [...existingUsers];
const emailUsers = new Map(existingUsers.map(user => [user.loginEmail, user]));
for (const email of emailsUsersToCreate) {
const user = await this.createUser(email, {manager: transaction});
if (user !== undefined) {
emailUsers.push(user);
}
emailUsers.set(user.loginEmail, user);
}
emails.forEach((email, i) => {
const userIdAffected = emailUsers[i]!.id;
emails.forEach((email) => {
const userIdAffected = emailUsers.get(email)!.id;
// Org-level sharing with everyone would allow serious spamming - forbid it.
if (emailMap[email] !== null && // allow removing anything
userId !== this.getSupportUserId() && // allow support user latitude
Expand Down

0 comments on commit 2279bd9

Please sign in to comment.