Skip to content

Commit

Permalink
chore!: remove deprecated endpoint livechat/room.visitor (#33461)
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinavkrin committed Oct 25, 2024
1 parent 10b4693 commit 3d45d98
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 131 deletions.
6 changes: 6 additions & 0 deletions .changeset/young-maps-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@rocket.chat/rest-typings': major
'@rocket.chat/meteor': major
---

Removes deprecated endpoint `livechat/room.visitor`.
45 changes: 1 addition & 44 deletions apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
isPOSTLivechatRoomTransferParams,
isPOSTLivechatRoomSurveyParams,
isLiveChatRoomJoinProps,
isPUTLivechatRoomVisitorParams,
isLiveChatRoomSaveInfoProps,
isPOSTLivechatRoomCloseByUserParams,
} from '@rocket.chat/rest-typings';
Expand All @@ -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';
Expand All @@ -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);

Expand Down Expand Up @@ -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 },
Expand Down
59 changes: 0 additions & 59 deletions apps/meteor/tests/end-to-end/api/livechat/09-visitors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', []);
Expand Down
28 changes: 0 additions & 28 deletions packages/rest-typings/src/v1/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2382,31 +2382,6 @@ const POSTLivechatRoomSurveyParamsSchema = {

export const isPOSTLivechatRoomSurveyParams = ajv.compile<POSTLivechatRoomSurveyParams>(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<PUTLivechatRoomVisitorParams>(PUTLivechatRoomVisitorParamsSchema);

type POSTCannedResponsesProps = {
_id?: string;
shortcut: string;
Expand Down Expand Up @@ -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[] }>;
};
Expand Down

0 comments on commit 3d45d98

Please sign in to comment.