mirror of
https://github.com/strapi/strapi.git
synced 2025-11-10 23:29:33 +00:00
Add audit logs support & update the features API
This commit is contained in:
parent
0da81577dd
commit
f3550cea82
@ -17,7 +17,6 @@ global.strapi = {
|
|||||||
isEE: false,
|
isEE: false,
|
||||||
features: {
|
features: {
|
||||||
SSO: 'sso',
|
SSO: 'sso',
|
||||||
allFeatures: [],
|
|
||||||
isEnabled: () => false,
|
isEnabled: () => false,
|
||||||
},
|
},
|
||||||
projectType: 'Community',
|
projectType: 'Community',
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
|
import appCustomisations from './app';
|
||||||
import { Components, Fields, Middlewares, Reducers } from './core/apis';
|
import { Components, Fields, Middlewares, Reducers } from './core/apis';
|
||||||
import { axiosInstance } from './core/utils';
|
import { axiosInstance } from './core/utils';
|
||||||
import appCustomisations from './app';
|
|
||||||
// eslint-disable-next-line import/extensions
|
// eslint-disable-next-line import/extensions
|
||||||
import plugins from './plugins';
|
import plugins from './plugins';
|
||||||
import appReducers from './reducers';
|
import appReducers from './reducers';
|
||||||
@ -12,7 +12,7 @@ window.strapi = {
|
|||||||
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
|
telemetryDisabled: process.env.STRAPI_TELEMETRY_DISABLED ?? false,
|
||||||
features: {
|
features: {
|
||||||
SSO: 'sso',
|
SSO: 'sso',
|
||||||
auditLogs: 'audit-logs',
|
AUDIT_LOGS: 'audit-logs',
|
||||||
},
|
},
|
||||||
projectType: 'Community',
|
projectType: 'Community',
|
||||||
};
|
};
|
||||||
@ -39,8 +39,7 @@ const run = async () => {
|
|||||||
window.strapi.isEE = isEE;
|
window.strapi.isEE = isEE;
|
||||||
window.strapi.features = {
|
window.strapi.features = {
|
||||||
...window.strapi.features,
|
...window.strapi.features,
|
||||||
allFeatures: features,
|
isEnabled: (featureName) => features.some((feature) => feature.name === featureName),
|
||||||
isEnabled: (f) => features.includes(f),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
window.strapi.projectType = isEE ? 'Enterprise' : 'Community';
|
window.strapi.projectType = isEE ? 'Enterprise' : 'Community';
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import adminPermissions from '../../../../../admin/src/permissions';
|
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' },
|
intlLabel: { id: 'global.auditLogs', defaultMessage: 'Audit Logs' },
|
||||||
|
|||||||
@ -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({
|
routes.push({
|
||||||
async Component() {
|
async Component() {
|
||||||
const component = await import(
|
const component = await import(
|
||||||
|
|||||||
@ -5,8 +5,8 @@ jest.mock('@strapi/strapi/ee', () => ({
|
|||||||
isEnabled() {
|
isEnabled() {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
getEnabled() {
|
list() {
|
||||||
return ['sso'];
|
return [{ name: 'sso' }];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|||||||
@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
const localProvider = require('@strapi/provider-audit-logs-local');
|
const localProvider = require('@strapi/provider-audit-logs-local');
|
||||||
const { scheduleJob } = require('node-schedule');
|
const { scheduleJob } = require('node-schedule');
|
||||||
|
const { features } = require('@strapi/strapi/lib/utils/ee');
|
||||||
|
|
||||||
const RETENTION_DAYS = 90;
|
const DEFAULT_RETENTION_DAYS = 90;
|
||||||
|
|
||||||
const defaultEvents = [
|
const defaultEvents = [
|
||||||
'entry.create',
|
'entry.create',
|
||||||
@ -88,10 +89,12 @@ const createAuditLogsService = (strapi) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
async register() {
|
async register() {
|
||||||
|
const retentionDays =
|
||||||
|
features.get('audit-logs')?.options.retentionDays ?? DEFAULT_RETENTION_DAYS;
|
||||||
this._provider = await localProvider.register({ strapi });
|
this._provider = await localProvider.register({ strapi });
|
||||||
this._eventHubUnsubscribe = strapi.eventHub.subscribe(handleEvent.bind(this));
|
this._eventHubUnsubscribe = strapi.eventHub.subscribe(handleEvent.bind(this));
|
||||||
this._deleteExpiredJob = scheduleJob('0 0 * * *', () => {
|
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);
|
this._provider.deleteExpiredEvents(expirationDate);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ jest.mock('@strapi/strapi/lib/utils/ee', () => {
|
|||||||
isEnabled() {
|
isEnabled() {
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
getEnabled() {
|
list() {
|
||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -37,7 +37,7 @@ module.exports = {
|
|||||||
async getProjectType() {
|
async getProjectType() {
|
||||||
// FIXME
|
// FIXME
|
||||||
try {
|
try {
|
||||||
return { data: { isEE: strapi.EE, features: ee.features.getEnabled() } };
|
return { data: { isEE: strapi.EE, features: ee.features.list() } };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return { data: { isEE: false, features: [] } };
|
return { data: { isEE: false, features: [] } };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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({
|
module.exports = Object.freeze({
|
||||||
init,
|
init,
|
||||||
checkLicense,
|
checkLicense,
|
||||||
@ -155,7 +165,8 @@ module.exports = Object.freeze({
|
|||||||
},
|
},
|
||||||
|
|
||||||
features: Object.freeze({
|
features: Object.freeze({
|
||||||
isEnabled: (feature) => (ee.enabled && ee.licenseInfo.features?.includes(feature)) || false,
|
list,
|
||||||
getEnabled: () => (ee.enabled && ee.licenseInfo.features) || [],
|
get,
|
||||||
|
isEnabled: (featureName) => get(featureName) !== undefined,
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const machineId = require('../lib/utils/machine-id');
|
|||||||
const DEFAULT_FEATURES = {
|
const DEFAULT_FEATURES = {
|
||||||
bronze: [],
|
bronze: [],
|
||||||
silver: [],
|
silver: [],
|
||||||
gold: ['sso'],
|
gold: ['sso', { name: 'audit-logs', options: { retentionDays: 90 } }],
|
||||||
};
|
};
|
||||||
|
|
||||||
const publicKey = fs.readFileSync(join(__dirname, 'resources/key.pub'));
|
const publicKey = fs.readFileSync(join(__dirname, 'resources/key.pub'));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user