diff --git a/.changeset/kind-eels-brush.md b/.changeset/kind-eels-brush.md new file mode 100644 index 000000000000..1b82e431a7b1 --- /dev/null +++ b/.changeset/kind-eels-brush.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': major +--- + +Removes deprecated method `livechat:saveInfo`. Moving forward use the enpoint `livechat/room/save.info`. diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 55b69c552f02..ef8fb5067e22 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -39,7 +39,6 @@ import './methods/saveAppearance'; import './methods/saveCustomField'; import './methods/saveDepartment'; import './methods/saveDepartmentAgents'; -import './methods/saveInfo'; import './methods/saveIntegration'; import './methods/saveTrigger'; import './methods/sendMessageLivechat'; diff --git a/apps/meteor/app/livechat/server/methods/saveInfo.ts b/apps/meteor/app/livechat/server/methods/saveInfo.ts deleted file mode 100644 index bb22c127effa..000000000000 --- a/apps/meteor/app/livechat/server/methods/saveInfo.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { isOmnichannelRoom } from '@rocket.chat/core-typings'; -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { LivechatRooms, Users } from '@rocket.chat/models'; -import { Match, check } from 'meteor/check'; -import { Meteor } from 'meteor/meteor'; - -import { callbacks } from '../../../../lib/callbacks'; -import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission'; -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; -import { Livechat as LivechatTyped } from '../lib/LivechatTyped'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:saveInfo'( - guestData: { - _id: string; - name?: string; - email?: string; - phone?: string; - livechatData?: Record; - }, - roomData: { - _id: string; - topic?: string; - tags?: string[]; - livechatData?: Record; - priorityId?: string; - slaId?: string; - }, - ): boolean; - } -} - -Meteor.methods({ - async 'livechat:saveInfo'(guestData, roomData) { - methodDeprecationLogger.method('livechat:saveInfo', '7.0.0', 'Use "livechat/room.saveInfo" endpoint instead.'); - const userId = Meteor.userId(); - - if (!userId || !(await hasPermissionAsync(userId, 'view-l-room'))) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveInfo' }); - } - - check( - guestData, - Match.ObjectIncluding({ - _id: String, - name: Match.Optional(String), - email: Match.Optional(String), - phone: Match.Optional(String), - livechatData: Match.Optional(Object), - }), - ); - - check( - roomData, - Match.ObjectIncluding({ - _id: String, - topic: Match.Optional(String), - tags: Match.Optional([String]), - livechatData: Match.Optional(Object), - priorityId: Match.Optional(String), - slaId: Match.Optional(String), - }), - ); - - const room = await LivechatRooms.findOneById(roomData._id); - if (!room || !isOmnichannelRoom(room)) { - throw new Meteor.Error('error-invalid-room', 'Invalid room', { method: 'livechat:saveInfo' }); - } - - if ((!room.servedBy || room.servedBy._id !== userId) && !(await hasPermissionAsync(userId, 'save-others-livechat-room-info'))) { - throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:saveInfo' }); - } - - if (room.sms) { - delete guestData.phone; - } - - // Since the endpoint is going to be deprecated, we can live with this for a while - // @ts-expect-error - type is right, but `check` converts it to something else - await Promise.allSettled([LivechatTyped.saveGuest(guestData as any, userId), LivechatTyped.saveRoomInfo(roomData)]); - - const user = await Users.findOne({ _id: userId }, { projection: { _id: 1, username: 1 } }); - - setImmediate(async () => { - void callbacks.run('livechat.saveInfo', await LivechatRooms.findOneById(roomData._id), { - user, - oldRoom: room, - }); - }); - - return true; - }, -});