diff --git a/apps/meteor/ee/app/license/server/license.ts b/apps/meteor/ee/app/license/server/license.ts index 0857ad6e545..f8cd98dd324 100644 --- a/apps/meteor/ee/app/license/server/license.ts +++ b/apps/meteor/ee/app/license/server/license.ts @@ -174,7 +174,7 @@ class LicenseClass { return item; } if (!this._validateURL(license.url, this.url)) { - item.valid = false; + this.invalidate(item); console.error(`#### License error: invalid url, licensed to ${license.url}, used on ${this.url}`); this._invalidModules(license.modules); return item; @@ -182,7 +182,7 @@ class LicenseClass { } if (license.expiry && this._validateExpiration(license.expiry)) { - item.valid = false; + this.invalidate(item); console.error(`#### License error: expired, valid until ${license.expiry}`); this._invalidModules(license.modules); return item; @@ -212,6 +212,12 @@ class LicenseClass { this.showLicenses(); } + invalidate(item: IValidLicense): void { + item.valid = false; + + EnterpriseLicenses.emit('invalidate'); + } + async canAddNewUser(): Promise { if (!maxActiveUsers) { return true; @@ -421,6 +427,10 @@ export function onValidateLicenses(cb: (...args: any[]) => void): void { EnterpriseLicenses.on('validate', cb); } +export function onInvalidateLicense(cb: (...args: any[]) => void): void { + EnterpriseLicenses.on('invalidate', cb); +} + export function flatModules(modulesAndBundles: string[]): string[] { const bundles = modulesAndBundles.filter(isBundle); const modules = modulesAndBundles.filter((x) => !isBundle(x)); diff --git a/apps/meteor/ee/server/apps/orchestrator.js b/apps/meteor/ee/server/apps/orchestrator.js index 14d077d0cdd..abf98f08828 100644 --- a/apps/meteor/ee/server/apps/orchestrator.js +++ b/apps/meteor/ee/server/apps/orchestrator.js @@ -184,6 +184,14 @@ export class AppServerOrchestrator { this._rocketchatLogger.info(`Loaded the Apps Framework and loaded a total of ${this.getManager().get({ enabled: true }).length} Apps!`); } + async disableApps() { + await this.getManager() + .get() + .forEach((app) => { + this.getManager().disable(app.getID()); + }); + } + async unload() { // Don't try to unload it if it's already been // unlaoded or wasn't unloaded to start with diff --git a/apps/meteor/ee/server/startup/apps/index.ts b/apps/meteor/ee/server/startup/apps/index.ts new file mode 100644 index 00000000000..389658ee535 --- /dev/null +++ b/apps/meteor/ee/server/startup/apps/index.ts @@ -0,0 +1 @@ +import './trialExpiration'; diff --git a/apps/meteor/ee/server/startup/apps/trialExpiration.ts b/apps/meteor/ee/server/startup/apps/trialExpiration.ts new file mode 100644 index 00000000000..a96630be5c0 --- /dev/null +++ b/apps/meteor/ee/server/startup/apps/trialExpiration.ts @@ -0,0 +1,10 @@ +import { Meteor } from 'meteor/meteor'; + +import { Apps } from '../../apps'; +import { onInvalidateLicense } from '../../../app/license/server/license'; + +Meteor.startup(() => { + onInvalidateLicense(() => { + void Apps.disableApps(); + }); +}); diff --git a/apps/meteor/ee/server/startup/index.ts b/apps/meteor/ee/server/startup/index.ts index 605838552d7..409bc1bba59 100644 --- a/apps/meteor/ee/server/startup/index.ts +++ b/apps/meteor/ee/server/startup/index.ts @@ -1,4 +1,5 @@ import '../apps/startup'; +import './apps'; import './audit'; import './deviceManagement'; import './engagementDashboard';