From bc168bfffc37c367a5e3eb8dd930f9460d4fd3f6 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Fri, 4 Oct 2024 00:10:59 +0530 Subject: [PATCH] chore!: removed deprecated methods livechat:saveTrigger livechat:removeTrigger Signed-off-by: Abhinav Kumar --- .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 | 49 +++++++++---------- 5 files changed, 29 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 38462ef56c844..c2df2d0e8c942 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -33,7 +33,6 @@ import './methods/removeAllClosedRooms'; import './methods/removeCustomField'; import './methods/removeDepartment'; import './methods/removeManager'; -import './methods/removeTrigger'; import './methods/removeRoom'; import './methods/saveAgentInfo'; import './methods/saveAppearance'; @@ -43,7 +42,6 @@ import './methods/saveDepartmentAgents'; import './methods/saveInfo'; import './methods/saveIntegration'; import './methods/saveSurveyFeedback'; -import './methods/saveTrigger'; import './methods/sendMessageLivechat'; import './methods/sendFileLivechatMessage'; import './methods/sendOfflineMessage'; 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..f1f1f70dfecc5 100644 --- a/apps/meteor/tests/data/livechat/triggers.ts +++ b/apps/meteor/tests/data/livechat/triggers.ts @@ -1,39 +1,38 @@ 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(), + }, + ], + }) + .expect((res) => { + console.log(res.body); }) .end((err: Error, _res: DummyResponse) => { if (err) {