Skip to content

Commit

Permalink
Merge branch 'develop' into dev_feat/multiple_files_in_one_msg
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipatel0211 committed Oct 26, 2024
2 parents 5dbdfc6 + 465c8b8 commit d7e71b9
Show file tree
Hide file tree
Showing 161 changed files with 1,997 additions and 892 deletions.
5 changes: 5 additions & 0 deletions .changeset/bump-patch-1729717124346.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Bump @rocket.chat/meteor version.
5 changes: 5 additions & 0 deletions .changeset/bump-patch-1729881407116.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Bump @rocket.chat/meteor version.
3 changes: 3 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"brown-pants-press",
"bump-patch-1729526930133",
"bump-patch-1729648473274",
"bump-patch-1729717124346",
"bump-patch-1729881407116",
"chilled-boats-sip",
"chilled-files-relate",
"chilly-flowers-brake",
Expand Down Expand Up @@ -122,6 +124,7 @@
"pink-wombats-wait",
"plenty-hairs-camp",
"poor-falcons-doubt",
"pretty-ladybugs-sneeze",
"proud-bugs-cry",
"purple-papayas-collect",
"purple-tools-heal",
Expand Down
6 changes: 6 additions & 0 deletions .changeset/pretty-ladybugs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rocket.chat/meteor": patch
"@rocket.chat/ddp-streamer": patch
---

Fixes page loading during reconnections
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Free for 30 days. Afterward, choose between continuing to host on our secure clo

You can follow these instructions to setup a dev environment:

- Install **Node 14.x (LTS)** either [manually](https://nodejs.org/dist/latest-v14.x/) or using a tool like [nvm](https://github.com/creationix/nvm) or [volta](https://volta.sh/) (recommended)
- Install **Node 20.x (LTS)** either [manually](https://nodejs.org/dist/latest-v20.x/) or using a tool like [nvm](https://github.com/creationix/nvm) or [volta](https://volta.sh/) (recommended)
- Install **Meteor** ([version here](apps/meteor/.meteor/release)): https://docs.meteor.com/about/install.html
- Install **yarn**: https://yarnpkg.com/getting-started/install
- Install **Deno 1.x**: https://docs.deno.com/runtime/fundamentals/installation/
Expand Down
5 changes: 4 additions & 1 deletion _templates/service/new/service.ejs.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ to: ee/apps/<%= name %>/src/service.ts
---
import { api, getConnection, getTrashCollection } from '@rocket.chat/core-services';
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 () => {
const db = await getConnection();
const { db } = await getConnection();

startTracing({ service: '<%= name %>', db: client });

registerServiceModels(db, await getTrashCollection());

Expand Down
72 changes: 72 additions & 0 deletions apps/meteor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,77 @@
# @rocket.chat/meteor

## 7.0.0-rc.4

### Patch Changes

- Bump @rocket.chat/meteor version.

- ([#33770](https://github.com/RocketChat/Rocket.Chat/pull/33770)) Fixes page loading during reconnections

- <details><summary>Updated dependencies []:</summary>

- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
</details>

## 7.0.0-rc.3

### Patch Changes

- Bump @rocket.chat/meteor version.

- <details><summary>Updated dependencies []:</summary>

- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
- @rocket.chat/[email protected]
</details>

## 7.0.0-rc.2

### Patch Changes
Expand Down
3 changes: 2 additions & 1 deletion apps/meteor/app/api/server/v1/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,8 @@ API.v1.addRoute(
const settingsIds: string[] = [];

if (this.bodyParams.setDeploymentAs === 'new-workspace') {
await WorkspaceCredentials.unsetCredentialByScope();
await WorkspaceCredentials.removeAllCredentials();

settingsIds.push(
'Cloud_Service_Agree_PrivacyTerms',
'Cloud_Workspace_Id',
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/apps/server/bridges/cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class AppCloudBridge extends CloudWorkspaceBridge {
public async getWorkspaceToken(scope: string, appId: string): Promise<IWorkspaceToken> {
this.orch.debugLog(`App ${appId} is getting the workspace's token`);

const token = await getWorkspaceAccessTokenWithScope(scope);
const token = await getWorkspaceAccessTokenWithScope({ scope });

return token;
}
Expand Down
12 changes: 12 additions & 0 deletions apps/meteor/app/authentication/server/startup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,24 @@ import { setAvatarFromServiceWithValidation } from '../../../lib/server/function
import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import * as Mailer from '../../../mailer/server/api';
import { settings } from '../../../settings/server';
import { getBaseUserFields } from '../../../utils/server/functions/getBaseUserFields';
import { safeGetMeteorUser } from '../../../utils/server/functions/safeGetMeteorUser';
import { isValidAttemptByUser, isValidLoginAttemptByIp } from '../lib/restrictLoginAttempts';

Accounts.config({
forbidClientAccountCreation: true,
});
/**
* Accounts calls `_initServerPublications` and holds the `_defaultPublishFields`, without Object.assign its not possible
* to extend the projection
*
* the idea is to send all required fields to the client during login
* we tried `defaultFieldsSelector` , but it changes all Meteor.userAsync projections which is undesirable
*
*
* we are removing the status here because meteor send 'offline'
*/
Object.assign(Accounts._defaultPublishFields.projection, (({ status, ...rest }) => rest)(getBaseUserFields()));

Meteor.startup(() => {
settings.watchMultiple(['Accounts_LoginExpiration', 'Site_Name', 'From_Email'], () => {
Expand Down
21 changes: 15 additions & 6 deletions apps/meteor/app/cloud/server/functions/getWorkspaceAccessToken.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { IWorkspaceCredentials } from '@rocket.chat/core-typings';
import { WorkspaceCredentials } from '@rocket.chat/models';

import { SystemLogger } from '../../../../server/lib/logger/system';
import { workspaceScopes } from '../oauthScopes';
import { getWorkspaceAccessTokenWithScope } from './getWorkspaceAccessTokenWithScope';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';

Expand All @@ -24,20 +26,27 @@ export async function getWorkspaceAccessToken(forceNew = false, scope = '', save
return '';
}

const workspaceCredentials = await WorkspaceCredentials.getCredentialByScope(scope);
if (!workspaceCredentials) {
throw new CloudWorkspaceAccessTokenError();
// Note: If no scope is given, it means we should assume the default scope, we store the default scopes
// in the global variable workspaceScopes.
if (scope === '') {
scope = workspaceScopes.join(' ');
}

if (!hasWorkspaceAccessTokenExpired(workspaceCredentials) && !forceNew) {
const workspaceCredentials = await WorkspaceCredentials.getCredentialByScope(scope);
if (workspaceCredentials && !hasWorkspaceAccessTokenExpired(workspaceCredentials) && !forceNew) {
SystemLogger.debug(
`Workspace credentials cache hit using scope: ${scope}. Avoiding generating a new access token from cloud services.`,
);
return workspaceCredentials.accessToken;
}

const accessToken = await getWorkspaceAccessTokenWithScope(scope, throwOnError);
SystemLogger.debug(`Workspace credentials cache miss using scope: ${scope}, fetching new access token from cloud services.`);

const accessToken = await getWorkspaceAccessTokenWithScope({ scope, throwOnError });

if (save) {
await WorkspaceCredentials.updateCredentialByScope({
scope,
scope: accessToken.scope,
accessToken: accessToken.token,
expirationDate: accessToken.expiresAt,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,24 @@ import { CloudWorkspaceAccessTokenError } from './getWorkspaceAccessToken';
import { removeWorkspaceRegistrationInfo } from './removeWorkspaceRegistrationInfo';
import { retrieveRegistrationStatus } from './retrieveRegistrationStatus';

export async function getWorkspaceAccessTokenWithScope(scope = '', throwOnError = false) {
type WorkspaceAccessTokenWithScope = {
token: string;
expiresAt: Date;
scope: string;
};

type GetWorkspaceAccessTokenWithScopeParams = {
scope?: string;
throwOnError?: boolean;
};

export async function getWorkspaceAccessTokenWithScope({
scope = '',
throwOnError = false,
}: GetWorkspaceAccessTokenWithScopeParams): Promise<WorkspaceAccessTokenWithScope> {
const { workspaceRegistered } = await retrieveRegistrationStatus();

const tokenResponse = { token: '', expiresAt: new Date() };
const tokenResponse = { token: '', expiresAt: new Date(), scope: '' };

if (!workspaceRegistered) {
return tokenResponse;
Expand Down Expand Up @@ -62,6 +76,7 @@ export async function getWorkspaceAccessTokenWithScope(scope = '', throwOnError
return {
token: payload.access_token,
expiresAt,
scope: payload.scope,
};
} catch (err: any) {
if (err instanceof CloudWorkspaceAccessTokenError) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { applyLicense } from '@rocket.chat/license';
import { Settings, WorkspaceCredentials } from '@rocket.chat/models';
import { Settings } from '@rocket.chat/models';

import { notifyOnSettingChangedById } from '../../../lib/server/lib/notifyListener';
import { settings } from '../../../settings/server';
Expand Down Expand Up @@ -59,12 +59,6 @@ async function saveRegistrationDataBase({
{ _id: 'Cloud_Workspace_Registration_Client_Uri', value: registration_client_uri },
];

await WorkspaceCredentials.updateCredentialByScope({
scope: '',
accessToken: '',
expirationDate: new Date(0),
});

const promises = [...settingsData.map(({ _id, value }) => Settings.updateValueById(_id, value))];

(await Promise.all(promises)).forEach((value, index) => {
Expand Down
61 changes: 39 additions & 22 deletions apps/meteor/app/e2e/server/methods/updateGroupKey.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import type { ServerMethods } from '@rocket.chat/ddp-client';
import { Subscriptions } from '@rocket.chat/models';
import { Subscriptions, Rooms } from '@rocket.chat/models';
import { Meteor } from 'meteor/meteor';

import { methodDeprecationLogger } from '../../../lib/server/lib/deprecationWarningLogger';
import { notifyOnSubscriptionChangedById, notifyOnSubscriptionChanged } from '../../../lib/server/lib/notifyListener';
import {
notifyOnSubscriptionChangedById,
notifyOnSubscriptionChanged,
notifyOnRoomChangedById,
} from '../../../lib/server/lib/notifyListener';

declare module '@rocket.chat/ddp-client' {
// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -12,32 +16,45 @@ declare module '@rocket.chat/ddp-client' {
}
}

export async function updateGroupKey(rid: string, uid: string, key: string, callerUserId: string) {
// I have a subscription to this room
const mySub = await Subscriptions.findOneByRoomIdAndUserId(rid, callerUserId);

if (mySub) {
// Setting the key to myself, can set directly to the final field
if (callerUserId === uid) {
const setGroupE2EKeyResponse = await Subscriptions.setGroupE2EKey(mySub._id, key);
// Case: I create an encrypted room before setting up my keys, and I reset the e2e keys
// Next login, I'll create the keys for the room, and set them here.
// However as I reset my keys, I'm on the `usersWaitingForKeys` queue
// So I need to remove myself from the queue and notify the time i reach here
// This way, I can provide the keys to other users
const { modifiedCount } = await Rooms.removeUsersFromE2EEQueueByRoomId(mySub.rid, [callerUserId]);
if (setGroupE2EKeyResponse.modifiedCount) {
void notifyOnSubscriptionChangedById(mySub._id);
}
if (modifiedCount) {
void notifyOnRoomChangedById(mySub.rid);
}
return;
}

// uid also has subscription to this room
const { value } = await Subscriptions.setGroupE2ESuggestedKey(uid, rid, key);
if (value) {
void notifyOnSubscriptionChanged(value);
}
}
}

Meteor.methods<ServerMethods>({
async 'e2e.updateGroupKey'(rid, uid, key) {
methodDeprecationLogger.method('e2e.updateGroupKey', '8.0.0');
const userId = Meteor.userId();
if (!userId) {
throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'e2e.acceptSuggestedGroupKey' });
}

// I have a subscription to this room
const mySub = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);

if (mySub) {
// Setting the key to myself, can set directly to the final field
if (userId === uid) {
const setGroupE2EKeyResponse = await Subscriptions.setGroupE2EKey(mySub._id, key);
if (setGroupE2EKeyResponse.modifiedCount) {
void notifyOnSubscriptionChangedById(mySub._id);
}
return;
}

// uid also has subscription to this room
const { value } = await Subscriptions.setGroupE2ESuggestedKey(uid, rid, key);
if (value) {
void notifyOnSubscriptionChanged(value);
}
}
methodDeprecationLogger.method('e2e.updateGroupKey', '8.0.0');
return updateGroupKey(rid, uid, key, userId);
},
});
1 change: 0 additions & 1 deletion apps/meteor/app/livechat/server/lib/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ export const dispatchInquiryQueued = async (inquiry: ILivechatInquiryRecord, age
return;
}

logger.debug(`Notifying ${await onlineAgents.count()} agents of new inquiry`);
const notificationUserName = v && (v.name || v.username);

for await (const agent of onlineAgents) {
Expand Down
10 changes: 9 additions & 1 deletion apps/meteor/app/livechat/server/lib/LivechatTyped.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LivechatClass {
Livechat.logger.debug(`Fetching online bot agents for department ${department}`);
const botAgents = await Livechat.getBotAgents(department);
if (botAgents) {
const onlineBots = await botAgents.count();
const onlineBots = await Livechat.countBotAgents(department);
this.logger.debug(`Found ${onlineBots} online`);
if (onlineBots > 0) {
return true;
Expand Down Expand Up @@ -632,6 +632,14 @@ class LivechatClass {
return Users.findBotAgents();
}

private async countBotAgents(department?: string) {
if (department) {
return LivechatDepartmentAgents.countBotsForDepartment(department);
}

return Users.countBotAgents();
}

private async resolveChatTags(
room: IOmnichannelRoom,
options: CloseRoomParams['options'] = {},
Expand Down
Loading

0 comments on commit d7e71b9

Please sign in to comment.