From 18b28ce2ee803e19ce9e3c0b592038048c52bb1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= <8087692+remidej@users.noreply.github.com> Date: Tue, 23 Jan 2024 18:15:34 +0100 Subject: [PATCH] chore: set up content history files (#19298) * setup history server files * add admin files * chore: remove dedicated lifecycle files --- examples/getstarted/config/features.js | 6 +++- packages/core/admin/admin/src/StrapiApp.tsx | 2 +- .../admin/src/content-manager/history/LICENSE | 1 + .../src/content-manager/history/routes.tsx | 9 ++++++ .../admin/src/content-manager/routes.tsx | 3 ++ .../content-manager/server/src/bootstrap.ts | 3 ++ .../server/src/controllers/index.ts | 2 ++ .../content-manager/server/src/destroy.ts | 8 +++++ .../server/src/history/LICENSE | 1 + .../server/src/history/controllers/index.ts | 7 +++++ .../server/src/history/index.ts | 31 +++++++++++++++++++ .../server/src/history/routes/index.ts | 7 +++++ .../server/src/history/services/index.ts | 3 ++ .../core/content-manager/server/src/index.ts | 4 +++ .../content-manager/server/src/register.ts | 8 +++++ .../server/src/routes/index.ts | 6 +++- .../server/src/services/index.ts | 2 ++ 17 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 packages/core/admin/admin/src/content-manager/history/LICENSE create mode 100644 packages/core/admin/admin/src/content-manager/history/routes.tsx create mode 100644 packages/core/content-manager/server/src/destroy.ts create mode 100644 packages/core/content-manager/server/src/history/LICENSE create mode 100644 packages/core/content-manager/server/src/history/controllers/index.ts create mode 100644 packages/core/content-manager/server/src/history/index.ts create mode 100644 packages/core/content-manager/server/src/history/routes/index.ts create mode 100644 packages/core/content-manager/server/src/history/services/index.ts create mode 100644 packages/core/content-manager/server/src/register.ts diff --git a/examples/getstarted/config/features.js b/examples/getstarted/config/features.js index c381b7503a..f7113791de 100644 --- a/examples/getstarted/config/features.js +++ b/examples/getstarted/config/features.js @@ -1 +1,5 @@ -module.exports = ({ env }) => ({}); +module.exports = ({ env }) => ({ + future: { + history: true, + }, +}); diff --git a/packages/core/admin/admin/src/StrapiApp.tsx b/packages/core/admin/admin/src/StrapiApp.tsx index 437d6fa3e7..02a5ade6cb 100644 --- a/packages/core/admin/admin/src/StrapiApp.tsx +++ b/packages/core/admin/admin/src/StrapiApp.tsx @@ -472,7 +472,7 @@ class StrapiApp { ); invariant(component, 'A Component must be provided'); - // @ts-expect-error – we've alredy checked above that the block exists. + // @ts-expect-error – we've already checked above that the block exists. this.admin.injectionZones.contentManager[containerName][blockName].push(component); }; diff --git a/packages/core/admin/admin/src/content-manager/history/LICENSE b/packages/core/admin/admin/src/content-manager/history/LICENSE new file mode 100644 index 0000000000..2d66516358 --- /dev/null +++ b/packages/core/admin/admin/src/content-manager/history/LICENSE @@ -0,0 +1 @@ +If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software. Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software. BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT. IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS; IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS. diff --git a/packages/core/admin/admin/src/content-manager/history/routes.tsx b/packages/core/admin/admin/src/content-manager/history/routes.tsx new file mode 100644 index 0000000000..8445a47e88 --- /dev/null +++ b/packages/core/admin/admin/src/content-manager/history/routes.tsx @@ -0,0 +1,9 @@ +/* eslint-disable check-file/filename-naming-convention */ +import { type RouteObject } from 'react-router-dom'; + +/** + * These routes will be merged with the rest of the Content Manager routes + */ +const routes: RouteObject[] = []; + +export { routes }; diff --git a/packages/core/admin/admin/src/content-manager/routes.tsx b/packages/core/admin/admin/src/content-manager/routes.tsx index c7f4cfd4d2..57a81d0df4 100644 --- a/packages/core/admin/admin/src/content-manager/routes.tsx +++ b/packages/core/admin/admin/src/content-manager/routes.tsx @@ -2,6 +2,8 @@ import { UID } from '@strapi/types'; import { Navigate, RouteObject, useLoaderData } from 'react-router-dom'; +import { routes as historyRoutes } from './history/routes'; + const Redirect = () => { const pathname = useLoaderData() as string; @@ -132,6 +134,7 @@ const routes: RouteObject[] = [ }; }, }, + ...historyRoutes, ], }, ]; diff --git a/packages/core/content-manager/server/src/bootstrap.ts b/packages/core/content-manager/server/src/bootstrap.ts index d7b1802d2e..e04cdaed9b 100644 --- a/packages/core/content-manager/server/src/bootstrap.ts +++ b/packages/core/content-manager/server/src/bootstrap.ts @@ -1,5 +1,6 @@ import { getService } from './utils'; import { ALLOWED_WEBHOOK_EVENTS } from './constants'; +import history from './history'; export default async () => { Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => { @@ -10,4 +11,6 @@ export default async () => { await getService('components').syncConfigurations(); await getService('content-types').syncConfigurations(); await getService('permission').registerPermissions(); + + await history.bootstrap?.({ strapi }); }; diff --git a/packages/core/content-manager/server/src/controllers/index.ts b/packages/core/content-manager/server/src/controllers/index.ts index 625d0f986c..984aa30c8d 100644 --- a/packages/core/content-manager/server/src/controllers/index.ts +++ b/packages/core/content-manager/server/src/controllers/index.ts @@ -5,6 +5,7 @@ import init from './init'; import relations from './relations'; import singleTypes from './single-types'; import uid from './uid'; +import history from '../history'; export default { 'collection-types': collectionTypes, @@ -14,4 +15,5 @@ export default { relations, 'single-types': singleTypes, uid, + ...(history.controllers ? history.controllers : {}), }; diff --git a/packages/core/content-manager/server/src/destroy.ts b/packages/core/content-manager/server/src/destroy.ts new file mode 100644 index 0000000000..e386dd8084 --- /dev/null +++ b/packages/core/content-manager/server/src/destroy.ts @@ -0,0 +1,8 @@ +import type { Plugin } from '@strapi/types'; +import history from './history'; + +const destroy: Plugin.LoadedPlugin['destroy'] = async ({ strapi }) => { + await history.destroy?.({ strapi }); +}; + +export default destroy; diff --git a/packages/core/content-manager/server/src/history/LICENSE b/packages/core/content-manager/server/src/history/LICENSE new file mode 100644 index 0000000000..2d66516358 --- /dev/null +++ b/packages/core/content-manager/server/src/history/LICENSE @@ -0,0 +1 @@ +If you or the company you represent has entered into a written agreement referencing the Enterprise Edition of the Strapi source code available at https://github.com/strapi/strapi, then such agreement applies to your use of the Enterprise Edition of the Strapi Software. If you or the company you represent is using the Enterprise Edition of the Strapi Software in connection with a subscription to our cloud offering, then the agreement you have agreed to with respect to our cloud offering and the licenses included in such agreement apply to your use of the Enterprise Edition of the Strapi Software. Otherwise, the Strapi Enterprise Software License Agreement (found here https://strapi.io/enterprise-terms) applies to your use of the Enterprise Edition of the Strapi Software. BY ACCESSING OR USING THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE, YOU ARE AGREEING TO BE BOUND BY THE RELEVANT REFERENCED AGREEMENT. IF YOU ARE NOT AUTHORIZED TO ACCEPT THESE TERMS ON BEHALF OF THE COMPANY YOU REPRESENT OR IF YOU DO NOT AGREE TO ALL OF THE RELEVANT TERMS AND CONDITIONS REFERENCED AND YOU HAVE NOT OTHERWISE EXECUTED A WRITTEN AGREEMENT WITH STRAPI, YOU ARE NOT AUTHORIZED TO ACCESS OR USE OR ALLOW ANY USER TO ACCESS OR USE ANY PART OF THE ENTERPRISE EDITION OF THE STRAPI SOFTWARE. YOUR ACCESS RIGHTS ARE CONDITIONAL ON YOUR CONSENT TO THE RELEVANT REFERENCED TERMS TO THE EXCLUSION OF ALL OTHER TERMS; IF THE RELEVANT REFERENCED TERMS ARE CONSIDERED AN OFFER BY YOU, ACCEPTANCE IS EXPRESSLY LIMITED TO THE RELEVANT REFERENCED TERMS. diff --git a/packages/core/content-manager/server/src/history/controllers/index.ts b/packages/core/content-manager/server/src/history/controllers/index.ts new file mode 100644 index 0000000000..bca6bccb30 --- /dev/null +++ b/packages/core/content-manager/server/src/history/controllers/index.ts @@ -0,0 +1,7 @@ +import type { Plugin } from '@strapi/types'; + +/** + * The controllers will me merged with the other Content Manager controllers, + * so we need to avoid conficts in the controller names. + */ +export const controllers: Plugin.LoadedPlugin['controllers'] = {}; diff --git a/packages/core/content-manager/server/src/history/index.ts b/packages/core/content-manager/server/src/history/index.ts new file mode 100644 index 0000000000..179f7f6fff --- /dev/null +++ b/packages/core/content-manager/server/src/history/index.ts @@ -0,0 +1,31 @@ +import type { Plugin } from '@strapi/types'; +import { controllers } from './controllers'; +import { services } from './services'; + +/** + * Check once if the feature is enabled (both license info & feature flag) before loading it, + * so that we can assume it is enabled in the other files. + */ +const getFeature = (): Partial => { + // TODO: add license check here when it's ready on the license registry + if (strapi.features.future.isEnabled('history')) { + const register: Plugin.LoadedPlugin['register'] = async () => { + // TODO: remove log once there are actual features + console.log('registering history feature'); + }; + const bootstrap: Plugin.LoadedPlugin['bootstrap'] = async () => {}; + const destroy: Plugin.LoadedPlugin['destroy'] = async () => {}; + + return { + register, + bootstrap, + controllers, + services, + destroy, + }; + } + + return {}; +}; + +export default getFeature(); diff --git a/packages/core/content-manager/server/src/history/routes/index.ts b/packages/core/content-manager/server/src/history/routes/index.ts new file mode 100644 index 0000000000..2cdad6bbfb --- /dev/null +++ b/packages/core/content-manager/server/src/history/routes/index.ts @@ -0,0 +1,7 @@ +import type { Plugin } from '@strapi/types'; + +/** + * The routes will me merged with the other Content Manager routers, + * so we need to avoid conficts in the router name, and to prefix the path for each route. + */ +export const routes: Plugin.LoadedPlugin['routes'] = {}; diff --git a/packages/core/content-manager/server/src/history/services/index.ts b/packages/core/content-manager/server/src/history/services/index.ts new file mode 100644 index 0000000000..59e788eacc --- /dev/null +++ b/packages/core/content-manager/server/src/history/services/index.ts @@ -0,0 +1,3 @@ +import type { Plugin } from '@strapi/types'; + +export const services: Plugin.LoadedPlugin['services'] = {}; diff --git a/packages/core/content-manager/server/src/index.ts b/packages/core/content-manager/server/src/index.ts index fb788589c7..8c11d8a32f 100644 --- a/packages/core/content-manager/server/src/index.ts +++ b/packages/core/content-manager/server/src/index.ts @@ -1,4 +1,6 @@ +import register from './register'; import bootstrap from './bootstrap'; +import destroy from './destroy'; import routes from './routes'; import policies from './policies'; import controllers from './controllers'; @@ -6,7 +8,9 @@ import services from './services'; export default () => { return { + register, bootstrap, + destroy, controllers, routes, policies, diff --git a/packages/core/content-manager/server/src/register.ts b/packages/core/content-manager/server/src/register.ts new file mode 100644 index 0000000000..e219f71cb2 --- /dev/null +++ b/packages/core/content-manager/server/src/register.ts @@ -0,0 +1,8 @@ +import type { Plugin } from '@strapi/types'; +import history from './history'; + +const register: Plugin.LoadedPlugin['register'] = async ({ strapi }) => { + await history.register?.({ strapi }); +}; + +export default register; diff --git a/packages/core/content-manager/server/src/routes/index.ts b/packages/core/content-manager/server/src/routes/index.ts index de12cceb8b..2ddb4c9aac 100644 --- a/packages/core/content-manager/server/src/routes/index.ts +++ b/packages/core/content-manager/server/src/routes/index.ts @@ -1,3 +1,7 @@ import admin from './admin'; +import history from '../history'; -export default { admin }; +export default { + admin, + ...(history.routes ? history.routes : {}), +}; diff --git a/packages/core/content-manager/server/src/services/index.ts b/packages/core/content-manager/server/src/services/index.ts index cc1c697ca5..4c6d71404d 100644 --- a/packages/core/content-manager/server/src/services/index.ts +++ b/packages/core/content-manager/server/src/services/index.ts @@ -8,6 +8,7 @@ import permissionChecker from './permission-checker'; import permission from './permission'; import populateBuilder from './populate-builder'; import uid from './uid'; +import history from '../history'; export default { components, @@ -20,4 +21,5 @@ export default { permission, 'populate-builder': populateBuilder, uid, + ...(history.services ? history.services : {}), };