Skip to content

Commit

Permalink
fix: disable deletion for federated users (#32852)
Browse files Browse the repository at this point in the history
  • Loading branch information
debdutdeb authored and abhinavkrin committed Oct 25, 2024
1 parent ed8259b commit 5d01883
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/empty-toys-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Federated users can no longer be deleted.
16 changes: 15 additions & 1 deletion apps/meteor/app/lib/server/functions/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { api } from '@rocket.chat/core-services';
import type { IUser } from '@rocket.chat/core-typings';
import { isUserFederated, type IUser } from '@rocket.chat/core-typings';
import {
Integrations,
FederationServers,
Expand All @@ -12,6 +12,7 @@ import {
ReadReceipts,
LivechatUnitMonitors,
ModerationReports,
MatrixBridgedUser,
} from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

Expand Down Expand Up @@ -46,6 +47,19 @@ export async function deleteUser(userId: string, confirmRelinquish = false, dele
return;
}

if (isUserFederated(user)) {
throw new Meteor.Error('error-not-allowed', 'Deleting federated, external user is not allowed', {
method: 'deleteUser',
});
}

const remoteUser = await MatrixBridgedUser.getExternalUserIdByLocalUserId(userId);
if (remoteUser) {
throw new Meteor.Error('error-not-allowed', 'User participated in federation, this user can only be deactivated permanently', {
method: 'deleteUser',
});
}

const subscribedRooms = await getSubscribedRoomsForUserWithDetails(userId);

if (shouldRemoveOrChangeOwner(subscribedRooms) && !confirmRelinquish) {
Expand Down

0 comments on commit 5d01883

Please sign in to comment.