mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 02:16:03 +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,
|
||||
features: {
|
||||
SSO: 'sso',
|
||||
allFeatures: [],
|
||||
isEnabled: () => false,
|
||||
},
|
||||
projectType: 'Community',
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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' },
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -5,8 +5,8 @@ jest.mock('@strapi/strapi/ee', () => ({
|
||||
isEnabled() {
|
||||
return true;
|
||||
},
|
||||
getEnabled() {
|
||||
return ['sso'];
|
||||
list() {
|
||||
return [{ name: 'sso' }];
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
@ -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);
|
||||
});
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ jest.mock('@strapi/strapi/lib/utils/ee', () => {
|
||||
isEnabled() {
|
||||
return false;
|
||||
},
|
||||
getEnabled() {
|
||||
list() {
|
||||
return [];
|
||||
},
|
||||
},
|
||||
|
||||
@ -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: [] } };
|
||||
}
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
});
|
||||
|
||||
@ -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'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user