From a23961c7f9236235afefdff3fe35df77a41ea35d Mon Sep 17 00:00:00 2001 From: Kevin Aleman Date: Mon, 23 Oct 2023 11:33:39 -0600 Subject: [PATCH] why --- apps/meteor/app/livechat/server/api/v1/room.ts | 4 ++-- apps/meteor/app/livechat/server/api/v1/transcript.ts | 2 +- apps/meteor/app/livechat/server/api/v1/videoCall.ts | 4 ++-- apps/meteor/app/livechat/server/hooks/checkMAC.ts | 2 +- apps/meteor/app/livechat/server/lib/Livechat.js | 2 +- apps/meteor/app/livechat/server/lib/LivechatTyped.ts | 2 +- apps/meteor/app/livechat/server/lib/QueueManager.ts | 2 +- apps/meteor/app/livechat/server/lib/RoutingManager.ts | 4 ++-- apps/meteor/app/livechat/server/methods/returnAsInquiry.ts | 2 +- apps/meteor/app/livechat/server/methods/takeInquiry.ts | 2 +- apps/meteor/app/livechat/server/methods/transfer.ts | 2 +- apps/meteor/client/hooks/useLicense.ts | 6 +----- apps/meteor/server/services/omnichannel/service.ts | 6 +----- ee/packages/license/src/token.ts | 2 +- packages/core-services/src/types/IOmnichannelService.ts | 3 +-- 15 files changed, 18 insertions(+), 27 deletions(-) diff --git a/apps/meteor/app/livechat/server/api/v1/room.ts b/apps/meteor/app/livechat/server/api/v1/room.ts index 33aaa5c77dadc..b4779ce9e7bef 100644 --- a/apps/meteor/app/livechat/server/api/v1/room.ts +++ b/apps/meteor/app/livechat/server/api/v1/room.ts @@ -327,7 +327,7 @@ API.v1.addRoute( throw new Error('This_conversation_is_already_closed'); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } @@ -417,7 +417,7 @@ API.v1.addRoute( throw new Error('error-invalid-room'); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/api/v1/transcript.ts b/apps/meteor/app/livechat/server/api/v1/transcript.ts index ca9ddd38046ec..c32ecaff34159 100644 --- a/apps/meteor/app/livechat/server/api/v1/transcript.ts +++ b/apps/meteor/app/livechat/server/api/v1/transcript.ts @@ -46,7 +46,7 @@ API.v1.addRoute( throw new Error('error-transcript-not-requested'); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/api/v1/videoCall.ts b/apps/meteor/app/livechat/server/api/v1/videoCall.ts index 7238307f22138..94df06ba418cb 100644 --- a/apps/meteor/app/livechat/server/api/v1/videoCall.ts +++ b/apps/meteor/app/livechat/server/api/v1/videoCall.ts @@ -28,7 +28,7 @@ API.v1.addRoute( throw new Error('invalid-room'); } - if (!(await Omnichannel.isRoomEnabled(room as IOmnichannelRoom))) { + if (!(await Omnichannel.isWithinMACLimit(room as IOmnichannelRoom))) { throw new Error('error-mac-limit-reached'); } @@ -84,7 +84,7 @@ API.v1.addRoute( throw new Error('invalid-room'); } - if (!(await Omnichannel.isRoomEnabled(room as IOmnichannelRoom))) { + if (!(await Omnichannel.isWithinMACLimit(room as IOmnichannelRoom))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/hooks/checkMAC.ts b/apps/meteor/app/livechat/server/hooks/checkMAC.ts index cb9bf5a1c7052..4d0789252b50a 100644 --- a/apps/meteor/app/livechat/server/hooks/checkMAC.ts +++ b/apps/meteor/app/livechat/server/hooks/checkMAC.ts @@ -21,7 +21,7 @@ callbacks.add('beforeSaveMessage', async (message, room) => { return message; } - const canSendMessage = await Omnichannel.isRoomEnabled(room as IOmnichannelRoom); + const canSendMessage = await Omnichannel.isWithinMACLimit(room as IOmnichannelRoom); if (!canSendMessage) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/lib/Livechat.js b/apps/meteor/app/livechat/server/lib/Livechat.js index 007683e7e90b9..2e1a77ca7114e 100644 --- a/apps/meteor/app/livechat/server/lib/Livechat.js +++ b/apps/meteor/app/livechat/server/lib/Livechat.js @@ -411,7 +411,7 @@ export const Livechat = { throw new Meteor.Error('error-transcript-already-requested', 'Transcript already requested'); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/lib/LivechatTyped.ts b/apps/meteor/app/livechat/server/lib/LivechatTyped.ts index 14cf3e23af8a9..a23fd5ef7702e 100644 --- a/apps/meteor/app/livechat/server/lib/LivechatTyped.ts +++ b/apps/meteor/app/livechat/server/lib/LivechatTyped.ts @@ -521,7 +521,7 @@ class LivechatClass { throw new Error('error-invalid-room'); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/lib/QueueManager.ts b/apps/meteor/app/livechat/server/lib/QueueManager.ts index 29ae5b5485781..fffeae4d2f298 100644 --- a/apps/meteor/app/livechat/server/lib/QueueManager.ts +++ b/apps/meteor/app/livechat/server/lib/QueueManager.ts @@ -22,7 +22,7 @@ export const queueInquiry = async (inquiry: ILivechatInquiryRecord, defaultAgent await callbacks.run('livechat.beforeRouteChat', inquiry, inquiryAgent); const room = await LivechatRooms.findOneById(inquiry.rid, { projection: { v: 1 } }); - if (!room || !(await Omnichannel.isRoomEnabled(room))) { + if (!room || !(await Omnichannel.isWithinMACLimit(room))) { logger.error({ msg: 'MAC limit reached, not routing inquiry', inquiry }); // We'll queue these inquiries so when new license is applied, they just start rolling again // Minimizing disruption diff --git a/apps/meteor/app/livechat/server/lib/RoutingManager.ts b/apps/meteor/app/livechat/server/lib/RoutingManager.ts index ca0d46d53d37e..e9c173d86913b 100644 --- a/apps/meteor/app/livechat/server/lib/RoutingManager.ts +++ b/apps/meteor/app/livechat/server/lib/RoutingManager.ts @@ -178,7 +178,7 @@ export const RoutingManager: Routing = { return false; } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } @@ -269,7 +269,7 @@ export const RoutingManager: Routing = { }, async transferRoom(room, guest, transferData) { - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/methods/returnAsInquiry.ts b/apps/meteor/app/livechat/server/methods/returnAsInquiry.ts index 6c4f96e74459f..38b58b9d2d426 100644 --- a/apps/meteor/app/livechat/server/methods/returnAsInquiry.ts +++ b/apps/meteor/app/livechat/server/methods/returnAsInquiry.ts @@ -30,7 +30,7 @@ Meteor.methods({ }); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Meteor.Error('error-mac-limit-reached', 'MAC limit reached', { method: 'livechat:returnAsInquiry' }); } diff --git a/apps/meteor/app/livechat/server/methods/takeInquiry.ts b/apps/meteor/app/livechat/server/methods/takeInquiry.ts index e61f6038ea83a..3433b4a33ae86 100644 --- a/apps/meteor/app/livechat/server/methods/takeInquiry.ts +++ b/apps/meteor/app/livechat/server/methods/takeInquiry.ts @@ -50,7 +50,7 @@ export const takeInquiry = async ( } const room = await LivechatRooms.findOneById(inquiry.rid); - if (!room || !(await Omnichannel.isRoomEnabled(room))) { + if (!room || !(await Omnichannel.isWithinMACLimit(room))) { throw new Error('error-mac-limit-reached'); } diff --git a/apps/meteor/app/livechat/server/methods/transfer.ts b/apps/meteor/app/livechat/server/methods/transfer.ts index 1568dd411a286..64a32c24638c3 100644 --- a/apps/meteor/app/livechat/server/methods/transfer.ts +++ b/apps/meteor/app/livechat/server/methods/transfer.ts @@ -50,7 +50,7 @@ Meteor.methods({ throw new Meteor.Error('room-closed', 'Room closed', { method: 'livechat:transfer' }); } - if (!(await Omnichannel.isRoomEnabled(room))) { + if (!(await Omnichannel.isWithinMACLimit(room))) { throw new Meteor.Error('error-mac-limit-reached', 'MAC limit reached', { method: 'livechat:transfer' }); } diff --git a/apps/meteor/client/hooks/useLicense.ts b/apps/meteor/client/hooks/useLicense.ts index 8ba594c5b5d3c..1be830a101c8c 100644 --- a/apps/meteor/client/hooks/useLicense.ts +++ b/apps/meteor/client/hooks/useLicense.ts @@ -1,13 +1,12 @@ import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; import type { OperationResult } from '@rocket.chat/rest-typings'; -import { useEndpoint, usePermission, useSingleStream } from '@rocket.chat/ui-contexts'; +import { useEndpoint, useSingleStream } from '@rocket.chat/ui-contexts'; import type { UseQueryResult } from '@tanstack/react-query'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useEffect } from 'react'; export const useLicense = (): UseQueryResult> => { const getLicenses = useEndpoint('GET', '/v1/licenses.info'); - const canViewLicense = usePermission('view-privileged-setting'); const queryClient = useQueryClient(); @@ -26,9 +25,6 @@ export const useLicense = (): UseQueryResult { - if (!canViewLicense) { - throw new Error('unauthorized api call'); - } return getLicenses({}); }, { diff --git a/apps/meteor/server/services/omnichannel/service.ts b/apps/meteor/server/services/omnichannel/service.ts index edc720e135ab6..158d97ccee1d7 100644 --- a/apps/meteor/server/services/omnichannel/service.ts +++ b/apps/meteor/server/services/omnichannel/service.ts @@ -61,12 +61,8 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha return this.queueWorker; } - async isRoomEnabled(room: AtLeast): Promise { + async isWithinMACLimit(room: AtLeast): Promise { const currentMonth = moment.utc().format('YYYY-MM'); return room.v?.activity?.includes(currentMonth) || !(await License.shouldPreventAction('monthlyActiveContacts')); } - - async checkMACLimit(): Promise { - return !(await License.shouldPreventAction('monthlyActiveContacts')); - } } diff --git a/ee/packages/license/src/token.ts b/ee/packages/license/src/token.ts index 46daaef83974a..d8117c3018c11 100644 --- a/ee/packages/license/src/token.ts +++ b/ee/packages/license/src/token.ts @@ -5,7 +5,7 @@ import { verify, sign, getPairs } from '@rocket.chat/jwt'; import type { ILicenseV3 } from './definition/ILicenseV3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F3RUFBUT09Ci0tLS0tRU5EIFBVQkxJQyBLRVktLS0tLQo='; + '-----BEGIN PUBLIC KEY-----MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4PZJT08Moo8nKT9eDFYfXkhuAbuhOJyXW8aqGU6iSKGrheIt0Z9FVpY4Wkf/BGUmlCCXTIZEGlixZtMWbHVBfnKgdG285lLufGME1lb7QQi8li4Ij9OcAYf1xdVeCrUrBCYxKqyycqu1AjzJSr4b6y2rWIU3oz1sfD8daDKUOLLlAyeYvlmCAcJdGkVyMr6bJnN418T0lNrl2CCrWq8lV/JsLciuo0TGBCHS2SdNjKmDjKA7MRufPcMVjb4oSmGbNBcTm68/l1SP+bnl00EnPAgD1iunlxba1KgWGXINqB2koFkbbH2VAiztX1Z7MERhEGz7BStXGBNFtpdGrhSzUQIDAQAB-----END PUBLIC KEY-----'; const PUBLIC_LICENSE_KEY_V3 = PUBLIC_LICENSE_KEY_V2; diff --git a/packages/core-services/src/types/IOmnichannelService.ts b/packages/core-services/src/types/IOmnichannelService.ts index a1b2d1a9d9617..73006641c8cdf 100644 --- a/packages/core-services/src/types/IOmnichannelService.ts +++ b/packages/core-services/src/types/IOmnichannelService.ts @@ -4,6 +4,5 @@ import type { IServiceClass } from './ServiceClass'; export interface IOmnichannelService extends IServiceClass { getQueueWorker(): IOmnichannelQueue; - isRoomEnabled(_room: AtLeast): Promise; - checkMACLimit(): Promise; + isWithinMACLimit(_room: AtLeast): Promise; }