@strapi/content-manager 0.0.0-experimental.5788c38836be65c0321a2dcadbdf44f04b798e8a → 0.0.0-experimental.599b53360e581fdbd0afac055f1bf2d29816feec
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
- package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-D1YuKq8j.mjs → ComponentConfigurationPage-D4H-v0et.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-D1YuKq8j.mjs.map → ComponentConfigurationPage-D4H-v0et.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-B42mQr1K.js → ComponentConfigurationPage-DdkVGfXC.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-B42mQr1K.js.map → ComponentConfigurationPage-DdkVGfXC.js.map} +1 -1
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
- package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
- package/dist/_chunks/{EditConfigurationPage-C9yiwgI_.mjs → EditConfigurationPage-D1nvB7Br.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-C9yiwgI_.mjs.map → EditConfigurationPage-D1nvB7Br.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-NC89F29V.js → EditConfigurationPage-LYEvR4fW.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-NC89F29V.js.map → EditConfigurationPage-LYEvR4fW.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-k8UcfVwt.mjs → EditViewPage-Bcnff6Vd.mjs} +21 -54
- package/dist/_chunks/EditViewPage-Bcnff6Vd.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-DYDpe5Wi.js → EditViewPage-DqelJ9UK.js} +23 -57
- package/dist/_chunks/EditViewPage-DqelJ9UK.js.map +1 -0
- package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
- package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
- package/dist/_chunks/{Form-DUU19g6M.js → Form-CnHfBeiB.js} +6 -7
- package/dist/_chunks/Form-CnHfBeiB.js.map +1 -0
- package/dist/_chunks/{Form-UHu2eOuG.mjs → Form-CzPCJi3B.mjs} +4 -4
- package/dist/_chunks/Form-CzPCJi3B.mjs.map +1 -0
- package/dist/_chunks/{History-CpxkZXS3.mjs → History-CcmSn3Mj.mjs} +71 -104
- package/dist/_chunks/History-CcmSn3Mj.mjs.map +1 -0
- package/dist/_chunks/{History-CyA8tvJZ.js → History-zArjENzj.js} +81 -115
- package/dist/_chunks/History-zArjENzj.js.map +1 -0
- package/dist/_chunks/{Field-Crhugun2.js → Input-CDHKQd7o.js} +1266 -1239
- package/dist/_chunks/Input-CDHKQd7o.js.map +1 -0
- package/dist/_chunks/{Field-BLL5lknV.mjs → Input-aV8SSoTa.mjs} +1271 -1244
- package/dist/_chunks/Input-aV8SSoTa.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-OUwV8QF1.mjs → ListConfigurationPage-BPvzENJJ.mjs} +7 -6
- package/dist/_chunks/ListConfigurationPage-BPvzENJJ.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-pJV7aG2V.js → ListConfigurationPage-ByZAO_9H.js} +7 -7
- package/dist/_chunks/ListConfigurationPage-ByZAO_9H.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BIT0M8VG.js → ListViewPage-BVKBeQAA.js} +73 -48
- package/dist/_chunks/ListViewPage-BVKBeQAA.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BOnhCGkE.mjs → ListViewPage-HljQVnFH.mjs} +67 -41
- package/dist/_chunks/ListViewPage-HljQVnFH.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-uIBsBUmH.js → NoContentTypePage-BV5zfDxr.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-uIBsBUmH.js.map → NoContentTypePage-BV5zfDxr.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CwjlHGTn.mjs → NoContentTypePage-BfHaSM-K.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CwjlHGTn.mjs.map → NoContentTypePage-BfHaSM-K.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CcWbyT_z.mjs → NoPermissionsPage-D6ze2nQL.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CcWbyT_z.mjs.map → NoPermissionsPage-D6ze2nQL.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-C8wkEaOF.js → NoPermissionsPage-vdNpc6jb.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-C8wkEaOF.js.map → NoPermissionsPage-vdNpc6jb.js.map} +1 -1
- package/dist/_chunks/Preview-DEHdENT1.js +305 -0
- package/dist/_chunks/Preview-DEHdENT1.js.map +1 -0
- package/dist/_chunks/Preview-vfWOtPG5.mjs +287 -0
- package/dist/_chunks/Preview-vfWOtPG5.mjs.map +1 -0
- package/dist/_chunks/{Relations-wIdWJnA9.mjs → Relations-B7_hbF0w.mjs} +50 -24
- package/dist/_chunks/Relations-B7_hbF0w.mjs.map +1 -0
- package/dist/_chunks/{Relations-CwRu_eZv.js → Relations-DcoOBejP.js} +50 -25
- package/dist/_chunks/Relations-DcoOBejP.js.map +1 -0
- package/dist/_chunks/{en-Bm0D0IWz.js → en-BR48D_RH.js} +23 -4
- package/dist/_chunks/{en-Bm0D0IWz.js.map → en-BR48D_RH.js.map} +1 -1
- package/dist/_chunks/{en-DKV44jRb.mjs → en-D65uIF6Y.mjs} +23 -4
- package/dist/_chunks/{en-DKV44jRb.mjs.map → en-D65uIF6Y.mjs.map} +1 -1
- package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
- package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
- package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
- package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-C43IbhA_.js} +16 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-C43IbhA_.js.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr-DBseuRuB.mjs} +16 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr-DBseuRuB.mjs.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-BO-T2BdP.js → index-CxLSGwnk.js} +653 -249
- package/dist/_chunks/index-CxLSGwnk.js.map +1 -0
- package/dist/_chunks/{index-BQ8DxaCa.mjs → index-EH8ZtHd5.mjs} +670 -266
- package/dist/_chunks/index-EH8ZtHd5.mjs.map +1 -0
- package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
- package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
- package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
- package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
- package/dist/_chunks/{layout-N63eyE5E.mjs → layout-CxDMdJ13.mjs} +4 -4
- package/dist/_chunks/{layout-N63eyE5E.mjs.map → layout-CxDMdJ13.mjs.map} +1 -1
- package/dist/_chunks/{layout-BTB1_M8g.js → layout-DSeUTfMv.js} +5 -6
- package/dist/_chunks/{layout-BTB1_M8g.js.map → layout-DSeUTfMv.js.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-Bh9r0CVE.mjs → relations-B8_Uu38Q.mjs} +21 -8
- package/dist/_chunks/relations-B8_Uu38Q.mjs.map +1 -0
- package/dist/_chunks/{relations-C9AQuM2z.js → relations-S5nNKdN3.js} +20 -7
- package/dist/_chunks/relations-S5nNKdN3.js.map +1 -0
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
- package/dist/_chunks/{useDebounce-CtcjDB3L.js → usePrev-B9w_-eYc.js} +1 -14
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +1 -0
- package/dist/_chunks/usePrev-DH6iah0A.mjs +16 -0
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +6 -5
- package/dist/admin/src/content-manager.d.ts +3 -2
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +19 -2
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +3 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +27 -0
- package/dist/admin/src/pages/EditView/utils/data.d.ts +1 -0
- package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
- package/dist/admin/src/preview/routes.d.ts +3 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- package/dist/admin/src/router.d.ts +1 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +16 -19
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/server/index.js +566 -318
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +567 -318
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +16 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts +3 -3
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +6 -11
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +7 -6
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +13 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +16 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +32 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +12 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +19 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +12 -10
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +7 -6
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/index.d.ts +1 -0
- package/dist/shared/contracts/index.d.ts.map +1 -1
- package/dist/shared/contracts/preview.d.ts +27 -0
- package/dist/shared/contracts/preview.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +4 -0
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +14 -13
- package/dist/_chunks/EditViewPage-DYDpe5Wi.js.map +0 -1
- package/dist/_chunks/EditViewPage-k8UcfVwt.mjs.map +0 -1
- package/dist/_chunks/Field-BLL5lknV.mjs.map +0 -1
- package/dist/_chunks/Field-Crhugun2.js.map +0 -1
- package/dist/_chunks/Form-DUU19g6M.js.map +0 -1
- package/dist/_chunks/Form-UHu2eOuG.mjs.map +0 -1
- package/dist/_chunks/History-CpxkZXS3.mjs.map +0 -1
- package/dist/_chunks/History-CyA8tvJZ.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-OUwV8QF1.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-pJV7aG2V.js.map +0 -1
- package/dist/_chunks/ListViewPage-BIT0M8VG.js.map +0 -1
- package/dist/_chunks/ListViewPage-BOnhCGkE.mjs.map +0 -1
- package/dist/_chunks/Relations-CwRu_eZv.js.map +0 -1
- package/dist/_chunks/Relations-wIdWJnA9.mjs.map +0 -1
- package/dist/_chunks/index-BO-T2BdP.js.map +0 -1
- package/dist/_chunks/index-BQ8DxaCa.mjs.map +0 -1
- package/dist/_chunks/relations-Bh9r0CVE.mjs.map +0 -1
- package/dist/_chunks/relations-C9AQuM2z.js.map +0 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +0 -1
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +0 -29
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +0 -1
package/dist/server/index.js
CHANGED
@@ -10,8 +10,7 @@ const qs = require("qs");
|
|
10
10
|
const slugify = require("@sindresorhus/slugify");
|
11
11
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
12
12
|
function _interopNamespace(e) {
|
13
|
-
if (e && e.__esModule)
|
14
|
-
return e;
|
13
|
+
if (e && e.__esModule) return e;
|
15
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
16
15
|
if (e) {
|
17
16
|
for (const k in e) {
|
@@ -33,10 +32,10 @@ const isNil__default = /* @__PURE__ */ _interopDefault(isNil);
|
|
33
32
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
34
33
|
const qs__default = /* @__PURE__ */ _interopDefault(qs);
|
35
34
|
const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
|
36
|
-
const getService$
|
35
|
+
const getService$2 = (name) => {
|
37
36
|
return strapi.plugin("content-manager").service(name);
|
38
37
|
};
|
39
|
-
function getService(strapi2, name) {
|
38
|
+
function getService$1(strapi2, name) {
|
40
39
|
return strapi2.service(`plugin::content-manager.${name}`);
|
41
40
|
}
|
42
41
|
const historyRestoreVersionSchema = yup__namespace.object().shape({
|
@@ -72,7 +71,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
72
71
|
if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
|
73
72
|
throw new strapiUtils.errors.ForbiddenError("contentType and documentId are required");
|
74
73
|
}
|
75
|
-
const permissionChecker2 = getService$
|
74
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
76
75
|
userAbility: ctx.state.userAbility,
|
77
76
|
model: ctx.query.contentType
|
78
77
|
});
|
@@ -80,7 +79,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
80
79
|
return ctx.forbidden();
|
81
80
|
}
|
82
81
|
const query = await permissionChecker2.sanitizeQuery(ctx.query);
|
83
|
-
const { results, pagination } = await getService(strapi2, "history").findVersionsPage({
|
82
|
+
const { results, pagination } = await getService$1(strapi2, "history").findVersionsPage({
|
84
83
|
query: {
|
85
84
|
...query,
|
86
85
|
...getValidPagination({ page: query.page, pageSize: query.pageSize })
|
@@ -105,14 +104,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
105
104
|
async restoreVersion(ctx) {
|
106
105
|
const request = ctx.request;
|
107
106
|
await validateRestoreVersion(request.body, "contentType is required");
|
108
|
-
const permissionChecker2 = getService$
|
107
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
109
108
|
userAbility: ctx.state.userAbility,
|
110
109
|
model: request.body.contentType
|
111
110
|
});
|
112
111
|
if (permissionChecker2.cannot.update()) {
|
113
112
|
throw new strapiUtils.errors.ForbiddenError();
|
114
113
|
}
|
115
|
-
const restoredDocument = await getService(strapi2, "history").restoreVersion(
|
114
|
+
const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
|
116
115
|
request.params.versionId
|
117
116
|
);
|
118
117
|
return {
|
@@ -121,7 +120,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
121
120
|
}
|
122
121
|
};
|
123
122
|
};
|
124
|
-
const controllers$
|
123
|
+
const controllers$2 = {
|
125
124
|
"history-version": createHistoryVersionController
|
126
125
|
/**
|
127
126
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -167,8 +166,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
167
166
|
};
|
168
167
|
const getRelationRestoreValue = async (versionRelationData, attribute) => {
|
169
168
|
if (Array.isArray(versionRelationData)) {
|
170
|
-
if (versionRelationData.length === 0)
|
171
|
-
return versionRelationData;
|
169
|
+
if (versionRelationData.length === 0) return versionRelationData;
|
172
170
|
const existingAndMissingRelations = await Promise.all(
|
173
171
|
versionRelationData.map((relation) => {
|
174
172
|
return strapi2.documents(attribute.target).findOne({
|
@@ -177,19 +175,16 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
177
175
|
});
|
178
176
|
})
|
179
177
|
);
|
180
|
-
return existingAndMissingRelations.filter(
|
181
|
-
(relation) => relation !== null
|
182
|
-
);
|
178
|
+
return existingAndMissingRelations.filter((relation) => relation !== null);
|
183
179
|
}
|
184
180
|
return strapi2.documents(attribute.target).findOne({
|
185
181
|
documentId: versionRelationData.documentId,
|
186
182
|
locale: versionRelationData.locale || void 0
|
187
183
|
});
|
188
184
|
};
|
189
|
-
const getMediaRestoreValue = async (versionRelationData
|
190
|
-
if (
|
185
|
+
const getMediaRestoreValue = async (versionRelationData) => {
|
186
|
+
if (Array.isArray(versionRelationData)) {
|
191
187
|
const existingAndMissingMedias = await Promise.all(
|
192
|
-
// @ts-expect-error Fix the type definitions so this isn't any
|
193
188
|
versionRelationData.map((media) => {
|
194
189
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: media.id } });
|
195
190
|
})
|
@@ -203,8 +198,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
203
198
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
199
|
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
205
200
|
const getLocaleDictionary = async () => {
|
206
|
-
if (!localesService)
|
207
|
-
return {};
|
201
|
+
if (!localesService) return {};
|
208
202
|
const locales = await localesService.find() || [];
|
209
203
|
return locales.reduce(
|
210
204
|
(acc, locale) => {
|
@@ -228,6 +222,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
228
222
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
229
223
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
230
224
|
};
|
225
|
+
const getComponentFields = (componentUID) => {
|
226
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
227
|
+
(fieldsAcc, [key, attribute]) => {
|
228
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
229
|
+
fieldsAcc.push(key);
|
230
|
+
}
|
231
|
+
return fieldsAcc;
|
232
|
+
},
|
233
|
+
[]
|
234
|
+
);
|
235
|
+
};
|
231
236
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
232
237
|
const model = strapi2.getModel(uid2);
|
233
238
|
const attributes = Object.entries(model.attributes);
|
@@ -251,13 +256,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
251
256
|
}
|
252
257
|
case "component": {
|
253
258
|
const populate = getDeepPopulate2(attribute.component);
|
254
|
-
acc[attributeName] = {
|
259
|
+
acc[attributeName] = {
|
260
|
+
populate,
|
261
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
262
|
+
};
|
255
263
|
break;
|
256
264
|
}
|
257
265
|
case "dynamiczone": {
|
258
266
|
const populatedComponents = (attribute.components || []).reduce(
|
259
267
|
(acc2, componentUID) => {
|
260
|
-
acc2[componentUID] = {
|
268
|
+
acc2[componentUID] = {
|
269
|
+
populate: getDeepPopulate2(componentUID),
|
270
|
+
[fieldSelector]: getComponentFields(componentUID)
|
271
|
+
};
|
261
272
|
return acc2;
|
262
273
|
},
|
263
274
|
{}
|
@@ -342,8 +353,8 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
342
353
|
});
|
343
354
|
},
|
344
355
|
async findVersionsPage(params) {
|
345
|
-
const
|
346
|
-
const isLocalizedContentType = serviceUtils.isLocalizedContentType(
|
356
|
+
const schema = strapi2.getModel(params.query.contentType);
|
357
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(schema);
|
347
358
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
348
359
|
let locale = null;
|
349
360
|
if (isLocalizedContentType) {
|
@@ -364,78 +375,76 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
364
375
|
}),
|
365
376
|
serviceUtils.getLocaleDictionary()
|
366
377
|
]);
|
367
|
-
const
|
368
|
-
|
369
|
-
async (
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
model: "plugin::upload.file"
|
376
|
-
});
|
377
|
-
const response = await serviceUtils.buildMediaResponse(attributeValues);
|
378
|
-
const sanitizedResults = await Promise.all(
|
379
|
-
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
380
|
-
);
|
381
|
-
return {
|
382
|
-
...await currentDataWithRelations,
|
383
|
-
[attributeKey]: {
|
384
|
-
results: sanitizedResults,
|
385
|
-
meta: response.meta
|
386
|
-
}
|
387
|
-
};
|
378
|
+
const populateEntry = async (entry) => {
|
379
|
+
return strapiUtils.traverseEntity(
|
380
|
+
async (options, utils) => {
|
381
|
+
if (!options.attribute) return;
|
382
|
+
if (!options.value) return;
|
383
|
+
const currentValue = Array.isArray(options.value) ? options.value : [options.value];
|
384
|
+
if (options.attribute.type === "component") {
|
385
|
+
utils.remove("id");
|
388
386
|
}
|
389
|
-
if (
|
390
|
-
|
387
|
+
if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
|
388
|
+
options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
|
389
|
+
if (options.attribute.target === "admin::user") {
|
391
390
|
const adminUsers = await Promise.all(
|
392
|
-
|
391
|
+
currentValue.map((userToPopulate) => {
|
393
392
|
if (userToPopulate == null) {
|
394
393
|
return null;
|
395
394
|
}
|
396
|
-
return strapi2.query("admin::user").findOne({
|
395
|
+
return strapi2.query("admin::user").findOne({
|
396
|
+
where: {
|
397
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
398
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
399
|
+
}
|
400
|
+
});
|
397
401
|
})
|
398
402
|
);
|
399
|
-
|
400
|
-
...await currentDataWithRelations,
|
401
|
-
/**
|
402
|
-
* Ideally we would return the same "{results: [], meta: {}}" shape, however,
|
403
|
-
* when sanitizing the data as a whole in the controller before sending to the client,
|
404
|
-
* the data for admin relation user is completely sanitized if we return an object here as opposed to an array.
|
405
|
-
*/
|
406
|
-
[attributeKey]: adminUsers
|
407
|
-
};
|
403
|
+
utils.set(options.key, adminUsers);
|
408
404
|
}
|
409
|
-
const permissionChecker2 = getService$
|
405
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
410
406
|
userAbility: params.state.userAbility,
|
411
|
-
model:
|
407
|
+
model: options.attribute.target
|
412
408
|
});
|
413
409
|
const response = await serviceUtils.buildRelationReponse(
|
414
|
-
|
415
|
-
|
410
|
+
currentValue,
|
411
|
+
options.attribute
|
416
412
|
);
|
417
413
|
const sanitizedResults = await Promise.all(
|
418
414
|
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
419
415
|
);
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
meta: response.meta
|
425
|
-
}
|
426
|
-
};
|
416
|
+
utils.set(options.key, {
|
417
|
+
results: sanitizedResults,
|
418
|
+
meta: response.meta
|
419
|
+
});
|
427
420
|
}
|
428
|
-
|
421
|
+
if (options.attribute.type === "media") {
|
422
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
423
|
+
userAbility: params.state.userAbility,
|
424
|
+
model: "plugin::upload.file"
|
425
|
+
});
|
426
|
+
const response = await serviceUtils.buildMediaResponse(currentValue);
|
427
|
+
const sanitizedResults = await Promise.all(
|
428
|
+
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
429
|
+
);
|
430
|
+
utils.set(options.key, {
|
431
|
+
results: sanitizedResults,
|
432
|
+
meta: response.meta
|
433
|
+
});
|
434
|
+
}
|
435
|
+
},
|
436
|
+
{
|
437
|
+
schema,
|
438
|
+
getModel: strapi2.getModel.bind(strapi2)
|
429
439
|
},
|
430
|
-
|
440
|
+
entry.data
|
431
441
|
);
|
432
|
-
return entryWithRelations;
|
433
442
|
};
|
434
443
|
const formattedResults = await Promise.all(
|
435
444
|
results.map(async (result) => {
|
436
445
|
return {
|
437
446
|
...result,
|
438
|
-
data: await
|
447
|
+
data: await populateEntry(result),
|
439
448
|
meta: {
|
440
449
|
unknownAttributes: serviceUtils.getSchemaAttributesDiff(
|
441
450
|
result.schema,
|
@@ -466,30 +475,44 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
466
475
|
// Clone to avoid mutating the original version data
|
467
476
|
structuredClone(version.data)
|
468
477
|
);
|
469
|
-
const
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
478
|
+
const schema = structuredClone(version.schema);
|
479
|
+
schema.attributes = fp.omit(FIELDS_TO_IGNORE, contentTypeSchemaAttributes);
|
480
|
+
const dataWithoutMissingRelations = await strapiUtils.traverseEntity(
|
481
|
+
async (options, utils) => {
|
482
|
+
if (!options.attribute) return;
|
483
|
+
if (options.attribute.type === "component") {
|
484
|
+
utils.remove("id");
|
485
|
+
if (options.attribute.repeatable && options.value === null) {
|
486
|
+
utils.set(options.key, []);
|
487
|
+
}
|
479
488
|
}
|
480
|
-
if (attribute.type === "
|
481
|
-
|
482
|
-
|
483
|
-
|
489
|
+
if (options.attribute.type === "dynamiczone") {
|
490
|
+
if (options.value === null) {
|
491
|
+
utils.set(options.key, []);
|
492
|
+
}
|
484
493
|
}
|
485
|
-
if (attribute.type === "
|
486
|
-
|
487
|
-
|
494
|
+
if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
|
495
|
+
options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
|
496
|
+
if (!options.value) return;
|
497
|
+
const data2 = await serviceUtils.getRelationRestoreValue(
|
498
|
+
options.value,
|
499
|
+
options.attribute
|
500
|
+
);
|
501
|
+
utils.set(options.key, data2);
|
502
|
+
}
|
503
|
+
if (options.attribute.type === "media") {
|
504
|
+
if (!options.value) return;
|
505
|
+
const data2 = await serviceUtils.getMediaRestoreValue(
|
506
|
+
options.value
|
507
|
+
);
|
508
|
+
utils.set(options.key, data2);
|
488
509
|
}
|
489
|
-
return previousRelationAttributes;
|
490
510
|
},
|
491
|
-
|
492
|
-
|
511
|
+
{
|
512
|
+
schema,
|
513
|
+
getModel: strapi2.getModel.bind(strapi2)
|
514
|
+
},
|
515
|
+
dataWithoutAddedAttributes
|
493
516
|
);
|
494
517
|
const data = fp.omit(["id", ...Object.keys(schemaDiff.removed)], dataWithoutMissingRelations);
|
495
518
|
const restoredDocument = await strapi2.documents(version.contentType).update({
|
@@ -582,7 +605,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
582
605
|
onCommit(async () => {
|
583
606
|
for (const entry of localeEntries) {
|
584
607
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
585
|
-
await getService(strapi2, "history").createVersion({
|
608
|
+
await getService$1(strapi2, "history").createVersion({
|
586
609
|
contentType: uid2,
|
587
610
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
588
611
|
relatedDocumentId: documentId,
|
@@ -595,15 +618,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
595
618
|
});
|
596
619
|
return result;
|
597
620
|
});
|
598
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
621
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
599
622
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
600
623
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
601
624
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
602
625
|
where: {
|
603
626
|
created_at: {
|
604
|
-
$lt: expirationDate
|
627
|
+
$lt: expirationDate
|
605
628
|
}
|
606
629
|
}
|
630
|
+
}).catch((error) => {
|
631
|
+
if (error instanceof Error) {
|
632
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
633
|
+
}
|
607
634
|
});
|
608
635
|
});
|
609
636
|
state.isInitialized = true;
|
@@ -615,17 +642,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
615
642
|
}
|
616
643
|
};
|
617
644
|
};
|
618
|
-
const services$
|
645
|
+
const services$2 = {
|
619
646
|
history: createHistoryService,
|
620
647
|
lifecycles: createLifecyclesService
|
621
648
|
};
|
622
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
649
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
623
650
|
const historyVersionRouter = {
|
624
651
|
type: "admin",
|
625
652
|
routes: [
|
626
653
|
{
|
627
654
|
method: "GET",
|
628
|
-
info,
|
655
|
+
info: info$1,
|
629
656
|
path: "/history-versions",
|
630
657
|
handler: "history-version.findMany",
|
631
658
|
config: {
|
@@ -634,7 +661,7 @@ const historyVersionRouter = {
|
|
634
661
|
},
|
635
662
|
{
|
636
663
|
method: "PUT",
|
637
|
-
info,
|
664
|
+
info: info$1,
|
638
665
|
path: "/history-versions/:versionId/restore",
|
639
666
|
handler: "history-version.restoreVersion",
|
640
667
|
config: {
|
@@ -643,7 +670,7 @@ const historyVersionRouter = {
|
|
643
670
|
}
|
644
671
|
]
|
645
672
|
};
|
646
|
-
const routes$
|
673
|
+
const routes$2 = {
|
647
674
|
"history-version": historyVersionRouter
|
648
675
|
};
|
649
676
|
const historyVersion = {
|
@@ -690,21 +717,21 @@ const historyVersion = {
|
|
690
717
|
}
|
691
718
|
}
|
692
719
|
};
|
693
|
-
const getFeature = () => {
|
720
|
+
const getFeature$1 = () => {
|
694
721
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
695
722
|
return {
|
696
723
|
register({ strapi: strapi2 }) {
|
697
724
|
strapi2.get("models").add(historyVersion);
|
698
725
|
},
|
699
726
|
bootstrap({ strapi: strapi2 }) {
|
700
|
-
getService(strapi2, "lifecycles").bootstrap();
|
727
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
701
728
|
},
|
702
729
|
destroy({ strapi: strapi2 }) {
|
703
|
-
getService(strapi2, "lifecycles").destroy();
|
730
|
+
getService$1(strapi2, "lifecycles").destroy();
|
704
731
|
},
|
705
|
-
controllers: controllers$
|
706
|
-
services: services$
|
707
|
-
routes: routes$
|
732
|
+
controllers: controllers$2,
|
733
|
+
services: services$2,
|
734
|
+
routes: routes$2
|
708
735
|
};
|
709
736
|
}
|
710
737
|
return {
|
@@ -713,9 +740,201 @@ const getFeature = () => {
|
|
713
740
|
}
|
714
741
|
};
|
715
742
|
};
|
716
|
-
const history = getFeature();
|
743
|
+
const history = getFeature$1();
|
744
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
745
|
+
const previewRouter = {
|
746
|
+
type: "admin",
|
747
|
+
routes: [
|
748
|
+
{
|
749
|
+
method: "GET",
|
750
|
+
info,
|
751
|
+
path: "/preview/url/:contentType",
|
752
|
+
handler: "preview.getPreviewUrl",
|
753
|
+
config: {
|
754
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
755
|
+
}
|
756
|
+
}
|
757
|
+
]
|
758
|
+
};
|
759
|
+
const routes$1 = {
|
760
|
+
preview: previewRouter
|
761
|
+
};
|
762
|
+
function getService(strapi2, name) {
|
763
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
764
|
+
}
|
765
|
+
const getPreviewUrlSchema = yup__namespace.object().shape({
|
766
|
+
// Will be undefined for single types
|
767
|
+
documentId: yup__namespace.string(),
|
768
|
+
locale: yup__namespace.string().nullable(),
|
769
|
+
status: yup__namespace.string()
|
770
|
+
}).required();
|
771
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
772
|
+
await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
|
773
|
+
const newParams = fp.pick(["documentId", "locale", "status"], params);
|
774
|
+
const model = strapi2.getModel(uid2);
|
775
|
+
if (!model || model.modelType !== "contentType") {
|
776
|
+
throw new strapiUtils.errors.ValidationError("Invalid content type");
|
777
|
+
}
|
778
|
+
const isSingleType = model?.kind === "singleType";
|
779
|
+
if (!isSingleType && !params.documentId) {
|
780
|
+
throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
|
781
|
+
}
|
782
|
+
if (isSingleType) {
|
783
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
784
|
+
if (!doc) {
|
785
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
786
|
+
}
|
787
|
+
newParams.documentId = doc?.documentId;
|
788
|
+
}
|
789
|
+
if (!newParams.status) {
|
790
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
791
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
792
|
+
}
|
793
|
+
return newParams;
|
794
|
+
};
|
795
|
+
const createPreviewController = () => {
|
796
|
+
return {
|
797
|
+
/**
|
798
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
799
|
+
* in the Content Manager.
|
800
|
+
*/
|
801
|
+
async getPreviewUrl(ctx) {
|
802
|
+
const uid2 = ctx.params.contentType;
|
803
|
+
const query = ctx.request.query;
|
804
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
805
|
+
const previewService = getService(strapi, "preview");
|
806
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
807
|
+
if (!url) {
|
808
|
+
ctx.status = 204;
|
809
|
+
}
|
810
|
+
return {
|
811
|
+
data: { url }
|
812
|
+
};
|
813
|
+
}
|
814
|
+
};
|
815
|
+
};
|
816
|
+
const controllers$1 = {
|
817
|
+
preview: createPreviewController
|
818
|
+
/**
|
819
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
820
|
+
* passing a controller factory as the value, instead of a controller object directly
|
821
|
+
*/
|
822
|
+
};
|
823
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
824
|
+
const config = getService(strapi2, "preview-config");
|
825
|
+
return {
|
826
|
+
async getPreviewUrl(uid2, params) {
|
827
|
+
const handler = config.getPreviewHandler();
|
828
|
+
try {
|
829
|
+
return handler(uid2, params);
|
830
|
+
} catch (error) {
|
831
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
832
|
+
throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
|
833
|
+
}
|
834
|
+
return;
|
835
|
+
}
|
836
|
+
};
|
837
|
+
};
|
838
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
839
|
+
const middlewares = strapi.config.get("middlewares");
|
840
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
841
|
+
if (currentMiddleware === middleware.name) {
|
842
|
+
return middleware;
|
843
|
+
}
|
844
|
+
if (currentMiddleware.name === middleware.name) {
|
845
|
+
return fp.mergeWith(
|
846
|
+
(objValue, srcValue) => {
|
847
|
+
if (Array.isArray(objValue)) {
|
848
|
+
return objValue.concat(srcValue);
|
849
|
+
}
|
850
|
+
return void 0;
|
851
|
+
},
|
852
|
+
currentMiddleware,
|
853
|
+
middleware
|
854
|
+
);
|
855
|
+
}
|
856
|
+
return currentMiddleware;
|
857
|
+
});
|
858
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
859
|
+
};
|
860
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
861
|
+
return {
|
862
|
+
register() {
|
863
|
+
if (!this.isEnabled()) {
|
864
|
+
return;
|
865
|
+
}
|
866
|
+
const config = strapi2.config.get("admin.preview");
|
867
|
+
if (config.config?.allowedOrigins) {
|
868
|
+
extendMiddlewareConfiguration({
|
869
|
+
name: "strapi::security",
|
870
|
+
config: {
|
871
|
+
contentSecurityPolicy: {
|
872
|
+
directives: {
|
873
|
+
"frame-src": config.config.allowedOrigins
|
874
|
+
}
|
875
|
+
}
|
876
|
+
}
|
877
|
+
});
|
878
|
+
}
|
879
|
+
},
|
880
|
+
isEnabled() {
|
881
|
+
const config = strapi2.config.get("admin.preview");
|
882
|
+
if (!config) {
|
883
|
+
return false;
|
884
|
+
}
|
885
|
+
return config?.enabled ?? true;
|
886
|
+
},
|
887
|
+
/**
|
888
|
+
* Validate if the configuration is valid
|
889
|
+
*/
|
890
|
+
validate() {
|
891
|
+
if (!this.isEnabled()) {
|
892
|
+
return;
|
893
|
+
}
|
894
|
+
const handler = this.getPreviewHandler();
|
895
|
+
if (typeof handler !== "function") {
|
896
|
+
throw new strapiUtils.errors.ValidationError(
|
897
|
+
"Preview configuration is invalid. Handler must be a function"
|
898
|
+
);
|
899
|
+
}
|
900
|
+
},
|
901
|
+
/**
|
902
|
+
* Utility to get the preview handler from the configuration
|
903
|
+
*/
|
904
|
+
getPreviewHandler() {
|
905
|
+
const config = strapi2.config.get("admin.preview");
|
906
|
+
const emptyHandler = () => {
|
907
|
+
return void 0;
|
908
|
+
};
|
909
|
+
if (!this.isEnabled()) {
|
910
|
+
return emptyHandler;
|
911
|
+
}
|
912
|
+
return config?.config?.handler || emptyHandler;
|
913
|
+
}
|
914
|
+
};
|
915
|
+
};
|
916
|
+
const services$1 = {
|
917
|
+
preview: createPreviewService,
|
918
|
+
"preview-config": createPreviewConfigService
|
919
|
+
};
|
920
|
+
const getFeature = () => {
|
921
|
+
return {
|
922
|
+
register() {
|
923
|
+
const config = getService(strapi, "preview-config");
|
924
|
+
config.validate();
|
925
|
+
config.register();
|
926
|
+
},
|
927
|
+
bootstrap() {
|
928
|
+
},
|
929
|
+
routes: routes$1,
|
930
|
+
controllers: controllers$1,
|
931
|
+
services: services$1
|
932
|
+
};
|
933
|
+
};
|
934
|
+
const preview = getFeature();
|
717
935
|
const register = async ({ strapi: strapi2 }) => {
|
718
936
|
await history.register?.({ strapi: strapi2 });
|
937
|
+
await preview.register?.({ strapi: strapi2 });
|
719
938
|
};
|
720
939
|
const ALLOWED_WEBHOOK_EVENTS = {
|
721
940
|
ENTRY_PUBLISH: "entry.publish",
|
@@ -725,11 +944,12 @@ const bootstrap = async () => {
|
|
725
944
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
726
945
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
727
946
|
});
|
728
|
-
getService$
|
729
|
-
await getService$
|
730
|
-
await getService$
|
731
|
-
await getService$
|
947
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
948
|
+
await getService$2("components").syncConfigurations();
|
949
|
+
await getService$2("content-types").syncConfigurations();
|
950
|
+
await getService$2("permission").registerPermissions();
|
732
951
|
await history.bootstrap?.({ strapi });
|
952
|
+
await preview.bootstrap?.({ strapi });
|
733
953
|
};
|
734
954
|
const destroy = async ({ strapi: strapi2 }) => {
|
735
955
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1219,7 +1439,8 @@ const admin = {
|
|
1219
1439
|
};
|
1220
1440
|
const routes = {
|
1221
1441
|
admin,
|
1222
|
-
...history.routes ? history.routes : {}
|
1442
|
+
...history.routes ? history.routes : {},
|
1443
|
+
...preview.routes ? preview.routes : {}
|
1223
1444
|
};
|
1224
1445
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1225
1446
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1282,8 +1503,7 @@ const isSortable = (schema, name) => {
|
|
1282
1503
|
if (!___default.default.has(schema.attributes, name)) {
|
1283
1504
|
return false;
|
1284
1505
|
}
|
1285
|
-
if (schema.modelType === "component" && name === "id")
|
1286
|
-
return false;
|
1506
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1287
1507
|
const attribute = schema.attributes[name];
|
1288
1508
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1289
1509
|
return false;
|
@@ -1428,8 +1648,7 @@ const createDefaultSettings = async (schema) => {
|
|
1428
1648
|
};
|
1429
1649
|
};
|
1430
1650
|
const syncSettings = async (configuration, schema) => {
|
1431
|
-
if (fp.isEmpty(configuration.settings))
|
1432
|
-
return createDefaultSettings(schema);
|
1651
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1433
1652
|
const defaultField = getDefaultMainField(schema);
|
1434
1653
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1435
1654
|
return {
|
@@ -1476,7 +1695,7 @@ const createMetadasSchema = (schema) => {
|
|
1476
1695
|
if (!value) {
|
1477
1696
|
return strapiUtils.yup.string();
|
1478
1697
|
}
|
1479
|
-
const targetSchema = getService$
|
1698
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1480
1699
|
schema.attributes[key].targetModel
|
1481
1700
|
);
|
1482
1701
|
if (!targetSchema) {
|
@@ -1605,8 +1824,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1605
1824
|
}
|
1606
1825
|
switch (attribute.type) {
|
1607
1826
|
case "relation": {
|
1608
|
-
if (canCreate(attributePath))
|
1609
|
-
return body2;
|
1827
|
+
if (canCreate(attributePath)) return body2;
|
1610
1828
|
return fp.set(attributePath, { set: [] }, body2);
|
1611
1829
|
}
|
1612
1830
|
case "component": {
|
@@ -1616,8 +1834,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1616
1834
|
]);
|
1617
1835
|
}
|
1618
1836
|
default: {
|
1619
|
-
if (canCreate(attributePath))
|
1620
|
-
return body2;
|
1837
|
+
if (canCreate(attributePath)) return body2;
|
1621
1838
|
return fp.set(attributePath, null, body2);
|
1622
1839
|
}
|
1623
1840
|
}
|
@@ -1645,7 +1862,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1645
1862
|
}
|
1646
1863
|
};
|
1647
1864
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1648
|
-
const documentMetadata2 = getService$
|
1865
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1649
1866
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1650
1867
|
let {
|
1651
1868
|
meta: { availableLocales, availableStatus }
|
@@ -1671,8 +1888,8 @@ const createDocument = async (ctx, opts) => {
|
|
1671
1888
|
const { userAbility, user } = ctx.state;
|
1672
1889
|
const { model } = ctx.params;
|
1673
1890
|
const { body } = ctx.request;
|
1674
|
-
const documentManager2 = getService$
|
1675
|
-
const permissionChecker2 = getService$
|
1891
|
+
const documentManager2 = getService$2("document-manager");
|
1892
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1676
1893
|
if (permissionChecker2.cannot.create()) {
|
1677
1894
|
throw new strapiUtils.errors.ForbiddenError();
|
1678
1895
|
}
|
@@ -1692,13 +1909,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1692
1909
|
const { userAbility, user } = ctx.state;
|
1693
1910
|
const { id, model } = ctx.params;
|
1694
1911
|
const { body } = ctx.request;
|
1695
|
-
const documentManager2 = getService$
|
1696
|
-
const permissionChecker2 = getService$
|
1912
|
+
const documentManager2 = getService$2("document-manager");
|
1913
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1697
1914
|
if (permissionChecker2.cannot.update()) {
|
1698
1915
|
throw new strapiUtils.errors.ForbiddenError();
|
1699
1916
|
}
|
1700
1917
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1701
|
-
const populate = await getService$
|
1918
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1702
1919
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1703
1920
|
const [documentVersion, documentExists] = await Promise.all([
|
1704
1921
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1729,14 +1946,14 @@ const collectionTypes = {
|
|
1729
1946
|
const { userAbility } = ctx.state;
|
1730
1947
|
const { model } = ctx.params;
|
1731
1948
|
const { query } = ctx.request;
|
1732
|
-
const documentMetadata2 = getService$
|
1733
|
-
const documentManager2 = getService$
|
1734
|
-
const permissionChecker2 = getService$
|
1949
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1950
|
+
const documentManager2 = getService$2("document-manager");
|
1951
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1735
1952
|
if (permissionChecker2.cannot.read()) {
|
1736
1953
|
return ctx.forbidden();
|
1737
1954
|
}
|
1738
1955
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1739
|
-
const populate = await getService$
|
1956
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1740
1957
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1741
1958
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1742
1959
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1765,13 +1982,13 @@ const collectionTypes = {
|
|
1765
1982
|
async findOne(ctx) {
|
1766
1983
|
const { userAbility } = ctx.state;
|
1767
1984
|
const { model, id } = ctx.params;
|
1768
|
-
const documentManager2 = getService$
|
1769
|
-
const permissionChecker2 = getService$
|
1985
|
+
const documentManager2 = getService$2("document-manager");
|
1986
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1770
1987
|
if (permissionChecker2.cannot.read()) {
|
1771
1988
|
return ctx.forbidden();
|
1772
1989
|
}
|
1773
1990
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1774
|
-
const populate = await getService$
|
1991
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1775
1992
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1776
1993
|
const version = await documentManager2.findOne(id, model, {
|
1777
1994
|
populate,
|
@@ -1802,7 +2019,7 @@ const collectionTypes = {
|
|
1802
2019
|
async create(ctx) {
|
1803
2020
|
const { userAbility } = ctx.state;
|
1804
2021
|
const { model } = ctx.params;
|
1805
|
-
const permissionChecker2 = getService$
|
2022
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1806
2023
|
const [totalEntries, document] = await Promise.all([
|
1807
2024
|
strapi.db.query(model).count(),
|
1808
2025
|
createDocument(ctx)
|
@@ -1823,7 +2040,7 @@ const collectionTypes = {
|
|
1823
2040
|
async update(ctx) {
|
1824
2041
|
const { userAbility } = ctx.state;
|
1825
2042
|
const { model } = ctx.params;
|
1826
|
-
const permissionChecker2 = getService$
|
2043
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1827
2044
|
const updatedVersion = await updateDocument(ctx);
|
1828
2045
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1829
2046
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1832,13 +2049,13 @@ const collectionTypes = {
|
|
1832
2049
|
const { userAbility, user } = ctx.state;
|
1833
2050
|
const { model, sourceId: id } = ctx.params;
|
1834
2051
|
const { body } = ctx.request;
|
1835
|
-
const documentManager2 = getService$
|
1836
|
-
const permissionChecker2 = getService$
|
2052
|
+
const documentManager2 = getService$2("document-manager");
|
2053
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1837
2054
|
if (permissionChecker2.cannot.create()) {
|
1838
2055
|
return ctx.forbidden();
|
1839
2056
|
}
|
1840
2057
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1841
|
-
const populate = await getService$
|
2058
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1842
2059
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1843
2060
|
const document = await documentManager2.findOne(id, model, {
|
1844
2061
|
populate,
|
@@ -1877,13 +2094,13 @@ const collectionTypes = {
|
|
1877
2094
|
async delete(ctx) {
|
1878
2095
|
const { userAbility } = ctx.state;
|
1879
2096
|
const { id, model } = ctx.params;
|
1880
|
-
const documentManager2 = getService$
|
1881
|
-
const permissionChecker2 = getService$
|
2097
|
+
const documentManager2 = getService$2("document-manager");
|
2098
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1882
2099
|
if (permissionChecker2.cannot.delete()) {
|
1883
2100
|
return ctx.forbidden();
|
1884
2101
|
}
|
1885
2102
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1886
|
-
const populate = await getService$
|
2103
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1887
2104
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1888
2105
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1889
2106
|
if (documentLocales.length === 0) {
|
@@ -1905,14 +2122,14 @@ const collectionTypes = {
|
|
1905
2122
|
const { userAbility } = ctx.state;
|
1906
2123
|
const { id, model } = ctx.params;
|
1907
2124
|
const { body } = ctx.request;
|
1908
|
-
const documentManager2 = getService$
|
1909
|
-
const permissionChecker2 = getService$
|
2125
|
+
const documentManager2 = getService$2("document-manager");
|
2126
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1910
2127
|
if (permissionChecker2.cannot.publish()) {
|
1911
2128
|
return ctx.forbidden();
|
1912
2129
|
}
|
1913
2130
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1914
2131
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1915
|
-
const populate = await getService$
|
2132
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1916
2133
|
let document;
|
1917
2134
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1918
2135
|
const isCreate = fp.isNil(id);
|
@@ -1960,13 +2177,13 @@ const collectionTypes = {
|
|
1960
2177
|
const { body } = ctx.request;
|
1961
2178
|
const { documentIds } = body;
|
1962
2179
|
await validateBulkActionInput(body);
|
1963
|
-
const documentManager2 = getService$
|
1964
|
-
const permissionChecker2 = getService$
|
2180
|
+
const documentManager2 = getService$2("document-manager");
|
2181
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1965
2182
|
if (permissionChecker2.cannot.publish()) {
|
1966
2183
|
return ctx.forbidden();
|
1967
2184
|
}
|
1968
2185
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1969
|
-
const populate = await getService$
|
2186
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1970
2187
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1971
2188
|
allowMultipleLocales: true
|
1972
2189
|
});
|
@@ -1991,8 +2208,8 @@ const collectionTypes = {
|
|
1991
2208
|
const { body } = ctx.request;
|
1992
2209
|
const { documentIds } = body;
|
1993
2210
|
await validateBulkActionInput(body);
|
1994
|
-
const documentManager2 = getService$
|
1995
|
-
const permissionChecker2 = getService$
|
2211
|
+
const documentManager2 = getService$2("document-manager");
|
2212
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1996
2213
|
if (permissionChecker2.cannot.unpublish()) {
|
1997
2214
|
return ctx.forbidden();
|
1998
2215
|
}
|
@@ -2021,8 +2238,8 @@ const collectionTypes = {
|
|
2021
2238
|
const {
|
2022
2239
|
body: { discardDraft, ...body }
|
2023
2240
|
} = ctx.request;
|
2024
|
-
const documentManager2 = getService$
|
2025
|
-
const permissionChecker2 = getService$
|
2241
|
+
const documentManager2 = getService$2("document-manager");
|
2242
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2026
2243
|
if (permissionChecker2.cannot.unpublish()) {
|
2027
2244
|
return ctx.forbidden();
|
2028
2245
|
}
|
@@ -2030,7 +2247,7 @@ const collectionTypes = {
|
|
2030
2247
|
return ctx.forbidden();
|
2031
2248
|
}
|
2032
2249
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2033
|
-
const populate = await getService$
|
2250
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2034
2251
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2035
2252
|
const document = await documentManager2.findOne(id, model, {
|
2036
2253
|
populate,
|
@@ -2061,13 +2278,13 @@ const collectionTypes = {
|
|
2061
2278
|
const { userAbility } = ctx.state;
|
2062
2279
|
const { id, model } = ctx.params;
|
2063
2280
|
const { body } = ctx.request;
|
2064
|
-
const documentManager2 = getService$
|
2065
|
-
const permissionChecker2 = getService$
|
2281
|
+
const documentManager2 = getService$2("document-manager");
|
2282
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2066
2283
|
if (permissionChecker2.cannot.discard()) {
|
2067
2284
|
return ctx.forbidden();
|
2068
2285
|
}
|
2069
2286
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2070
|
-
const populate = await getService$
|
2287
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2071
2288
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2072
2289
|
const document = await documentManager2.findOne(id, model, {
|
2073
2290
|
populate,
|
@@ -2092,13 +2309,13 @@ const collectionTypes = {
|
|
2092
2309
|
const { query, body } = ctx.request;
|
2093
2310
|
const { documentIds } = body;
|
2094
2311
|
await validateBulkActionInput(body);
|
2095
|
-
const documentManager2 = getService$
|
2096
|
-
const permissionChecker2 = getService$
|
2312
|
+
const documentManager2 = getService$2("document-manager");
|
2313
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2097
2314
|
if (permissionChecker2.cannot.delete()) {
|
2098
2315
|
return ctx.forbidden();
|
2099
2316
|
}
|
2100
2317
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2101
|
-
const populate = await getService$
|
2318
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2102
2319
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2103
2320
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2104
2321
|
populate,
|
@@ -2119,13 +2336,13 @@ const collectionTypes = {
|
|
2119
2336
|
async countDraftRelations(ctx) {
|
2120
2337
|
const { userAbility } = ctx.state;
|
2121
2338
|
const { model, id } = ctx.params;
|
2122
|
-
const documentManager2 = getService$
|
2123
|
-
const permissionChecker2 = getService$
|
2339
|
+
const documentManager2 = getService$2("document-manager");
|
2340
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2124
2341
|
if (permissionChecker2.cannot.read()) {
|
2125
2342
|
return ctx.forbidden();
|
2126
2343
|
}
|
2127
2344
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2128
|
-
const populate = await getService$
|
2345
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2129
2346
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2130
2347
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2131
2348
|
if (!entity) {
|
@@ -2144,8 +2361,8 @@ const collectionTypes = {
|
|
2144
2361
|
const ids = ctx.request.query.documentIds;
|
2145
2362
|
const locale = ctx.request.query.locale;
|
2146
2363
|
const { model } = ctx.params;
|
2147
|
-
const documentManager2 = getService$
|
2148
|
-
const permissionChecker2 = getService$
|
2364
|
+
const documentManager2 = getService$2("document-manager");
|
2365
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2149
2366
|
if (permissionChecker2.cannot.read()) {
|
2150
2367
|
return ctx.forbidden();
|
2151
2368
|
}
|
@@ -2169,13 +2386,13 @@ const collectionTypes = {
|
|
2169
2386
|
};
|
2170
2387
|
const components$1 = {
|
2171
2388
|
findComponents(ctx) {
|
2172
|
-
const components2 = getService$
|
2173
|
-
const { toDto } = getService$
|
2389
|
+
const components2 = getService$2("components").findAllComponents();
|
2390
|
+
const { toDto } = getService$2("data-mapper");
|
2174
2391
|
ctx.body = { data: components2.map(toDto) };
|
2175
2392
|
},
|
2176
2393
|
async findComponentConfiguration(ctx) {
|
2177
2394
|
const { uid: uid2 } = ctx.params;
|
2178
|
-
const componentService = getService$
|
2395
|
+
const componentService = getService$2("components");
|
2179
2396
|
const component = componentService.findComponent(uid2);
|
2180
2397
|
if (!component) {
|
2181
2398
|
return ctx.notFound("component.notFound");
|
@@ -2192,7 +2409,7 @@ const components$1 = {
|
|
2192
2409
|
async updateComponentConfiguration(ctx) {
|
2193
2410
|
const { uid: uid2 } = ctx.params;
|
2194
2411
|
const { body } = ctx.request;
|
2195
|
-
const componentService = getService$
|
2412
|
+
const componentService = getService$2("components");
|
2196
2413
|
const component = componentService.findComponent(uid2);
|
2197
2414
|
if (!component) {
|
2198
2415
|
return ctx.notFound("component.notFound");
|
@@ -2226,12 +2443,12 @@ const contentTypes = {
|
|
2226
2443
|
} catch (error) {
|
2227
2444
|
return ctx.send({ error }, 400);
|
2228
2445
|
}
|
2229
|
-
const contentTypes2 = getService$
|
2230
|
-
const { toDto } = getService$
|
2446
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2447
|
+
const { toDto } = getService$2("data-mapper");
|
2231
2448
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2232
2449
|
},
|
2233
2450
|
async findContentTypesSettings(ctx) {
|
2234
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2451
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2235
2452
|
const contentTypes2 = await findAllContentTypes();
|
2236
2453
|
const configurations = await Promise.all(
|
2237
2454
|
contentTypes2.map(async (contentType) => {
|
@@ -2245,7 +2462,7 @@ const contentTypes = {
|
|
2245
2462
|
},
|
2246
2463
|
async findContentTypeConfiguration(ctx) {
|
2247
2464
|
const { uid: uid2 } = ctx.params;
|
2248
|
-
const contentTypeService = getService$
|
2465
|
+
const contentTypeService = getService$2("content-types");
|
2249
2466
|
const contentType = await contentTypeService.findContentType(uid2);
|
2250
2467
|
if (!contentType) {
|
2251
2468
|
return ctx.notFound("contentType.notFound");
|
@@ -2267,13 +2484,13 @@ const contentTypes = {
|
|
2267
2484
|
const { userAbility } = ctx.state;
|
2268
2485
|
const { uid: uid2 } = ctx.params;
|
2269
2486
|
const { body } = ctx.request;
|
2270
|
-
const contentTypeService = getService$
|
2271
|
-
const metricsService = getService$
|
2487
|
+
const contentTypeService = getService$2("content-types");
|
2488
|
+
const metricsService = getService$2("metrics");
|
2272
2489
|
const contentType = await contentTypeService.findContentType(uid2);
|
2273
2490
|
if (!contentType) {
|
2274
2491
|
return ctx.notFound("contentType.notFound");
|
2275
2492
|
}
|
2276
|
-
if (!getService$
|
2493
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2277
2494
|
return ctx.forbidden();
|
2278
2495
|
}
|
2279
2496
|
let input;
|
@@ -2306,10 +2523,10 @@ const contentTypes = {
|
|
2306
2523
|
};
|
2307
2524
|
const init = {
|
2308
2525
|
getInitData(ctx) {
|
2309
|
-
const { toDto } = getService$
|
2310
|
-
const { findAllComponents } = getService$
|
2311
|
-
const { getAllFieldSizes } = getService$
|
2312
|
-
const { findAllContentTypes } = getService$
|
2526
|
+
const { toDto } = getService$2("data-mapper");
|
2527
|
+
const { findAllComponents } = getService$2("components");
|
2528
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2529
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2313
2530
|
ctx.body = {
|
2314
2531
|
data: {
|
2315
2532
|
fieldSizes: getAllFieldSizes(),
|
@@ -2345,7 +2562,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2345
2562
|
params.filters.$and.push(filtersClause);
|
2346
2563
|
};
|
2347
2564
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2348
|
-
const permissionChecker2 = getService$
|
2565
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2349
2566
|
userAbility,
|
2350
2567
|
model: model.uid
|
2351
2568
|
});
|
@@ -2359,15 +2576,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2359
2576
|
}
|
2360
2577
|
return mainField;
|
2361
2578
|
};
|
2362
|
-
const addStatusToRelations = async (
|
2363
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2579
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2580
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2581
|
+
return relations2;
|
2582
|
+
}
|
2583
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2584
|
+
if (!relations2.length) {
|
2364
2585
|
return relations2;
|
2365
2586
|
}
|
2366
|
-
const
|
2367
|
-
const
|
2587
|
+
const firstRelation = relations2[0];
|
2588
|
+
const filters = {
|
2589
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2590
|
+
// NOTE: find the "opposite" status
|
2591
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2592
|
+
};
|
2593
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2594
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2595
|
+
filters
|
2596
|
+
});
|
2368
2597
|
return relations2.map((relation) => {
|
2369
|
-
const availableStatuses =
|
2370
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2598
|
+
const availableStatuses = availableStatus.filter(
|
2599
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2371
2600
|
);
|
2372
2601
|
return {
|
2373
2602
|
...relation,
|
@@ -2398,8 +2627,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2398
2627
|
const sourceModel = strapi.getModel(sourceUid);
|
2399
2628
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2400
2629
|
const isSourceDP = isDP(sourceModel);
|
2401
|
-
if (!isSourceDP)
|
2402
|
-
return { status: void 0 };
|
2630
|
+
if (!isSourceDP) return { status: void 0 };
|
2403
2631
|
switch (status) {
|
2404
2632
|
case "published":
|
2405
2633
|
return { status: "published" };
|
@@ -2429,7 +2657,7 @@ const relations = {
|
|
2429
2657
|
ctx.request?.query?.locale
|
2430
2658
|
);
|
2431
2659
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2432
|
-
const permissionChecker2 = getService$
|
2660
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2433
2661
|
userAbility,
|
2434
2662
|
model
|
2435
2663
|
});
|
@@ -2454,7 +2682,7 @@ const relations = {
|
|
2454
2682
|
where.id = id;
|
2455
2683
|
}
|
2456
2684
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2457
|
-
const populate = await getService$
|
2685
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2458
2686
|
const currentEntity = await strapi.db.query(model).findOne({
|
2459
2687
|
where,
|
2460
2688
|
populate
|
@@ -2469,7 +2697,7 @@ const relations = {
|
|
2469
2697
|
}
|
2470
2698
|
entryId = currentEntity.id;
|
2471
2699
|
}
|
2472
|
-
const modelConfig = isComponent2 ? await getService$
|
2700
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2473
2701
|
const targetSchema = strapi.getModel(targetUid);
|
2474
2702
|
const mainField = fp.flow(
|
2475
2703
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2523,7 +2751,7 @@ const relations = {
|
|
2523
2751
|
}
|
2524
2752
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2525
2753
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2526
|
-
const permissionChecker2 = getService$
|
2754
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2527
2755
|
userAbility: ctx.state.userAbility,
|
2528
2756
|
model: targetUid
|
2529
2757
|
});
|
@@ -2596,21 +2824,33 @@ const relations = {
|
|
2596
2824
|
attribute,
|
2597
2825
|
targetField,
|
2598
2826
|
fieldsToSelect,
|
2599
|
-
|
2600
|
-
|
2601
|
-
}
|
2602
|
-
target: {
|
2603
|
-
schema: { uid: targetUid }
|
2604
|
-
}
|
2827
|
+
status,
|
2828
|
+
source: { schema: sourceSchema },
|
2829
|
+
target: { schema: targetSchema }
|
2605
2830
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2606
|
-
const
|
2831
|
+
const { uid: sourceUid } = sourceSchema;
|
2832
|
+
const { uid: targetUid } = targetSchema;
|
2833
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2607
2834
|
const dbQuery = strapi.db.query(sourceUid);
|
2608
2835
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2836
|
+
const filters = {};
|
2837
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2838
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2839
|
+
if (status === "published") {
|
2840
|
+
filters.publishedAt = { $notNull: true };
|
2841
|
+
} else {
|
2842
|
+
filters.publishedAt = { $null: true };
|
2843
|
+
}
|
2844
|
+
}
|
2845
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2846
|
+
filters.publishedAt = { $null: true };
|
2847
|
+
}
|
2609
2848
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2610
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2849
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2611
2850
|
ordering: "desc",
|
2612
2851
|
page: ctx.request.query.page,
|
2613
|
-
pageSize: ctx.request.query.pageSize
|
2852
|
+
pageSize: ctx.request.query.pageSize,
|
2853
|
+
filters
|
2614
2854
|
});
|
2615
2855
|
const loadedIds = res.results.map((item) => item.id);
|
2616
2856
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2631,10 +2871,10 @@ const relations = {
|
|
2631
2871
|
}
|
2632
2872
|
};
|
2633
2873
|
const buildPopulateFromQuery = async (query, model) => {
|
2634
|
-
return getService$
|
2874
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2635
2875
|
};
|
2636
2876
|
const findDocument = async (query, uid2, opts = {}) => {
|
2637
|
-
const documentManager2 = getService$
|
2877
|
+
const documentManager2 = getService$2("document-manager");
|
2638
2878
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2639
2879
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2640
2880
|
};
|
@@ -2642,8 +2882,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2642
2882
|
const { user, userAbility } = ctx.state;
|
2643
2883
|
const { model } = ctx.params;
|
2644
2884
|
const { body, query } = ctx.request;
|
2645
|
-
const documentManager2 = getService$
|
2646
|
-
const permissionChecker2 = getService$
|
2885
|
+
const documentManager2 = getService$2("document-manager");
|
2886
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2647
2887
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2648
2888
|
throw new strapiUtils.errors.ForbiddenError();
|
2649
2889
|
}
|
@@ -2684,7 +2924,7 @@ const singleTypes = {
|
|
2684
2924
|
const { userAbility } = ctx.state;
|
2685
2925
|
const { model } = ctx.params;
|
2686
2926
|
const { query = {} } = ctx.request;
|
2687
|
-
const permissionChecker2 = getService$
|
2927
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2688
2928
|
if (permissionChecker2.cannot.read()) {
|
2689
2929
|
return ctx.forbidden();
|
2690
2930
|
}
|
@@ -2718,7 +2958,7 @@ const singleTypes = {
|
|
2718
2958
|
async createOrUpdate(ctx) {
|
2719
2959
|
const { userAbility } = ctx.state;
|
2720
2960
|
const { model } = ctx.params;
|
2721
|
-
const permissionChecker2 = getService$
|
2961
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2722
2962
|
const document = await createOrUpdateDocument(ctx);
|
2723
2963
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2724
2964
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2727,8 +2967,8 @@ const singleTypes = {
|
|
2727
2967
|
const { userAbility } = ctx.state;
|
2728
2968
|
const { model } = ctx.params;
|
2729
2969
|
const { query = {} } = ctx.request;
|
2730
|
-
const documentManager2 = getService$
|
2731
|
-
const permissionChecker2 = getService$
|
2970
|
+
const documentManager2 = getService$2("document-manager");
|
2971
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2732
2972
|
if (permissionChecker2.cannot.delete()) {
|
2733
2973
|
return ctx.forbidden();
|
2734
2974
|
}
|
@@ -2756,8 +2996,8 @@ const singleTypes = {
|
|
2756
2996
|
const { userAbility } = ctx.state;
|
2757
2997
|
const { model } = ctx.params;
|
2758
2998
|
const { query = {} } = ctx.request;
|
2759
|
-
const documentManager2 = getService$
|
2760
|
-
const permissionChecker2 = getService$
|
2999
|
+
const documentManager2 = getService$2("document-manager");
|
3000
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2761
3001
|
if (permissionChecker2.cannot.publish()) {
|
2762
3002
|
return ctx.forbidden();
|
2763
3003
|
}
|
@@ -2785,8 +3025,8 @@ const singleTypes = {
|
|
2785
3025
|
body: { discardDraft, ...body },
|
2786
3026
|
query = {}
|
2787
3027
|
} = ctx.request;
|
2788
|
-
const documentManager2 = getService$
|
2789
|
-
const permissionChecker2 = getService$
|
3028
|
+
const documentManager2 = getService$2("document-manager");
|
3029
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2790
3030
|
if (permissionChecker2.cannot.unpublish()) {
|
2791
3031
|
return ctx.forbidden();
|
2792
3032
|
}
|
@@ -2820,8 +3060,8 @@ const singleTypes = {
|
|
2820
3060
|
const { userAbility } = ctx.state;
|
2821
3061
|
const { model } = ctx.params;
|
2822
3062
|
const { body, query = {} } = ctx.request;
|
2823
|
-
const documentManager2 = getService$
|
2824
|
-
const permissionChecker2 = getService$
|
3063
|
+
const documentManager2 = getService$2("document-manager");
|
3064
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2825
3065
|
if (permissionChecker2.cannot.discard()) {
|
2826
3066
|
return ctx.forbidden();
|
2827
3067
|
}
|
@@ -2844,8 +3084,8 @@ const singleTypes = {
|
|
2844
3084
|
const { userAbility } = ctx.state;
|
2845
3085
|
const { model } = ctx.params;
|
2846
3086
|
const { query } = ctx.request;
|
2847
|
-
const documentManager2 = getService$
|
2848
|
-
const permissionChecker2 = getService$
|
3087
|
+
const documentManager2 = getService$2("document-manager");
|
3088
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2849
3089
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2850
3090
|
if (permissionChecker2.cannot.read()) {
|
2851
3091
|
return ctx.forbidden();
|
@@ -2869,7 +3109,7 @@ const uid$1 = {
|
|
2869
3109
|
const { query = {} } = ctx.request;
|
2870
3110
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2871
3111
|
await validateUIDField(contentTypeUID, field);
|
2872
|
-
const uidService = getService$
|
3112
|
+
const uidService = getService$2("uid");
|
2873
3113
|
ctx.body = {
|
2874
3114
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2875
3115
|
};
|
@@ -2881,7 +3121,7 @@ const uid$1 = {
|
|
2881
3121
|
const { query = {} } = ctx.request;
|
2882
3122
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2883
3123
|
await validateUIDField(contentTypeUID, field);
|
2884
|
-
const uidService = getService$
|
3124
|
+
const uidService = getService$2("uid");
|
2885
3125
|
const isAvailable = await uidService.checkUIDAvailability({
|
2886
3126
|
contentTypeUID,
|
2887
3127
|
field,
|
@@ -2902,7 +3142,8 @@ const controllers = {
|
|
2902
3142
|
relations,
|
2903
3143
|
"single-types": singleTypes,
|
2904
3144
|
uid: uid$1,
|
2905
|
-
...history.controllers ? history.controllers : {}
|
3145
|
+
...history.controllers ? history.controllers : {},
|
3146
|
+
...preview.controllers ? preview.controllers : {}
|
2906
3147
|
};
|
2907
3148
|
const keys = {
|
2908
3149
|
CONFIGURATION: "configuration"
|
@@ -3031,18 +3272,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3031
3272
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3032
3273
|
___default.default.set(acc, [key], updatedMeta);
|
3033
3274
|
}
|
3034
|
-
if (!___default.default.has(edit, "mainField"))
|
3035
|
-
return acc;
|
3275
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3036
3276
|
if (!isRelation$1(attr)) {
|
3037
3277
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3038
3278
|
___default.default.set(acc, [key], updatedMeta);
|
3039
3279
|
return acc;
|
3040
3280
|
}
|
3041
|
-
if (edit.mainField === "id")
|
3042
|
-
return acc;
|
3281
|
+
if (edit.mainField === "id") return acc;
|
3043
3282
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3044
|
-
if (!targetSchema)
|
3045
|
-
return acc;
|
3283
|
+
if (!targetSchema) return acc;
|
3046
3284
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3047
3285
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3048
3286
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3053,12 +3291,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3053
3291
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3054
3292
|
}
|
3055
3293
|
const getTargetSchema = (targetModel) => {
|
3056
|
-
return getService$
|
3294
|
+
return getService$2("content-types").findContentType(targetModel);
|
3057
3295
|
};
|
3058
3296
|
const DEFAULT_LIST_LENGTH = 4;
|
3059
3297
|
const MAX_ROW_SIZE = 12;
|
3060
3298
|
const isAllowedFieldSize = (type, size) => {
|
3061
|
-
const { getFieldSize } = getService$
|
3299
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3062
3300
|
const fieldSize = getFieldSize(type);
|
3063
3301
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3064
3302
|
return false;
|
@@ -3066,7 +3304,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3066
3304
|
return size <= MAX_ROW_SIZE;
|
3067
3305
|
};
|
3068
3306
|
const getDefaultFieldSize = (attribute) => {
|
3069
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3307
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3070
3308
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3071
3309
|
};
|
3072
3310
|
async function createDefaultLayouts(schema) {
|
@@ -3087,8 +3325,7 @@ function createDefaultEditLayout(schema) {
|
|
3087
3325
|
return appendToEditLayout([], keys2, schema);
|
3088
3326
|
}
|
3089
3327
|
function syncLayouts(configuration, schema) {
|
3090
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3091
|
-
return createDefaultLayouts(schema);
|
3328
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3092
3329
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3093
3330
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3094
3331
|
const cleanEditRelations = editRelations.filter(
|
@@ -3099,9 +3336,8 @@ function syncLayouts(configuration, schema) {
|
|
3099
3336
|
for (const row of edit) {
|
3100
3337
|
const newRow = [];
|
3101
3338
|
for (const el of row) {
|
3102
|
-
if (!hasEditableAttribute(schema, el.name))
|
3103
|
-
|
3104
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3339
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3340
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3105
3341
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3106
3342
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3107
3343
|
elementsToReAppend.push(el.name);
|
@@ -3131,8 +3367,7 @@ function syncLayouts(configuration, schema) {
|
|
3131
3367
|
};
|
3132
3368
|
}
|
3133
3369
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3134
|
-
if (keysToAppend.length === 0)
|
3135
|
-
return layout;
|
3370
|
+
if (keysToAppend.length === 0) return layout;
|
3136
3371
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3137
3372
|
if (!layout[currentRowIndex]) {
|
3138
3373
|
layout[currentRowIndex] = [];
|
@@ -3241,17 +3476,17 @@ const configurationService$1 = createConfigurationService({
|
|
3241
3476
|
isComponent: true,
|
3242
3477
|
prefix: STORE_KEY_PREFIX,
|
3243
3478
|
getModels() {
|
3244
|
-
const { toContentManagerModel } = getService$
|
3479
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3245
3480
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3246
3481
|
}
|
3247
3482
|
});
|
3248
3483
|
const components = ({ strapi: strapi2 }) => ({
|
3249
3484
|
findAllComponents() {
|
3250
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3251
3486
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3252
3487
|
},
|
3253
3488
|
findComponent(uid2) {
|
3254
|
-
const { toContentManagerModel } = getService$
|
3489
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3255
3490
|
const component = strapi2.components[uid2];
|
3256
3491
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3257
3492
|
},
|
@@ -3302,17 +3537,17 @@ const configurationService = createConfigurationService({
|
|
3302
3537
|
storeUtils,
|
3303
3538
|
prefix: "content_types",
|
3304
3539
|
getModels() {
|
3305
|
-
const { toContentManagerModel } = getService$
|
3540
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3306
3541
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3307
3542
|
}
|
3308
3543
|
});
|
3309
3544
|
const service = ({ strapi: strapi2 }) => ({
|
3310
3545
|
findAllContentTypes() {
|
3311
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3312
3547
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3313
3548
|
},
|
3314
3549
|
findContentType(uid2) {
|
3315
|
-
const { toContentManagerModel } = getService$
|
3550
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3316
3551
|
const contentType = strapi2.contentTypes[uid2];
|
3317
3552
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3318
3553
|
},
|
@@ -3341,7 +3576,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3341
3576
|
return this.findConfiguration(contentType);
|
3342
3577
|
},
|
3343
3578
|
findComponentsConfigurations(contentType) {
|
3344
|
-
return getService$
|
3579
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3345
3580
|
},
|
3346
3581
|
syncConfigurations() {
|
3347
3582
|
return configurationService.syncConfigurations();
|
@@ -3613,7 +3848,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3613
3848
|
return userAbility.can(action);
|
3614
3849
|
},
|
3615
3850
|
async registerPermissions() {
|
3616
|
-
const displayedContentTypes = getService$
|
3851
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3617
3852
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3618
3853
|
const actions = [
|
3619
3854
|
{
|
@@ -3698,6 +3933,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3698
3933
|
if (initialPopulate) {
|
3699
3934
|
return initialPopulate;
|
3700
3935
|
}
|
3936
|
+
if (attributeName === "localizations") {
|
3937
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3938
|
+
return {
|
3939
|
+
populate: validationPopulate.populate
|
3940
|
+
};
|
3941
|
+
}
|
3701
3942
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3702
3943
|
return true;
|
3703
3944
|
}
|
@@ -3757,6 +3998,9 @@ const getDeepPopulate = (uid2, {
|
|
3757
3998
|
return {};
|
3758
3999
|
}
|
3759
4000
|
const model = strapi.getModel(uid2);
|
4001
|
+
if (!model) {
|
4002
|
+
return {};
|
4003
|
+
}
|
3760
4004
|
return Object.keys(model.attributes).reduce(
|
3761
4005
|
(populateAcc, attributeName) => fp.merge(
|
3762
4006
|
populateAcc,
|
@@ -3776,40 +4020,46 @@ const getDeepPopulate = (uid2, {
|
|
3776
4020
|
{}
|
3777
4021
|
);
|
3778
4022
|
};
|
3779
|
-
const
|
3780
|
-
|
3781
|
-
|
3782
|
-
countOne = false,
|
3783
|
-
maxLevel = Infinity
|
3784
|
-
} = {}, level = 1) => {
|
3785
|
-
if (level > maxLevel) {
|
4023
|
+
const getPopulateForValidation = (uid2) => {
|
4024
|
+
const model = strapi.getModel(uid2);
|
4025
|
+
if (!model) {
|
3786
4026
|
return {};
|
3787
4027
|
}
|
3788
|
-
const model = strapi.getModel(uid2);
|
3789
4028
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3790
|
-
if (
|
4029
|
+
if (isScalarAttribute(attribute)) {
|
4030
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4031
|
+
populateAcc.fields = populateAcc.fields || [];
|
4032
|
+
populateAcc.fields.push(attributeName);
|
4033
|
+
}
|
3791
4034
|
return populateAcc;
|
3792
4035
|
}
|
3793
|
-
if (
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
4036
|
+
if (isComponent(attribute)) {
|
4037
|
+
const component = attribute.component;
|
4038
|
+
const componentResult = getPopulateForValidation(component);
|
4039
|
+
if (Object.keys(componentResult).length > 0) {
|
4040
|
+
populateAcc.populate = populateAcc.populate || {};
|
4041
|
+
populateAcc.populate[attributeName] = componentResult;
|
4042
|
+
}
|
4043
|
+
return populateAcc;
|
3797
4044
|
}
|
3798
|
-
|
3799
|
-
|
3800
|
-
|
3801
|
-
|
3802
|
-
|
3803
|
-
|
3804
|
-
|
3805
|
-
|
3806
|
-
|
3807
|
-
countOne,
|
3808
|
-
maxLevel
|
4045
|
+
if (isDynamicZone(attribute)) {
|
4046
|
+
const components2 = attribute.components;
|
4047
|
+
const componentsResult = (components2 || []).reduce(
|
4048
|
+
(acc, componentUID) => {
|
4049
|
+
const componentResult = getPopulateForValidation(componentUID);
|
4050
|
+
if (Object.keys(componentResult).length > 0) {
|
4051
|
+
acc[componentUID] = componentResult;
|
4052
|
+
}
|
4053
|
+
return acc;
|
3809
4054
|
},
|
3810
|
-
|
3811
|
-
)
|
3812
|
-
|
4055
|
+
{}
|
4056
|
+
);
|
4057
|
+
if (Object.keys(componentsResult).length > 0) {
|
4058
|
+
populateAcc.populate = populateAcc.populate || {};
|
4059
|
+
populateAcc.populate[attributeName] = { on: componentsResult };
|
4060
|
+
}
|
4061
|
+
}
|
4062
|
+
return populateAcc;
|
3813
4063
|
}, {});
|
3814
4064
|
};
|
3815
4065
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3889,7 +4139,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3889
4139
|
return populateQuery;
|
3890
4140
|
};
|
3891
4141
|
const buildDeepPopulate = (uid2) => {
|
3892
|
-
return getService$
|
4142
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3893
4143
|
};
|
3894
4144
|
const populateBuilder = (uid2) => {
|
3895
4145
|
let getInitialPopulate = async () => {
|
@@ -4051,7 +4301,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4051
4301
|
"locale",
|
4052
4302
|
"updatedAt",
|
4053
4303
|
"createdAt",
|
4054
|
-
"status",
|
4055
4304
|
"publishedAt",
|
4056
4305
|
"documentId"
|
4057
4306
|
];
|
@@ -4072,34 +4321,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4072
4321
|
/**
|
4073
4322
|
* Returns available locales of a document for the current status
|
4074
4323
|
*/
|
4075
|
-
async getAvailableLocales(uid2, version, allVersions
|
4324
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4076
4325
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4077
|
-
|
4326
|
+
if (version.locale) {
|
4327
|
+
delete versionsByLocale[version.locale];
|
4328
|
+
}
|
4078
4329
|
const model = strapi2.getModel(uid2);
|
4079
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4080
|
-
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4081
|
-
({ key }, { remove }) => {
|
4082
|
-
if (keysToKeep.includes(key)) {
|
4083
|
-
return;
|
4084
|
-
}
|
4085
|
-
remove(key);
|
4086
|
-
},
|
4087
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4088
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4089
|
-
localeVersion
|
4090
|
-
);
|
4091
4330
|
const mappingResult = await strapiUtils.async.map(
|
4092
4331
|
Object.values(versionsByLocale),
|
4093
4332
|
async (localeVersions) => {
|
4094
|
-
const mappedLocaleVersions = await strapiUtils.async.map(
|
4095
|
-
localeVersions,
|
4096
|
-
traversalFunction
|
4097
|
-
);
|
4098
4333
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4099
|
-
return
|
4334
|
+
return localeVersions[0];
|
4100
4335
|
}
|
4101
|
-
const draftVersion =
|
4102
|
-
const otherVersions =
|
4336
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4337
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4103
4338
|
if (!draftVersion) {
|
4104
4339
|
return;
|
4105
4340
|
}
|
@@ -4121,8 +4356,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4121
4356
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4122
4357
|
return matchLocale && matchStatus;
|
4123
4358
|
});
|
4124
|
-
if (!availableStatus)
|
4125
|
-
return availableStatus;
|
4359
|
+
if (!availableStatus) return availableStatus;
|
4126
4360
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4127
4361
|
},
|
4128
4362
|
/**
|
@@ -4132,18 +4366,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4132
4366
|
* @returns
|
4133
4367
|
*/
|
4134
4368
|
async getManyAvailableStatus(uid2, documents) {
|
4135
|
-
if (!documents.length)
|
4136
|
-
return [];
|
4369
|
+
if (!documents.length) return [];
|
4137
4370
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4138
|
-
const
|
4139
|
-
const
|
4140
|
-
|
4141
|
-
|
4142
|
-
|
4143
|
-
|
4144
|
-
|
4145
|
-
|
4146
|
-
|
4371
|
+
const locales = documents.map((d) => d.locale).filter(Boolean);
|
4372
|
+
const where = {
|
4373
|
+
documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
|
4374
|
+
publishedAt: { $null: status === "published" }
|
4375
|
+
};
|
4376
|
+
if (locales.length) {
|
4377
|
+
where.locale = { $in: locales };
|
4378
|
+
}
|
4379
|
+
return strapi2.query(uid2).findMany({
|
4380
|
+
where,
|
4381
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
|
4147
4382
|
});
|
4148
4383
|
},
|
4149
4384
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4160,10 +4395,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4160
4395
|
} else if (otherVersion) {
|
4161
4396
|
draftVersion = otherVersion;
|
4162
4397
|
}
|
4163
|
-
if (!draftVersion)
|
4164
|
-
|
4165
|
-
if (!publishedVersion)
|
4166
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4398
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4399
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4167
4400
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4168
4401
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4169
4402
|
},
|
@@ -4171,11 +4404,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4171
4404
|
// We could refactor this so the locales are only loaded when they're
|
4172
4405
|
// needed. e.g. in the bulk locale action modal.
|
4173
4406
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4174
|
-
const populate =
|
4175
|
-
const
|
4176
|
-
where: { documentId: version.documentId },
|
4407
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4408
|
+
const params = {
|
4177
4409
|
populate: {
|
4178
|
-
// Populate only fields that require validation for bulk locale actions
|
4179
4410
|
...populate,
|
4180
4411
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4181
4412
|
createdBy: {
|
@@ -4184,9 +4415,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4184
4415
|
updatedBy: {
|
4185
4416
|
select: ["id", "firstname", "lastname", "email"]
|
4186
4417
|
}
|
4418
|
+
},
|
4419
|
+
fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4420
|
+
filters: {
|
4421
|
+
documentId: version.documentId
|
4187
4422
|
}
|
4188
|
-
}
|
4189
|
-
const
|
4423
|
+
};
|
4424
|
+
const dbParams = strapi2.get("query-params").transform(uid2, params);
|
4425
|
+
const versions = await strapi2.db.query(uid2).findMany(dbParams);
|
4426
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
|
4190
4427
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4191
4428
|
return {
|
4192
4429
|
availableLocales: availableLocalesResult,
|
@@ -4213,6 +4450,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4213
4450
|
opts.availableStatus = false;
|
4214
4451
|
}
|
4215
4452
|
const meta = await this.getMetadata(uid2, document, opts);
|
4453
|
+
if (document.localizations) {
|
4454
|
+
const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
|
4455
|
+
document.localizations = document.localizations.map((d) => {
|
4456
|
+
const status = otherStatus.find((s) => s.documentId === d.documentId);
|
4457
|
+
return {
|
4458
|
+
...d,
|
4459
|
+
status: this.getStatus(d, status ? [status] : [])
|
4460
|
+
};
|
4461
|
+
});
|
4462
|
+
}
|
4216
4463
|
return {
|
4217
4464
|
data: {
|
4218
4465
|
...document,
|
@@ -4430,7 +4677,8 @@ const services = {
|
|
4430
4677
|
permission,
|
4431
4678
|
"populate-builder": populateBuilder$1,
|
4432
4679
|
uid,
|
4433
|
-
...history.services ? history.services : {}
|
4680
|
+
...history.services ? history.services : {},
|
4681
|
+
...preview.services ? preview.services : {}
|
4434
4682
|
};
|
4435
4683
|
const index = () => {
|
4436
4684
|
return {
|