Skip to content

Commit

Permalink
Merge branch 'develop' into chore/setup-wizard-step-four
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoevanp authored Oct 2, 2023
2 parents 643766c + 6d4cb42 commit 1d173db
Show file tree
Hide file tree
Showing 272 changed files with 5,278 additions and 2,665 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-pandas-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": minor
---

New setting to automatically enable autotranslate when joining rooms
5 changes: 5 additions & 0 deletions .changeset/thirty-jokes-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

chore: Deprecate un-used meteor method for omnichannel analytics
22 changes: 22 additions & 0 deletions .changeset/twelve-files-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@rocket.chat/license': minor
'@rocket.chat/jwt': minor
'@rocket.chat/omnichannel-services': minor
'@rocket.chat/omnichannel-transcript': minor
'@rocket.chat/authorization-service': minor
'@rocket.chat/stream-hub-service': minor
'@rocket.chat/presence-service': minor
'@rocket.chat/account-service': minor
'@rocket.chat/core-services': minor
'@rocket.chat/model-typings': minor
'@rocket.chat/core-typings': minor
'@rocket.chat/rest-typings': minor
'@rocket.chat/ddp-streamer': minor
'@rocket.chat/queue-worker': minor
'@rocket.chat/presence': minor
'@rocket.chat/meteor': minor
---

Implemented the License library, it is used to handle the functionality like expiration date, modules, limits, etc.
Also added a version v3 of the license, which contains an extended list of features.
v2 is still supported, since we convert it to v3 on the fly.
22 changes: 22 additions & 0 deletions .github/workflows/vulnerabilities-jira-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Github vulnerabilities and jira board integration

on:
schedule:
- cron: '0 1 * * *'

jobs:
IntegrateSecurityVulnerabilities:
runs-on: ubuntu-latest
steps:
- name: "Github vulnerabilities and jira board integration"
uses: RocketChat/[email protected]
env:
JIRA_URL: https://rocketchat.atlassian.net/
JIRA_TOKEN: ${{ secrets.JIRA_TOKEN }}
GITHUB_TOKEN: ${{ secrets._GITHUB_TOKEN }}
JIRA_EMAIL: [email protected]
JIRA_PROJECT_ID: GJIT
UID_CUSTOMFIELD_ID: customfield_10059
JIRA_COMPLETE_PHASE_ID: 31
JIRA_START_PHASE_ID: 11

1 change: 0 additions & 1 deletion apps/meteor/app/api/server/default/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ API.default.addRoute(
{
async get() {
const user = await getLoggedInUser(this.request);

return API.v1.success(await getServerInfo(user?._id));
},
},
Expand Down
52 changes: 52 additions & 0 deletions apps/meteor/app/api/server/lib/getServerInfo.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';
import proxyquire from 'proxyquire';
import sinon from 'sinon';

const hasAllPermissionAsyncMock = sinon.stub();
const getCachedSupportedVersionsTokenMock = sinon.stub();

const { getServerInfo } = proxyquire.noCallThru().load('./getServerInfo', {
'../../../utils/rocketchat.info': {
Info: {
version: '3.0.1',
},
},
'../../../authorization/server/functions/hasPermission': {
hasPermissionAsync: hasAllPermissionAsyncMock,
},
'../../../cloud/server/functions/supportedVersionsToken/supportedVersionsToken': {
getCachedSupportedVersionsToken: getCachedSupportedVersionsTokenMock,
},
'../../../settings/server': {
settings: new Map(),
},
});
describe('#getServerInfo()', () => {
beforeEach(() => {
hasAllPermissionAsyncMock.reset();
getCachedSupportedVersionsTokenMock.reset();
});

it('should return only the version (without the patch info) when the user is not present', async () => {
expect(await getServerInfo(undefined)).to.be.eql({ version: '3.0' });
});

it('should return only the version (without the patch info) when the user present but they dont have permission', async () => {
hasAllPermissionAsyncMock.resolves(false);
expect(await getServerInfo('userId')).to.be.eql({ version: '3.0' });
});

it('should return the info object + the supportedVersions from the cloud when the request to the cloud was a success', async () => {
const signedJwt = 'signedJwt';
hasAllPermissionAsyncMock.resolves(true);
getCachedSupportedVersionsTokenMock.resolves(signedJwt);
expect(await getServerInfo('userId')).to.be.eql({ info: { version: '3.0.1', supportedVersions: signedJwt } });
});

it('should return the info object ONLY from the cloud when the request to the cloud was NOT a success', async () => {
hasAllPermissionAsyncMock.resolves(true);
getCachedSupportedVersionsTokenMock.rejects();
expect(await getServerInfo('userId')).to.be.eql({ info: { version: '3.0.1' } });
});
});
40 changes: 27 additions & 13 deletions apps/meteor/app/api/server/lib/getServerInfo.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
import { hasPermissionAsync } from '../../../authorization/server/functions/hasPermission';
import { Info } from '../../../utils/rocketchat.info';
import {
getCachedSupportedVersionsToken,
wrapPromise,
} from '../../../cloud/server/functions/supportedVersionsToken/supportedVersionsToken';
import { Info, minimumClientVersions } from '../../../utils/rocketchat.info';

type ServerInfo =
| {
info: typeof Info;
}
| {
version: string | undefined;
};
type ServerInfo = {
info?: typeof Info;
supportedVersions?: { signed: string };
minimumClientVersions: typeof minimumClientVersions;
version: string;
};

const removePatchInfo = (version: string): string => version.replace(/(\d+\.\d+).*/, '$1');

export async function getServerInfo(userId?: string): Promise<ServerInfo> {
if (userId && (await hasPermissionAsync(userId, 'get-server-info'))) {
return {
info: Info,
};
}
const hasPermissionToViewStatistics = userId && (await hasPermissionAsync(userId, 'view-statistics'));
const supportedVersionsToken = await wrapPromise(getCachedSupportedVersionsToken());

return {
version: removePatchInfo(Info.version),

...(hasPermissionToViewStatistics && {
info: {
...Info,
},
version: Info.version,
}),

minimumClientVersions,
...(supportedVersionsToken.success &&
supportedVersionsToken.result && {
supportedVersions: { signed: supportedVersionsToken.result },
}),
};
}
4 changes: 2 additions & 2 deletions apps/meteor/app/api/server/v1/federation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Federation, FederationEE } from '@rocket.chat/core-services';
import { License } from '@rocket.chat/license';
import { isFederationVerifyMatrixIdProps } from '@rocket.chat/rest-typings';

import { isEnterprise } from '../../../../ee/app/license/server';
import { API } from '../api';

API.v1.addRoute(
Expand All @@ -14,7 +14,7 @@ API.v1.addRoute(
async get() {
const { matrixIds } = this.queryParams;

const federationService = isEnterprise() ? FederationEE : Federation;
const federationService = License.hasValidLicense() ? FederationEE : Federation;

const results = await federationService.verifyMatrixIds(matrixIds);

Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/api/server/v1/voip/omnichannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ API.v1.addRoute(
}

try {
logger.debug(`Setting extension ${extension} for agent with id ${user._id}`);
await Users.setExtension(user._id, extension);
return API.v1.success();
} catch (e) {
Expand Down Expand Up @@ -146,7 +145,6 @@ API.v1.addRoute(
return API.v1.notFound();
}
if (!user.extension) {
logger.debug(`User ${user._id} is not associated with any extension. Skipping`);
return API.v1.success();
}

Expand Down
24 changes: 12 additions & 12 deletions apps/meteor/app/cloud/server/functions/buildRegistrationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { settings } from '../../../settings/server';
import { statistics } from '../../../statistics/server';
import { LICENSE_VERSION } from '../license';

type WorkspaceRegistrationData<T> = {
export type WorkspaceRegistrationData<T> = {
uniqueId: string;
workspaceId: SettingValue;
address: SettingValue;
Expand All @@ -14,11 +14,11 @@ type WorkspaceRegistrationData<T> = {
seats: number;
allowMarketing: SettingValue;
accountName: SettingValue;
organizationType: unknown;
industry: unknown;
orgSize: unknown;
country: unknown;
language: unknown;
organizationType: string;
industry: string;
orgSize: string;
country: string;
language: string;
agreePrivacyTerms: SettingValue;
website: SettingValue;
siteName: SettingValue;
Expand Down Expand Up @@ -61,15 +61,15 @@ export async function buildWorkspaceRegistrationData<T extends string | undefine
seats,
allowMarketing,
accountName,
organizationType,
industry,
orgSize,
country,
language,
organizationType: String(organizationType),
industry: String(industry),
orgSize: String(orgSize),
country: String(country),
language: String(language),
agreePrivacyTerms,
website,
siteName,
workspaceType,
workspaceType: String(workspaceType),
deploymentMethod: stats.deploy.method,
deploymentPlatform: stats.deploy.platform,
version: stats.version,
Expand Down
85 changes: 54 additions & 31 deletions apps/meteor/app/cloud/server/functions/connectWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,73 @@
import { serverFetch as fetch } from '@rocket.chat/server-fetch';

import { CloudWorkspaceConnectionError } from '../../../../lib/errors/CloudWorkspaceConnectionError';
import { SystemLogger } from '../../../../server/lib/logger/system';
import { settings } from '../../../settings/server';
import { getRedirectUri } from './getRedirectUri';
import { saveRegistrationData } from './saveRegistrationData';

const fetchRegistrationDataPayload = async ({
token,
body,
}: {
token: string;
body: {
email: string;
client_name: string;
redirect_uris: string[];
};
}) => {
const cloudUrl = settings.get<string>('Cloud_Url');
const response = await fetch(`${cloudUrl}/api/oauth/clients`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
body,
});

if (!response.ok) {
try {
const { error } = await response.json();
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${error}`);
} catch (error) {
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${response.statusText}`);
}
}

const payload = await response.json();

if (!payload) {
return undefined;
}

return payload;
};

export async function connectWorkspace(token: string) {
// shouldn't get here due to checking this on the method
// but this is just to double check
if (!token) {
return new Error('Invalid token; the registration token is required.');
throw new CloudWorkspaceConnectionError('Invalid registration token');
}

const redirectUri = getRedirectUri();
try {
const redirectUri = getRedirectUri();

const regInfo = {
email: settings.get('Organization_Email'),
client_name: settings.get('Site_Name'),
redirect_uris: [redirectUri],
};
const body = {
email: settings.get<string>('Organization_Email'),
client_name: settings.get<string>('Site_Name'),
redirect_uris: [redirectUri],
};

const cloudUrl = settings.get('Cloud_Url');
let result;
try {
const request = await fetch(`${cloudUrl}/api/oauth/clients`, {
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
},
body: regInfo,
});
const payload = await fetchRegistrationDataPayload({ token, body });

if (!request.ok) {
throw new Error((await request.json()).error);
if (!payload) {
return false;
}

result = await request.json();
} catch (err: any) {
await saveRegistrationData(payload);

return true;
} catch (err) {
SystemLogger.error({
msg: 'Failed to Connect with Rocket.Chat Cloud',
url: '/api/oauth/clients',
Expand All @@ -45,12 +76,4 @@ export async function connectWorkspace(token: string) {

return false;
}

if (!result) {
return false;
}

await saveRegistrationData(result);

return true;
}
Loading

0 comments on commit 1d173db

Please sign in to comment.