From 203304782f05216373e07b31df0c9153ad67b4bb Mon Sep 17 00:00:00 2001 From: Matheus Barbosa Silva <36537004+matheusbsilva137@users.noreply.github.com> Date: Fri, 1 Sep 2023 12:10:12 -0300 Subject: [PATCH] fix: new `overrideDestinationChannelEnabled` param in integrations' endpoints is required (#30202) Co-authored-by: Gabriel Casals <83978645+casalsgh@users.noreply.github.com> --- .changeset/chilled-phones-give.md | 7 ++++++ .../incoming/addIncomingIntegration.ts | 3 ++- .../incoming/updateIncomingIntegration.ts | 4 ++- .../api/07-incoming-integrations.js | 25 +++++++++++++++++++ packages/core-typings/src/IIntegration.ts | 2 +- .../integrations/IntegrationsCreateProps.ts | 4 +-- .../integrations/IntegrationsUpdateProps.ts | 12 +++------ 7 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 .changeset/chilled-phones-give.md diff --git a/.changeset/chilled-phones-give.md b/.changeset/chilled-phones-give.md new file mode 100644 index 000000000000..cb0887db0883 --- /dev/null +++ b/.changeset/chilled-phones-give.md @@ -0,0 +1,7 @@ +--- +"@rocket.chat/meteor": patch +"@rocket.chat/core-typings": patch +"@rocket.chat/rest-typings": patch +--- + +Fixed `overrideDestinationChannelEnabled` treated as a required param in `integrations.create` and `integration.update` endpoints diff --git a/apps/meteor/app/integrations/server/methods/incoming/addIncomingIntegration.ts b/apps/meteor/app/integrations/server/methods/incoming/addIncomingIntegration.ts index 307e83f7aef7..bf84957ba8ea 100644 --- a/apps/meteor/app/integrations/server/methods/incoming/addIncomingIntegration.ts +++ b/apps/meteor/app/integrations/server/methods/incoming/addIncomingIntegration.ts @@ -32,7 +32,7 @@ export const addIncomingIntegration = async (userId: string, integration: INewIn alias: Match.Maybe(String), emoji: Match.Maybe(String), scriptEnabled: Boolean, - overrideDestinationChannelEnabled: Boolean, + overrideDestinationChannelEnabled: Match.Maybe(Boolean), script: Match.Maybe(String), avatar: Match.Maybe(String), }), @@ -92,6 +92,7 @@ export const addIncomingIntegration = async (userId: string, integration: INewIn ...integration, type: 'webhook-incoming', channel: channels, + overrideDestinationChannelEnabled: integration.overrideDestinationChannelEnabled ?? false, token: Random.id(48), userId: user._id, _createdAt: new Date(), diff --git a/apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts b/apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts index 5e5fe67f3977..b865c72e0cca 100644 --- a/apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts +++ b/apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts @@ -171,7 +171,9 @@ Meteor.methods({ script: integration.script, scriptEnabled: integration.scriptEnabled, }), - overrideDestinationChannelEnabled: integration.overrideDestinationChannelEnabled, + ...(typeof integration.overrideDestinationChannelEnabled !== 'undefined' && { + overrideDestinationChannelEnabled: integration.overrideDestinationChannelEnabled, + }), _updatedAt: new Date(), _updatedBy: await Users.findOne({ _id: this.userId }, { projection: { username: 1 } }), }, diff --git a/apps/meteor/tests/end-to-end/api/07-incoming-integrations.js b/apps/meteor/tests/end-to-end/api/07-incoming-integrations.js index 683cdb2e331b..b6eff60393e5 100644 --- a/apps/meteor/tests/end-to-end/api/07-incoming-integrations.js +++ b/apps/meteor/tests/end-to-end/api/07-incoming-integrations.js @@ -144,6 +144,31 @@ describe('[Incoming Integrations]', function () { }); }); + it('should set overrideDestinationChannelEnabled setting to false when it is not provided', async () => { + let integrationId; + await request + .post(api('integrations.create')) + .set(credentials) + .send({ + type: 'webhook-incoming', + name: 'Incoming test', + enabled: true, + alias: 'test', + username: 'rocket.cat', + scriptEnabled: false, + channel: '#general', + }) + .expect('Content-Type', 'application/json') + .expect(200) + .expect((res) => { + expect(res.body).to.have.property('success', true); + expect(res.body).to.have.property('integration').and.to.be.an('object'); + expect(res.body.integration).to.have.property('overrideDestinationChannelEnabled', false); + integrationId = res.body.integration._id; + }); + await removeIntegration(integrationId, 'incoming'); + }); + it('should add the integration successfully when the user ONLY has the permission "manage-own-incoming-integrations" to add an incoming integration', (done) => { updatePermission('manage-incoming-integrations', []).then(() => { updatePermission('manage-own-incoming-integrations', ['admin']).then(() => { diff --git a/packages/core-typings/src/IIntegration.ts b/packages/core-typings/src/IIntegration.ts index 5f31c9f7879a..6b99424264b2 100644 --- a/packages/core-typings/src/IIntegration.ts +++ b/packages/core-typings/src/IIntegration.ts @@ -10,7 +10,6 @@ export interface IIncomingIntegration extends IRocketChatRecord { channel: string[]; token: string; - overrideDestinationChannelEnabled: boolean; scriptEnabled: boolean; script: string; scriptCompiled?: string; @@ -19,6 +18,7 @@ export interface IIncomingIntegration extends IRocketChatRecord { name: string; enabled: boolean; + overrideDestinationChannelEnabled?: boolean; alias?: string; avatar?: string; emoji?: string; diff --git a/packages/rest-typings/src/v1/integrations/IntegrationsCreateProps.ts b/packages/rest-typings/src/v1/integrations/IntegrationsCreateProps.ts index 2817d4beb0cf..e9ef650656cd 100644 --- a/packages/rest-typings/src/v1/integrations/IntegrationsCreateProps.ts +++ b/packages/rest-typings/src/v1/integrations/IntegrationsCreateProps.ts @@ -8,7 +8,7 @@ export type IntegrationsCreateProps = type: 'webhook-incoming'; username: string; channel: string; - overrideDestinationChannelEnabled: boolean; + overrideDestinationChannelEnabled?: boolean; scriptEnabled: boolean; script?: string; name: string; @@ -70,7 +70,7 @@ const integrationsCreateSchema = { }, overrideDestinationChannelEnabled: { type: 'boolean', - nullable: false, + nullable: true, }, script: { type: 'string', diff --git a/packages/rest-typings/src/v1/integrations/IntegrationsUpdateProps.ts b/packages/rest-typings/src/v1/integrations/IntegrationsUpdateProps.ts index 7237b73fdcc3..6b0e7ce046d1 100644 --- a/packages/rest-typings/src/v1/integrations/IntegrationsUpdateProps.ts +++ b/packages/rest-typings/src/v1/integrations/IntegrationsUpdateProps.ts @@ -9,7 +9,7 @@ export type IntegrationsUpdateProps = integrationId: string; channel: string; scriptEnabled: boolean; - overrideDestinationChannelEnabled: boolean; + overrideDestinationChannelEnabled?: boolean; script?: string; name: string; enabled: boolean; @@ -72,7 +72,7 @@ const integrationsUpdateSchema = { }, overrideDestinationChannelEnabled: { type: 'boolean', - nullable: false, + nullable: true, }, script: { type: 'string', @@ -99,7 +99,7 @@ const integrationsUpdateSchema = { nullable: true, }, }, - required: ['integrationId', 'type', 'channel', 'scriptEnabled', 'overrideDestinationChannelEnabled', 'name', 'enabled'], + required: ['integrationId', 'type', 'channel', 'scriptEnabled', 'name', 'enabled'], additionalProperties: true, }, { @@ -162,10 +162,6 @@ const integrationsUpdateSchema = { type: 'boolean', nullable: false, }, - overrideDestinationChannelEnabled: { - type: 'boolean', - nullable: false, - }, script: { type: 'string', nullable: true, @@ -211,7 +207,7 @@ const integrationsUpdateSchema = { nullable: true, }, }, - required: ['type', 'username', 'channel', 'event', 'scriptEnabled', 'overrideDestinationChannelEnabled', 'name', 'enabled'], + required: ['type', 'username', 'channel', 'event', 'scriptEnabled', 'name', 'enabled'], additionalProperties: false, }, ],