From 009f344537fe36d9ec583192ab125504f2a6c694 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Fri, 11 Oct 2024 22:12:48 +0530 Subject: [PATCH] chore!: remove deprecated endpoint livechat/room.visitor (#33461) --- .changeset/young-maps-push.md | 6 ++ .../meteor/app/livechat/server/api/v1/room.ts | 45 +------------- .../end-to-end/api/livechat/09-visitors.ts | 59 ------------------- packages/rest-typings/src/v1/omnichannel.ts | 28 --------- 4 files changed, 7 insertions(+), 131 deletions(-) create mode 100644 .changeset/young-maps-push.md diff --git a/.changeset/young-maps-push.md b/.changeset/young-maps-push.md new file mode 100644 index 000000000000..fb94912e3cc8 --- /dev/null +++ b/.changeset/young-maps-push.md @@ -0,0 +1,6 @@ +--- +'@rocket.chat/rest-typings': major +'@rocket.chat/meteor': major +--- + +Removes deprecated endpoint `livechat/room.visitor`. diff --git a/apps/meteor/app/livechat/server/api/v1/room.ts b/apps/meteor/app/livechat/server/api/v1/room.ts index 7aacfacb4476..45428f683531 100644 --- a/apps/meteor/app/livechat/server/api/v1/room.ts +++ b/apps/meteor/app/livechat/server/api/v1/room.ts @@ -8,7 +8,6 @@ import { isPOSTLivechatRoomTransferParams, isPOSTLivechatRoomSurveyParams, isLiveChatRoomJoinProps, - isPUTLivechatRoomVisitorParams, isLiveChatRoomSaveInfoProps, isPOSTLivechatRoomCloseByUserParams, } from '@rocket.chat/rest-typings'; @@ -18,7 +17,7 @@ import { callbacks } from '../../../../../lib/callbacks'; import { i18n } from '../../../../../server/lib/i18n'; import { API } from '../../../../api/server'; import { isWidget } from '../../../../api/server/helpers/isWidget'; -import { canAccessRoomAsync, roomAccessAttributes } from '../../../../authorization/server'; +import { canAccessRoomAsync } from '../../../../authorization/server'; import { hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission'; import { addUserToRoom } from '../../../../lib/server/functions/addUserToRoom'; import { closeLivechatRoom } from '../../../../lib/server/functions/closeLivechatRoom'; @@ -27,7 +26,6 @@ import { normalizeTransferredByData } from '../../lib/Helper'; import type { CloseRoomParams } from '../../lib/LivechatTyped'; import { Livechat as LivechatTyped } from '../../lib/LivechatTyped'; import { findGuest, findRoom, settings, findAgent, onCheckRoomParams } from '../lib/livechat'; -import { findVisitorInfo } from '../lib/visitors'; const isAgentWithInfo = (agentObj: ILivechatAgent | { hiddenInfo: boolean }): agentObj is ILivechatAgent => !('hiddenInfo' in agentObj); @@ -328,47 +326,6 @@ API.v1.addRoute( }, ); -API.v1.addRoute( - 'livechat/room.visitor', - { - authRequired: true, - permissionsRequired: ['change-livechat-room-visitor'], - validateParams: isPUTLivechatRoomVisitorParams, - deprecation: { - version: '7.0.0', - }, - }, - { - async put() { - // This endpoint is deprecated and will be removed in future versions. - const { rid, newVisitorId, oldVisitorId } = this.bodyParams; - - const { visitor } = await findVisitorInfo({ visitorId: newVisitorId }); - if (!visitor) { - throw new Error('invalid-visitor'); - } - - const room = await LivechatRooms.findOneById(rid, { projection: { ...roomAccessAttributes, _id: 1, t: 1, v: 1 } }); // TODO: check _id - if (!room) { - throw new Error('invalid-room'); - } - - const { v: { _id: roomVisitorId = undefined } = {} } = room; // TODO: v it will be undefined - if (roomVisitorId !== oldVisitorId) { - throw new Error('invalid-room-visitor'); - } - - const roomAfterChange = await LivechatTyped.changeRoomVisitor(this.userId, room, visitor); - - if (!roomAfterChange) { - return API.v1.failure(); - } - - return API.v1.success({ room: roomAfterChange }); - }, - }, -); - API.v1.addRoute( 'livechat/room.join', { authRequired: true, permissionsRequired: ['view-l-room'], validateParams: isLiveChatRoomJoinProps }, diff --git a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts index d3a40999314c..7fe093d708a3 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts @@ -981,66 +981,7 @@ describe('LIVECHAT - visitors', () => { expect(res.body.contact).to.be.null; }); }); - // Check if this endpoint is still being used - describe('livechat/room.visitor', () => { - it('should fail if user doesnt have view-l-room permission', async () => { - await updatePermission('view-l-room', []); - const res = await request.put(api(`livechat/room.visitor`)).set(credentials).send(); - expect(res.body).to.have.property('success', false); - }); - it('should fail if rid is not on body params', async () => { - await updatePermission('view-l-room', ['admin', 'livechat-agent']); - const res = await request.put(api(`livechat/room.visitor`)).set(credentials).send(); - expect(res.body).to.have.property('success', false); - }); - it('should fail if oldVisitorId is not on body params', async () => { - const res = await request.put(api(`livechat/room.visitor`)).set(credentials).send({ rid: 'GENERAL' }); - expect(res.body).to.have.property('success', false); - }); - it('should fail if newVisitorId is not on body params', async () => { - const res = await request.put(api(`livechat/room.visitor`)).set(credentials).send({ rid: 'GENERAL', oldVisitorId: 'GENERAL' }); - expect(res.body).to.have.property('success', false); - }); - it('should fail if oldVisitorId doesnt point to a valid visitor', async () => { - const res = await request - .put(api(`livechat/room.visitor`)) - .set(credentials) - .send({ rid: 'GENERAL', oldVisitorId: 'GENERAL', newVisitorId: 'GENERAL' }); - expect(res.body).to.have.property('success', false); - }); - it('should fail if rid doesnt point to a valid room', async () => { - const visitor = await createVisitor(); - const res = await request - .put(api(`livechat/room.visitor`)) - .set(credentials) - .send({ rid: 'GENERAL', oldVisitorId: visitor._id, newVisitorId: visitor._id }); - expect(res.body).to.have.property('success', false); - }); - it('should fail if oldVisitorId is trying to change a room is not theirs', async () => { - const visitor = await createVisitor(); - const room = await createLivechatRoom(visitor.token); - const visitor2 = await createVisitor(); - const res = await request - .put(api(`livechat/room.visitor`)) - .set(credentials) - .send({ rid: room._id, oldVisitorId: visitor2._id, newVisitorId: visitor._id }); - expect(res.body).to.have.property('success', false); - }); - it('should successfully change a room visitor with a new one', async () => { - const visitor = await createVisitor(); - const room = await createLivechatRoom(visitor.token); - const visitor2 = await createVisitor(); - - const res = await request - .put(api(`livechat/room.visitor`)) - .set(credentials) - .send({ rid: room._id, oldVisitorId: visitor._id, newVisitorId: visitor2._id }); - expect(res.body).to.have.property('success', true); - expect(res.body.room).to.have.property('v'); - expect(res.body.room.v._id).to.equal(visitor2._id); - }); - }); describe('livechat/visitors.search', () => { it('should fail if user doesnt have view-l-room permission', async () => { await updatePermission('view-l-room', []); diff --git a/packages/rest-typings/src/v1/omnichannel.ts b/packages/rest-typings/src/v1/omnichannel.ts index 82df994de1ba..0e2522e5b3ee 100644 --- a/packages/rest-typings/src/v1/omnichannel.ts +++ b/packages/rest-typings/src/v1/omnichannel.ts @@ -2382,31 +2382,6 @@ const POSTLivechatRoomSurveyParamsSchema = { export const isPOSTLivechatRoomSurveyParams = ajv.compile(POSTLivechatRoomSurveyParamsSchema); -type PUTLivechatRoomVisitorParams = { - rid: string; - oldVisitorId: string; - newVisitorId: string; -}; - -const PUTLivechatRoomVisitorParamsSchema = { - type: 'object', - properties: { - rid: { - type: 'string', - }, - oldVisitorId: { - type: 'string', - }, - newVisitorId: { - type: 'string', - }, - }, - required: ['rid', 'oldVisitorId', 'newVisitorId'], - additionalProperties: false, -}; - -export const isPUTLivechatRoomVisitorParams = ajv.compile(PUTLivechatRoomVisitorParamsSchema); - type POSTCannedResponsesProps = { _id?: string; shortcut: string; @@ -3844,9 +3819,6 @@ export type OmnichannelEndpoints = { '/v1/livechat/room.survey': { POST: (params: POSTLivechatRoomSurveyParams) => { rid: string; data: unknown }; }; - '/v1/livechat/room.visitor': { - PUT: (params: PUTLivechatRoomVisitorParams) => Deprecated<{ room: IOmnichannelRoom }>; - }; '/v1/livechat/visitors.pagesVisited/:roomId': { GET: (params: GETLivechatVisitorsPagesVisitedRoomIdParams) => PaginatedResult<{ pages: IMessage[] }>; };