Skip to content

Commit 4ab2b7f

Browse files
chore: Adds deprecation warning on livechat:removeTag with new endpoint to replace it (RocketChat#37136)
1 parent 7997811 commit 4ab2b7f

7 files changed

Lines changed: 90 additions & 7 deletions

File tree

.changeset/shaggy-clocks-allow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@rocket.chat/meteor": patch
3+
"@rocket.chat/rest-typings": patch
4+
---
5+
6+
Adds deprecation warning on `livechat:removeTag` with new endpoint replacing it; `livechat/tags.remove`

apps/meteor/client/omnichannel/tags/useRemoveTag.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { useEffectEvent } from '@rocket.chat/fuselage-hooks';
22
import { GenericModal } from '@rocket.chat/ui-client';
3-
import { useSetModal, useToastMessageDispatch, useRouter, useMethod } from '@rocket.chat/ui-contexts';
3+
import { useSetModal, useToastMessageDispatch, useRouter, useEndpoint } from '@rocket.chat/ui-contexts';
44
import { useQueryClient } from '@tanstack/react-query';
55
import { useTranslation } from 'react-i18next';
66

77
export const useRemoveTag = () => {
88
const { t } = useTranslation();
99
const setModal = useSetModal();
1010
const dispatchToastMessage = useToastMessageDispatch();
11-
const removeTag = useMethod('livechat:removeTag');
11+
const removeTag = useEndpoint('POST', '/v1/livechat/tags.delete');
1212
const queryClient = useQueryClient();
1313
const router = useRouter();
1414

1515
const handleDeleteTag = useEffectEvent((tagId: string) => {
1616
const handleDelete = async () => {
1717
try {
18-
await removeTag(tagId);
18+
await removeTag({ id: tagId });
1919
dispatchToastMessage({ type: 'success', message: t('Tag_removed') });
2020
router.navigate('/omnichannel/tags');
2121
queryClient.invalidateQueries({

apps/meteor/ee/app/livechat-enterprise/server/api/tags.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import {
2+
isPOSTLivechatTagsRemoveParams,
3+
POSTLivechatTagsRemoveSuccessResponse,
4+
validateBadRequestErrorResponse,
5+
validateForbiddenErrorResponse,
6+
validateUnauthorizedErrorResponse,
7+
} from '@rocket.chat/rest-typings';
8+
19
import { findTags, findTagById } from './lib/tags';
210
import { API } from '../../../../../app/api/server';
11+
import type { ExtractRoutesFromAPI } from '../../../../../app/api/server/ApiClass';
312
import { getPaginationItems } from '../../../../../app/api/server/helpers/getPaginationItems';
13+
import { LivechatEnterprise } from '../lib/LivechatEnterprise';
414

515
API.v1.addRoute(
616
'livechat/tags',
@@ -56,3 +66,40 @@ API.v1.addRoute(
5666
},
5767
},
5868
);
69+
70+
const livechatTagsEndpoints = API.v1.post(
71+
'livechat/tags.delete',
72+
{
73+
response: {
74+
200: POSTLivechatTagsRemoveSuccessResponse,
75+
400: validateBadRequestErrorResponse,
76+
401: validateUnauthorizedErrorResponse,
77+
403: validateForbiddenErrorResponse,
78+
},
79+
authRequired: true,
80+
permissions: ['manage-livechat-tags'],
81+
license: ['livechat-enterprise'],
82+
body: isPOSTLivechatTagsRemoveParams,
83+
},
84+
async function action() {
85+
const { id } = this.bodyParams;
86+
try {
87+
await LivechatEnterprise.removeTag(id);
88+
89+
return API.v1.success();
90+
} catch (error: unknown) {
91+
if (error instanceof Meteor.Error) {
92+
return API.v1.failure(error.reason);
93+
}
94+
95+
return API.v1.failure('error-removing-tag');
96+
}
97+
},
98+
);
99+
100+
type LivechatTagsEndpoints = ExtractRoutesFromAPI<typeof livechatTagsEndpoints>;
101+
102+
declare module '@rocket.chat/rest-typings' {
103+
// eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-empty-interface
104+
interface Endpoints extends LivechatTagsEndpoints {}
105+
}

apps/meteor/ee/app/livechat-enterprise/server/methods/removeTag.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { check } from 'meteor/check';
33
import { Meteor } from 'meteor/meteor';
44

55
import { hasPermissionAsync } from '../../../../../app/authorization/server/functions/hasPermission';
6+
import { methodDeprecationLogger } from '../../../../../app/lib/server/lib/deprecationWarningLogger';
67
import { LivechatEnterprise } from '../lib/LivechatEnterprise';
78

89
declare module '@rocket.chat/ddp-client' {
@@ -14,6 +15,7 @@ declare module '@rocket.chat/ddp-client' {
1415

1516
Meteor.methods<ServerMethods>({
1617
async 'livechat:removeTag'(id) {
18+
methodDeprecationLogger.method('livechat:removeTag', '8.0.0', '/v1/livechat/tags.delete');
1719
const uid = Meteor.userId();
1820
if (!uid || !(await hasPermissionAsync(uid, 'manage-livechat-tags'))) {
1921
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'livechat:removeTag' });

apps/meteor/tests/e2e/utils/omnichannel/tags.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ type CreateTagParams = {
1010
departments?: { departmentId: string }[];
1111
};
1212

13-
const removeTag = async (api: BaseTest['api'], id: string) =>
14-
api.post('/method.call/omnichannel:removeTag', {
15-
message: JSON.stringify({ msg: 'method', id: '33', method: 'livechat:removeTag', params: [id] }),
16-
});
13+
const removeTag = async (api: BaseTest['api'], id: string) => api.post('/livechat/tags.delete', { id });
1714

1815
export const createTag = async (api: BaseTest['api'], { id = null, name, description = '', departments = [] }: CreateTagParams = {}) => {
1916
const response = await api.post('/method.call/livechat:saveTag', {

packages/i18n/src/locales/en.i18n.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6232,6 +6232,7 @@
62326232
"error-invalid-user": "Invalid user",
62336233
"error-invalid-username": "Invalid username",
62346234
"error-invalid-value": "Invalid value",
6235+
"error-removing-tag": "Error removing tag",
62356236
"error-invalid-webhook-response": "The webhook URL responded with a status other than 200",
62366237
"error-license-user-limit-reached": "The maximum number of users has been reached.",
62376238
"error-loading-extension-list": "Failed to load extension list",

packages/rest-typings/src/v1/omnichannel.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,36 @@ const LivechatMonitorsListSchema = {
513513

514514
export const isLivechatMonitorsListProps = ajv.compile<LivechatMonitorsListProps>(LivechatMonitorsListSchema);
515515

516+
type POSTLivechatTagsRemoveParams = {
517+
id: string;
518+
};
519+
520+
const POSTLivechatTagsRemoveSchema = {
521+
type: 'object',
522+
properties: {
523+
id: {
524+
type: 'string',
525+
},
526+
},
527+
required: ['id'],
528+
additionalProperties: false,
529+
};
530+
531+
export const isPOSTLivechatTagsRemoveParams = ajv.compile<POSTLivechatTagsRemoveParams>(POSTLivechatTagsRemoveSchema);
532+
533+
const POSTLivechatTagsRemoveSuccessResponseSchema = {
534+
type: 'object',
535+
properties: {
536+
success: {
537+
type: 'boolean',
538+
enum: [true],
539+
},
540+
},
541+
additionalProperties: false,
542+
};
543+
544+
export const POSTLivechatTagsRemoveSuccessResponse = ajv.compile<void>(POSTLivechatTagsRemoveSuccessResponseSchema);
545+
516546
type LivechatTagsListProps = PaginatedRequest<{ text: string; viewAll?: 'true' | 'false'; department?: string }, 'name'>;
517547

518548
const LivechatTagsListSchema = {

0 commit comments

Comments
 (0)