Skip to content

Commit

Permalink
chore: adds logic to handle cloud announcement data
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-a-pelegrino committed Oct 17, 2024
1 parent cb0d572 commit 56e54c6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Cloud, Serialized } from '@rocket.chat/core-typings';
import { DuplicatedLicenseError } from '@rocket.chat/license';
import { Settings } from '@rocket.chat/models';
import { serverFetch as fetch } from '@rocket.chat/server-fetch';
import { v, compile } from 'suretype';

Expand Down Expand Up @@ -50,7 +51,35 @@ const fetchWorkspaceSyncPayload = async ({

assertWorkspaceSyncPayload(payload);

return payload;
const cloudSyncAnnouncement = {
viewId: 'license',
appId: 'cloud-announcements-core',
blocks: [
{
type: 'callout',
title: {
type: 'plain_text',
text: 'Callout Title',
},
text: {
type: 'plain_text',
text: 'Callout Text',
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Callout Action',
},
actionId: 'callout-action',
appId: 'cloud-announcements-core',
blockId: 'section-button',
},
},
],
};

return { ...payload, cloudSyncAnnouncement };
};

export async function syncCloudData() {
Expand All @@ -67,11 +96,19 @@ export async function syncCloudData() {

const workspaceRegistrationData = await buildWorkspaceRegistrationData(undefined);

const { license, removeLicense = false } = await fetchWorkspaceSyncPayload({
const {
license,
removeLicense = false,
cloudSyncAnnouncement,
} = await fetchWorkspaceSyncPayload({
token,
data: workspaceRegistrationData,
});

if (cloudSyncAnnouncement) {
await Settings.updateValueById('Cloud_Sync_Announcement_Payload', JSON.stringify(cloudSyncAnnouncement));
}

if (removeLicense) {
await callbacks.run('workspaceLicenseRemoved');
} else {
Expand Down
39 changes: 6 additions & 33 deletions apps/meteor/client/views/admin/subscription/SubscriptionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const SubscriptionPage = () => {

const showSubscriptionCallout = useDebouncedValue(subscriptionSuccess || syncLicenseUpdate.isLoading, 10000);

const { license, limits, activeModules = [] } = licensesData || {};
const { license, limits, activeModules = [], cloudSyncAnnouncement } = licensesData || {};
const { isEnterprise = true } = enterpriseData || {};

const getKeyLimit = (key: 'monthlyActiveContacts' | 'activeUsers') => {
Expand Down Expand Up @@ -114,38 +114,11 @@ const SubscriptionPage = () => {
</UpgradeButton>
</ButtonGroup>
</PageHeaderNoShadow>
<PageBlockWithBorder>
<UiKitSubscriptionLicense
key='license'
initialView={{
viewId: 'license',
appId: 'cloud-announcements-core',
blocks: [
{
type: 'callout',
title: {
type: 'plain_text',
text: 'Callout Title',
},
text: {
type: 'plain_text',
text: 'Callout Text',
},
accessory: {
type: 'button',
text: {
type: 'plain_text',
text: 'Callout Action',
},
actionId: 'callout-action',
appId: 'cloud-announcements-core',
blockId: 'section-button',
},
},
],
}}
/>
</PageBlockWithBorder>
{cloudSyncAnnouncement && (
<PageBlockWithBorder>
<UiKitSubscriptionLicense key='license' initialView={JSON.parse(cloudSyncAnnouncement)} />
</PageBlockWithBorder>
)}
<PageScrollableContentWithShadow p={16}>
{(showSubscriptionCallout || syncLicenseUpdate.isLoading) && (
<Callout type='info' title={t('Sync_license_update_Callout_Title')} m={8}>
Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/server/settings/setup-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,5 +1364,10 @@ export const createSetupWSettings = () =>
},
secret: true,
});
await this.add('Cloud_Sync_Announcement_Payload', '{}', {
type: 'string', // tODO: replace setting type string for object once is implemented.
hidden: true,
secret: true,
});
});
});
5 changes: 4 additions & 1 deletion ee/packages/license/src/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
LimitContext,
} from '@rocket.chat/core-typings';
import { Emitter } from '@rocket.chat/emitter';
import { Settings } from '@rocket.chat/models';

import { getLicenseLimit } from './deprecated';
import { DuplicatedLicenseError } from './errors/DuplicatedLicenseError';
Expand Down Expand Up @@ -473,7 +474,8 @@ export class LicenseManager extends Emitter<LicenseEvents> {
}): Promise<LicenseInfo> {
const activeModules = getModules.call(this);
const license = this.getLicense();

const cloudSyncAnnouncementSetting = await Settings.findOneById('Cloud_Sync_Announcement_Payload');
console.info(cloudSyncAnnouncementSetting);
// Get all limits present in the license and their current value
const limits = Object.fromEntries(
(includeLimits &&
Expand All @@ -500,6 +502,7 @@ export class LicenseManager extends Emitter<LicenseEvents> {
limits: limits as Record<LicenseLimitKind, { max: number; value: number }>,
tags: license?.information.tags || [],
trial: Boolean(license?.information.trial),
cloudSyncAnnouncement: cloudSyncAnnouncementSetting?.value,
};
}
}
1 change: 1 addition & 0 deletions packages/core-typings/src/cloud/WorkspaceSyncPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface WorkspaceSyncResponse {
publicKey: string;
license: unknown;
removeLicense?: boolean;
cloudSyncAnnouncement: unknown;
}

export interface WorkspaceCommsRequestPayload {
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/license/LicenseInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type LicenseInfo = {
limits: Record<LicenseLimitKind, { value?: number; max: number }>;
tags: ILicenseTag[];
trial: boolean;
cloudSyncAnnouncement?: unknown;
};

0 comments on commit 56e54c6

Please sign in to comment.