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

fix: disable deletion for federated users #32852

Merged
merged 12 commits into from
Aug 14, 2024
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
Loading