From 1a113034fdff9bf1cdddefe4985015c65a11dd4f Mon Sep 17 00:00:00 2001 From: Debdut Chakraborty Date: Tue, 17 Dec 2024 21:26:03 +0530 Subject: [PATCH] fix(federation-v2): don't throw on username validation before creating dm (#33280) --- .changeset/fifty-parrots-wonder.md | 5 +++++ .../federation/infrastructure/rocket-chat/hooks/index.ts | 4 +--- .../infrastructure/rocket-chat/hooks/hooks.spec.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 .changeset/fifty-parrots-wonder.md diff --git a/.changeset/fifty-parrots-wonder.md b/.changeset/fifty-parrots-wonder.md new file mode 100644 index 000000000000..f0078cd51136 --- /dev/null +++ b/.changeset/fifty-parrots-wonder.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixes an issue preventing the creation of normal direct message rooms due to an invalid federation configuration, allowing proper room creation under standard settings. diff --git a/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts b/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts index 8cac9bc9ffb0..4d8f8cf298f0 100644 --- a/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts +++ b/apps/meteor/server/services/federation/infrastructure/rocket-chat/hooks/index.ts @@ -74,12 +74,10 @@ export class FederationHooks { callbacks.add( 'federation.beforeCreateDirectMessage', async (members: IUser[]): Promise => { - if (!members) { + if (!members || !isFederationEnabled()) { return; } - throwIfFederationNotEnabledOrNotReady(); - await callback(members); }, callbacks.priority.HIGH, diff --git a/apps/meteor/tests/unit/server/federation/infrastructure/rocket-chat/hooks/hooks.spec.ts b/apps/meteor/tests/unit/server/federation/infrastructure/rocket-chat/hooks/hooks.spec.ts index 94d8fa26bd9c..be1a935eb06c 100644 --- a/apps/meteor/tests/unit/server/federation/infrastructure/rocket-chat/hooks/hooks.spec.ts +++ b/apps/meteor/tests/unit/server/federation/infrastructure/rocket-chat/hooks/hooks.spec.ts @@ -279,9 +279,18 @@ describe('Federation - Infrastructure - RocketChat - Hooks', () => { it('should execute the callback when everything is correct', () => { const stub = sinon.stub(); FederationHooks.canCreateDirectMessageFromUI(stub); + isFederationEnabled.returns(true); hooks['federation-v2-can-create-direct-message-from-ui-ce']([]); expect(stub.calledWith([])).to.be.true; }); + + it('should not execute callback or throw error when federation is disabled', () => { + const stub = sinon.stub(); + FederationHooks.canCreateDirectMessageFromUI(stub); + isFederationEnabled.returns(false); + hooks['federation-v2-can-create-direct-message-from-ui-ce']([]); + expect(stub.calledWith([])).to.be.false; + }); }); describe('#afterMessageReacted()', () => {