Skip to content

Commit

Permalink
fix: new overrideDestinationChannelEnabled param in integrations' e…
Browse files Browse the repository at this point in the history
…ndpoints is required (#30202)

Co-authored-by: Gabriel Casals <83978645+casalsgh@users.noreply.github.com>
  • Loading branch information
matheusbsilva137 and casalsgh committed Sep 1, 2023
1 parent 459c857 commit 2033047
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
7 changes: 7 additions & 0 deletions .changeset/chilled-phones-give.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ Meteor.methods<ServerMethods>({
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 } }),
},
Expand Down
25 changes: 25 additions & 0 deletions apps/meteor/tests/end-to-end/api/07-incoming-integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-typings/src/IIntegration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface IIncomingIntegration extends IRocketChatRecord {
channel: string[];

token: string;
overrideDestinationChannelEnabled: boolean;
scriptEnabled: boolean;
script: string;
scriptCompiled?: string;
Expand All @@ -19,6 +18,7 @@ export interface IIncomingIntegration extends IRocketChatRecord {
name: string;
enabled: boolean;

overrideDestinationChannelEnabled?: boolean;
alias?: string;
avatar?: string;
emoji?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type IntegrationsCreateProps =
type: 'webhook-incoming';
username: string;
channel: string;
overrideDestinationChannelEnabled: boolean;
overrideDestinationChannelEnabled?: boolean;
scriptEnabled: boolean;
script?: string;
name: string;
Expand Down Expand Up @@ -70,7 +70,7 @@ const integrationsCreateSchema = {
},
overrideDestinationChannelEnabled: {
type: 'boolean',
nullable: false,
nullable: true,
},
script: {
type: 'string',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type IntegrationsUpdateProps =
integrationId: string;
channel: string;
scriptEnabled: boolean;
overrideDestinationChannelEnabled: boolean;
overrideDestinationChannelEnabled?: boolean;
script?: string;
name: string;
enabled: boolean;
Expand Down Expand Up @@ -72,7 +72,7 @@ const integrationsUpdateSchema = {
},
overrideDestinationChannelEnabled: {
type: 'boolean',
nullable: false,
nullable: true,
},
script: {
type: 'string',
Expand All @@ -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,
},
{
Expand Down Expand Up @@ -162,10 +162,6 @@ const integrationsUpdateSchema = {
type: 'boolean',
nullable: false,
},
overrideDestinationChannelEnabled: {
type: 'boolean',
nullable: false,
},
script: {
type: 'string',
nullable: true,
Expand Down Expand Up @@ -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,
},
],
Expand Down

0 comments on commit 2033047

Please sign in to comment.