From 7706edcfffbae327a88d90288bc241ca479e9f90 Mon Sep 17 00:00:00 2001 From: Abhinav Kumar Date: Wed, 2 Oct 2024 00:10:30 +0530 Subject: [PATCH] chore!: remove deprecated livechat:loginByToken method (#33391) Signed-off-by: Abhinav Kumar Co-authored-by: Guilherme Gazzo --- .changeset/grumpy-weeks-appear.md | 5 ++ apps/meteor/app/livechat/server/index.ts | 1 - .../livechat/server/methods/loginByToken.ts | 28 -------- .../api/livechat/methods/loginByToken.ts | 66 ------------------- 4 files changed, 5 insertions(+), 95 deletions(-) create mode 100644 .changeset/grumpy-weeks-appear.md delete mode 100644 apps/meteor/app/livechat/server/methods/loginByToken.ts delete mode 100644 apps/meteor/tests/end-to-end/api/livechat/methods/loginByToken.ts diff --git a/.changeset/grumpy-weeks-appear.md b/.changeset/grumpy-weeks-appear.md new file mode 100644 index 000000000000..3253870b84e4 --- /dev/null +++ b/.changeset/grumpy-weeks-appear.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': major +--- + +Removed deprecated method `livechat:loginByToken`. Moving forward, use the endpoint `livechat/visitor/:token`. diff --git a/apps/meteor/app/livechat/server/index.ts b/apps/meteor/app/livechat/server/index.ts index 7716abcf80de..0405d6fb6609 100644 --- a/apps/meteor/app/livechat/server/index.ts +++ b/apps/meteor/app/livechat/server/index.ts @@ -27,7 +27,6 @@ import './methods/getAnalyticsChartData'; import './methods/getAnalyticsOverviewData'; import './methods/getNextAgent'; import './methods/getRoutingConfig'; -import './methods/loginByToken'; import './methods/pageVisited'; import './methods/registerGuest'; import './methods/removeAgent'; diff --git a/apps/meteor/app/livechat/server/methods/loginByToken.ts b/apps/meteor/app/livechat/server/methods/loginByToken.ts deleted file mode 100644 index 3b82413e038a..000000000000 --- a/apps/meteor/app/livechat/server/methods/loginByToken.ts +++ /dev/null @@ -1,28 +0,0 @@ -import type { ServerMethods } from '@rocket.chat/ddp-client'; -import { LivechatVisitors } from '@rocket.chat/models'; -import { Meteor } from 'meteor/meteor'; - -import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger'; - -declare module '@rocket.chat/ddp-client' { - // eslint-disable-next-line @typescript-eslint/naming-convention - interface ServerMethods { - 'livechat:loginByToken'(token: string): { _id: string } | undefined; - } -} - -Meteor.methods({ - async 'livechat:loginByToken'(token) { - methodDeprecationLogger.method('livechat:loginByToken', '7.0.0'); - check(token, String); - const visitor = await LivechatVisitors.getVisitorByToken(token, { projection: { _id: 1 } }); - - if (!visitor) { - return; - } - - return { - _id: visitor._id, - }; - }, -}); diff --git a/apps/meteor/tests/end-to-end/api/livechat/methods/loginByToken.ts b/apps/meteor/tests/end-to-end/api/livechat/methods/loginByToken.ts deleted file mode 100644 index be6fee9144d8..000000000000 --- a/apps/meteor/tests/end-to-end/api/livechat/methods/loginByToken.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { ILivechatAgent, ILivechatVisitor, IOmnichannelRoom } from '@rocket.chat/core-typings'; -import { expect } from 'chai'; -import { before, describe, it, after } from 'mocha'; -import type { Response } from 'supertest'; - -import { getCredentials, request, methodCallAnon, credentials } from '../../../../data/api-data'; -import { - closeOmnichannelRoom, - createAgent, - makeAgentAvailable, - sendMessage, - startANewLivechatRoomAndTakeIt, -} from '../../../../data/livechat/rooms'; -import { removeAgent } from '../../../../data/livechat/users'; -import { updateSetting } from '../../../../data/permissions.helper'; -import { adminUsername } from '../../../../data/user'; - -describe('livechat:loginByTokens', function () { - let visitor: ILivechatVisitor; - let agent: ILivechatAgent; - let room: IOmnichannelRoom; - - this.retries(0); - - before((done) => getCredentials(done)); - - before(async () => { - await updateSetting('Livechat_enabled', true); - agent = await createAgent(adminUsername); - await makeAgentAvailable(credentials); - }); - - before('open livechat room', async () => { - const data = await startANewLivechatRoomAndTakeIt(); - visitor = data.visitor; - room = data.room; - await sendMessage(data.room._id, 'Hello from visitor!', visitor.token); - }); - - after('remove agent and close room', async () => { - await closeOmnichannelRoom(room._id); - await removeAgent(agent._id); - }); - - describe('loginByTokens', async () => { - it('prevent getting arbitrary visitor id using regex in params', async () => { - await request - .post(methodCallAnon('livechat:loginByToken')) - .send({ - message: JSON.stringify({ - msg: 'method', - id: 'id1', - method: 'livechat:loginByToken', - params: [{ $regex: `.*` }], - }), - }) - .expect(200) - .expect((res: Response) => { - expect(res.body).to.have.property('success', true); - const parsedBody = JSON.parse(res.body.message); - expect(parsedBody).to.have.property('error'); - expect(parsedBody).to.not.have.property('result'); - }); - }); - }); -});