Skip to content

Commit

Permalink
why
Browse files Browse the repository at this point in the history
  • Loading branch information
KevLehman committed Oct 23, 2023
1 parent 88030af commit a23961c
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 27 deletions.
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/api/v1/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/api/v1/transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/api/v1/videoCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/hooks/checkMAC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/Livechat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/app/livechat/server/lib/RoutingManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/methods/returnAsInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Meteor.methods<ServerMethods>({
});
}

if (!(await Omnichannel.isRoomEnabled(room))) {
if (!(await Omnichannel.isWithinMACLimit(room))) {
throw new Meteor.Error('error-mac-limit-reached', 'MAC limit reached', { method: 'livechat:returnAsInquiry' });
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/methods/takeInquiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/livechat/server/methods/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Meteor.methods<ServerMethods>({
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' });
}

Expand Down
6 changes: 1 addition & 5 deletions apps/meteor/client/hooks/useLicense.ts
Original file line number Diff line number Diff line change
@@ -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<OperationResult<'GET', '/v1/licenses.info'>> => {
const getLicenses = useEndpoint('GET', '/v1/licenses.info');
const canViewLicense = usePermission('view-privileged-setting');

const queryClient = useQueryClient();

Expand All @@ -26,9 +25,6 @@ export const useLicense = (): UseQueryResult<OperationResult<'GET', '/v1/license
return useQuery(
['licenses', 'getLicenses'],
() => {
if (!canViewLicense) {
throw new Error('unauthorized api call');
}
return getLicenses({});
},
{
Expand Down
6 changes: 1 addition & 5 deletions apps/meteor/server/services/omnichannel/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,8 @@ export class OmnichannelService extends ServiceClassInternal implements IOmnicha
return this.queueWorker;
}

async isRoomEnabled(room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean> {
async isWithinMACLimit(room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean> {
const currentMonth = moment.utc().format('YYYY-MM');
return room.v?.activity?.includes(currentMonth) || !(await License.shouldPreventAction('monthlyActiveContacts'));
}

async checkMACLimit(): Promise<boolean> {
return !(await License.shouldPreventAction('monthlyActiveContacts'));
}
}
2 changes: 1 addition & 1 deletion ee/packages/license/src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { verify, sign, getPairs } from '@rocket.chat/jwt';
import type { ILicenseV3 } from './definition/ILicenseV3';

const PUBLIC_LICENSE_KEY_V2 =
'LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQ0lqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FnOEFNSUlDQ2dLQ0FnRUFxV1Nza2Q5LzZ6Ung4a3lQY2ljcwpiMzJ3Mnd4VnV3N3lCVDk2clEvOEQreU1lQ01POXdTU3BIYS85bkZ5d293RXRpZ3B0L3dyb1BOK1ZHU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BCYxKqyycqu1AjzJSr4b6y2rWIU3oz1sfD8daDKUOLLlAyeYvlmCAcJdGkVyMr6bJnN418T0lNrl2CCrWq8lV/JsLciuo0TGBCHS2SdNjKmDjKA7MRufPcMVjb4oSmGbNBcTm68/l1SP+bnl00EnPAgD1iunlxba1KgWGXINqB2koFkbbH2VAiztX1Z7MERhEGz7BStXGBNFtpdGrhSzUQIDAQAB-----END PUBLIC KEY-----';

const PUBLIC_LICENSE_KEY_V3 = PUBLIC_LICENSE_KEY_V2;

Expand Down
3 changes: 1 addition & 2 deletions packages/core-services/src/types/IOmnichannelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import type { IServiceClass } from './ServiceClass';

export interface IOmnichannelService extends IServiceClass {
getQueueWorker(): IOmnichannelQueue;
isRoomEnabled(_room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean>;
checkMACLimit(): Promise<boolean>;
isWithinMACLimit(_room: AtLeast<IOmnichannelRoom, 'v'>): Promise<boolean>;
}

0 comments on commit a23961c

Please sign in to comment.