Skip to content
Merged
5 changes: 5 additions & 0 deletions .changeset/strong-shoes-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Allows deleting federated remote users in case they are not present in the homeserver.
27 changes: 17 additions & 10 deletions apps/meteor/app/lib/server/functions/deleteUser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Apps, AppEvents } from '@rocket.chat/apps';
import { api } from '@rocket.chat/core-services';
import { api, Federation, FederationEE, License } from '@rocket.chat/core-services';
import { isUserFederated, type IUser } from '@rocket.chat/core-typings';
import {
Integrations,
Expand All @@ -23,6 +23,7 @@ import { relinquishRoomOwnerships } from './relinquishRoomOwnerships';
import { updateGroupDMsName } from './updateGroupDMsName';
import { callbacks } from '../../../../lib/callbacks';
import { i18n } from '../../../../server/lib/i18n';
import { VerificationStatus } from '../../../../server/services/federation/infrastructure/matrix/helpers/MatrixIdVerificationTypes';
import { FileUpload } from '../../../file-upload/server';
import { settings } from '../../../settings/server';
import {
Expand All @@ -49,16 +50,22 @@ export async function deleteUser(userId: string, confirmRelinquish = false, dele
}

if (isUserFederated(user)) {
throw new Meteor.Error('error-not-allowed', 'Deleting federated, external user is not allowed', {
method: 'deleteUser',
});
}
const service = (await License.hasValidLicense()) ? FederationEE : Federation;

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 result = await service.verifyMatrixIds([user.username as string]);

if (result.get(user.username as string) === VerificationStatus.VERIFIED) {
throw new Meteor.Error('error-not-allowed', 'Deleting federated, external user is not allowed', {
method: 'deleteUser',
});
}
} else {
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);
Expand Down
Loading