From afa20a95dc2ef3807fb09b08c45e5c0ecd218557 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Fri, 11 Oct 2024 21:51:18 +0530 Subject: [PATCH] chore!: remove deprecated livechat:saveTrigger and livechat:removeTrigger method (#33429) --- .changeset/hot-socks-play.md | 5 ++ apps/meteor/app/livechat/server/index.ts | 2 - .../livechat/server/methods/removeTrigger.ts | 33 ------------- .../livechat/server/methods/saveTrigger.ts | 45 ------------------ apps/meteor/tests/data/livechat/triggers.ts | 46 +++++++++---------- 5 files changed, 26 insertions(+), 105 deletions(-) create mode 100644 .changeset/hot-socks-play.md delete mode 100644 apps/meteor/app/livechat/server/methods/removeTrigger.ts delete mode 100644 apps/meteor/app/livechat/server/methods/saveTrigger.ts diff --git a/.changeset/hot-socks-play.md b/.changeset/hot-socks-play.md new file mode 100644 index 0000000000000..7d441eb5ffd22 --- /dev/null +++ b/.changeset/hot-socks-play.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': major +--- + +Removed deprecated methods `livechat:saveTrigger` and `livechat:removeTrigger`. Moving forward use the endpoints `livechat/triggers (POST)` and `livechat/triggers/:_id (DELETE)` respectively. diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index b21bc048c254f..993d522f298fc 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -26,13 +26,11 @@ import './methods/getRoutingConfig'; import './methods/registerGuest'; import './methods/removeAllClosedRooms'; import './methods/removeCustomField'; -import './methods/removeTrigger'; import './methods/removeRoom'; import './methods/saveAgentInfo'; import './methods/saveCustomField'; import './methods/saveDepartment'; import './methods/saveDepartmentAgents'; -import './methods/saveTrigger'; import './methods/sendMessageLivechat'; import './methods/sendFileLivechatMessage'; import './methods/setDepartmentForVisitor'; diff --git a/apps/meteor/app/livechat/server/methods/removeTrigger.ts b/apps/meteor/app/livechat/server/methods/removeTrigger.ts deleted file mode 100644 index 41d79d7251768..0000000000000 --- a/apps/meteor/app/livechat/server/methods/removeTrigger.ts +++ /dev/null @@ -1,33 +0,0 @@ -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { LivechatTrigger } from '@rocket.chat/models'; -import { check } from 'meteor/check'; -import { Meteor } from 'meteor/meteor'; - -import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:removeTrigger'(triggerId: string): boolean; - } -} - -Meteor.methods({ - async 'livechat:removeTrigger'(triggerId) { - methodDeprecationLogger.method('livechat:removeTrigger', '7.0.0'); - - const uid = Meteor.userId(); - if (!uid || !(await hasPermissionAsync(uid, 'view-livechat-manager'))) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { - method: 'livechat:removeTrigger', - }); - } - - check(triggerId, String); - - await LivechatTrigger.removeById(triggerId); - - return true; - }, -}); diff --git a/apps/meteor/app/livechat/server/methods/saveTrigger.ts b/apps/meteor/app/livechat/server/methods/saveTrigger.ts deleted file mode 100644 index 850dead9a5898..0000000000000 --- a/apps/meteor/app/livechat/server/methods/saveTrigger.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { ILivechatTrigger } from '@rocket.chat/core-typings'; -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { LivechatTrigger } from '@rocket.chat/models'; -import { Match, check } from 'meteor/check'; -import { Meteor } from 'meteor/meteor'; - -import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:saveTrigger'(trigger: ILivechatTrigger): boolean; - } -} - -Meteor.methods({ - async 'livechat:saveTrigger'(trigger) { - methodDeprecationLogger.method('livechat:saveTrigger', '7.0.0'); - const uid = Meteor.userId(); - if (!uid || !(await hasPermissionAsync(uid, 'view-livechat-manager'))) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { - method: 'livechat:saveTrigger', - }); - } - - check(trigger, { - _id: Match.Maybe(String), - name: String, - description: String, - enabled: Boolean, - runOnce: Boolean, - conditions: Array, - actions: Array, - }); - - if (trigger._id) { - await LivechatTrigger.updateById(trigger._id, trigger); - return true; - } - await LivechatTrigger.insertOne(trigger); - - return true; - }, -}); diff --git a/apps/meteor/tests/data/livechat/triggers.ts b/apps/meteor/tests/data/livechat/triggers.ts index 4c8905a50825a..6c1798ba64cfd 100644 --- a/apps/meteor/tests/data/livechat/triggers.ts +++ b/apps/meteor/tests/data/livechat/triggers.ts @@ -1,39 +1,35 @@ import { faker } from '@faker-js/faker'; import type { ILivechatTrigger } from '@rocket.chat/core-typings'; -import { api, credentials, methodCall, request } from '../api-data'; +import { api, credentials, request } from '../api-data'; import type { DummyResponse } from './utils'; export const createTrigger = (name: string): Promise => { return new Promise((resolve, reject) => { void request - .post(methodCall(`livechat:saveTrigger`)) + .post(api('livechat/triggers')) .set(credentials) .send({ - message: JSON.stringify({ - method: 'livechat:saveTrigger', - params: [ - { - name, - description: faker.lorem.sentence(), - enabled: true, - runOnce: faker.datatype.boolean(), - actions: [ - { - name: 'send-message', - params: { - msg: faker.lorem.sentence(), - name: faker.person.firstName(), - sender: faker.helpers.arrayElement(['queue', 'custom']), - }, - }, - ], - conditions: [{ name: faker.lorem.word(), value: faker.number.int() }], + name, + description: faker.lorem.sentence(), + enabled: true, + runOnce: faker.datatype.boolean(), + actions: [ + { + name: 'send-message', + params: { + msg: faker.lorem.sentence(), + name: faker.person.firstName(), + sender: faker.helpers.arrayElement(['queue', 'custom']), }, - ], - id: '101', - msg: 'method', - }), + }, + ], + conditions: [ + { + name: faker.helpers.arrayElement(['time-on-site', 'page-url', 'chat-opened-by-visitor', 'after-guest-registration']), + value: faker.string.alpha(), + }, + ], }) .end((err: Error, _res: DummyResponse) => { if (err) {