diff --git a/packages/admin-test-utils/lib/setup/strapi.js b/packages/admin-test-utils/lib/setup/strapi.js index 3147b86eb6..ae36c8d04d 100644 --- a/packages/admin-test-utils/lib/setup/strapi.js +++ b/packages/admin-test-utils/lib/setup/strapi.js @@ -17,7 +17,6 @@ global.strapi = { isEE: false, features: { SSO: 'sso', - allFeatures: [], isEnabled: () => false, }, projectType: 'Community', diff --git a/packages/core/admin/admin/src/index.js b/packages/core/admin/admin/src/index.js index 2ba98d9270..dadfafe3a1 100644 --- a/packages/core/admin/admin/src/index.js +++ b/packages/core/admin/admin/src/index.js @@ -1,7 +1,7 @@ import ReactDOM from 'react-dom'; +import appCustomisations from './app'; import { Components, Fields, Middlewares, Reducers } from './core/apis'; import { axiosInstance } from './core/utils'; -import appCustomisations from './app'; // eslint-disable-next-line import/extensions import plugins from './plugins'; import appReducers from './reducers'; @@ -12,7 +12,7 @@ window.strapi = { telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false, features: { SSO: 'sso', - auditLogs: 'audit-logs', + AUDIT_LOGS: 'audit-logs', }, projectType: 'Community', }; @@ -39,8 +39,7 @@ const run = async () => { window.strapi.isEE = isEE; window.strapi.features = { ...window.strapi.features, - allFeatures: features, - isEnabled: (f) => features.includes(f), + isEnabled: (featureName) => features.some((feature) => feature.name === featureName), }; window.strapi.projectType = isEE ? 'Enterprise' : 'Community'; diff --git a/packages/core/admin/ee/admin/hooks/useSettingsMenu/utils/customAdminLinks.js b/packages/core/admin/ee/admin/hooks/useSettingsMenu/utils/customAdminLinks.js index c3e7b8ecb2..22ff23cbca 100644 --- a/packages/core/admin/ee/admin/hooks/useSettingsMenu/utils/customAdminLinks.js +++ b/packages/core/admin/ee/admin/hooks/useSettingsMenu/utils/customAdminLinks.js @@ -1,6 +1,6 @@ import adminPermissions from '../../../../../admin/src/permissions'; -const auditLogsRoutes = strapi.features.isEnabled(strapi.features.auditLogs) +const auditLogsRoutes = strapi.features.isEnabled(strapi.features.AUDIT_LOGS) ? [ { intlLabel: { id: 'global.auditLogs', defaultMessage: 'Audit Logs' }, diff --git a/packages/core/admin/ee/admin/pages/SettingsPage/utils/customRoutes.js b/packages/core/admin/ee/admin/pages/SettingsPage/utils/customRoutes.js index 601e68587f..fe47f3026c 100644 --- a/packages/core/admin/ee/admin/pages/SettingsPage/utils/customRoutes.js +++ b/packages/core/admin/ee/admin/pages/SettingsPage/utils/customRoutes.js @@ -14,7 +14,7 @@ if (strapi.features.isEnabled(strapi.features.SSO)) { }); } -if (strapi.features.isEnabled(strapi.features.auditLogs)) { +if (strapi.features.isEnabled(strapi.features.AUDIT_LOGS)) { routes.push({ async Component() { const component = await import( diff --git a/packages/core/admin/ee/server/services/__tests__/sso.test.js b/packages/core/admin/ee/server/services/__tests__/sso.test.js index 6d66df817d..874ae71664 100644 --- a/packages/core/admin/ee/server/services/__tests__/sso.test.js +++ b/packages/core/admin/ee/server/services/__tests__/sso.test.js @@ -5,8 +5,8 @@ jest.mock('@strapi/strapi/ee', () => ({ isEnabled() { return true; }, - getEnabled() { - return ['sso']; + list() { + return [{ name: 'sso' }]; }, }, })); diff --git a/packages/core/admin/ee/server/services/audit-logs.js b/packages/core/admin/ee/server/services/audit-logs.js index 610cc04f22..48644a056d 100644 --- a/packages/core/admin/ee/server/services/audit-logs.js +++ b/packages/core/admin/ee/server/services/audit-logs.js @@ -2,8 +2,9 @@ const localProvider = require('@strapi/provider-audit-logs-local'); const { scheduleJob } = require('node-schedule'); +const { features } = require('@strapi/strapi/lib/utils/ee'); -const RETENTION_DAYS = 90; +const DEFAULT_RETENTION_DAYS = 90; const defaultEvents = [ 'entry.create', @@ -88,10 +89,12 @@ const createAuditLogsService = (strapi) => { return { async register() { + const retentionDays = + features.get('audit-logs')?.options.retentionDays ?? DEFAULT_RETENTION_DAYS; this._provider = await localProvider.register({ strapi }); this._eventHubUnsubscribe = strapi.eventHub.subscribe(handleEvent.bind(this)); this._deleteExpiredJob = scheduleJob('0 0 * * *', () => { - const expirationDate = new Date(Date.now() - RETENTION_DAYS * 24 * 60 * 60 * 1000); + const expirationDate = new Date(Date.now() - retentionDays * 24 * 60 * 60 * 1000); this._provider.deleteExpiredEvents(expirationDate); }); diff --git a/packages/core/admin/server/controllers/__tests__/admin.test.js b/packages/core/admin/server/controllers/__tests__/admin.test.js index 579512f383..e00daf5eb4 100644 --- a/packages/core/admin/server/controllers/__tests__/admin.test.js +++ b/packages/core/admin/server/controllers/__tests__/admin.test.js @@ -8,7 +8,7 @@ jest.mock('@strapi/strapi/lib/utils/ee', () => { isEnabled() { return false; }, - getEnabled() { + list() { return []; }, }, diff --git a/packages/core/admin/server/controllers/admin.js b/packages/core/admin/server/controllers/admin.js index 73cb3e42c1..ad3623e0c1 100644 --- a/packages/core/admin/server/controllers/admin.js +++ b/packages/core/admin/server/controllers/admin.js @@ -37,7 +37,7 @@ module.exports = { async getProjectType() { // FIXME try { - return { data: { isEE: strapi.EE, features: ee.features.getEnabled() } }; + return { data: { isEE: strapi.EE, features: ee.features.list() } }; } catch (err) { return { data: { isEE: false, features: [] } }; } diff --git a/packages/core/strapi/ee/index.js b/packages/core/strapi/ee/index.js index b46a5afdd0..e8d0df8a26 100644 --- a/packages/core/strapi/ee/index.js +++ b/packages/core/strapi/ee/index.js @@ -146,6 +146,16 @@ const checkLicense = async ({ strapi }) => { } }; +const list = () => { + return ( + ee.licenseInfo.features?.map((feature) => + typeof feature === 'object' ? feature : { name: feature } + ) || [] + ); +}; + +const get = (featureName) => list().find((feature) => feature.name === featureName); + module.exports = Object.freeze({ init, checkLicense, @@ -155,7 +165,8 @@ module.exports = Object.freeze({ }, features: Object.freeze({ - isEnabled: (feature) => (ee.enabled && ee.licenseInfo.features?.includes(feature)) || false, - getEnabled: () => (ee.enabled && ee.licenseInfo.features) || [], + list, + get, + isEnabled: (featureName) => get(featureName) !== undefined, }), }); diff --git a/packages/core/strapi/ee/license.js b/packages/core/strapi/ee/license.js index 93253ee6ec..e5a28078ff 100644 --- a/packages/core/strapi/ee/license.js +++ b/packages/core/strapi/ee/license.js @@ -10,7 +10,7 @@ const machineId = require('../lib/utils/machine-id'); const DEFAULT_FEATURES = { bronze: [], silver: [], - gold: ['sso'], + gold: ['sso', { name: 'audit-logs', options: { retentionDays: 90 } }], }; const publicKey = fs.readFileSync(join(__dirname, 'resources/key.pub'));