2022-12-06 12:14:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2022-12-12 18:09:24 +01:00
|
|
|
const { features } = require('@strapi/strapi/lib/utils/ee');
|
2023-02-20 18:58:09 +01:00
|
|
|
const { set } = require('lodash/fp');
|
2022-12-07 14:43:28 +01:00
|
|
|
const executeCERegister = require('../../server/register');
|
2023-02-08 11:38:58 +01:00
|
|
|
const migrateAuditLogsTable = require('./migrations/audit-logs-table');
|
2022-12-12 18:09:24 +01:00
|
|
|
const createAuditLogsService = require('./services/audit-logs');
|
2022-12-06 12:14:33 +01:00
|
|
|
|
|
|
|
module.exports = async ({ strapi }) => {
|
2022-12-12 18:09:24 +01:00
|
|
|
if (features.isEnabled('audit-logs')) {
|
2023-02-07 12:11:28 +01:00
|
|
|
strapi.hook('strapi::content-types.beforeSync').register(migrateAuditLogsTable);
|
2022-12-12 18:09:24 +01:00
|
|
|
const auditLogsService = createAuditLogsService(strapi);
|
|
|
|
strapi.container.register('audit-logs', auditLogsService);
|
2022-12-21 12:37:47 +01:00
|
|
|
await auditLogsService.register();
|
2022-12-12 18:09:24 +01:00
|
|
|
}
|
2023-02-20 18:58:09 +01:00
|
|
|
if (features.isEnabled('review-workflows')) {
|
|
|
|
addReviewWorkflowMiddleware(strapi);
|
|
|
|
}
|
2022-12-21 18:39:15 +01:00
|
|
|
await executeCERegister({ strapi });
|
2022-12-06 12:14:33 +01:00
|
|
|
};
|
2023-02-20 18:58:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A Strapi middleware function that adds support for review workflows.
|
|
|
|
*
|
|
|
|
* @param {object} strapi - The Strapi instance.
|
|
|
|
*/
|
|
|
|
const addReviewWorkflowMiddleware = (strapi) => {
|
|
|
|
/**
|
|
|
|
* A middleware function that moves the `reviewWorkflows` attribute from the top level of
|
|
|
|
* the request body to the `options` object within the request body.
|
|
|
|
*
|
|
|
|
* @param {object} ctx - The Koa context object.
|
|
|
|
*/
|
|
|
|
const moveReviewWorkflowOption = (ctx) => {
|
|
|
|
// Move reviewWorkflows to options.reviewWorkflows
|
|
|
|
const { reviewWorkflows, ...contentType } = ctx.request.body.contentType;
|
|
|
|
ctx.request.body.contentType = set('options.reviewWorkflows', reviewWorkflows, contentType);
|
|
|
|
};
|
|
|
|
strapi.server.router.use('/content-type-builder/content-types/:uid', (ctx, next) => {
|
|
|
|
if (ctx.method === 'PUT') {
|
|
|
|
moveReviewWorkflowOption(ctx);
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
strapi.server.router.use('/content-type-builder/content-types', (ctx, next) => {
|
|
|
|
if (ctx.method === 'POST') {
|
|
|
|
moveReviewWorkflowOption(ctx);
|
|
|
|
}
|
|
|
|
return next();
|
|
|
|
});
|
|
|
|
};
|