Skip to content
Snippets Groups Projects
Unverified Commit 2192b91b authored by Cauê Felchar's avatar Cauê Felchar Committed by GitHub
Browse files

[FIX] Removing user also removes them from Omni collections (#25444)

parent 47c54981
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ import { TAPi18n } from 'meteor/rocketchat:tap-i18n';
import { FileProp } from '@rocket.chat/core-typings';
import { FileUpload } from '../../../file-upload/server';
import { Users, Subscriptions, Messages, Rooms } from '../../../models/server';
import { Users, Subscriptions, Messages, Rooms, LivechatDepartmentAgents, LivechatVisitors } from '../../../models/server';
import { FederationServers, Integrations } from '../../../models/server/raw';
import { settings } from '../../../settings/server';
import { updateGroupDMsName } from './updateGroupDMsName';
......@@ -11,10 +11,11 @@ import { relinquishRoomOwnerships } from './relinquishRoomOwnerships';
import { getSubscribedRoomsForUserWithDetails, shouldRemoveOrChangeOwner } from './getRoomsWithSingleOwner';
import { getUserSingleOwnedRooms } from './getUserSingleOwnedRooms';
import { api } from '../../../../server/sdk/api';
import { LivechatUnitMonitors } from '../../../../ee/app/models/server';
export async function deleteUser(userId: string, confirmRelinquish = false): Promise<void> {
const user = Users.findOneById(userId, {
fields: { username: 1, avatarOrigin: 1, federation: 1 },
fields: { username: 1, avatarOrigin: 1, federation: 1, roles: 1 },
});
if (!user) {
......@@ -61,6 +62,18 @@ export async function deleteUser(userId: string, confirmRelinquish = false): Pro
Subscriptions.removeByUserId(userId); // Remove user subscriptions
if (user.roles.includes('livechat-agent')) {
// Remove user as livechat agent
LivechatDepartmentAgents.removeByAgentId(userId);
LivechatVisitors.removeContactManagerByUsername(user.username);
}
if (user.roles.includes('livechat-monitor')) {
// Remove user as Unit Monitor
LivechatUnitMonitors.removeByMonitorId(userId);
LivechatVisitors.removeContactManagerByUsername(user.username);
}
// removes user's avatar
if (user.avatarOrigin === 'upload' || user.avatarOrigin === 'url') {
FileUpload.getStore('Avatars').deleteByName(user.username);
......@@ -68,7 +81,7 @@ export async function deleteUser(userId: string, confirmRelinquish = false): Pro
await Integrations.disableByUserId(userId); // Disables all the integrations which rely on the user being deleted.
// Don't broadcast user.deleted for Erasure Type of 'Keep' so that messages don't dissappear from logged in sessions
// Don't broadcast user.deleted for Erasure Type of 'Keep' so that messages don't disappear from logged in sessions
if (messageErasureType !== 'Keep') {
api.broadcast('user.deleted', user);
}
......
......@@ -13,6 +13,7 @@ export class LivechatVisitors extends Base {
this.tryEnsureIndex({ 'visitorEmails.address': 1 }, { sparse: true });
this.tryEnsureIndex({ name: 1 }, { sparse: true });
this.tryEnsureIndex({ username: 1 });
this.tryEnsureIndex({ 'contactManager.username': 1 }, { sparse: true });
}
/**
......@@ -247,6 +248,20 @@ export class LivechatVisitors extends Base {
const query = { _id };
return this.remove(query);
}
removeContactManagerByUsername(manager) {
const query = {
contactManager: {
username: manager,
},
};
const update = {
$unset: {
contactManager: 1,
},
};
return this.update(query, update);
}
}
export default new LivechatVisitors();
......@@ -39,6 +39,10 @@ export class LivechatUnitMonitors extends Base {
removeByUnitId(unitId) {
this.remove({ unitId });
}
removeByMonitorId(monitorId) {
this.remove({ monitorId });
}
}
export default new LivechatUnitMonitors();
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment