@strapi/content-manager 0.0.0-experimental.145e7d7ddefd1aef71aaf3d9bb86440d013035bf → 0.0.0-experimental.15989d13d8be058bf37afc84b7a8377ef1da3263
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-D_g11bYV.js → ComponentConfigurationPage-BSEZcJVB.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-D_g11bYV.js.map → ComponentConfigurationPage-BSEZcJVB.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DJEJ49QD.mjs → ComponentConfigurationPage-BiASGi7x.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DJEJ49QD.mjs.map → ComponentConfigurationPage-BiASGi7x.mjs.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-CeL712KW.js → EditConfigurationPage-D2rtvneE.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-CeL712KW.js.map → EditConfigurationPage-D2rtvneE.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-QBZdUYyG.mjs → EditConfigurationPage-vN4zupij.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-QBZdUYyG.mjs.map → EditConfigurationPage-vN4zupij.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-g5TwrgRY.js → EditViewPage-BwisF04Q.js} +50 -11
- package/dist/_chunks/EditViewPage-BwisF04Q.js.map +1 -0
- package/dist/_chunks/{EditViewPage-CvRUUpVh.mjs → EditViewPage-_A31Cl4g.mjs} +50 -10
- package/dist/_chunks/EditViewPage-_A31Cl4g.mjs.map +1 -0
- package/dist/_chunks/{Field-reyvfnop.mjs → Field-CvIunNOj.mjs} +238 -152
- package/dist/_chunks/Field-CvIunNOj.mjs.map +1 -0
- package/dist/_chunks/{Field-ncdInvxS.js → Field-Dsu6-FrM.js} +244 -158
- package/dist/_chunks/Field-Dsu6-FrM.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-DoMGsYxH.mjs → Form-DK0fG0Gj.mjs} +15 -9
- package/dist/_chunks/Form-DK0fG0Gj.mjs.map +1 -0
- package/dist/_chunks/{Form-BJ7bYiUx.js → Form-DUwWcCmA.js} +17 -12
- package/dist/_chunks/Form-DUwWcCmA.js.map +1 -0
- package/dist/_chunks/{History-pbhkxIrf.js → History-CeCDhoJG.js} +42 -100
- package/dist/_chunks/History-CeCDhoJG.js.map +1 -0
- package/dist/_chunks/{History-BseDJOrj.mjs → History-DP8gmXpm.mjs} +43 -100
- package/dist/_chunks/History-DP8gmXpm.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DWE_fr5B.mjs → ListConfigurationPage-BCkO5iuN.mjs} +7 -6
- package/dist/_chunks/ListConfigurationPage-BCkO5iuN.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-Bna8zfjr.js → ListConfigurationPage-C-bAd44a.js} +7 -7
- package/dist/_chunks/ListConfigurationPage-C-bAd44a.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Dymsvnv6.js → ListViewPage-BKTZFhsM.js} +88 -54
- package/dist/_chunks/ListViewPage-BKTZFhsM.js.map +1 -0
- package/dist/_chunks/{ListViewPage-lQ-VLV2G.mjs → ListViewPage-Cf_DgaFV.mjs} +83 -48
- package/dist/_chunks/ListViewPage-Cf_DgaFV.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-B4t_OsDR.js → NoContentTypePage-D3Cm3v3q.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-B4t_OsDR.js.map → NoContentTypePage-D3Cm3v3q.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-VCQOMwlf.mjs → NoContentTypePage-nHIyvJcB.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-VCQOMwlf.mjs.map → NoContentTypePage-nHIyvJcB.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-TV830k4P.mjs → NoPermissionsPage-BALVSJ7x.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-TV830k4P.mjs.map → NoPermissionsPage-BALVSJ7x.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BOwB6hki.js → NoPermissionsPage-CChGWBj5.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BOwB6hki.js.map → NoPermissionsPage-CChGWBj5.js.map} +1 -1
- package/dist/_chunks/Preview-C4NBzKUV.mjs +294 -0
- package/dist/_chunks/Preview-C4NBzKUV.mjs.map +1 -0
- package/dist/_chunks/Preview-CT28Ckpg.js +312 -0
- package/dist/_chunks/Preview-CT28Ckpg.js.map +1 -0
- package/dist/_chunks/{Relations-D6NAlnsl.mjs → Relations-C8uC89cT.mjs} +75 -41
- package/dist/_chunks/Relations-C8uC89cT.mjs.map +1 -0
- package/dist/_chunks/{Relations-DdlstXTu.js → Relations-CvkPCng_.js} +75 -42
- package/dist/_chunks/Relations-CvkPCng_.js.map +1 -0
- package/dist/_chunks/{en-Cf41pH5f.js → en-BK8Xyl5I.js} +24 -12
- package/dist/_chunks/{en-Cf41pH5f.js.map → en-BK8Xyl5I.js.map} +1 -1
- package/dist/_chunks/{en-DCszE74t.mjs → en-Dtk_ot79.mjs} +24 -12
- package/dist/_chunks/{en-DCszE74t.mjs.map → en-Dtk_ot79.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-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-CQos-KS0.js → index-CnX_j5h-.js} +1239 -942
- package/dist/_chunks/index-CnX_j5h-.js.map +1 -0
- package/dist/_chunks/{index-BYSWwHBJ.mjs → index-Dh2aGTGJ.mjs} +1241 -944
- package/dist/_chunks/index-Dh2aGTGJ.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-0TY7UtKO.mjs → layout-B5qsPihj.mjs} +6 -5
- package/dist/_chunks/{layout-0TY7UtKO.mjs.map → layout-B5qsPihj.mjs.map} +1 -1
- package/dist/_chunks/{layout-B4XAqu1v.js → layout-B_qdWGny.js} +7 -7
- package/dist/_chunks/{layout-B4XAqu1v.js.map → layout-B_qdWGny.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-xZ2tMj1G.js → relations-ChcieiF5.js} +6 -7
- package/dist/_chunks/relations-ChcieiF5.js.map +1 -0
- package/dist/_chunks/{relations-DFDWfa0s.mjs → relations-DMXpNY-e.mjs} +6 -7
- package/dist/_chunks/relations-DMXpNY-e.mjs.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.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/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +4 -3
- package/dist/admin/src/content-manager.d.ts +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- 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 +2 -2
- 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/Header.d.ts +11 -11
- 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/documents.d.ts +0 -3
- package/dist/server/index.js +513 -260
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +514 -260
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.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/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 +2 -3
- 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 +17 -15
- package/dist/_chunks/EditViewPage-CvRUUpVh.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-g5TwrgRY.js.map +0 -1
- package/dist/_chunks/Field-ncdInvxS.js.map +0 -1
- package/dist/_chunks/Field-reyvfnop.mjs.map +0 -1
- package/dist/_chunks/Form-BJ7bYiUx.js.map +0 -1
- package/dist/_chunks/Form-DoMGsYxH.mjs.map +0 -1
- package/dist/_chunks/History-BseDJOrj.mjs.map +0 -1
- package/dist/_chunks/History-pbhkxIrf.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-Bna8zfjr.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DWE_fr5B.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Dymsvnv6.js.map +0 -1
- package/dist/_chunks/ListViewPage-lQ-VLV2G.mjs.map +0 -1
- package/dist/_chunks/Relations-D6NAlnsl.mjs.map +0 -1
- package/dist/_chunks/Relations-DdlstXTu.js.map +0 -1
- package/dist/_chunks/index-BYSWwHBJ.mjs.map +0 -1
- package/dist/_chunks/index-CQos-KS0.js.map +0 -1
- package/dist/_chunks/relations-DFDWfa0s.mjs.map +0 -1
- package/dist/_chunks/relations-xZ2tMj1G.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
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({
|
@@ -203,8 +201,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
203
201
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
202
|
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
205
203
|
const getLocaleDictionary = async () => {
|
206
|
-
if (!localesService)
|
207
|
-
return {};
|
204
|
+
if (!localesService) return {};
|
208
205
|
const locales = await localesService.find() || [];
|
209
206
|
return locales.reduce(
|
210
207
|
(acc, locale) => {
|
@@ -228,6 +225,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
228
225
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
229
226
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
230
227
|
};
|
228
|
+
const getComponentFields = (componentUID) => {
|
229
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
230
|
+
(fieldsAcc, [key, attribute]) => {
|
231
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
232
|
+
fieldsAcc.push(key);
|
233
|
+
}
|
234
|
+
return fieldsAcc;
|
235
|
+
},
|
236
|
+
[]
|
237
|
+
);
|
238
|
+
};
|
231
239
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
232
240
|
const model = strapi2.getModel(uid2);
|
233
241
|
const attributes = Object.entries(model.attributes);
|
@@ -251,13 +259,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
251
259
|
}
|
252
260
|
case "component": {
|
253
261
|
const populate = getDeepPopulate2(attribute.component);
|
254
|
-
acc[attributeName] = {
|
262
|
+
acc[attributeName] = {
|
263
|
+
populate,
|
264
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
265
|
+
};
|
255
266
|
break;
|
256
267
|
}
|
257
268
|
case "dynamiczone": {
|
258
269
|
const populatedComponents = (attribute.components || []).reduce(
|
259
270
|
(acc2, componentUID) => {
|
260
|
-
acc2[componentUID] = {
|
271
|
+
acc2[componentUID] = {
|
272
|
+
populate: getDeepPopulate2(componentUID),
|
273
|
+
[fieldSelector]: getComponentFields(componentUID)
|
274
|
+
};
|
261
275
|
return acc2;
|
262
276
|
},
|
263
277
|
{}
|
@@ -370,7 +384,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
370
384
|
const attributeValue = entry.data[attributeKey];
|
371
385
|
const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
|
372
386
|
if (attributeSchema.type === "media") {
|
373
|
-
const permissionChecker2 = getService$
|
387
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
374
388
|
userAbility: params.state.userAbility,
|
375
389
|
model: "plugin::upload.file"
|
376
390
|
});
|
@@ -393,7 +407,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
393
407
|
if (userToPopulate == null) {
|
394
408
|
return null;
|
395
409
|
}
|
396
|
-
return strapi2.query("admin::user").findOne({
|
410
|
+
return strapi2.query("admin::user").findOne({
|
411
|
+
where: {
|
412
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
413
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
414
|
+
}
|
415
|
+
});
|
397
416
|
})
|
398
417
|
);
|
399
418
|
return {
|
@@ -406,7 +425,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
406
425
|
[attributeKey]: adminUsers
|
407
426
|
};
|
408
427
|
}
|
409
|
-
const permissionChecker2 = getService$
|
428
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
410
429
|
userAbility: params.state.userAbility,
|
411
430
|
model: attributeSchema.target
|
412
431
|
});
|
@@ -582,7 +601,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
582
601
|
onCommit(async () => {
|
583
602
|
for (const entry of localeEntries) {
|
584
603
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
585
|
-
await getService(strapi2, "history").createVersion({
|
604
|
+
await getService$1(strapi2, "history").createVersion({
|
586
605
|
contentType: uid2,
|
587
606
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
588
607
|
relatedDocumentId: documentId,
|
@@ -595,15 +614,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
595
614
|
});
|
596
615
|
return result;
|
597
616
|
});
|
598
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
617
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
599
618
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
600
619
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
601
620
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
602
621
|
where: {
|
603
622
|
created_at: {
|
604
|
-
$lt: expirationDate
|
623
|
+
$lt: expirationDate
|
605
624
|
}
|
606
625
|
}
|
626
|
+
}).catch((error) => {
|
627
|
+
if (error instanceof Error) {
|
628
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
629
|
+
}
|
607
630
|
});
|
608
631
|
});
|
609
632
|
state.isInitialized = true;
|
@@ -615,17 +638,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
615
638
|
}
|
616
639
|
};
|
617
640
|
};
|
618
|
-
const services$
|
641
|
+
const services$2 = {
|
619
642
|
history: createHistoryService,
|
620
643
|
lifecycles: createLifecyclesService
|
621
644
|
};
|
622
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
645
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
623
646
|
const historyVersionRouter = {
|
624
647
|
type: "admin",
|
625
648
|
routes: [
|
626
649
|
{
|
627
650
|
method: "GET",
|
628
|
-
info,
|
651
|
+
info: info$1,
|
629
652
|
path: "/history-versions",
|
630
653
|
handler: "history-version.findMany",
|
631
654
|
config: {
|
@@ -634,7 +657,7 @@ const historyVersionRouter = {
|
|
634
657
|
},
|
635
658
|
{
|
636
659
|
method: "PUT",
|
637
|
-
info,
|
660
|
+
info: info$1,
|
638
661
|
path: "/history-versions/:versionId/restore",
|
639
662
|
handler: "history-version.restoreVersion",
|
640
663
|
config: {
|
@@ -643,7 +666,7 @@ const historyVersionRouter = {
|
|
643
666
|
}
|
644
667
|
]
|
645
668
|
};
|
646
|
-
const routes$
|
669
|
+
const routes$2 = {
|
647
670
|
"history-version": historyVersionRouter
|
648
671
|
};
|
649
672
|
const historyVersion = {
|
@@ -690,21 +713,21 @@ const historyVersion = {
|
|
690
713
|
}
|
691
714
|
}
|
692
715
|
};
|
693
|
-
const getFeature = () => {
|
716
|
+
const getFeature$1 = () => {
|
694
717
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
695
718
|
return {
|
696
719
|
register({ strapi: strapi2 }) {
|
697
720
|
strapi2.get("models").add(historyVersion);
|
698
721
|
},
|
699
722
|
bootstrap({ strapi: strapi2 }) {
|
700
|
-
getService(strapi2, "lifecycles").bootstrap();
|
723
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
701
724
|
},
|
702
725
|
destroy({ strapi: strapi2 }) {
|
703
|
-
getService(strapi2, "lifecycles").destroy();
|
726
|
+
getService$1(strapi2, "lifecycles").destroy();
|
704
727
|
},
|
705
|
-
controllers: controllers$
|
706
|
-
services: services$
|
707
|
-
routes: routes$
|
728
|
+
controllers: controllers$2,
|
729
|
+
services: services$2,
|
730
|
+
routes: routes$2
|
708
731
|
};
|
709
732
|
}
|
710
733
|
return {
|
@@ -713,9 +736,201 @@ const getFeature = () => {
|
|
713
736
|
}
|
714
737
|
};
|
715
738
|
};
|
716
|
-
const history = getFeature();
|
739
|
+
const history = getFeature$1();
|
740
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
741
|
+
const previewRouter = {
|
742
|
+
type: "admin",
|
743
|
+
routes: [
|
744
|
+
{
|
745
|
+
method: "GET",
|
746
|
+
info,
|
747
|
+
path: "/preview/url/:contentType",
|
748
|
+
handler: "preview.getPreviewUrl",
|
749
|
+
config: {
|
750
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
751
|
+
}
|
752
|
+
}
|
753
|
+
]
|
754
|
+
};
|
755
|
+
const routes$1 = {
|
756
|
+
preview: previewRouter
|
757
|
+
};
|
758
|
+
function getService(strapi2, name) {
|
759
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
760
|
+
}
|
761
|
+
const getPreviewUrlSchema = yup__namespace.object().shape({
|
762
|
+
// Will be undefined for single types
|
763
|
+
documentId: yup__namespace.string(),
|
764
|
+
locale: yup__namespace.string().nullable(),
|
765
|
+
status: yup__namespace.string()
|
766
|
+
}).required();
|
767
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
768
|
+
await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
|
769
|
+
const newParams = fp.pick(["documentId", "locale", "status"], params);
|
770
|
+
const model = strapi2.getModel(uid2);
|
771
|
+
if (!model || model.modelType !== "contentType") {
|
772
|
+
throw new strapiUtils.errors.ValidationError("Invalid content type");
|
773
|
+
}
|
774
|
+
const isSingleType = model?.kind === "singleType";
|
775
|
+
if (!isSingleType && !params.documentId) {
|
776
|
+
throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
|
777
|
+
}
|
778
|
+
if (isSingleType) {
|
779
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
780
|
+
if (!doc) {
|
781
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
782
|
+
}
|
783
|
+
newParams.documentId = doc?.documentId;
|
784
|
+
}
|
785
|
+
if (!newParams.status) {
|
786
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
787
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
788
|
+
}
|
789
|
+
return newParams;
|
790
|
+
};
|
791
|
+
const createPreviewController = () => {
|
792
|
+
return {
|
793
|
+
/**
|
794
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
795
|
+
* in the Content Manager.
|
796
|
+
*/
|
797
|
+
async getPreviewUrl(ctx) {
|
798
|
+
const uid2 = ctx.params.contentType;
|
799
|
+
const query = ctx.request.query;
|
800
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
801
|
+
const previewService = getService(strapi, "preview");
|
802
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
803
|
+
if (!url) {
|
804
|
+
ctx.status = 204;
|
805
|
+
}
|
806
|
+
return {
|
807
|
+
data: { url }
|
808
|
+
};
|
809
|
+
}
|
810
|
+
};
|
811
|
+
};
|
812
|
+
const controllers$1 = {
|
813
|
+
preview: createPreviewController
|
814
|
+
/**
|
815
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
816
|
+
* passing a controller factory as the value, instead of a controller object directly
|
817
|
+
*/
|
818
|
+
};
|
819
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
820
|
+
const config = getService(strapi2, "preview-config");
|
821
|
+
return {
|
822
|
+
async getPreviewUrl(uid2, params) {
|
823
|
+
const handler = config.getPreviewHandler();
|
824
|
+
try {
|
825
|
+
return handler(uid2, params);
|
826
|
+
} catch (error) {
|
827
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
828
|
+
throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
|
829
|
+
}
|
830
|
+
return;
|
831
|
+
}
|
832
|
+
};
|
833
|
+
};
|
834
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
835
|
+
const middlewares = strapi.config.get("middlewares");
|
836
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
837
|
+
if (currentMiddleware === middleware.name) {
|
838
|
+
return middleware;
|
839
|
+
}
|
840
|
+
if (currentMiddleware.name === middleware.name) {
|
841
|
+
return fp.mergeWith(
|
842
|
+
(objValue, srcValue) => {
|
843
|
+
if (Array.isArray(objValue)) {
|
844
|
+
return objValue.concat(srcValue);
|
845
|
+
}
|
846
|
+
return void 0;
|
847
|
+
},
|
848
|
+
currentMiddleware,
|
849
|
+
middleware
|
850
|
+
);
|
851
|
+
}
|
852
|
+
return currentMiddleware;
|
853
|
+
});
|
854
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
855
|
+
};
|
856
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
857
|
+
return {
|
858
|
+
register() {
|
859
|
+
if (!this.isEnabled()) {
|
860
|
+
return;
|
861
|
+
}
|
862
|
+
const config = strapi2.config.get("admin.preview");
|
863
|
+
if (config.config?.allowedOrigins) {
|
864
|
+
extendMiddlewareConfiguration({
|
865
|
+
name: "strapi::security",
|
866
|
+
config: {
|
867
|
+
contentSecurityPolicy: {
|
868
|
+
directives: {
|
869
|
+
"frame-src": config.config.allowedOrigins
|
870
|
+
}
|
871
|
+
}
|
872
|
+
}
|
873
|
+
});
|
874
|
+
}
|
875
|
+
},
|
876
|
+
isEnabled() {
|
877
|
+
const config = strapi2.config.get("admin.preview");
|
878
|
+
if (!config) {
|
879
|
+
return false;
|
880
|
+
}
|
881
|
+
return config?.enabled ?? true;
|
882
|
+
},
|
883
|
+
/**
|
884
|
+
* Validate if the configuration is valid
|
885
|
+
*/
|
886
|
+
validate() {
|
887
|
+
if (!this.isEnabled()) {
|
888
|
+
return;
|
889
|
+
}
|
890
|
+
const handler = this.getPreviewHandler();
|
891
|
+
if (typeof handler !== "function") {
|
892
|
+
throw new strapiUtils.errors.ValidationError(
|
893
|
+
"Preview configuration is invalid. Handler must be a function"
|
894
|
+
);
|
895
|
+
}
|
896
|
+
},
|
897
|
+
/**
|
898
|
+
* Utility to get the preview handler from the configuration
|
899
|
+
*/
|
900
|
+
getPreviewHandler() {
|
901
|
+
const config = strapi2.config.get("admin.preview");
|
902
|
+
const emptyHandler = () => {
|
903
|
+
return void 0;
|
904
|
+
};
|
905
|
+
if (!this.isEnabled()) {
|
906
|
+
return emptyHandler;
|
907
|
+
}
|
908
|
+
return config?.config?.handler || emptyHandler;
|
909
|
+
}
|
910
|
+
};
|
911
|
+
};
|
912
|
+
const services$1 = {
|
913
|
+
preview: createPreviewService,
|
914
|
+
"preview-config": createPreviewConfigService
|
915
|
+
};
|
916
|
+
const getFeature = () => {
|
917
|
+
return {
|
918
|
+
register() {
|
919
|
+
const config = getService(strapi, "preview-config");
|
920
|
+
config.validate();
|
921
|
+
config.register();
|
922
|
+
},
|
923
|
+
bootstrap() {
|
924
|
+
},
|
925
|
+
routes: routes$1,
|
926
|
+
controllers: controllers$1,
|
927
|
+
services: services$1
|
928
|
+
};
|
929
|
+
};
|
930
|
+
const preview = getFeature();
|
717
931
|
const register = async ({ strapi: strapi2 }) => {
|
718
932
|
await history.register?.({ strapi: strapi2 });
|
933
|
+
await preview.register?.({ strapi: strapi2 });
|
719
934
|
};
|
720
935
|
const ALLOWED_WEBHOOK_EVENTS = {
|
721
936
|
ENTRY_PUBLISH: "entry.publish",
|
@@ -725,11 +940,12 @@ const bootstrap = async () => {
|
|
725
940
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
726
941
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
727
942
|
});
|
728
|
-
getService$
|
729
|
-
await getService$
|
730
|
-
await getService$
|
731
|
-
await getService$
|
943
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
944
|
+
await getService$2("components").syncConfigurations();
|
945
|
+
await getService$2("content-types").syncConfigurations();
|
946
|
+
await getService$2("permission").registerPermissions();
|
732
947
|
await history.bootstrap?.({ strapi });
|
948
|
+
await preview.bootstrap?.({ strapi });
|
733
949
|
};
|
734
950
|
const destroy = async ({ strapi: strapi2 }) => {
|
735
951
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1219,7 +1435,8 @@ const admin = {
|
|
1219
1435
|
};
|
1220
1436
|
const routes = {
|
1221
1437
|
admin,
|
1222
|
-
...history.routes ? history.routes : {}
|
1438
|
+
...history.routes ? history.routes : {},
|
1439
|
+
...preview.routes ? preview.routes : {}
|
1223
1440
|
};
|
1224
1441
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1225
1442
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1282,8 +1499,7 @@ const isSortable = (schema, name) => {
|
|
1282
1499
|
if (!___default.default.has(schema.attributes, name)) {
|
1283
1500
|
return false;
|
1284
1501
|
}
|
1285
|
-
if (schema.modelType === "component" && name === "id")
|
1286
|
-
return false;
|
1502
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1287
1503
|
const attribute = schema.attributes[name];
|
1288
1504
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1289
1505
|
return false;
|
@@ -1428,8 +1644,7 @@ const createDefaultSettings = async (schema) => {
|
|
1428
1644
|
};
|
1429
1645
|
};
|
1430
1646
|
const syncSettings = async (configuration, schema) => {
|
1431
|
-
if (fp.isEmpty(configuration.settings))
|
1432
|
-
return createDefaultSettings(schema);
|
1647
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1433
1648
|
const defaultField = getDefaultMainField(schema);
|
1434
1649
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1435
1650
|
return {
|
@@ -1476,7 +1691,7 @@ const createMetadasSchema = (schema) => {
|
|
1476
1691
|
if (!value) {
|
1477
1692
|
return strapiUtils.yup.string();
|
1478
1693
|
}
|
1479
|
-
const targetSchema = getService$
|
1694
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1480
1695
|
schema.attributes[key].targetModel
|
1481
1696
|
);
|
1482
1697
|
if (!targetSchema) {
|
@@ -1605,8 +1820,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1605
1820
|
}
|
1606
1821
|
switch (attribute.type) {
|
1607
1822
|
case "relation": {
|
1608
|
-
if (canCreate(attributePath))
|
1609
|
-
return body2;
|
1823
|
+
if (canCreate(attributePath)) return body2;
|
1610
1824
|
return fp.set(attributePath, { set: [] }, body2);
|
1611
1825
|
}
|
1612
1826
|
case "component": {
|
@@ -1616,8 +1830,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1616
1830
|
]);
|
1617
1831
|
}
|
1618
1832
|
default: {
|
1619
|
-
if (canCreate(attributePath))
|
1620
|
-
return body2;
|
1833
|
+
if (canCreate(attributePath)) return body2;
|
1621
1834
|
return fp.set(attributePath, null, body2);
|
1622
1835
|
}
|
1623
1836
|
}
|
@@ -1645,7 +1858,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1645
1858
|
}
|
1646
1859
|
};
|
1647
1860
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1648
|
-
const documentMetadata2 = getService$
|
1861
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1649
1862
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1650
1863
|
let {
|
1651
1864
|
meta: { availableLocales, availableStatus }
|
@@ -1671,8 +1884,8 @@ const createDocument = async (ctx, opts) => {
|
|
1671
1884
|
const { userAbility, user } = ctx.state;
|
1672
1885
|
const { model } = ctx.params;
|
1673
1886
|
const { body } = ctx.request;
|
1674
|
-
const documentManager2 = getService$
|
1675
|
-
const permissionChecker2 = getService$
|
1887
|
+
const documentManager2 = getService$2("document-manager");
|
1888
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1676
1889
|
if (permissionChecker2.cannot.create()) {
|
1677
1890
|
throw new strapiUtils.errors.ForbiddenError();
|
1678
1891
|
}
|
@@ -1692,13 +1905,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1692
1905
|
const { userAbility, user } = ctx.state;
|
1693
1906
|
const { id, model } = ctx.params;
|
1694
1907
|
const { body } = ctx.request;
|
1695
|
-
const documentManager2 = getService$
|
1696
|
-
const permissionChecker2 = getService$
|
1908
|
+
const documentManager2 = getService$2("document-manager");
|
1909
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1697
1910
|
if (permissionChecker2.cannot.update()) {
|
1698
1911
|
throw new strapiUtils.errors.ForbiddenError();
|
1699
1912
|
}
|
1700
1913
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1701
|
-
const populate = await getService$
|
1914
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1702
1915
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1703
1916
|
const [documentVersion, documentExists] = await Promise.all([
|
1704
1917
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1715,7 +1928,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1715
1928
|
throw new strapiUtils.errors.ForbiddenError();
|
1716
1929
|
}
|
1717
1930
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1718
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1931
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1719
1932
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1720
1933
|
const sanitizedBody = await sanitizeFn(body);
|
1721
1934
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1729,14 +1942,14 @@ const collectionTypes = {
|
|
1729
1942
|
const { userAbility } = ctx.state;
|
1730
1943
|
const { model } = ctx.params;
|
1731
1944
|
const { query } = ctx.request;
|
1732
|
-
const documentMetadata2 = getService$
|
1733
|
-
const documentManager2 = getService$
|
1734
|
-
const permissionChecker2 = getService$
|
1945
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1946
|
+
const documentManager2 = getService$2("document-manager");
|
1947
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1735
1948
|
if (permissionChecker2.cannot.read()) {
|
1736
1949
|
return ctx.forbidden();
|
1737
1950
|
}
|
1738
1951
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1739
|
-
const populate = await getService$
|
1952
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1740
1953
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1741
1954
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1742
1955
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1765,13 +1978,13 @@ const collectionTypes = {
|
|
1765
1978
|
async findOne(ctx) {
|
1766
1979
|
const { userAbility } = ctx.state;
|
1767
1980
|
const { model, id } = ctx.params;
|
1768
|
-
const documentManager2 = getService$
|
1769
|
-
const permissionChecker2 = getService$
|
1981
|
+
const documentManager2 = getService$2("document-manager");
|
1982
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1770
1983
|
if (permissionChecker2.cannot.read()) {
|
1771
1984
|
return ctx.forbidden();
|
1772
1985
|
}
|
1773
1986
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1774
|
-
const populate = await getService$
|
1987
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1775
1988
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1776
1989
|
const version = await documentManager2.findOne(id, model, {
|
1777
1990
|
populate,
|
@@ -1787,7 +2000,7 @@ const collectionTypes = {
|
|
1787
2000
|
permissionChecker2,
|
1788
2001
|
model,
|
1789
2002
|
// @ts-expect-error TODO: fix
|
1790
|
-
{ id, locale, publishedAt: null },
|
2003
|
+
{ documentId: id, locale, publishedAt: null },
|
1791
2004
|
{ availableLocales: true, availableStatus: false }
|
1792
2005
|
);
|
1793
2006
|
ctx.body = { data: {}, meta };
|
@@ -1802,7 +2015,7 @@ const collectionTypes = {
|
|
1802
2015
|
async create(ctx) {
|
1803
2016
|
const { userAbility } = ctx.state;
|
1804
2017
|
const { model } = ctx.params;
|
1805
|
-
const permissionChecker2 = getService$
|
2018
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1806
2019
|
const [totalEntries, document] = await Promise.all([
|
1807
2020
|
strapi.db.query(model).count(),
|
1808
2021
|
createDocument(ctx)
|
@@ -1823,7 +2036,7 @@ const collectionTypes = {
|
|
1823
2036
|
async update(ctx) {
|
1824
2037
|
const { userAbility } = ctx.state;
|
1825
2038
|
const { model } = ctx.params;
|
1826
|
-
const permissionChecker2 = getService$
|
2039
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1827
2040
|
const updatedVersion = await updateDocument(ctx);
|
1828
2041
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1829
2042
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1832,13 +2045,13 @@ const collectionTypes = {
|
|
1832
2045
|
const { userAbility, user } = ctx.state;
|
1833
2046
|
const { model, sourceId: id } = ctx.params;
|
1834
2047
|
const { body } = ctx.request;
|
1835
|
-
const documentManager2 = getService$
|
1836
|
-
const permissionChecker2 = getService$
|
2048
|
+
const documentManager2 = getService$2("document-manager");
|
2049
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1837
2050
|
if (permissionChecker2.cannot.create()) {
|
1838
2051
|
return ctx.forbidden();
|
1839
2052
|
}
|
1840
2053
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1841
|
-
const populate = await getService$
|
2054
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1842
2055
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1843
2056
|
const document = await documentManager2.findOne(id, model, {
|
1844
2057
|
populate,
|
@@ -1877,13 +2090,13 @@ const collectionTypes = {
|
|
1877
2090
|
async delete(ctx) {
|
1878
2091
|
const { userAbility } = ctx.state;
|
1879
2092
|
const { id, model } = ctx.params;
|
1880
|
-
const documentManager2 = getService$
|
1881
|
-
const permissionChecker2 = getService$
|
2093
|
+
const documentManager2 = getService$2("document-manager");
|
2094
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1882
2095
|
if (permissionChecker2.cannot.delete()) {
|
1883
2096
|
return ctx.forbidden();
|
1884
2097
|
}
|
1885
2098
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1886
|
-
const populate = await getService$
|
2099
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1887
2100
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1888
2101
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1889
2102
|
if (documentLocales.length === 0) {
|
@@ -1905,14 +2118,14 @@ const collectionTypes = {
|
|
1905
2118
|
const { userAbility } = ctx.state;
|
1906
2119
|
const { id, model } = ctx.params;
|
1907
2120
|
const { body } = ctx.request;
|
1908
|
-
const documentManager2 = getService$
|
1909
|
-
const permissionChecker2 = getService$
|
2121
|
+
const documentManager2 = getService$2("document-manager");
|
2122
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1910
2123
|
if (permissionChecker2.cannot.publish()) {
|
1911
2124
|
return ctx.forbidden();
|
1912
2125
|
}
|
1913
2126
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1914
2127
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1915
|
-
const populate = await getService$
|
2128
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1916
2129
|
let document;
|
1917
2130
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1918
2131
|
const isCreate = fp.isNil(id);
|
@@ -1924,11 +2137,17 @@ const collectionTypes = {
|
|
1924
2137
|
}
|
1925
2138
|
const isUpdate = !isCreate;
|
1926
2139
|
if (isUpdate) {
|
1927
|
-
|
1928
|
-
if (!
|
2140
|
+
const documentExists = documentManager2.exists(model, id);
|
2141
|
+
if (!documentExists) {
|
1929
2142
|
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1930
2143
|
}
|
1931
|
-
|
2144
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
2145
|
+
if (!document) {
|
2146
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
2147
|
+
throw new strapiUtils.errors.ForbiddenError();
|
2148
|
+
}
|
2149
|
+
document = await updateDocument(ctx);
|
2150
|
+
} else if (permissionChecker2.can.update(document)) {
|
1932
2151
|
await updateDocument(ctx);
|
1933
2152
|
}
|
1934
2153
|
}
|
@@ -1954,13 +2173,13 @@ const collectionTypes = {
|
|
1954
2173
|
const { body } = ctx.request;
|
1955
2174
|
const { documentIds } = body;
|
1956
2175
|
await validateBulkActionInput(body);
|
1957
|
-
const documentManager2 = getService$
|
1958
|
-
const permissionChecker2 = getService$
|
2176
|
+
const documentManager2 = getService$2("document-manager");
|
2177
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1959
2178
|
if (permissionChecker2.cannot.publish()) {
|
1960
2179
|
return ctx.forbidden();
|
1961
2180
|
}
|
1962
2181
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1963
|
-
const populate = await getService$
|
2182
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1964
2183
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1965
2184
|
allowMultipleLocales: true
|
1966
2185
|
});
|
@@ -1985,8 +2204,8 @@ const collectionTypes = {
|
|
1985
2204
|
const { body } = ctx.request;
|
1986
2205
|
const { documentIds } = body;
|
1987
2206
|
await validateBulkActionInput(body);
|
1988
|
-
const documentManager2 = getService$
|
1989
|
-
const permissionChecker2 = getService$
|
2207
|
+
const documentManager2 = getService$2("document-manager");
|
2208
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1990
2209
|
if (permissionChecker2.cannot.unpublish()) {
|
1991
2210
|
return ctx.forbidden();
|
1992
2211
|
}
|
@@ -2015,8 +2234,8 @@ const collectionTypes = {
|
|
2015
2234
|
const {
|
2016
2235
|
body: { discardDraft, ...body }
|
2017
2236
|
} = ctx.request;
|
2018
|
-
const documentManager2 = getService$
|
2019
|
-
const permissionChecker2 = getService$
|
2237
|
+
const documentManager2 = getService$2("document-manager");
|
2238
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2020
2239
|
if (permissionChecker2.cannot.unpublish()) {
|
2021
2240
|
return ctx.forbidden();
|
2022
2241
|
}
|
@@ -2024,7 +2243,7 @@ const collectionTypes = {
|
|
2024
2243
|
return ctx.forbidden();
|
2025
2244
|
}
|
2026
2245
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2027
|
-
const populate = await getService$
|
2246
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2028
2247
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2029
2248
|
const document = await documentManager2.findOne(id, model, {
|
2030
2249
|
populate,
|
@@ -2055,13 +2274,13 @@ const collectionTypes = {
|
|
2055
2274
|
const { userAbility } = ctx.state;
|
2056
2275
|
const { id, model } = ctx.params;
|
2057
2276
|
const { body } = ctx.request;
|
2058
|
-
const documentManager2 = getService$
|
2059
|
-
const permissionChecker2 = getService$
|
2277
|
+
const documentManager2 = getService$2("document-manager");
|
2278
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2060
2279
|
if (permissionChecker2.cannot.discard()) {
|
2061
2280
|
return ctx.forbidden();
|
2062
2281
|
}
|
2063
2282
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2064
|
-
const populate = await getService$
|
2283
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2065
2284
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2066
2285
|
const document = await documentManager2.findOne(id, model, {
|
2067
2286
|
populate,
|
@@ -2086,13 +2305,13 @@ const collectionTypes = {
|
|
2086
2305
|
const { query, body } = ctx.request;
|
2087
2306
|
const { documentIds } = body;
|
2088
2307
|
await validateBulkActionInput(body);
|
2089
|
-
const documentManager2 = getService$
|
2090
|
-
const permissionChecker2 = getService$
|
2308
|
+
const documentManager2 = getService$2("document-manager");
|
2309
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2091
2310
|
if (permissionChecker2.cannot.delete()) {
|
2092
2311
|
return ctx.forbidden();
|
2093
2312
|
}
|
2094
2313
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2095
|
-
const populate = await getService$
|
2314
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2096
2315
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2097
2316
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2098
2317
|
populate,
|
@@ -2113,13 +2332,13 @@ const collectionTypes = {
|
|
2113
2332
|
async countDraftRelations(ctx) {
|
2114
2333
|
const { userAbility } = ctx.state;
|
2115
2334
|
const { model, id } = ctx.params;
|
2116
|
-
const documentManager2 = getService$
|
2117
|
-
const permissionChecker2 = getService$
|
2335
|
+
const documentManager2 = getService$2("document-manager");
|
2336
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2118
2337
|
if (permissionChecker2.cannot.read()) {
|
2119
2338
|
return ctx.forbidden();
|
2120
2339
|
}
|
2121
2340
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2122
|
-
const populate = await getService$
|
2341
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2123
2342
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2124
2343
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2125
2344
|
if (!entity) {
|
@@ -2138,8 +2357,8 @@ const collectionTypes = {
|
|
2138
2357
|
const ids = ctx.request.query.documentIds;
|
2139
2358
|
const locale = ctx.request.query.locale;
|
2140
2359
|
const { model } = ctx.params;
|
2141
|
-
const documentManager2 = getService$
|
2142
|
-
const permissionChecker2 = getService$
|
2360
|
+
const documentManager2 = getService$2("document-manager");
|
2361
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2143
2362
|
if (permissionChecker2.cannot.read()) {
|
2144
2363
|
return ctx.forbidden();
|
2145
2364
|
}
|
@@ -2163,13 +2382,13 @@ const collectionTypes = {
|
|
2163
2382
|
};
|
2164
2383
|
const components$1 = {
|
2165
2384
|
findComponents(ctx) {
|
2166
|
-
const components2 = getService$
|
2167
|
-
const { toDto } = getService$
|
2385
|
+
const components2 = getService$2("components").findAllComponents();
|
2386
|
+
const { toDto } = getService$2("data-mapper");
|
2168
2387
|
ctx.body = { data: components2.map(toDto) };
|
2169
2388
|
},
|
2170
2389
|
async findComponentConfiguration(ctx) {
|
2171
2390
|
const { uid: uid2 } = ctx.params;
|
2172
|
-
const componentService = getService$
|
2391
|
+
const componentService = getService$2("components");
|
2173
2392
|
const component = componentService.findComponent(uid2);
|
2174
2393
|
if (!component) {
|
2175
2394
|
return ctx.notFound("component.notFound");
|
@@ -2186,7 +2405,7 @@ const components$1 = {
|
|
2186
2405
|
async updateComponentConfiguration(ctx) {
|
2187
2406
|
const { uid: uid2 } = ctx.params;
|
2188
2407
|
const { body } = ctx.request;
|
2189
|
-
const componentService = getService$
|
2408
|
+
const componentService = getService$2("components");
|
2190
2409
|
const component = componentService.findComponent(uid2);
|
2191
2410
|
if (!component) {
|
2192
2411
|
return ctx.notFound("component.notFound");
|
@@ -2220,12 +2439,12 @@ const contentTypes = {
|
|
2220
2439
|
} catch (error) {
|
2221
2440
|
return ctx.send({ error }, 400);
|
2222
2441
|
}
|
2223
|
-
const contentTypes2 = getService$
|
2224
|
-
const { toDto } = getService$
|
2442
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2443
|
+
const { toDto } = getService$2("data-mapper");
|
2225
2444
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2226
2445
|
},
|
2227
2446
|
async findContentTypesSettings(ctx) {
|
2228
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2447
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2229
2448
|
const contentTypes2 = await findAllContentTypes();
|
2230
2449
|
const configurations = await Promise.all(
|
2231
2450
|
contentTypes2.map(async (contentType) => {
|
@@ -2239,7 +2458,7 @@ const contentTypes = {
|
|
2239
2458
|
},
|
2240
2459
|
async findContentTypeConfiguration(ctx) {
|
2241
2460
|
const { uid: uid2 } = ctx.params;
|
2242
|
-
const contentTypeService = getService$
|
2461
|
+
const contentTypeService = getService$2("content-types");
|
2243
2462
|
const contentType = await contentTypeService.findContentType(uid2);
|
2244
2463
|
if (!contentType) {
|
2245
2464
|
return ctx.notFound("contentType.notFound");
|
@@ -2261,13 +2480,13 @@ const contentTypes = {
|
|
2261
2480
|
const { userAbility } = ctx.state;
|
2262
2481
|
const { uid: uid2 } = ctx.params;
|
2263
2482
|
const { body } = ctx.request;
|
2264
|
-
const contentTypeService = getService$
|
2265
|
-
const metricsService = getService$
|
2483
|
+
const contentTypeService = getService$2("content-types");
|
2484
|
+
const metricsService = getService$2("metrics");
|
2266
2485
|
const contentType = await contentTypeService.findContentType(uid2);
|
2267
2486
|
if (!contentType) {
|
2268
2487
|
return ctx.notFound("contentType.notFound");
|
2269
2488
|
}
|
2270
|
-
if (!getService$
|
2489
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2271
2490
|
return ctx.forbidden();
|
2272
2491
|
}
|
2273
2492
|
let input;
|
@@ -2300,10 +2519,10 @@ const contentTypes = {
|
|
2300
2519
|
};
|
2301
2520
|
const init = {
|
2302
2521
|
getInitData(ctx) {
|
2303
|
-
const { toDto } = getService$
|
2304
|
-
const { findAllComponents } = getService$
|
2305
|
-
const { getAllFieldSizes } = getService$
|
2306
|
-
const { findAllContentTypes } = getService$
|
2522
|
+
const { toDto } = getService$2("data-mapper");
|
2523
|
+
const { findAllComponents } = getService$2("components");
|
2524
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2525
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2307
2526
|
ctx.body = {
|
2308
2527
|
data: {
|
2309
2528
|
fieldSizes: getAllFieldSizes(),
|
@@ -2339,7 +2558,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2339
2558
|
params.filters.$and.push(filtersClause);
|
2340
2559
|
};
|
2341
2560
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2342
|
-
const permissionChecker2 = getService$
|
2561
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2343
2562
|
userAbility,
|
2344
2563
|
model: model.uid
|
2345
2564
|
});
|
@@ -2353,15 +2572,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2353
2572
|
}
|
2354
2573
|
return mainField;
|
2355
2574
|
};
|
2356
|
-
const addStatusToRelations = async (
|
2357
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2575
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2576
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2577
|
+
return relations2;
|
2578
|
+
}
|
2579
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2580
|
+
if (!relations2.length) {
|
2358
2581
|
return relations2;
|
2359
2582
|
}
|
2360
|
-
const
|
2361
|
-
const
|
2583
|
+
const firstRelation = relations2[0];
|
2584
|
+
const filters = {
|
2585
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2586
|
+
// NOTE: find the "opposite" status
|
2587
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2588
|
+
};
|
2589
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2590
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2591
|
+
filters
|
2592
|
+
});
|
2362
2593
|
return relations2.map((relation) => {
|
2363
|
-
const availableStatuses =
|
2364
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2594
|
+
const availableStatuses = availableStatus.filter(
|
2595
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2365
2596
|
);
|
2366
2597
|
return {
|
2367
2598
|
...relation,
|
@@ -2382,11 +2613,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2382
2613
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2383
2614
|
const isSourceLocalized = isLocalized(sourceModel);
|
2384
2615
|
const isTargetLocalized = isLocalized(targetModel);
|
2385
|
-
let validatedLocale = locale;
|
2386
|
-
if (!targetModel || !isTargetLocalized)
|
2387
|
-
validatedLocale = void 0;
|
2388
2616
|
return {
|
2389
|
-
locale
|
2617
|
+
locale,
|
2390
2618
|
isSourceLocalized,
|
2391
2619
|
isTargetLocalized
|
2392
2620
|
};
|
@@ -2395,8 +2623,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2395
2623
|
const sourceModel = strapi.getModel(sourceUid);
|
2396
2624
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2397
2625
|
const isSourceDP = isDP(sourceModel);
|
2398
|
-
if (!isSourceDP)
|
2399
|
-
return { status: void 0 };
|
2626
|
+
if (!isSourceDP) return { status: void 0 };
|
2400
2627
|
switch (status) {
|
2401
2628
|
case "published":
|
2402
2629
|
return { status: "published" };
|
@@ -2426,7 +2653,7 @@ const relations = {
|
|
2426
2653
|
ctx.request?.query?.locale
|
2427
2654
|
);
|
2428
2655
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2429
|
-
const permissionChecker2 = getService$
|
2656
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2430
2657
|
userAbility,
|
2431
2658
|
model
|
2432
2659
|
});
|
@@ -2451,7 +2678,7 @@ const relations = {
|
|
2451
2678
|
where.id = id;
|
2452
2679
|
}
|
2453
2680
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2454
|
-
const populate = await getService$
|
2681
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2455
2682
|
const currentEntity = await strapi.db.query(model).findOne({
|
2456
2683
|
where,
|
2457
2684
|
populate
|
@@ -2466,7 +2693,7 @@ const relations = {
|
|
2466
2693
|
}
|
2467
2694
|
entryId = currentEntity.id;
|
2468
2695
|
}
|
2469
|
-
const modelConfig = isComponent2 ? await getService$
|
2696
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2470
2697
|
const targetSchema = strapi.getModel(targetUid);
|
2471
2698
|
const mainField = fp.flow(
|
2472
2699
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2489,7 +2716,7 @@ const relations = {
|
|
2489
2716
|
attribute,
|
2490
2717
|
fieldsToSelect,
|
2491
2718
|
mainField,
|
2492
|
-
source: { schema: sourceSchema },
|
2719
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2493
2720
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2494
2721
|
sourceSchema,
|
2495
2722
|
targetSchema,
|
@@ -2511,7 +2738,8 @@ const relations = {
|
|
2511
2738
|
fieldsToSelect,
|
2512
2739
|
mainField,
|
2513
2740
|
source: {
|
2514
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2741
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2742
|
+
isLocalized: isSourceLocalized
|
2515
2743
|
},
|
2516
2744
|
target: {
|
2517
2745
|
schema: { uid: targetUid },
|
@@ -2519,7 +2747,7 @@ const relations = {
|
|
2519
2747
|
}
|
2520
2748
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2521
2749
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2522
|
-
const permissionChecker2 = getService$
|
2750
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2523
2751
|
userAbility: ctx.state.userAbility,
|
2524
2752
|
model: targetUid
|
2525
2753
|
});
|
@@ -2549,12 +2777,16 @@ const relations = {
|
|
2549
2777
|
} else {
|
2550
2778
|
where.id = id;
|
2551
2779
|
}
|
2552
|
-
|
2553
|
-
|
2780
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2781
|
+
if (!fp.isEmpty(publishedAt)) {
|
2782
|
+
where[`${alias}.published_at`] = publishedAt;
|
2554
2783
|
}
|
2555
|
-
if (
|
2784
|
+
if (isTargetLocalized && locale) {
|
2556
2785
|
where[`${alias}.locale`] = locale;
|
2557
2786
|
}
|
2787
|
+
if (isSourceLocalized && locale) {
|
2788
|
+
where.locale = locale;
|
2789
|
+
}
|
2558
2790
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2559
2791
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2560
2792
|
}
|
@@ -2572,7 +2804,8 @@ const relations = {
|
|
2572
2804
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2573
2805
|
});
|
2574
2806
|
}
|
2575
|
-
const
|
2807
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2808
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2576
2809
|
ctx.body = {
|
2577
2810
|
...res,
|
2578
2811
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2587,21 +2820,33 @@ const relations = {
|
|
2587
2820
|
attribute,
|
2588
2821
|
targetField,
|
2589
2822
|
fieldsToSelect,
|
2590
|
-
|
2591
|
-
|
2592
|
-
}
|
2593
|
-
target: {
|
2594
|
-
schema: { uid: targetUid }
|
2595
|
-
}
|
2823
|
+
status,
|
2824
|
+
source: { schema: sourceSchema },
|
2825
|
+
target: { schema: targetSchema }
|
2596
2826
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2597
|
-
const
|
2827
|
+
const { uid: sourceUid } = sourceSchema;
|
2828
|
+
const { uid: targetUid } = targetSchema;
|
2829
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2598
2830
|
const dbQuery = strapi.db.query(sourceUid);
|
2599
2831
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2832
|
+
const filters = {};
|
2833
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2834
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2835
|
+
if (status === "published") {
|
2836
|
+
filters.publishedAt = { $notNull: true };
|
2837
|
+
} else {
|
2838
|
+
filters.publishedAt = { $null: true };
|
2839
|
+
}
|
2840
|
+
}
|
2841
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2842
|
+
filters.publishedAt = { $null: true };
|
2843
|
+
}
|
2600
2844
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2601
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2845
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2602
2846
|
ordering: "desc",
|
2603
2847
|
page: ctx.request.query.page,
|
2604
|
-
pageSize: ctx.request.query.pageSize
|
2848
|
+
pageSize: ctx.request.query.pageSize,
|
2849
|
+
filters
|
2605
2850
|
});
|
2606
2851
|
const loadedIds = res.results.map((item) => item.id);
|
2607
2852
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2622,10 +2867,10 @@ const relations = {
|
|
2622
2867
|
}
|
2623
2868
|
};
|
2624
2869
|
const buildPopulateFromQuery = async (query, model) => {
|
2625
|
-
return getService$
|
2870
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2626
2871
|
};
|
2627
2872
|
const findDocument = async (query, uid2, opts = {}) => {
|
2628
|
-
const documentManager2 = getService$
|
2873
|
+
const documentManager2 = getService$2("document-manager");
|
2629
2874
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2630
2875
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2631
2876
|
};
|
@@ -2633,8 +2878,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2633
2878
|
const { user, userAbility } = ctx.state;
|
2634
2879
|
const { model } = ctx.params;
|
2635
2880
|
const { body, query } = ctx.request;
|
2636
|
-
const documentManager2 = getService$
|
2637
|
-
const permissionChecker2 = getService$
|
2881
|
+
const documentManager2 = getService$2("document-manager");
|
2882
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2638
2883
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2639
2884
|
throw new strapiUtils.errors.ForbiddenError();
|
2640
2885
|
}
|
@@ -2675,7 +2920,7 @@ const singleTypes = {
|
|
2675
2920
|
const { userAbility } = ctx.state;
|
2676
2921
|
const { model } = ctx.params;
|
2677
2922
|
const { query = {} } = ctx.request;
|
2678
|
-
const permissionChecker2 = getService$
|
2923
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2679
2924
|
if (permissionChecker2.cannot.read()) {
|
2680
2925
|
return ctx.forbidden();
|
2681
2926
|
}
|
@@ -2694,7 +2939,7 @@ const singleTypes = {
|
|
2694
2939
|
permissionChecker2,
|
2695
2940
|
model,
|
2696
2941
|
// @ts-expect-error - fix types
|
2697
|
-
{
|
2942
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2698
2943
|
{ availableLocales: true, availableStatus: false }
|
2699
2944
|
);
|
2700
2945
|
ctx.body = { data: {}, meta };
|
@@ -2709,7 +2954,7 @@ const singleTypes = {
|
|
2709
2954
|
async createOrUpdate(ctx) {
|
2710
2955
|
const { userAbility } = ctx.state;
|
2711
2956
|
const { model } = ctx.params;
|
2712
|
-
const permissionChecker2 = getService$
|
2957
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2713
2958
|
const document = await createOrUpdateDocument(ctx);
|
2714
2959
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2715
2960
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2718,8 +2963,8 @@ const singleTypes = {
|
|
2718
2963
|
const { userAbility } = ctx.state;
|
2719
2964
|
const { model } = ctx.params;
|
2720
2965
|
const { query = {} } = ctx.request;
|
2721
|
-
const documentManager2 = getService$
|
2722
|
-
const permissionChecker2 = getService$
|
2966
|
+
const documentManager2 = getService$2("document-manager");
|
2967
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2723
2968
|
if (permissionChecker2.cannot.delete()) {
|
2724
2969
|
return ctx.forbidden();
|
2725
2970
|
}
|
@@ -2747,8 +2992,8 @@ const singleTypes = {
|
|
2747
2992
|
const { userAbility } = ctx.state;
|
2748
2993
|
const { model } = ctx.params;
|
2749
2994
|
const { query = {} } = ctx.request;
|
2750
|
-
const documentManager2 = getService$
|
2751
|
-
const permissionChecker2 = getService$
|
2995
|
+
const documentManager2 = getService$2("document-manager");
|
2996
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2752
2997
|
if (permissionChecker2.cannot.publish()) {
|
2753
2998
|
return ctx.forbidden();
|
2754
2999
|
}
|
@@ -2776,8 +3021,8 @@ const singleTypes = {
|
|
2776
3021
|
body: { discardDraft, ...body },
|
2777
3022
|
query = {}
|
2778
3023
|
} = ctx.request;
|
2779
|
-
const documentManager2 = getService$
|
2780
|
-
const permissionChecker2 = getService$
|
3024
|
+
const documentManager2 = getService$2("document-manager");
|
3025
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2781
3026
|
if (permissionChecker2.cannot.unpublish()) {
|
2782
3027
|
return ctx.forbidden();
|
2783
3028
|
}
|
@@ -2811,8 +3056,8 @@ const singleTypes = {
|
|
2811
3056
|
const { userAbility } = ctx.state;
|
2812
3057
|
const { model } = ctx.params;
|
2813
3058
|
const { body, query = {} } = ctx.request;
|
2814
|
-
const documentManager2 = getService$
|
2815
|
-
const permissionChecker2 = getService$
|
3059
|
+
const documentManager2 = getService$2("document-manager");
|
3060
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2816
3061
|
if (permissionChecker2.cannot.discard()) {
|
2817
3062
|
return ctx.forbidden();
|
2818
3063
|
}
|
@@ -2835,8 +3080,8 @@ const singleTypes = {
|
|
2835
3080
|
const { userAbility } = ctx.state;
|
2836
3081
|
const { model } = ctx.params;
|
2837
3082
|
const { query } = ctx.request;
|
2838
|
-
const documentManager2 = getService$
|
2839
|
-
const permissionChecker2 = getService$
|
3083
|
+
const documentManager2 = getService$2("document-manager");
|
3084
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2840
3085
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2841
3086
|
if (permissionChecker2.cannot.read()) {
|
2842
3087
|
return ctx.forbidden();
|
@@ -2860,7 +3105,7 @@ const uid$1 = {
|
|
2860
3105
|
const { query = {} } = ctx.request;
|
2861
3106
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2862
3107
|
await validateUIDField(contentTypeUID, field);
|
2863
|
-
const uidService = getService$
|
3108
|
+
const uidService = getService$2("uid");
|
2864
3109
|
ctx.body = {
|
2865
3110
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2866
3111
|
};
|
@@ -2872,7 +3117,7 @@ const uid$1 = {
|
|
2872
3117
|
const { query = {} } = ctx.request;
|
2873
3118
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2874
3119
|
await validateUIDField(contentTypeUID, field);
|
2875
|
-
const uidService = getService$
|
3120
|
+
const uidService = getService$2("uid");
|
2876
3121
|
const isAvailable = await uidService.checkUIDAvailability({
|
2877
3122
|
contentTypeUID,
|
2878
3123
|
field,
|
@@ -2893,7 +3138,8 @@ const controllers = {
|
|
2893
3138
|
relations,
|
2894
3139
|
"single-types": singleTypes,
|
2895
3140
|
uid: uid$1,
|
2896
|
-
...history.controllers ? history.controllers : {}
|
3141
|
+
...history.controllers ? history.controllers : {},
|
3142
|
+
...preview.controllers ? preview.controllers : {}
|
2897
3143
|
};
|
2898
3144
|
const keys = {
|
2899
3145
|
CONFIGURATION: "configuration"
|
@@ -3022,18 +3268,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3022
3268
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3023
3269
|
___default.default.set(acc, [key], updatedMeta);
|
3024
3270
|
}
|
3025
|
-
if (!___default.default.has(edit, "mainField"))
|
3026
|
-
return acc;
|
3271
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3027
3272
|
if (!isRelation$1(attr)) {
|
3028
3273
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3029
3274
|
___default.default.set(acc, [key], updatedMeta);
|
3030
3275
|
return acc;
|
3031
3276
|
}
|
3032
|
-
if (edit.mainField === "id")
|
3033
|
-
return acc;
|
3277
|
+
if (edit.mainField === "id") return acc;
|
3034
3278
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3035
|
-
if (!targetSchema)
|
3036
|
-
return acc;
|
3279
|
+
if (!targetSchema) return acc;
|
3037
3280
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3038
3281
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3039
3282
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3044,12 +3287,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3044
3287
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3045
3288
|
}
|
3046
3289
|
const getTargetSchema = (targetModel) => {
|
3047
|
-
return getService$
|
3290
|
+
return getService$2("content-types").findContentType(targetModel);
|
3048
3291
|
};
|
3049
3292
|
const DEFAULT_LIST_LENGTH = 4;
|
3050
3293
|
const MAX_ROW_SIZE = 12;
|
3051
3294
|
const isAllowedFieldSize = (type, size) => {
|
3052
|
-
const { getFieldSize } = getService$
|
3295
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3053
3296
|
const fieldSize = getFieldSize(type);
|
3054
3297
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3055
3298
|
return false;
|
@@ -3057,7 +3300,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3057
3300
|
return size <= MAX_ROW_SIZE;
|
3058
3301
|
};
|
3059
3302
|
const getDefaultFieldSize = (attribute) => {
|
3060
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3303
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3061
3304
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3062
3305
|
};
|
3063
3306
|
async function createDefaultLayouts(schema) {
|
@@ -3078,8 +3321,7 @@ function createDefaultEditLayout(schema) {
|
|
3078
3321
|
return appendToEditLayout([], keys2, schema);
|
3079
3322
|
}
|
3080
3323
|
function syncLayouts(configuration, schema) {
|
3081
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3082
|
-
return createDefaultLayouts(schema);
|
3324
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3083
3325
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3084
3326
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3085
3327
|
const cleanEditRelations = editRelations.filter(
|
@@ -3090,9 +3332,8 @@ function syncLayouts(configuration, schema) {
|
|
3090
3332
|
for (const row of edit) {
|
3091
3333
|
const newRow = [];
|
3092
3334
|
for (const el of row) {
|
3093
|
-
if (!hasEditableAttribute(schema, el.name))
|
3094
|
-
|
3095
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3335
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3336
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3096
3337
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3097
3338
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3098
3339
|
elementsToReAppend.push(el.name);
|
@@ -3122,8 +3363,7 @@ function syncLayouts(configuration, schema) {
|
|
3122
3363
|
};
|
3123
3364
|
}
|
3124
3365
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3125
|
-
if (keysToAppend.length === 0)
|
3126
|
-
return layout;
|
3366
|
+
if (keysToAppend.length === 0) return layout;
|
3127
3367
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3128
3368
|
if (!layout[currentRowIndex]) {
|
3129
3369
|
layout[currentRowIndex] = [];
|
@@ -3232,17 +3472,17 @@ const configurationService$1 = createConfigurationService({
|
|
3232
3472
|
isComponent: true,
|
3233
3473
|
prefix: STORE_KEY_PREFIX,
|
3234
3474
|
getModels() {
|
3235
|
-
const { toContentManagerModel } = getService$
|
3475
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3236
3476
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3237
3477
|
}
|
3238
3478
|
});
|
3239
3479
|
const components = ({ strapi: strapi2 }) => ({
|
3240
3480
|
findAllComponents() {
|
3241
|
-
const { toContentManagerModel } = getService$
|
3481
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3242
3482
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3243
3483
|
},
|
3244
3484
|
findComponent(uid2) {
|
3245
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3246
3486
|
const component = strapi2.components[uid2];
|
3247
3487
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3248
3488
|
},
|
@@ -3293,17 +3533,17 @@ const configurationService = createConfigurationService({
|
|
3293
3533
|
storeUtils,
|
3294
3534
|
prefix: "content_types",
|
3295
3535
|
getModels() {
|
3296
|
-
const { toContentManagerModel } = getService$
|
3536
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3297
3537
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3298
3538
|
}
|
3299
3539
|
});
|
3300
3540
|
const service = ({ strapi: strapi2 }) => ({
|
3301
3541
|
findAllContentTypes() {
|
3302
|
-
const { toContentManagerModel } = getService$
|
3542
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3303
3543
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3304
3544
|
},
|
3305
3545
|
findContentType(uid2) {
|
3306
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3307
3547
|
const contentType = strapi2.contentTypes[uid2];
|
3308
3548
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3309
3549
|
},
|
@@ -3332,7 +3572,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3332
3572
|
return this.findConfiguration(contentType);
|
3333
3573
|
},
|
3334
3574
|
findComponentsConfigurations(contentType) {
|
3335
|
-
return getService$
|
3575
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3336
3576
|
},
|
3337
3577
|
syncConfigurations() {
|
3338
3578
|
return configurationService.syncConfigurations();
|
@@ -3604,7 +3844,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3604
3844
|
return userAbility.can(action);
|
3605
3845
|
},
|
3606
3846
|
async registerPermissions() {
|
3607
|
-
const displayedContentTypes = getService$
|
3847
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3608
3848
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3609
3849
|
const actions = [
|
3610
3850
|
{
|
@@ -3689,6 +3929,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3689
3929
|
if (initialPopulate) {
|
3690
3930
|
return initialPopulate;
|
3691
3931
|
}
|
3932
|
+
if (attributeName === "localizations") {
|
3933
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3934
|
+
return {
|
3935
|
+
populate: validationPopulate.populate
|
3936
|
+
};
|
3937
|
+
}
|
3692
3938
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3693
3939
|
return true;
|
3694
3940
|
}
|
@@ -3748,6 +3994,9 @@ const getDeepPopulate = (uid2, {
|
|
3748
3994
|
return {};
|
3749
3995
|
}
|
3750
3996
|
const model = strapi.getModel(uid2);
|
3997
|
+
if (!model) {
|
3998
|
+
return {};
|
3999
|
+
}
|
3751
4000
|
return Object.keys(model.attributes).reduce(
|
3752
4001
|
(populateAcc, attributeName) => fp.merge(
|
3753
4002
|
populateAcc,
|
@@ -3767,40 +4016,46 @@ const getDeepPopulate = (uid2, {
|
|
3767
4016
|
{}
|
3768
4017
|
);
|
3769
4018
|
};
|
3770
|
-
const
|
3771
|
-
|
3772
|
-
|
3773
|
-
countOne = false,
|
3774
|
-
maxLevel = Infinity
|
3775
|
-
} = {}, level = 1) => {
|
3776
|
-
if (level > maxLevel) {
|
4019
|
+
const getPopulateForValidation = (uid2) => {
|
4020
|
+
const model = strapi.getModel(uid2);
|
4021
|
+
if (!model) {
|
3777
4022
|
return {};
|
3778
4023
|
}
|
3779
|
-
const model = strapi.getModel(uid2);
|
3780
4024
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3781
|
-
if (
|
4025
|
+
if (isScalarAttribute(attribute)) {
|
4026
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4027
|
+
populateAcc.fields = populateAcc.fields || [];
|
4028
|
+
populateAcc.fields.push(attributeName);
|
4029
|
+
}
|
3782
4030
|
return populateAcc;
|
3783
4031
|
}
|
3784
|
-
if (
|
3785
|
-
|
3786
|
-
|
3787
|
-
|
4032
|
+
if (isComponent(attribute)) {
|
4033
|
+
const component = attribute.component;
|
4034
|
+
const componentResult = getPopulateForValidation(component);
|
4035
|
+
if (Object.keys(componentResult).length > 0) {
|
4036
|
+
populateAcc.populate = populateAcc.populate || {};
|
4037
|
+
populateAcc.populate[attributeName] = componentResult;
|
4038
|
+
}
|
4039
|
+
return populateAcc;
|
3788
4040
|
}
|
3789
|
-
|
3790
|
-
|
3791
|
-
|
3792
|
-
|
3793
|
-
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
3797
|
-
|
3798
|
-
countOne,
|
3799
|
-
maxLevel
|
4041
|
+
if (isDynamicZone(attribute)) {
|
4042
|
+
const components2 = attribute.components;
|
4043
|
+
const componentsResult = (components2 || []).reduce(
|
4044
|
+
(acc, componentUID) => {
|
4045
|
+
const componentResult = getPopulateForValidation(componentUID);
|
4046
|
+
if (Object.keys(componentResult).length > 0) {
|
4047
|
+
acc[componentUID] = componentResult;
|
4048
|
+
}
|
4049
|
+
return acc;
|
3800
4050
|
},
|
3801
|
-
|
3802
|
-
)
|
3803
|
-
|
4051
|
+
{}
|
4052
|
+
);
|
4053
|
+
if (Object.keys(componentsResult).length > 0) {
|
4054
|
+
populateAcc.populate = populateAcc.populate || {};
|
4055
|
+
populateAcc.populate[attributeName] = { on: componentsResult };
|
4056
|
+
}
|
4057
|
+
}
|
4058
|
+
return populateAcc;
|
3804
4059
|
}, {});
|
3805
4060
|
};
|
3806
4061
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3880,7 +4135,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3880
4135
|
return populateQuery;
|
3881
4136
|
};
|
3882
4137
|
const buildDeepPopulate = (uid2) => {
|
3883
|
-
return getService$
|
4138
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3884
4139
|
};
|
3885
4140
|
const populateBuilder = (uid2) => {
|
3886
4141
|
let getInitialPopulate = async () => {
|
@@ -4042,7 +4297,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4042
4297
|
"locale",
|
4043
4298
|
"updatedAt",
|
4044
4299
|
"createdAt",
|
4045
|
-
"status",
|
4046
4300
|
"publishedAt",
|
4047
4301
|
"documentId"
|
4048
4302
|
];
|
@@ -4063,34 +4317,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4063
4317
|
/**
|
4064
4318
|
* Returns available locales of a document for the current status
|
4065
4319
|
*/
|
4066
|
-
async getAvailableLocales(uid2, version, allVersions
|
4320
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4067
4321
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4068
|
-
|
4322
|
+
if (version.locale) {
|
4323
|
+
delete versionsByLocale[version.locale];
|
4324
|
+
}
|
4069
4325
|
const model = strapi2.getModel(uid2);
|
4070
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4071
|
-
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4072
|
-
({ key }, { remove }) => {
|
4073
|
-
if (keysToKeep.includes(key)) {
|
4074
|
-
return;
|
4075
|
-
}
|
4076
|
-
remove(key);
|
4077
|
-
},
|
4078
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4079
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4080
|
-
localeVersion
|
4081
|
-
);
|
4082
4326
|
const mappingResult = await strapiUtils.async.map(
|
4083
4327
|
Object.values(versionsByLocale),
|
4084
4328
|
async (localeVersions) => {
|
4085
|
-
const mappedLocaleVersions = await strapiUtils.async.map(
|
4086
|
-
localeVersions,
|
4087
|
-
traversalFunction
|
4088
|
-
);
|
4089
4329
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4090
|
-
return
|
4330
|
+
return localeVersions[0];
|
4091
4331
|
}
|
4092
|
-
const draftVersion =
|
4093
|
-
const otherVersions =
|
4332
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4333
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4094
4334
|
if (!draftVersion) {
|
4095
4335
|
return;
|
4096
4336
|
}
|
@@ -4112,8 +4352,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4112
4352
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4113
4353
|
return matchLocale && matchStatus;
|
4114
4354
|
});
|
4115
|
-
if (!availableStatus)
|
4116
|
-
return availableStatus;
|
4355
|
+
if (!availableStatus) return availableStatus;
|
4117
4356
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4118
4357
|
},
|
4119
4358
|
/**
|
@@ -4123,18 +4362,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4123
4362
|
* @returns
|
4124
4363
|
*/
|
4125
4364
|
async getManyAvailableStatus(uid2, documents) {
|
4126
|
-
if (!documents.length)
|
4127
|
-
return [];
|
4365
|
+
if (!documents.length) return [];
|
4128
4366
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4129
|
-
const
|
4130
|
-
const
|
4131
|
-
|
4132
|
-
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4136
|
-
|
4137
|
-
|
4367
|
+
const locales = documents.map((d) => d.locale).filter(Boolean);
|
4368
|
+
const where = {
|
4369
|
+
documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
|
4370
|
+
publishedAt: { $null: status === "published" }
|
4371
|
+
};
|
4372
|
+
if (locales.length) {
|
4373
|
+
where.locale = { $in: locales };
|
4374
|
+
}
|
4375
|
+
return strapi2.query(uid2).findMany({
|
4376
|
+
where,
|
4377
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
|
4138
4378
|
});
|
4139
4379
|
},
|
4140
4380
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4151,10 +4391,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4151
4391
|
} else if (otherVersion) {
|
4152
4392
|
draftVersion = otherVersion;
|
4153
4393
|
}
|
4154
|
-
if (!draftVersion)
|
4155
|
-
|
4156
|
-
if (!publishedVersion)
|
4157
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4394
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4395
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4158
4396
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4159
4397
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4160
4398
|
},
|
@@ -4162,11 +4400,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4162
4400
|
// We could refactor this so the locales are only loaded when they're
|
4163
4401
|
// needed. e.g. in the bulk locale action modal.
|
4164
4402
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4165
|
-
const populate =
|
4166
|
-
const
|
4167
|
-
where: { documentId: version.documentId },
|
4403
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4404
|
+
const params = {
|
4168
4405
|
populate: {
|
4169
|
-
// Populate only fields that require validation for bulk locale actions
|
4170
4406
|
...populate,
|
4171
4407
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4172
4408
|
createdBy: {
|
@@ -4175,9 +4411,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4175
4411
|
updatedBy: {
|
4176
4412
|
select: ["id", "firstname", "lastname", "email"]
|
4177
4413
|
}
|
4414
|
+
},
|
4415
|
+
fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4416
|
+
filters: {
|
4417
|
+
documentId: version.documentId
|
4178
4418
|
}
|
4179
|
-
}
|
4180
|
-
const
|
4419
|
+
};
|
4420
|
+
const dbParams = strapi2.get("query-params").transform(uid2, params);
|
4421
|
+
const versions = await strapi2.db.query(uid2).findMany(dbParams);
|
4422
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
|
4181
4423
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4182
4424
|
return {
|
4183
4425
|
availableLocales: availableLocalesResult,
|
@@ -4204,6 +4446,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4204
4446
|
opts.availableStatus = false;
|
4205
4447
|
}
|
4206
4448
|
const meta = await this.getMetadata(uid2, document, opts);
|
4449
|
+
if (document.localizations) {
|
4450
|
+
const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
|
4451
|
+
document.localizations = document.localizations.map((d) => {
|
4452
|
+
const status = otherStatus.find((s) => s.documentId === d.documentId);
|
4453
|
+
return {
|
4454
|
+
...d,
|
4455
|
+
status: this.getStatus(d, status ? [status] : [])
|
4456
|
+
};
|
4457
|
+
});
|
4458
|
+
}
|
4207
4459
|
return {
|
4208
4460
|
data: {
|
4209
4461
|
...document,
|
@@ -4421,7 +4673,8 @@ const services = {
|
|
4421
4673
|
permission,
|
4422
4674
|
"populate-builder": populateBuilder$1,
|
4423
4675
|
uid,
|
4424
|
-
...history.services ? history.services : {}
|
4676
|
+
...history.services ? history.services : {},
|
4677
|
+
...preview.services ? preview.services : {}
|
4425
4678
|
};
|
4426
4679
|
const index = () => {
|
4427
4680
|
return {
|