From 6b362b6643b1dc145b56b72847970ef27d68432d Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 21 May 2025 13:11:47 +0200 Subject: [PATCH] feat: Filter out enterprise apps if there is no ee license --- packages/backend/src/helpers/get-app.js | 14 +++++++---- packages/backend/src/models/app.js | 33 +++++++++++++++++++------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/helpers/get-app.js b/packages/backend/src/helpers/get-app.js index 5e23fb18..6f769f5e 100644 --- a/packages/backend/src/helpers/get-app.js +++ b/packages/backend/src/helpers/get-app.js @@ -5,6 +5,7 @@ import cloneDeep from 'lodash/cloneDeep.js'; import addAuthenticationSteps from './add-authentication-steps.js'; import addReconnectionSteps from './add-reconnection-steps.js'; import { fileURLToPath, pathToFileURL } from 'url'; +import { hasValidLicense } from './license.ee.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); @@ -13,9 +14,14 @@ const apps = fs .reduce((apps, dirent) => { if (!dirent.isDirectory()) return apps; - apps[dirent.name] = import( - pathToFileURL(join(__dirname, '../apps', dirent.name, 'index.js')) - ); + const indexPath = join(__dirname, '../apps', dirent.name, 'index.js'); + const indexEePath = join(__dirname, '../apps', dirent.name, 'index.ee.js'); + + if (fs.existsSync(indexEePath) && hasValidLicense()) { + apps[dirent.name] = import(pathToFileURL(indexEePath)); + } else { + apps[dirent.name] = import(pathToFileURL(indexPath)); + } return apps; }, {}); @@ -85,10 +91,8 @@ const addStaticSubsteps = (stepType, appData, step) => { arguments: step.arguments, }); } - computedStep.substeps.push(testStep(stepType)); return computedStep; }; - export default getApp; diff --git a/packages/backend/src/models/app.js b/packages/backend/src/models/app.js index 6decb5ba..a9446b5c 100644 --- a/packages/backend/src/models/app.js +++ b/packages/backend/src/models/app.js @@ -3,26 +3,45 @@ import path, { join } from 'path'; import { fileURLToPath } from 'url'; import appInfoConverter from '../helpers/app-info-converter.js'; import getApp from '../helpers/get-app.js'; +import { hasValidLicense } from '../helpers/license.ee.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); class App { static folderPath = join(__dirname, '../apps'); - static list = fs - .readdirSync(this.folderPath) - .filter((file) => fs.statSync(join(this.folderPath, file)).isDirectory()); + static async list() { + const directories = fs + .readdirSync(this.folderPath) + .filter((file) => fs.statSync(join(this.folderPath, file)).isDirectory()); + + if (!(await hasValidLicense())) { + // Filter out enterprise apps if no valid license + const nonEnterpriseApps = []; + + for (const dir of directories) { + const appData = await getApp(dir, true); + if (!appData.enterprise) { + nonEnterpriseApps.push(dir); + } + } + + return nonEnterpriseApps; + } + + return directories; + } static async findAll(name, stripFuncs = true) { + const appList = await this.list(); + if (!name) return Promise.all( - this.list.map( - async (name) => await this.findOneByName(name, stripFuncs) - ) + appList.map(async (name) => await this.findOneByName(name, stripFuncs)) ); return Promise.all( - this.list + appList .filter((app) => app.includes(name.toLowerCase())) .map((name) => this.findOneByName(name, stripFuncs)) );