Skip to content

Commit

Permalink
Merge branch 'develop' into fix/queue-inactivity-mon
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 18, 2024
2 parents c491aa7 + b23f9ed commit 80cb3dd
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-shoes-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

Fixes the supported versions problem, where in most cases the data chosen was the oldest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SignedSupportedVersions } from '@rocket.chat/server-cloud-communic

export const supportedVersionsChooseLatest = async (...tokens: (SignedSupportedVersions | undefined)[]) => {
const [token] = (tokens.filter((r) => r?.timestamp != null) as SignedSupportedVersions[]).sort((a, b) => {
return new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
return new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime();
});

return token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const cacheValueInSettings = <T extends SettingValue>(
reset: () => Promise<T>;
} => {
const reset = async () => {
SystemLogger.debug(`Resetting cached value ${key} in settings`);
const value = await fn();

await Settings.updateValueById(key, value);
Expand Down Expand Up @@ -134,6 +135,31 @@ const getSupportedVersionsToken = async () => {
(response.success && response.result) || undefined,
);

SystemLogger.debug({
msg: 'Supported versions',
supportedVersionsFromBuild: supportedVersionsFromBuild.timestamp,
versionsFromLicense: versionsFromLicense?.supportedVersions?.timestamp,
response: response.success && response.result?.timestamp,
});

switch (supportedVersions) {
case supportedVersionsFromBuild:
SystemLogger.info({
msg: 'Using supported versions from build',
});
break;
case versionsFromLicense?.supportedVersions:
SystemLogger.info({
msg: 'Using supported versions from license',
});
break;
case response.success && response.result:
SystemLogger.info({
msg: 'Using supported versions from cloud',
});
break;
}

await buildVersionUpdateMessage(supportedVersions?.versions);

return supportedVersions?.signed;
Expand Down
1 change: 1 addition & 0 deletions apps/meteor/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const config: Config = {
'<rootDir>/app/livechat/server/business-hour/**/*.spec.ts?(x)',
'<rootDir>/app/livechat/server/api/**/*.spec.ts',
'<rootDir>/ee/app/authorization/server/validateUserRoles.spec.ts',
'<rootDir>/app/cloud/server/functions/supportedVersionsToken/**.spec.ts',
],
transformIgnorePatterns: ['!/node_modules/jose'],
errorOnDeprecated: true,
Expand Down
23 changes: 18 additions & 5 deletions apps/meteor/packages/rocketchat-version/plugin/compile-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class VersionCompiler {
function handleError(err) {
console.error(err);
// TODO remove this when we are ready to fail
// if (process.env.NODE_ENV !== 'development') {
// reject(err);
// return;
// }
if (process.env.NODE_ENV !== 'development') {
reject(err);
return;
}
resolve({});
}

Expand All @@ -34,11 +34,24 @@ class VersionCompiler {
response.on('data', function (chunk) {
data += chunk;
});
response.on('end', function () {
response.on('end', async function () {
const supportedVersions = JSON.parse(data);
if (!supportedVersions?.signed) {
return handleError(new Error(`Invalid supportedVersions result:\n URL: ${url} \n RESULT: ${data}`));
}

// check if timestamp is inside 1 hour within build
if (Math.abs(new Date().getTime() - new Date(supportedVersions.timestamp).getTime()) > 1000 * 60 * 60) {
return handleError(new Error(`Invalid supportedVersions timestamp:\n URL: ${url} \n RESULT: ${data}`));
}

for await (const version of supportedVersions.versions) {
// check if expiration is after the first rocket.chat release
if (new Date(version.expiration) < new Date('2019-04-01T00:00:00.000Z')) {
return handleError(new Error(`Invalid supportedVersions expiration:\n URL: ${url} \n RESULT: ${data}`));
}
}

resolve(supportedVersions);
});
response.on('error', function (err) {
Expand Down
8 changes: 1 addition & 7 deletions apps/meteor/server/lib/roles/createOrUpdateProtectedRole.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import type { IRole, AtLeast } from '@rocket.chat/core-typings';
import { Roles } from '@rocket.chat/models';

import { notifyOnRoleChanged, notifyOnRoleChangedById } from '../../../app/lib/server/lib/notifyListener';

export const createOrUpdateProtectedRoleAsync = async (
roleId: string,
roleData: AtLeast<Omit<IRole, '_id' | 'protected'>, 'name'>,
Expand All @@ -12,16 +10,14 @@ export const createOrUpdateProtectedRoleAsync = async (
});

if (role) {
const updatedRole = await Roles.updateById(
await Roles.updateById(
roleId,
roleData.name || role.name,
roleData.scope || role.scope,
roleData.description || role.description,
roleData.mandatory2fa || role.mandatory2fa,
);

void notifyOnRoleChanged(updatedRole);

return;
}

Expand All @@ -33,6 +29,4 @@ export const createOrUpdateProtectedRoleAsync = async (
...roleData,
protected: true,
});

void notifyOnRoleChangedById(roleId);
};

0 comments on commit 80cb3dd

Please sign in to comment.