Skip to content

Commit e5eda7e

Browse files
fix: LDAP Sync sending repeated deactivation emails to inactive users (#36235)
1 parent 4c2a437 commit e5eda7e

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

.changeset/violet-donuts-warn.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@rocket.chat/model-typings': patch
3+
'@rocket.chat/models': patch
4+
'@rocket.chat/meteor': patch
5+
---
6+
7+
Fixes the issue of deactivation emails being sent to users that were removed from AD even if they were not active in the workspace

apps/meteor/ee/server/lib/ldap/Manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,14 +620,14 @@ export class LDAPEEManager extends LDAPManager {
620620
if (ldapUser) {
621621
const userData = this.mapUserData(ldapUser, user.username);
622622
converter.addObjectToMemory(userData, { dn: ldapUser.dn, username: this.getLdapUsername(ldapUser) });
623-
} else if (disableMissingUsers) {
623+
} else if (disableMissingUsers && user.active) {
624624
await setUserActiveStatus(user._id, false, true);
625625
}
626626
}
627627
}
628628

629629
private static async disableMissingUsers(foundUsers: IUser['_id'][]): Promise<void> {
630-
const userIds = (await Users.findLDAPUsersExceptIds(foundUsers, { projection: { _id: 1 } }).toArray()).map(({ _id }) => _id);
630+
const userIds = (await Users.findActiveLDAPUsersExceptIds(foundUsers, { projection: { _id: 1 } }).toArray()).map(({ _id }) => _id);
631631

632632
await Promise.allSettled(userIds.map((id) => setUserActiveStatus(id, false, true)));
633633
}

packages/model-typings/src/models/IUsersModel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export interface IUsersModel extends IBaseModel<IUser> {
8989

9090
findLDAPUsers<T extends Document = IUser>(options?: FindOptions<IUser>): FindCursor<T>;
9191

92-
findLDAPUsersExceptIds<T extends Document = IUser>(userIds: IUser['_id'][], options?: FindOptions<IUser>): FindCursor<T>;
92+
findActiveLDAPUsersExceptIds<T extends Document = IUser>(userIds: IUser['_id'][], options?: FindOptions<IUser>): FindCursor<T>;
9393

9494
findConnectedLDAPUsers<T extends Document = IUser>(options?: FindOptions<IUser>): FindCursor<T>;
9595

packages/models/src/models/Users.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,10 @@ export class UsersRaw extends BaseRaw<IUser, DefaultFields<IUser>> implements IU
504504
return this.find<T>(query, options);
505505
}
506506

507-
findLDAPUsersExceptIds<T extends Document = IUser>(userIds: IUser['_id'][], options: FindOptions<IUser> = {}) {
507+
findActiveLDAPUsersExceptIds<T extends Document = IUser>(userIds: IUser['_id'][], options: FindOptions<IUser> = {}) {
508508
const query = {
509509
ldap: true,
510+
active: true,
510511
_id: {
511512
$nin: userIds,
512513
},

0 commit comments

Comments
 (0)