Skip to content

Commit

Permalink
Merge branch 'release-6.5.0' into chore/prevent-states
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Nov 17, 2023
2 parents de7e40f + 935d650 commit 066ac29
Show file tree
Hide file tree
Showing 25 changed files with 195 additions and 119 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-socks-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

fix: Google Maps and Katex config settings were not visible
5 changes: 5 additions & 0 deletions .changeset/ninety-files-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rocket.chat/meteor": patch
---

regression: changed UniqueID modal being displayed wrongly during startup
7 changes: 7 additions & 0 deletions .changeset/old-buckets-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@rocket.chat/meteor": patch
---

Add the date and time to the email sent when a new device logs in


31 changes: 24 additions & 7 deletions apps/meteor/app/cloud/server/functions/saveRegistrationData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Settings } from '@rocket.chat/models';

import { callbacks } from '../../../../lib/callbacks';
import { settings } from '../../../settings/server';
import { syncCloudData } from './syncWorkspace/syncCloudData';

export function saveRegistrationData({
workspaceId,
Expand All @@ -10,7 +11,6 @@ export function saveRegistrationData({
client_secret_expires_at,
publicKey,
registration_client_uri,
licenseData,
}: {
workspaceId: string;
client_name: string;
Expand All @@ -19,9 +19,6 @@ export function saveRegistrationData({
client_secret_expires_at: number;
publicKey: string;
registration_client_uri: string;
licenseData: {
license: string;
};
}) {
return Promise.all([
Settings.updateValueById('Register_Server', true),
Expand All @@ -32,9 +29,29 @@ export function saveRegistrationData({
Settings.updateValueById('Cloud_Workspace_Client_Secret_Expires_At', client_secret_expires_at),
Settings.updateValueById('Cloud_Workspace_PublicKey', publicKey),
Settings.updateValueById('Cloud_Workspace_Registration_Client_Uri', registration_client_uri),
Settings.updateValueById('Cloud_Workspace_License', licenseData.license || ''),
]).then(async (...results) => {
await callbacks.run('workspaceLicenseChanged', licenseData.license);
// wait until all the settings are updated before syncing the data
for await (const retry of Array.from({ length: 10 })) {
if (
settings.get('Register_Server') === true &&
settings.get('Cloud_Workspace_Id') === workspaceId &&
settings.get('Cloud_Workspace_Name') === client_name &&
settings.get('Cloud_Workspace_Client_Id') === client_id &&
settings.get('Cloud_Workspace_Client_Secret') === client_secret &&
settings.get('Cloud_Workspace_Client_Secret_Expires_At') === client_secret_expires_at &&
settings.get('Cloud_Workspace_PublicKey') === publicKey &&
settings.get('Cloud_Workspace_Registration_Client_Uri') === registration_client_uri
) {
break;
}

if (retry === 9) {
throw new Error('Failed to save registration data');
}
await new Promise((resolve) => setTimeout(resolve, 1000));
}

await syncCloudData();
return results;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const SubscriptionPage = () => {
{seatsLimit.value !== undefined && (
<Grid.Item lg={6} xs={4} p={8}>
{seatsLimit.max !== Infinity ? (
<SeatsCard value={seatsLimit.value} max={seatsLimit.max} />
<SeatsCard value={seatsLimit.value} max={seatsLimit.max} hideManageSubscription={licensesData?.trial} />
) : (
<CountSeatsCard activeUsers={seatsLimit?.value} />
)}
Expand All @@ -115,7 +115,7 @@ const SubscriptionPage = () => {
{macLimit.value !== undefined && (
<Grid.Item lg={6} xs={4} p={8}>
{macLimit.max !== Infinity ? (
<MACCard max={macLimit.max} value={macLimit.value} />
<MACCard max={macLimit.max} value={macLimit.value} hideManageSubscription={licensesData?.trial} />
) : (
<CountMACCard macsCount={macLimit.value} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ const UsagePieGraph = ({ used = 0, total = 0, label, color, size = 140 }: UsageP
<Box is='span' fontScale='p2' color='font-secondary-info'>
{used} / {unlimited ? '∞' : total}
</Box>
<Box is='span' mbs={4} color='font-secondary-info'>
{label}
</Box>
{label && (
<Box is='span' mbs={4} color='font-secondary-info'>
{label}
</Box>
)}
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import type { CardProps } from '../FeatureUsageCard';
import FeatureUsageCard from '../FeatureUsageCard';
import UsagePieGraph from '../UsagePieGraph';

const MACCard = ({ value = 0, max }: { value: number; max: number }): ReactElement => {
const MACCard = ({
value = 0,
max,
hideManageSubscription,
}: {
value: number;
max: number;
hideManageSubscription?: boolean;
}): ReactElement => {
const { t } = useTranslation();

const pieGraph = {
Expand All @@ -22,15 +30,18 @@ const MACCard = ({ value = 0, max }: { value: number; max: number }): ReactEleme
const card: CardProps = {
title: t('Monthly_active_contacts'),
infoText: t('MAC_InfoText'),
upgradeButtonText: t('Buy_more'),
...(nearLimit && {
upgradeButtonText: t('Upgrade'),

...(!hideManageSubscription && {
upgradeButtonText: t('Buy_more'),
...(nearLimit && {
upgradeButtonText: t('Upgrade'),
}),
}),
};

const color = nearLimit ? Palette.statusColor['status-font-on-danger'].toString() : undefined;

const message = macLeft > 0 ? t('MAC_Available', { macLeft }) : t('MAC_Required', { macRequired: -macLeft });
const message = macLeft > 0 ? t('MAC_Available', { macLeft }) : undefined;

return (
<FeatureUsageCard card={card}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import UsagePieGraph from '../UsagePieGraph';
type SeatsCardProps = {
value: number;
max: number;
hideManageSubscription?: boolean;
};

const SeatsCard = ({ value, max }: SeatsCardProps): ReactElement => {
const SeatsCard = ({ value, max, hideManageSubscription }: SeatsCardProps): ReactElement => {
const { t } = useTranslation();

const pieGraph = {
Expand All @@ -25,15 +26,16 @@ const SeatsCard = ({ value, max }: SeatsCardProps): ReactElement => {
const card: CardProps = {
title: t('Seats'),
infoText: t('Seats_InfoText'),
...(nearLimit && {
upgradeButtonText: t('Buy_more'),
}),
...(!hideManageSubscription &&
nearLimit && {
upgradeButtonText: t('Buy_more'),
}),
};

const seatsLeft = pieGraph.total - pieGraph.used;
const color = pieGraph.used / pieGraph.total >= 0.8 ? Palette.statusColor['status-font-on-danger'].toString() : undefined;

const message = seatsLeft > 0 ? t('Seats_Available', { seatsLeft }) : t('Seats_Required', { seatsRequired: -seatsLeft });
const message = seatsLeft > 0 ? t('Seats_Available', { seatsLeft }) : undefined;
return (
<FeatureUsageCard card={card}>
<UsagePieGraph label={message} used={pieGraph.used} total={pieGraph.total} color={color} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,22 @@ const VersionCard = ({ serverInfo }: VersionCardProps): ReactElement => {

const serverVersion = serverInfo.version;

const supportedVersions = useMemo(
() => decodeBase64(serverInfo?.supportedVersions?.signed || ''),
[serverInfo?.supportedVersions?.signed],
);

const isOverLimits = limits && isOverLicenseLimits(limits);
const { versionStatus, versions } = useMemo(() => {
const supportedVersions = serverInfo?.supportedVersions?.signed ? decodeBase64(serverInfo?.supportedVersions?.signed) : undefined;

const versionStatus = useMemo(() => {
if (!supportedVersions.versions) {
return;
if (!supportedVersions) {
return {};
}
return getVersionStatus(serverVersion, supportedVersions.versions);
}, [serverVersion, supportedVersions.versions]);

const versionStatus = getVersionStatus(serverVersion, supportedVersions?.versions);

return {
versionStatus,
versions: supportedVersions?.versions,
};
}, [serverInfo?.supportedVersions?.signed, serverVersion]);

const isOverLimits = limits && isOverLicenseLimits(limits);

const actionButton:
| undefined
Expand Down Expand Up @@ -120,7 +123,7 @@ const VersionCard = ({ serverInfo }: VersionCardProps): ReactElement => {
icon: 'check',
label: t('Operating_withing_plan_limits'),
},
isAirgapped && {
(isAirgapped || !versions) && {
type: 'neutral',
icon: 'warning',
label: (
Expand Down Expand Up @@ -167,7 +170,7 @@ const VersionCard = ({ serverInfo }: VersionCardProps): ReactElement => {
},
].filter(Boolean) as VersionActionItem[]
).sort((a) => (a.type === 'danger' ? -1 : 1));
}, [isOverLimits, t, isAirgapped, versionStatus, formatDate, isRegistered]);
}, [isOverLimits, t, isAirgapped, versions, versionStatus?.label, versionStatus?.expiration, formatDate, isRegistered]);

return (
<Card background={cardBackground}>
Expand All @@ -179,7 +182,7 @@ const VersionCard = ({ serverInfo }: VersionCardProps): ReactElement => {
<Box fontScale='h3' mbe={4} display='flex'>
{t('Version_version', { version: serverVersion })}
<Box mis={8} alignSelf='center' width='auto'>
<VersionTag versionStatus={versionStatus?.label} />
{!isAirgapped && versions && <VersionTag versionStatus={versionStatus?.label} />}
</Box>
</Box>
</CardColTitle>
Expand Down Expand Up @@ -211,8 +214,12 @@ const VersionCard = ({ serverInfo }: VersionCardProps): ReactElement => {

export default VersionCard;

const decodeBase64 = (b64: string): SupportedVersions => {
const decodeBase64 = (b64: string): SupportedVersions | undefined => {
const [, bodyEncoded] = b64.split('.');
if (!bodyEncoded) {
return;
}

return JSON.parse(atob(bodyEncoded));
};

Expand Down
37 changes: 31 additions & 6 deletions apps/meteor/ee/app/license/server/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,29 @@ const applyLicense = async (license: string, isNewLicense: boolean): Promise<boo
}
};

const syncByTrigger = async (context: string) => {
/**
* This is a debounced function that will sync the workspace data to the cloud.
* it caches the context, waits for a second and then syncs the data.
*/

const syncByTriggerDebounced = (() => {
let timeout: NodeJS.Timeout | undefined;
const contexts: Set<string> = new Set();
return async (context: string) => {
contexts.add(context);
if (timeout) {
clearTimeout(timeout);
}

timeout = setTimeout(() => {
timeout = undefined;
void syncByTrigger([...contexts]);
contexts.clear();
}, 1000);
};
})();

const syncByTrigger = async (contexts: string[]) => {
if (!License.encryptedLicense) {
return;
}
Expand All @@ -60,16 +82,19 @@ const syncByTrigger = async (context: string) => {
const [, , signed] = License.encryptedLicense.split('.');

// Check if this sync has already been done. Based on License, behavior.
if (existingData.signed === signed && existingData[context] === period) {

if ([...contexts.values()].every((context) => existingData.signed === signed && existingData[context] === period)) {
return;
}

const obj = Object.fromEntries(contexts.map((context) => [context, period]));

await Settings.updateValueById(
'Enterprise_License_Data',
JSON.stringify({
...(existingData.signed === signed && existingData),
...existingData,
[context]: period,
...obj,
signed,
}),
);
Expand All @@ -91,11 +116,11 @@ settings.onReady(async () => {

callbacks.add('workspaceLicenseChanged', async (updatedLicense) => applyLicense(updatedLicense, true));

License.onBehaviorTriggered('prevent_action', (context) => syncByTrigger(`prevent_action_${context.limit}`));
License.onBehaviorTriggered('prevent_action', (context) => syncByTriggerDebounced(`prevent_action_${context.limit}`));

License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTrigger(`start_fair_policy_${context.limit}`));
License.onBehaviorTriggered('start_fair_policy', async (context) => syncByTriggerDebounced(`start_fair_policy_${context.limit}`));

License.onBehaviorTriggered('disable_modules', async (context) => syncByTrigger(`disable_modules_${context.limit}`));
License.onBehaviorTriggered('disable_modules', async (context) => syncByTriggerDebounced(`disable_modules_${context.limit}`));

License.onChange(() => api.broadcast('license.sync'));

Expand Down
4 changes: 4 additions & 0 deletions apps/meteor/ee/server/lib/deviceManagement/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ISocketConnection } from '@rocket.chat/core-typings';
import { Users } from '@rocket.chat/models';
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import moment from 'moment';
import { UAParser } from 'ua-parser-js';

import * as Mailer from '../../../../app/mailer/server/api';
Expand Down Expand Up @@ -58,6 +59,8 @@ export const listenSessionLogin = () => {
return;
}

const dateFormat = settings.get('Message_TimeAndDateFormat');

const {
name,
username,
Expand All @@ -75,6 +78,7 @@ export const listenSessionLogin = () => {
}`,
ipInfo: connection.clientAddress,
userAgent: '',
date: moment().format(String(dateFormat)),
};

switch (device.type) {
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/server/lib/deviceManagement/startup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const createEmailTemplates = async (): Promise<void> => {
});
await this.add(
'Device_Management_Email_Body',
'<h2 class="rc-color">{Login_Detected}</h2><p><strong>[name] ([username]) {Logged_In_Via}</strong></p><p><strong>{Device_Management_Client}:</strong> [browserInfo]<br><strong>{Device_Management_OS}:</strong> [osInfo]<br><strong>{Device_Management_Device}:</strong> [deviceInfo]<br><strong>{Device_Management_IP}:</strong>[ipInfo]</p><p><small>[userAgent]</small></p><a class="btn" href="[Site_URL]">{Access_Your_Account}</a><p>{Or_Copy_And_Paste_This_URL_Into_A_Tab_Of_Your_Browser}<br><a href="[Site_URL]">[SITE_URL]</a></p><p>{Thank_You_For_Choosing_RocketChat}</p>',
'<h2 class="rc-color">{Login_Detected}</h2><p><strong>[name] ([username]) {Logged_In_Via}</strong></p><p><strong>{Device_Management_Client}:</strong> [browserInfo]<br><strong>{Device_Management_OS}:</strong> [osInfo]<br><strong>{Device_Management_Device}:</strong> [deviceInfo]<br><strong>{Device_Management_IP}:</strong>[ipInfo]<br><strong>{Date}:</strong> [date]</p><p><small>[userAgent]</small></p><a class="btn" href="[Site_URL]">{Access_Your_Account}</a><p>{Or_Copy_And_Paste_This_URL_Into_A_Tab_Of_Your_Browser}<br><a href="[Site_URL]">[SITE_URL]</a></p><p>{Thank_You_For_Choosing_RocketChat}</p>',
{
type: 'code',
code: 'text/html',
Expand Down
21 changes: 6 additions & 15 deletions apps/meteor/packages/rocketchat-livechat/assets/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@

<head>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<script type="text/javascript">
(function(w, d, s, u) {
w.RocketChat = function(c) { w.RocketChat._.push(c) };
w.RocketChat._ = [];
w.RocketChat.url = u;
var h = d.getElementsByTagName(s)[0],
j = d.createElement(s);
j.async = true;
j.src = '/packages/rocketchat_livechat/assets/rocketchat-livechat.min.js?_=201702160944';
h.parentNode.insertBefore(j, h);
})(window, document, 'script', '/livechat');
</script>
</head>

<!-- Access: http://localhost:3000/packages/rocketchat_livechat/assets/demo.html -->
Expand All @@ -35,9 +23,12 @@ <h2>without changing page title</h2>
<a href="#page-7">page 7</a><br>

<script type="text/javascript">
RocketChat(function() {
this.setCustomField('key-test', 'value test');
});
(function(w, d, s, u) {
w.RocketChat = function(c) { w.RocketChat._.push(c) }; w.RocketChat._ = []; w.RocketChat.url = u;
var h = d.getElementsByTagName(s)[0], j = d.createElement(s);
j.async = true; j.src = `${window.location.origin}/livechat/rocketchat-livechat.min.js?_=201903270000`;
h.parentNode.insertBefore(j, h);
})(window, document, 'script', `${window.location.origin}/livechat`);
</script>
</body>

Expand Down
Loading

0 comments on commit 066ac29

Please sign in to comment.