Skip to content

Commit

Permalink
Merge branch 'develop' into update-gitpod-config
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Dec 27, 2024
2 parents 986975a + e229533 commit 02b2292
Show file tree
Hide file tree
Showing 2,042 changed files with 2,598 additions and 3,562 deletions.
7 changes: 7 additions & 0 deletions .changeset/beige-kiwis-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": minor
"@rocket.chat/livechat": minor
"@rocket.chat/model-typings": minor
---

Added `departmentsAllowedToForward` property to departments returned in the `livechat/config` endpoint
5 changes: 5 additions & 0 deletions .changeset/healthy-coins-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixes an issue where changing user role in a room displays the wrong message
6 changes: 6 additions & 0 deletions .changeset/popular-cameras-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/model-typings": patch
---

Fixes livechat conversations not being assigned to the contact manager even when the "Assign new conversations to the contact manager" setting is enabled
10 changes: 10 additions & 0 deletions .changeset/quick-rivers-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@rocket.chat/meteor": patch
---

Fixes dates being incorrect when fetching omnichannel reports with the following time periods:

last week
last month
last 6 months
last year
1 change: 0 additions & 1 deletion .vscode/client.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"prefix": "sbmodule",
"body": [
"import type { Meta, StoryFn } from '@storybook/react';",
"import React from 'react';",
"",
"import $1 from './$1';",
"",
Expand Down
3 changes: 1 addition & 2 deletions _templates/service/new/service.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
to: ee/apps/<%= name %>/src/service.ts
---
import { api, getConnection, getTrashCollection } from '@rocket.chat/core-services';
import { registerServiceModels } from '@rocket.chat/models';
import { broker } from '@rocket.chat/network-broker';
import { startTracing } from '@rocket.chat/tracing';
import polka from 'polka';

import { registerServiceModels } from '../../../../apps/meteor/ee/server/lib/registerServiceModels';

const PORT = process.env.PORT || <%= h.random() %>;

(async () => {
Expand Down
8 changes: 8 additions & 0 deletions apps/meteor/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
}
]
],
"plugins": [
[
"@babel/plugin-transform-react-jsx",
{
"runtime": "automatic"
}
]
],
"env": {
"coverage": {
"plugins": [
Expand Down
1 change: 0 additions & 1 deletion apps/meteor/.storybook/decorators.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { mockAppRoot } from '@rocket.chat/mock-providers';
import type { Decorator } from '@storybook/react';
import React from 'react';

import ModalContextMock from '../client/stories/contexts/ModalContextMock';
import RouterContextMock from '../client/stories/contexts/RouterContextMock';
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { isRoleAddUserToRoleProps, isRoleDeleteProps, isRoleRemoveUserFromRolePr
import { check, Match } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import { removeUserFromRolesAsync } from '../../../../server/lib/roles/removeUserFromRoles';
import { getUsersInRolePaginated } from '../../../authorization/server/functions/getUsersInRole';
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { hasRoleAsync, hasAnyRoleAsync } from '../../../authorization/server/functions/hasRole';
Expand Down Expand Up @@ -221,7 +222,7 @@ API.v1.addRoute(
}
}

await Roles.removeUserRoles(user._id, [role._id], scope);
await removeUserFromRolesAsync(user._id, [role._id], scope);

if (settings.get('UI_DisplayRoles')) {
void api.broadcast('user.roleUpdate', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Roles, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { addUserRolesAsync } from '../../../../server/lib/roles/addUserRoles';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { settings } from '../../../settings/server';
import { hasPermissionAsync } from '../functions/hasPermission';
Expand Down Expand Up @@ -75,7 +76,7 @@ Meteor.methods<ServerMethods>({
});
}

const add = await Roles.addUserRoles(user._id, [role._id], scope);
const add = await addUserRolesAsync(user._id, [role._id], scope);

if (settings.get('UI_DisplayRoles')) {
void api.broadcast('user.roleUpdate', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Roles, Users } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { removeUserFromRolesAsync } from '../../../../server/lib/roles/removeUserFromRoles';
import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { settings } from '../../../settings/server';
import { hasPermissionAsync } from '../functions/hasPermission';
Expand Down Expand Up @@ -79,7 +80,7 @@ Meteor.methods<ServerMethods>({
}
}

const remove = await Roles.removeUserRoles(user._id, [role._id], scope);
const remove = await removeUserFromRolesAsync(user._id, [role._id], scope);
const event = {
type: 'removed',
_id: role._id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { INewIncomingIntegration, IIncomingIntegration } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Integrations, Roles, Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Integrations, Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Random } from '@rocket.chat/random';
import { Babel } from 'meteor/babel-compiler';
import { Match, check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { addUserRolesAsync } from '../../../../../server/lib/roles/addUserRoles';
import { hasPermissionAsync, hasAllPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { notifyOnIntegrationChanged } from '../../../../lib/server/lib/notifyListener';
import { validateScriptEngine, isScriptEngineFrozen } from '../../lib/validateScriptEngine';
Expand Down Expand Up @@ -154,7 +155,7 @@ export const addIncomingIntegration = async (userId: string, integration: INewIn
}
}

await Roles.addUserRoles(user._id, ['bot']);
await addUserRolesAsync(user._id, ['bot']);

const { insertedId } = await Integrations.insertOne(integrationData);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import type { IIntegration, INewIncomingIntegration, IUpdateIncomingIntegration } from '@rocket.chat/core-typings';
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Integrations, Roles, Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { Integrations, Subscriptions, Users, Rooms } from '@rocket.chat/models';
import { wrapExceptions } from '@rocket.chat/tools';
import { Babel } from 'meteor/babel-compiler';
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';

import { addUserRolesAsync } from '../../../../../server/lib/roles/addUserRoles';
import { hasAllPermissionAsync, hasPermissionAsync } from '../../../../authorization/server/functions/hasPermission';
import { notifyOnIntegrationChanged } from '../../../../lib/server/lib/notifyListener';
import { isScriptEngineFrozen, validateScriptEngine } from '../../lib/validateScriptEngine';
Expand Down Expand Up @@ -164,7 +165,7 @@ Meteor.methods<ServerMethods>({
});
}

await Roles.addUserRoles(user._id, ['bot']);
await addUserRolesAsync(user._id, ['bot']);

const updatedIntegration = await Integrations.findOneAndUpdate(
{ _id: integrationId },
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/app/lib/server/functions/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ async function createUsersSubscriptions({
extraData: {
...extra,
...autoTranslateConfig,
...getDefaultSubscriptionPref(member),
},
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Messages, Roles, Rooms, Subscriptions, ReadReceipts } from '@rocket.chat/models';
import { Messages, Rooms, Subscriptions, ReadReceipts } from '@rocket.chat/models';

import type { SubscribedRoomsForUserWithDetails } from './getRoomsWithSingleOwner';
import { addUserRolesAsync } from '../../../../server/lib/roles/addUserRoles';
import { FileUpload } from '../../../file-upload/server';
import { notifyOnSubscriptionChanged } from '../lib/notifyListener';

Expand Down Expand Up @@ -29,7 +30,7 @@ export const relinquishRoomOwnerships = async function (
const changeOwner = subscribedRooms.filter(({ shouldChangeOwner }) => shouldChangeOwner);

for await (const { newOwner, rid } of changeOwner) {
newOwner && (await Roles.addUserRoles(newOwner, ['owner'], rid));
newOwner && (await addUserRolesAsync(newOwner, ['owner'], rid));
}

const roomIdsToRemove: string[] = subscribedRooms.filter(({ shouldBeRemoved }) => shouldBeRemoved).map(({ rid }) => rid);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Button, Modal } from '@rocket.chat/fuselage';
import React from 'react';
import { useTranslation } from 'react-i18next';

type PlaceChatOnHoldModalProps = {
Expand Down
26 changes: 11 additions & 15 deletions apps/meteor/app/livechat/server/api/lib/livechat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,19 @@ async function findTriggers(): Promise<Pick<ILivechatTrigger, '_id' | 'actions'

async function findDepartments(
businessUnit?: string,
): Promise<Pick<ILivechatDepartment, '_id' | 'name' | 'showOnRegistration' | 'showOnOfflineForm'>[]> {
): Promise<Pick<ILivechatDepartment, '_id' | 'name' | 'showOnRegistration' | 'showOnOfflineForm' | 'departmentsAllowedToForward'>[]> {
// TODO: check this function usage
return (
await (
await LivechatDepartment.findEnabledWithAgentsAndBusinessUnit(businessUnit, {
_id: 1,
name: 1,
showOnRegistration: 1,
showOnOfflineForm: 1,
})
).toArray()
).map(({ _id, name, showOnRegistration, showOnOfflineForm }) => ({
_id,
name,
showOnRegistration,
showOnOfflineForm,
}));
await LivechatDepartment.findEnabledWithAgentsAndBusinessUnit<
Pick<ILivechatDepartment, '_id' | 'name' | 'showOnRegistration' | 'showOnOfflineForm' | 'departmentsAllowedToForward'>
>(businessUnit, {
_id: 1,
name: 1,
showOnRegistration: 1,
showOnOfflineForm: 1,
departmentsAllowedToForward: 1,
})
).toArray();
}

export function findGuest(token: string): Promise<ILivechatVisitor | null> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { AtLeast, ILivechatAgentStatus, ILivechatBusinessHour, ILivechatDepartment } from '@rocket.chat/core-typings';
import type { ILivechatBusinessHoursModel, IUsersModel } from '@rocket.chat/model-typings';
import { LivechatBusinessHours, Users } from '@rocket.chat/models';
import type { IWorkHoursCronJobsWrapper } from '@rocket.chat/models';
import moment from 'moment-timezone';
import type { UpdateFilter } from 'mongodb';

import type { IWorkHoursCronJobsWrapper } from '../../../../server/models/raw/LivechatBusinessHours';
import { notifyOnUserChange } from '../../../lib/server/lib/notifyListener';

export interface IBusinessHourBehavior {
Expand Down
7 changes: 6 additions & 1 deletion apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,12 @@ class LivechatClass {
throw new Error('error-contact-channel-blocked');
}

const defaultAgent = await callbacks.run('livechat.checkDefaultAgentOnNewRoom', agent, visitor);
const defaultAgent =
agent ??
(await callbacks.run('livechat.checkDefaultAgentOnNewRoom', agent, {
visitorId: visitor._id,
source: roomInfo.source,
}));
// if no department selected verify if there is at least one active and pick the first
if (!defaultAgent && !visitor.department) {
const department = await getRequiredDepartment();
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/livechat/server/lib/QueueManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
import { i18n } from '../../../utils/lib/i18n';
import { getOmniChatSortQuery } from '../../lib/inquiries';

const logger = new Logger('QueueManager');

Expand Down Expand Up @@ -336,7 +337,7 @@ export class QueueManager {
const [inq] = await LivechatInquiry.getCurrentSortedQueueAsync({
inquiryId: inquiry._id,
department: room.departmentId,
queueSortBy: getInquirySortMechanismSetting(),
queueSortBy: getOmniChatSortQuery(getInquirySortMechanismSetting()),
});

if (inq) {
Expand Down
33 changes: 30 additions & 3 deletions apps/meteor/app/livechat/server/lib/analytics/departments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { LivechatRooms, Messages } from '@rocket.chat/models';

import { settings } from '../../../../settings/server';

type Params = {
start: Date;
end: Date;
Expand Down Expand Up @@ -139,9 +141,25 @@ export const findAllNumberOfAbandonedRoomsAsync = async ({ start, end, departmen
if (!start || !end) {
throw new Error('"start" and "end" must be provided');
}
const total = await (await LivechatRooms.findAllNumberOfAbandonedRooms({ start, end, departmentId, onlyCount: true })).toArray();
const total = await (
await LivechatRooms.findAllNumberOfAbandonedRooms({
start,
end,
departmentId,
inactivityTimeout: settings.get('Livechat_visitor_inactivity_timeout'),
onlyCount: true,
})
).toArray();
return {
departments: await (await LivechatRooms.findAllNumberOfAbandonedRooms({ start, end, departmentId, options })).toArray(),
departments: await (
await LivechatRooms.findAllNumberOfAbandonedRooms({
start,
end,
departmentId,
inactivityTimeout: settings.get('Livechat_visitor_inactivity_timeout'),
options,
})
).toArray(),
total: total.length ? total[0].total : 0,
};
};
Expand All @@ -155,11 +173,20 @@ export const findPercentageOfAbandonedRoomsAsync = async ({ start, end, departme
start,
end,
departmentId,
inactivityTimeout: settings.get('Livechat_visitor_inactivity_timeout'),
onlyCount: true,
})
).toArray();
return {
departments: await (await LivechatRooms.findPercentageOfAbandonedRooms({ start, end, departmentId, options })).toArray(),
departments: await (
await LivechatRooms.findPercentageOfAbandonedRooms({
start,
end,
departmentId,
inactivityTimeout: settings.get('Livechat_visitor_inactivity_timeout'),
options,
})
).toArray(),
total: total.length ? total[0].total : 0,
};
};
4 changes: 4 additions & 0 deletions apps/meteor/app/livechat/server/lib/departmentsLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ export async function saveDepartment(
await updateDepartmentAgents(departmentDB._id, departmentAgents, departmentDB.enabled);
}

if (department?.enabled !== departmentData.enabled) {
void notifyOnLivechatDepartmentAgentChangedByDepartmentId(departmentDB._id, department ? 'updated' : 'inserted');
}

// Disable event
if (department?.enabled && !departmentDB?.enabled) {
await callbacks.run('livechat.afterDepartmentDisabled', departmentDB);
Expand Down
3 changes: 1 addition & 2 deletions apps/meteor/app/statistics/server/lib/SAUMonitor.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { ISession, ISessionDevice, ISocketConnectionLogged, IUser } from '@rocket.chat/core-typings';
import { cronJobs } from '@rocket.chat/cron';
import { Logger } from '@rocket.chat/logger';
import { Sessions, Users } from '@rocket.chat/models';
import { Sessions, Users, aggregates } from '@rocket.chat/models';
import mem from 'mem';
import { Meteor } from 'meteor/meteor';
import UAParser from 'ua-parser-js';

import { UAParserMobile, UAParserDesktop } from './UAParserCustom';
import { getMostImportantRole } from '../../../../lib/roles/getMostImportantRole';
import { getClientAddress } from '../../../../server/lib/getClientAddress';
import { aggregates } from '../../../../server/models/raw/Sessions';
import { sauEvents } from '../../../../server/services/sauMonitor/events';

type DateObj = { day: number; month: number; year: number };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Field, FieldGroup, TextInput, FieldLabel, FieldRow, Box } from '@rocket.chat/fuselage';
import { useUniqueId } from '@rocket.chat/fuselage-hooks';
import React, { useEffect } from 'react';
import { useEffect } from 'react';
import { useForm, Controller } from 'react-hook-form';
import { useTranslation } from 'react-i18next';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/NavBarV2/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useToolbar } from '@react-aria/toolbar';
import { NavBar as NavBarComponent, NavBarSection, NavBarGroup, NavBarDivider } from '@rocket.chat/fuselage';
import { usePermission, useTranslation, useUser } from '@rocket.chat/ui-contexts';
import { useVoipState } from '@rocket.chat/ui-voip';
import React, { useRef } from 'react';
import { useRef } from 'react';

import {
NavBarItemOmniChannelCallDialPad,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { NavBarItem } from '@rocket.chat/fuselage';
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';
import { useTranslation } from 'react-i18next';

import { useVoipOutboundStates } from '../../contexts/CallContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ComponentPropsWithoutRef } from 'react';
import React from 'react';

import NavBarItemOmnichannelCallToggleError from './NavBarItemOmnichannelCallToggleError';
import NavBarItemOmnichannelCallToggleLoading from './NavBarItemOmnichannelCallToggleLoading';
Expand Down
Loading

0 comments on commit 02b2292

Please sign in to comment.