fix: new `overrideDestinationChannelEnabled` param in integrations' endpoints is required (#30202)

Co-authored-by: Gabriel Casals <83978645+casalsgh@users.noreply.github.com>
pull/30233/head
Matheus Barbosa Silva 3 years ago committed by GitHub
parent 459c8574ed
commit 203304782f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      .changeset/chilled-phones-give.md
  2. 3
      apps/meteor/app/integrations/server/methods/incoming/addIncomingIntegration.ts
  3. 4
      apps/meteor/app/integrations/server/methods/incoming/updateIncomingIntegration.ts
  4. 25
      apps/meteor/tests/end-to-end/api/07-incoming-integrations.js
  5. 2
      packages/core-typings/src/IIntegration.ts
  6. 4
      packages/rest-typings/src/v1/integrations/IntegrationsCreateProps.ts
  7. 12
      packages/rest-typings/src/v1/integrations/IntegrationsUpdateProps.ts

@ -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

@ -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(),

@ -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 } }),
},

@ -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(() => {

@ -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;

@ -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',

@ -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,
},
],

Loading…
Cancel
Save