@strapi/content-manager 0.0.0-next.4052765aa209dd4f3d92b81baee295fc0213c04c → 0.0.0-next.40d132bcf8139c1d691684ec83a5834c98dfd41f
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-BEGp0IOV.js → ComponentConfigurationPage-BSEZcJVB.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-BEGp0IOV.js.map → ComponentConfigurationPage-BSEZcJVB.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DUXYqQwA.mjs → ComponentConfigurationPage-BiASGi7x.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DUXYqQwA.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-BFAn2GH9.js → EditConfigurationPage-D2rtvneE.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-BFAn2GH9.js.map → EditConfigurationPage-D2rtvneE.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-D7PzCWYW.mjs → EditConfigurationPage-vN4zupij.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-D7PzCWYW.mjs.map → EditConfigurationPage-vN4zupij.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CB017yCP.js → EditViewPage-BwisF04Q.js} +38 -9
- package/dist/_chunks/EditViewPage-BwisF04Q.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DmKviP3U.mjs → EditViewPage-_A31Cl4g.mjs} +38 -8
- package/dist/_chunks/EditViewPage-_A31Cl4g.mjs.map +1 -0
- package/dist/_chunks/{Field-DztIyw14.mjs → Field-CvIunNOj.mjs} +170 -118
- package/dist/_chunks/Field-CvIunNOj.mjs.map +1 -0
- package/dist/_chunks/{Field-ByXbOZL6.js → Field-Dsu6-FrM.js} +172 -120
- 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-D993gfLL.mjs → Form-DK0fG0Gj.mjs} +3 -3
- package/dist/_chunks/{Form-D993gfLL.mjs.map → Form-DK0fG0Gj.mjs.map} +1 -1
- package/dist/_chunks/{Form-WgML3Oqo.js → Form-DUwWcCmA.js} +5 -6
- package/dist/_chunks/{Form-WgML3Oqo.js.map → Form-DUwWcCmA.js.map} +1 -1
- package/dist/_chunks/{History-BmxGh1cB.js → History-CeCDhoJG.js} +22 -93
- package/dist/_chunks/History-CeCDhoJG.js.map +1 -0
- package/dist/_chunks/{History-GcW_hfMD.mjs → History-DP8gmXpm.mjs} +22 -92
- package/dist/_chunks/History-DP8gmXpm.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-kBho1y__.mjs → ListConfigurationPage-BCkO5iuN.mjs} +7 -6
- package/dist/_chunks/ListConfigurationPage-BCkO5iuN.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-16rxMcAO.js → ListConfigurationPage-C-bAd44a.js} +7 -7
- package/dist/_chunks/ListConfigurationPage-C-bAd44a.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BXqw44Ja.js → ListViewPage-BKTZFhsM.js} +64 -53
- package/dist/_chunks/ListViewPage-BKTZFhsM.js.map +1 -0
- package/dist/_chunks/{ListViewPage-6rg02vWk.mjs → ListViewPage-Cf_DgaFV.mjs} +63 -51
- package/dist/_chunks/ListViewPage-Cf_DgaFV.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DYfH0OD-.js → NoContentTypePage-D3Cm3v3q.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DYfH0OD-.js.map → NoContentTypePage-D3Cm3v3q.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BVtZUY-U.mjs → NoContentTypePage-nHIyvJcB.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-BVtZUY-U.mjs.map → NoContentTypePage-nHIyvJcB.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-D9R6cWCY.mjs → NoPermissionsPage-BALVSJ7x.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-D9R6cWCY.mjs.map → NoPermissionsPage-BALVSJ7x.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-ClDJKdA9.js → NoPermissionsPage-CChGWBj5.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-ClDJKdA9.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-uEN7K10I.mjs → Relations-C8uC89cT.mjs} +47 -22
- package/dist/_chunks/Relations-C8uC89cT.mjs.map +1 -0
- package/dist/_chunks/{Relations-CvsqEtYj.js → Relations-CvkPCng_.js} +47 -23
- package/dist/_chunks/Relations-CvkPCng_.js.map +1 -0
- package/dist/_chunks/{en-Bm0D0IWz.js → en-BK8Xyl5I.js} +16 -4
- package/dist/_chunks/{en-Bm0D0IWz.js.map → en-BK8Xyl5I.js.map} +1 -1
- package/dist/_chunks/{en-DKV44jRb.mjs → en-Dtk_ot79.mjs} +16 -4
- package/dist/_chunks/{en-DKV44jRb.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-BrzMjag-.js → index-CnX_j5h-.js} +355 -188
- package/dist/_chunks/index-CnX_j5h-.js.map +1 -0
- package/dist/_chunks/{index-BHBrXMdZ.mjs → index-Dh2aGTGJ.mjs} +357 -190
- 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-TDRwTVM6.mjs → layout-B5qsPihj.mjs} +4 -4
- package/dist/_chunks/{layout-TDRwTVM6.mjs.map → layout-B5qsPihj.mjs.map} +1 -1
- package/dist/_chunks/{layout-Dwmw0D0e.js → layout-B_qdWGny.js} +5 -6
- package/dist/_chunks/{layout-Dwmw0D0e.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-CIcMvUXZ.js → relations-ChcieiF5.js} +6 -7
- package/dist/_chunks/relations-ChcieiF5.js.map +1 -0
- package/dist/_chunks/{relations-41Z1upHL.mjs → relations-DMXpNY-e.mjs} +6 -7
- package/dist/_chunks/relations-DMXpNY-e.mjs.map +1 -0
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -1
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -1
- 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 +1 -1
- package/dist/admin/index.mjs +4 -4
- package/dist/admin/src/content-manager.d.ts +3 -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 +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/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 +1 -1
- 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 +478 -252
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +479 -252
- package/dist/server/index.mjs.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/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.map +1 -1
- 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 +13 -11
- package/dist/_chunks/EditViewPage-CB017yCP.js.map +0 -1
- package/dist/_chunks/EditViewPage-DmKviP3U.mjs.map +0 -1
- package/dist/_chunks/Field-ByXbOZL6.js.map +0 -1
- package/dist/_chunks/Field-DztIyw14.mjs.map +0 -1
- package/dist/_chunks/History-BmxGh1cB.js.map +0 -1
- package/dist/_chunks/History-GcW_hfMD.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-16rxMcAO.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-kBho1y__.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-6rg02vWk.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BXqw44Ja.js.map +0 -1
- package/dist/_chunks/Relations-CvsqEtYj.js.map +0 -1
- package/dist/_chunks/Relations-uEN7K10I.mjs.map +0 -1
- package/dist/_chunks/index-BHBrXMdZ.mjs.map +0 -1
- package/dist/_chunks/index-BrzMjag-.js.map +0 -1
- package/dist/_chunks/relations-41Z1upHL.mjs.map +0 -1
- package/dist/_chunks/relations-CIcMvUXZ.js.map +0 -1
- package/dist/admin/src/preview/constants.d.ts +0 -1
- package/dist/server/src/preview/constants.d.ts +0 -2
- package/dist/server/src/preview/constants.d.ts.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({
|
@@ -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
|
});
|
@@ -411,7 +425,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
411
425
|
[attributeKey]: adminUsers
|
412
426
|
};
|
413
427
|
}
|
414
|
-
const permissionChecker2 = getService$
|
428
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
415
429
|
userAbility: params.state.userAbility,
|
416
430
|
model: attributeSchema.target
|
417
431
|
});
|
@@ -587,7 +601,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
587
601
|
onCommit(async () => {
|
588
602
|
for (const entry of localeEntries) {
|
589
603
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
-
await getService(strapi2, "history").createVersion({
|
604
|
+
await getService$1(strapi2, "history").createVersion({
|
591
605
|
contentType: uid2,
|
592
606
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
607
|
relatedDocumentId: documentId,
|
@@ -600,15 +614,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
600
614
|
});
|
601
615
|
return result;
|
602
616
|
});
|
603
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
617
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
604
618
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
605
619
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
606
620
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
607
621
|
where: {
|
608
622
|
created_at: {
|
609
|
-
$lt: expirationDate
|
623
|
+
$lt: expirationDate
|
610
624
|
}
|
611
625
|
}
|
626
|
+
}).catch((error) => {
|
627
|
+
if (error instanceof Error) {
|
628
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
629
|
+
}
|
612
630
|
});
|
613
631
|
});
|
614
632
|
state.isInitialized = true;
|
@@ -620,17 +638,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
620
638
|
}
|
621
639
|
};
|
622
640
|
};
|
623
|
-
const services$
|
641
|
+
const services$2 = {
|
624
642
|
history: createHistoryService,
|
625
643
|
lifecycles: createLifecyclesService
|
626
644
|
};
|
627
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
645
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
628
646
|
const historyVersionRouter = {
|
629
647
|
type: "admin",
|
630
648
|
routes: [
|
631
649
|
{
|
632
650
|
method: "GET",
|
633
|
-
info,
|
651
|
+
info: info$1,
|
634
652
|
path: "/history-versions",
|
635
653
|
handler: "history-version.findMany",
|
636
654
|
config: {
|
@@ -639,7 +657,7 @@ const historyVersionRouter = {
|
|
639
657
|
},
|
640
658
|
{
|
641
659
|
method: "PUT",
|
642
|
-
info,
|
660
|
+
info: info$1,
|
643
661
|
path: "/history-versions/:versionId/restore",
|
644
662
|
handler: "history-version.restoreVersion",
|
645
663
|
config: {
|
@@ -648,7 +666,7 @@ const historyVersionRouter = {
|
|
648
666
|
}
|
649
667
|
]
|
650
668
|
};
|
651
|
-
const routes$
|
669
|
+
const routes$2 = {
|
652
670
|
"history-version": historyVersionRouter
|
653
671
|
};
|
654
672
|
const historyVersion = {
|
@@ -702,14 +720,14 @@ const getFeature$1 = () => {
|
|
702
720
|
strapi2.get("models").add(historyVersion);
|
703
721
|
},
|
704
722
|
bootstrap({ strapi: strapi2 }) {
|
705
|
-
getService(strapi2, "lifecycles").bootstrap();
|
723
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
706
724
|
},
|
707
725
|
destroy({ strapi: strapi2 }) {
|
708
|
-
getService(strapi2, "lifecycles").destroy();
|
726
|
+
getService$1(strapi2, "lifecycles").destroy();
|
709
727
|
},
|
710
|
-
controllers: controllers$
|
711
|
-
services: services$
|
712
|
-
routes: routes$
|
728
|
+
controllers: controllers$2,
|
729
|
+
services: services$2,
|
730
|
+
routes: routes$2
|
713
731
|
};
|
714
732
|
}
|
715
733
|
return {
|
@@ -719,33 +737,213 @@ const getFeature$1 = () => {
|
|
719
737
|
};
|
720
738
|
};
|
721
739
|
const history = getFeature$1();
|
722
|
-
const
|
723
|
-
|
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
|
+
]
|
724
754
|
};
|
725
|
-
const
|
726
|
-
|
727
|
-
ENTRY_UNPUBLISH: "entry.unpublish"
|
755
|
+
const routes$1 = {
|
756
|
+
preview: previewRouter
|
728
757
|
};
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
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";
|
733
788
|
}
|
789
|
+
return newParams;
|
790
|
+
};
|
791
|
+
const createPreviewController = () => {
|
734
792
|
return {
|
735
|
-
|
736
|
-
|
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;
|
737
831
|
}
|
738
832
|
};
|
739
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
|
+
};
|
740
930
|
const preview = getFeature();
|
931
|
+
const register = async ({ strapi: strapi2 }) => {
|
932
|
+
await history.register?.({ strapi: strapi2 });
|
933
|
+
await preview.register?.({ strapi: strapi2 });
|
934
|
+
};
|
935
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
936
|
+
ENTRY_PUBLISH: "entry.publish",
|
937
|
+
ENTRY_UNPUBLISH: "entry.unpublish"
|
938
|
+
};
|
741
939
|
const bootstrap = async () => {
|
742
940
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
743
941
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
744
942
|
});
|
745
|
-
getService$
|
746
|
-
await getService$
|
747
|
-
await getService$
|
748
|
-
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();
|
749
947
|
await history.bootstrap?.({ strapi });
|
750
948
|
await preview.bootstrap?.({ strapi });
|
751
949
|
};
|
@@ -1237,7 +1435,8 @@ const admin = {
|
|
1237
1435
|
};
|
1238
1436
|
const routes = {
|
1239
1437
|
admin,
|
1240
|
-
...history.routes ? history.routes : {}
|
1438
|
+
...history.routes ? history.routes : {},
|
1439
|
+
...preview.routes ? preview.routes : {}
|
1241
1440
|
};
|
1242
1441
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1243
1442
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1300,8 +1499,7 @@ const isSortable = (schema, name) => {
|
|
1300
1499
|
if (!___default.default.has(schema.attributes, name)) {
|
1301
1500
|
return false;
|
1302
1501
|
}
|
1303
|
-
if (schema.modelType === "component" && name === "id")
|
1304
|
-
return false;
|
1502
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1305
1503
|
const attribute = schema.attributes[name];
|
1306
1504
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1307
1505
|
return false;
|
@@ -1446,8 +1644,7 @@ const createDefaultSettings = async (schema) => {
|
|
1446
1644
|
};
|
1447
1645
|
};
|
1448
1646
|
const syncSettings = async (configuration, schema) => {
|
1449
|
-
if (fp.isEmpty(configuration.settings))
|
1450
|
-
return createDefaultSettings(schema);
|
1647
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1451
1648
|
const defaultField = getDefaultMainField(schema);
|
1452
1649
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1453
1650
|
return {
|
@@ -1494,7 +1691,7 @@ const createMetadasSchema = (schema) => {
|
|
1494
1691
|
if (!value) {
|
1495
1692
|
return strapiUtils.yup.string();
|
1496
1693
|
}
|
1497
|
-
const targetSchema = getService$
|
1694
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1498
1695
|
schema.attributes[key].targetModel
|
1499
1696
|
);
|
1500
1697
|
if (!targetSchema) {
|
@@ -1623,8 +1820,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1623
1820
|
}
|
1624
1821
|
switch (attribute.type) {
|
1625
1822
|
case "relation": {
|
1626
|
-
if (canCreate(attributePath))
|
1627
|
-
return body2;
|
1823
|
+
if (canCreate(attributePath)) return body2;
|
1628
1824
|
return fp.set(attributePath, { set: [] }, body2);
|
1629
1825
|
}
|
1630
1826
|
case "component": {
|
@@ -1634,8 +1830,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1634
1830
|
]);
|
1635
1831
|
}
|
1636
1832
|
default: {
|
1637
|
-
if (canCreate(attributePath))
|
1638
|
-
return body2;
|
1833
|
+
if (canCreate(attributePath)) return body2;
|
1639
1834
|
return fp.set(attributePath, null, body2);
|
1640
1835
|
}
|
1641
1836
|
}
|
@@ -1663,7 +1858,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1663
1858
|
}
|
1664
1859
|
};
|
1665
1860
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1666
|
-
const documentMetadata2 = getService$
|
1861
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1667
1862
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1668
1863
|
let {
|
1669
1864
|
meta: { availableLocales, availableStatus }
|
@@ -1689,8 +1884,8 @@ const createDocument = async (ctx, opts) => {
|
|
1689
1884
|
const { userAbility, user } = ctx.state;
|
1690
1885
|
const { model } = ctx.params;
|
1691
1886
|
const { body } = ctx.request;
|
1692
|
-
const documentManager2 = getService$
|
1693
|
-
const permissionChecker2 = getService$
|
1887
|
+
const documentManager2 = getService$2("document-manager");
|
1888
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1694
1889
|
if (permissionChecker2.cannot.create()) {
|
1695
1890
|
throw new strapiUtils.errors.ForbiddenError();
|
1696
1891
|
}
|
@@ -1710,13 +1905,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1710
1905
|
const { userAbility, user } = ctx.state;
|
1711
1906
|
const { id, model } = ctx.params;
|
1712
1907
|
const { body } = ctx.request;
|
1713
|
-
const documentManager2 = getService$
|
1714
|
-
const permissionChecker2 = getService$
|
1908
|
+
const documentManager2 = getService$2("document-manager");
|
1909
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1715
1910
|
if (permissionChecker2.cannot.update()) {
|
1716
1911
|
throw new strapiUtils.errors.ForbiddenError();
|
1717
1912
|
}
|
1718
1913
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1719
|
-
const populate = await getService$
|
1914
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1720
1915
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1721
1916
|
const [documentVersion, documentExists] = await Promise.all([
|
1722
1917
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1747,14 +1942,14 @@ const collectionTypes = {
|
|
1747
1942
|
const { userAbility } = ctx.state;
|
1748
1943
|
const { model } = ctx.params;
|
1749
1944
|
const { query } = ctx.request;
|
1750
|
-
const documentMetadata2 = getService$
|
1751
|
-
const documentManager2 = getService$
|
1752
|
-
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 });
|
1753
1948
|
if (permissionChecker2.cannot.read()) {
|
1754
1949
|
return ctx.forbidden();
|
1755
1950
|
}
|
1756
1951
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1757
|
-
const populate = await getService$
|
1952
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1758
1953
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1759
1954
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1760
1955
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1783,13 +1978,13 @@ const collectionTypes = {
|
|
1783
1978
|
async findOne(ctx) {
|
1784
1979
|
const { userAbility } = ctx.state;
|
1785
1980
|
const { model, id } = ctx.params;
|
1786
|
-
const documentManager2 = getService$
|
1787
|
-
const permissionChecker2 = getService$
|
1981
|
+
const documentManager2 = getService$2("document-manager");
|
1982
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1788
1983
|
if (permissionChecker2.cannot.read()) {
|
1789
1984
|
return ctx.forbidden();
|
1790
1985
|
}
|
1791
1986
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1792
|
-
const populate = await getService$
|
1987
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1793
1988
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1794
1989
|
const version = await documentManager2.findOne(id, model, {
|
1795
1990
|
populate,
|
@@ -1820,7 +2015,7 @@ const collectionTypes = {
|
|
1820
2015
|
async create(ctx) {
|
1821
2016
|
const { userAbility } = ctx.state;
|
1822
2017
|
const { model } = ctx.params;
|
1823
|
-
const permissionChecker2 = getService$
|
2018
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1824
2019
|
const [totalEntries, document] = await Promise.all([
|
1825
2020
|
strapi.db.query(model).count(),
|
1826
2021
|
createDocument(ctx)
|
@@ -1841,7 +2036,7 @@ const collectionTypes = {
|
|
1841
2036
|
async update(ctx) {
|
1842
2037
|
const { userAbility } = ctx.state;
|
1843
2038
|
const { model } = ctx.params;
|
1844
|
-
const permissionChecker2 = getService$
|
2039
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1845
2040
|
const updatedVersion = await updateDocument(ctx);
|
1846
2041
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1847
2042
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1850,13 +2045,13 @@ const collectionTypes = {
|
|
1850
2045
|
const { userAbility, user } = ctx.state;
|
1851
2046
|
const { model, sourceId: id } = ctx.params;
|
1852
2047
|
const { body } = ctx.request;
|
1853
|
-
const documentManager2 = getService$
|
1854
|
-
const permissionChecker2 = getService$
|
2048
|
+
const documentManager2 = getService$2("document-manager");
|
2049
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1855
2050
|
if (permissionChecker2.cannot.create()) {
|
1856
2051
|
return ctx.forbidden();
|
1857
2052
|
}
|
1858
2053
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1859
|
-
const populate = await getService$
|
2054
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1860
2055
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1861
2056
|
const document = await documentManager2.findOne(id, model, {
|
1862
2057
|
populate,
|
@@ -1895,13 +2090,13 @@ const collectionTypes = {
|
|
1895
2090
|
async delete(ctx) {
|
1896
2091
|
const { userAbility } = ctx.state;
|
1897
2092
|
const { id, model } = ctx.params;
|
1898
|
-
const documentManager2 = getService$
|
1899
|
-
const permissionChecker2 = getService$
|
2093
|
+
const documentManager2 = getService$2("document-manager");
|
2094
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1900
2095
|
if (permissionChecker2.cannot.delete()) {
|
1901
2096
|
return ctx.forbidden();
|
1902
2097
|
}
|
1903
2098
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1904
|
-
const populate = await getService$
|
2099
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1905
2100
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1906
2101
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1907
2102
|
if (documentLocales.length === 0) {
|
@@ -1923,14 +2118,14 @@ const collectionTypes = {
|
|
1923
2118
|
const { userAbility } = ctx.state;
|
1924
2119
|
const { id, model } = ctx.params;
|
1925
2120
|
const { body } = ctx.request;
|
1926
|
-
const documentManager2 = getService$
|
1927
|
-
const permissionChecker2 = getService$
|
2121
|
+
const documentManager2 = getService$2("document-manager");
|
2122
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1928
2123
|
if (permissionChecker2.cannot.publish()) {
|
1929
2124
|
return ctx.forbidden();
|
1930
2125
|
}
|
1931
2126
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1932
2127
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1933
|
-
const populate = await getService$
|
2128
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1934
2129
|
let document;
|
1935
2130
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1936
2131
|
const isCreate = fp.isNil(id);
|
@@ -1978,13 +2173,13 @@ const collectionTypes = {
|
|
1978
2173
|
const { body } = ctx.request;
|
1979
2174
|
const { documentIds } = body;
|
1980
2175
|
await validateBulkActionInput(body);
|
1981
|
-
const documentManager2 = getService$
|
1982
|
-
const permissionChecker2 = getService$
|
2176
|
+
const documentManager2 = getService$2("document-manager");
|
2177
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1983
2178
|
if (permissionChecker2.cannot.publish()) {
|
1984
2179
|
return ctx.forbidden();
|
1985
2180
|
}
|
1986
2181
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1987
|
-
const populate = await getService$
|
2182
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1988
2183
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1989
2184
|
allowMultipleLocales: true
|
1990
2185
|
});
|
@@ -2009,8 +2204,8 @@ const collectionTypes = {
|
|
2009
2204
|
const { body } = ctx.request;
|
2010
2205
|
const { documentIds } = body;
|
2011
2206
|
await validateBulkActionInput(body);
|
2012
|
-
const documentManager2 = getService$
|
2013
|
-
const permissionChecker2 = getService$
|
2207
|
+
const documentManager2 = getService$2("document-manager");
|
2208
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2014
2209
|
if (permissionChecker2.cannot.unpublish()) {
|
2015
2210
|
return ctx.forbidden();
|
2016
2211
|
}
|
@@ -2039,8 +2234,8 @@ const collectionTypes = {
|
|
2039
2234
|
const {
|
2040
2235
|
body: { discardDraft, ...body }
|
2041
2236
|
} = ctx.request;
|
2042
|
-
const documentManager2 = getService$
|
2043
|
-
const permissionChecker2 = getService$
|
2237
|
+
const documentManager2 = getService$2("document-manager");
|
2238
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2044
2239
|
if (permissionChecker2.cannot.unpublish()) {
|
2045
2240
|
return ctx.forbidden();
|
2046
2241
|
}
|
@@ -2048,7 +2243,7 @@ const collectionTypes = {
|
|
2048
2243
|
return ctx.forbidden();
|
2049
2244
|
}
|
2050
2245
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2051
|
-
const populate = await getService$
|
2246
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2052
2247
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2053
2248
|
const document = await documentManager2.findOne(id, model, {
|
2054
2249
|
populate,
|
@@ -2079,13 +2274,13 @@ const collectionTypes = {
|
|
2079
2274
|
const { userAbility } = ctx.state;
|
2080
2275
|
const { id, model } = ctx.params;
|
2081
2276
|
const { body } = ctx.request;
|
2082
|
-
const documentManager2 = getService$
|
2083
|
-
const permissionChecker2 = getService$
|
2277
|
+
const documentManager2 = getService$2("document-manager");
|
2278
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2084
2279
|
if (permissionChecker2.cannot.discard()) {
|
2085
2280
|
return ctx.forbidden();
|
2086
2281
|
}
|
2087
2282
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2088
|
-
const populate = await getService$
|
2283
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2089
2284
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2090
2285
|
const document = await documentManager2.findOne(id, model, {
|
2091
2286
|
populate,
|
@@ -2110,13 +2305,13 @@ const collectionTypes = {
|
|
2110
2305
|
const { query, body } = ctx.request;
|
2111
2306
|
const { documentIds } = body;
|
2112
2307
|
await validateBulkActionInput(body);
|
2113
|
-
const documentManager2 = getService$
|
2114
|
-
const permissionChecker2 = getService$
|
2308
|
+
const documentManager2 = getService$2("document-manager");
|
2309
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2115
2310
|
if (permissionChecker2.cannot.delete()) {
|
2116
2311
|
return ctx.forbidden();
|
2117
2312
|
}
|
2118
2313
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2119
|
-
const populate = await getService$
|
2314
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2120
2315
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2121
2316
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2122
2317
|
populate,
|
@@ -2137,13 +2332,13 @@ const collectionTypes = {
|
|
2137
2332
|
async countDraftRelations(ctx) {
|
2138
2333
|
const { userAbility } = ctx.state;
|
2139
2334
|
const { model, id } = ctx.params;
|
2140
|
-
const documentManager2 = getService$
|
2141
|
-
const permissionChecker2 = getService$
|
2335
|
+
const documentManager2 = getService$2("document-manager");
|
2336
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2142
2337
|
if (permissionChecker2.cannot.read()) {
|
2143
2338
|
return ctx.forbidden();
|
2144
2339
|
}
|
2145
2340
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2146
|
-
const populate = await getService$
|
2341
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2147
2342
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2148
2343
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2149
2344
|
if (!entity) {
|
@@ -2162,8 +2357,8 @@ const collectionTypes = {
|
|
2162
2357
|
const ids = ctx.request.query.documentIds;
|
2163
2358
|
const locale = ctx.request.query.locale;
|
2164
2359
|
const { model } = ctx.params;
|
2165
|
-
const documentManager2 = getService$
|
2166
|
-
const permissionChecker2 = getService$
|
2360
|
+
const documentManager2 = getService$2("document-manager");
|
2361
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2167
2362
|
if (permissionChecker2.cannot.read()) {
|
2168
2363
|
return ctx.forbidden();
|
2169
2364
|
}
|
@@ -2187,13 +2382,13 @@ const collectionTypes = {
|
|
2187
2382
|
};
|
2188
2383
|
const components$1 = {
|
2189
2384
|
findComponents(ctx) {
|
2190
|
-
const components2 = getService$
|
2191
|
-
const { toDto } = getService$
|
2385
|
+
const components2 = getService$2("components").findAllComponents();
|
2386
|
+
const { toDto } = getService$2("data-mapper");
|
2192
2387
|
ctx.body = { data: components2.map(toDto) };
|
2193
2388
|
},
|
2194
2389
|
async findComponentConfiguration(ctx) {
|
2195
2390
|
const { uid: uid2 } = ctx.params;
|
2196
|
-
const componentService = getService$
|
2391
|
+
const componentService = getService$2("components");
|
2197
2392
|
const component = componentService.findComponent(uid2);
|
2198
2393
|
if (!component) {
|
2199
2394
|
return ctx.notFound("component.notFound");
|
@@ -2210,7 +2405,7 @@ const components$1 = {
|
|
2210
2405
|
async updateComponentConfiguration(ctx) {
|
2211
2406
|
const { uid: uid2 } = ctx.params;
|
2212
2407
|
const { body } = ctx.request;
|
2213
|
-
const componentService = getService$
|
2408
|
+
const componentService = getService$2("components");
|
2214
2409
|
const component = componentService.findComponent(uid2);
|
2215
2410
|
if (!component) {
|
2216
2411
|
return ctx.notFound("component.notFound");
|
@@ -2244,12 +2439,12 @@ const contentTypes = {
|
|
2244
2439
|
} catch (error) {
|
2245
2440
|
return ctx.send({ error }, 400);
|
2246
2441
|
}
|
2247
|
-
const contentTypes2 = getService$
|
2248
|
-
const { toDto } = getService$
|
2442
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2443
|
+
const { toDto } = getService$2("data-mapper");
|
2249
2444
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2250
2445
|
},
|
2251
2446
|
async findContentTypesSettings(ctx) {
|
2252
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2447
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2253
2448
|
const contentTypes2 = await findAllContentTypes();
|
2254
2449
|
const configurations = await Promise.all(
|
2255
2450
|
contentTypes2.map(async (contentType) => {
|
@@ -2263,7 +2458,7 @@ const contentTypes = {
|
|
2263
2458
|
},
|
2264
2459
|
async findContentTypeConfiguration(ctx) {
|
2265
2460
|
const { uid: uid2 } = ctx.params;
|
2266
|
-
const contentTypeService = getService$
|
2461
|
+
const contentTypeService = getService$2("content-types");
|
2267
2462
|
const contentType = await contentTypeService.findContentType(uid2);
|
2268
2463
|
if (!contentType) {
|
2269
2464
|
return ctx.notFound("contentType.notFound");
|
@@ -2285,13 +2480,13 @@ const contentTypes = {
|
|
2285
2480
|
const { userAbility } = ctx.state;
|
2286
2481
|
const { uid: uid2 } = ctx.params;
|
2287
2482
|
const { body } = ctx.request;
|
2288
|
-
const contentTypeService = getService$
|
2289
|
-
const metricsService = getService$
|
2483
|
+
const contentTypeService = getService$2("content-types");
|
2484
|
+
const metricsService = getService$2("metrics");
|
2290
2485
|
const contentType = await contentTypeService.findContentType(uid2);
|
2291
2486
|
if (!contentType) {
|
2292
2487
|
return ctx.notFound("contentType.notFound");
|
2293
2488
|
}
|
2294
|
-
if (!getService$
|
2489
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2295
2490
|
return ctx.forbidden();
|
2296
2491
|
}
|
2297
2492
|
let input;
|
@@ -2324,10 +2519,10 @@ const contentTypes = {
|
|
2324
2519
|
};
|
2325
2520
|
const init = {
|
2326
2521
|
getInitData(ctx) {
|
2327
|
-
const { toDto } = getService$
|
2328
|
-
const { findAllComponents } = getService$
|
2329
|
-
const { getAllFieldSizes } = getService$
|
2330
|
-
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");
|
2331
2526
|
ctx.body = {
|
2332
2527
|
data: {
|
2333
2528
|
fieldSizes: getAllFieldSizes(),
|
@@ -2363,7 +2558,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2363
2558
|
params.filters.$and.push(filtersClause);
|
2364
2559
|
};
|
2365
2560
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2366
|
-
const permissionChecker2 = getService$
|
2561
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2367
2562
|
userAbility,
|
2368
2563
|
model: model.uid
|
2369
2564
|
});
|
@@ -2377,15 +2572,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2377
2572
|
}
|
2378
2573
|
return mainField;
|
2379
2574
|
};
|
2380
|
-
const addStatusToRelations = async (
|
2381
|
-
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) {
|
2382
2581
|
return relations2;
|
2383
2582
|
}
|
2384
|
-
const
|
2385
|
-
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
|
+
});
|
2386
2593
|
return relations2.map((relation) => {
|
2387
|
-
const availableStatuses =
|
2388
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2594
|
+
const availableStatuses = availableStatus.filter(
|
2595
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2389
2596
|
);
|
2390
2597
|
return {
|
2391
2598
|
...relation,
|
@@ -2416,8 +2623,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2416
2623
|
const sourceModel = strapi.getModel(sourceUid);
|
2417
2624
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2418
2625
|
const isSourceDP = isDP(sourceModel);
|
2419
|
-
if (!isSourceDP)
|
2420
|
-
return { status: void 0 };
|
2626
|
+
if (!isSourceDP) return { status: void 0 };
|
2421
2627
|
switch (status) {
|
2422
2628
|
case "published":
|
2423
2629
|
return { status: "published" };
|
@@ -2447,7 +2653,7 @@ const relations = {
|
|
2447
2653
|
ctx.request?.query?.locale
|
2448
2654
|
);
|
2449
2655
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2450
|
-
const permissionChecker2 = getService$
|
2656
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2451
2657
|
userAbility,
|
2452
2658
|
model
|
2453
2659
|
});
|
@@ -2472,7 +2678,7 @@ const relations = {
|
|
2472
2678
|
where.id = id;
|
2473
2679
|
}
|
2474
2680
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2475
|
-
const populate = await getService$
|
2681
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2476
2682
|
const currentEntity = await strapi.db.query(model).findOne({
|
2477
2683
|
where,
|
2478
2684
|
populate
|
@@ -2487,7 +2693,7 @@ const relations = {
|
|
2487
2693
|
}
|
2488
2694
|
entryId = currentEntity.id;
|
2489
2695
|
}
|
2490
|
-
const modelConfig = isComponent2 ? await getService$
|
2696
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2491
2697
|
const targetSchema = strapi.getModel(targetUid);
|
2492
2698
|
const mainField = fp.flow(
|
2493
2699
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2541,7 +2747,7 @@ const relations = {
|
|
2541
2747
|
}
|
2542
2748
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2543
2749
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2544
|
-
const permissionChecker2 = getService$
|
2750
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2545
2751
|
userAbility: ctx.state.userAbility,
|
2546
2752
|
model: targetUid
|
2547
2753
|
});
|
@@ -2614,21 +2820,33 @@ const relations = {
|
|
2614
2820
|
attribute,
|
2615
2821
|
targetField,
|
2616
2822
|
fieldsToSelect,
|
2617
|
-
|
2618
|
-
|
2619
|
-
}
|
2620
|
-
target: {
|
2621
|
-
schema: { uid: targetUid }
|
2622
|
-
}
|
2823
|
+
status,
|
2824
|
+
source: { schema: sourceSchema },
|
2825
|
+
target: { schema: targetSchema }
|
2623
2826
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2624
|
-
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 });
|
2625
2830
|
const dbQuery = strapi.db.query(sourceUid);
|
2626
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
|
+
}
|
2627
2844
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2628
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2845
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2629
2846
|
ordering: "desc",
|
2630
2847
|
page: ctx.request.query.page,
|
2631
|
-
pageSize: ctx.request.query.pageSize
|
2848
|
+
pageSize: ctx.request.query.pageSize,
|
2849
|
+
filters
|
2632
2850
|
});
|
2633
2851
|
const loadedIds = res.results.map((item) => item.id);
|
2634
2852
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2649,10 +2867,10 @@ const relations = {
|
|
2649
2867
|
}
|
2650
2868
|
};
|
2651
2869
|
const buildPopulateFromQuery = async (query, model) => {
|
2652
|
-
return getService$
|
2870
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2653
2871
|
};
|
2654
2872
|
const findDocument = async (query, uid2, opts = {}) => {
|
2655
|
-
const documentManager2 = getService$
|
2873
|
+
const documentManager2 = getService$2("document-manager");
|
2656
2874
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2657
2875
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2658
2876
|
};
|
@@ -2660,8 +2878,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2660
2878
|
const { user, userAbility } = ctx.state;
|
2661
2879
|
const { model } = ctx.params;
|
2662
2880
|
const { body, query } = ctx.request;
|
2663
|
-
const documentManager2 = getService$
|
2664
|
-
const permissionChecker2 = getService$
|
2881
|
+
const documentManager2 = getService$2("document-manager");
|
2882
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2665
2883
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2666
2884
|
throw new strapiUtils.errors.ForbiddenError();
|
2667
2885
|
}
|
@@ -2702,7 +2920,7 @@ const singleTypes = {
|
|
2702
2920
|
const { userAbility } = ctx.state;
|
2703
2921
|
const { model } = ctx.params;
|
2704
2922
|
const { query = {} } = ctx.request;
|
2705
|
-
const permissionChecker2 = getService$
|
2923
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2706
2924
|
if (permissionChecker2.cannot.read()) {
|
2707
2925
|
return ctx.forbidden();
|
2708
2926
|
}
|
@@ -2736,7 +2954,7 @@ const singleTypes = {
|
|
2736
2954
|
async createOrUpdate(ctx) {
|
2737
2955
|
const { userAbility } = ctx.state;
|
2738
2956
|
const { model } = ctx.params;
|
2739
|
-
const permissionChecker2 = getService$
|
2957
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2740
2958
|
const document = await createOrUpdateDocument(ctx);
|
2741
2959
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2742
2960
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2745,8 +2963,8 @@ const singleTypes = {
|
|
2745
2963
|
const { userAbility } = ctx.state;
|
2746
2964
|
const { model } = ctx.params;
|
2747
2965
|
const { query = {} } = ctx.request;
|
2748
|
-
const documentManager2 = getService$
|
2749
|
-
const permissionChecker2 = getService$
|
2966
|
+
const documentManager2 = getService$2("document-manager");
|
2967
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2750
2968
|
if (permissionChecker2.cannot.delete()) {
|
2751
2969
|
return ctx.forbidden();
|
2752
2970
|
}
|
@@ -2774,8 +2992,8 @@ const singleTypes = {
|
|
2774
2992
|
const { userAbility } = ctx.state;
|
2775
2993
|
const { model } = ctx.params;
|
2776
2994
|
const { query = {} } = ctx.request;
|
2777
|
-
const documentManager2 = getService$
|
2778
|
-
const permissionChecker2 = getService$
|
2995
|
+
const documentManager2 = getService$2("document-manager");
|
2996
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2779
2997
|
if (permissionChecker2.cannot.publish()) {
|
2780
2998
|
return ctx.forbidden();
|
2781
2999
|
}
|
@@ -2803,8 +3021,8 @@ const singleTypes = {
|
|
2803
3021
|
body: { discardDraft, ...body },
|
2804
3022
|
query = {}
|
2805
3023
|
} = ctx.request;
|
2806
|
-
const documentManager2 = getService$
|
2807
|
-
const permissionChecker2 = getService$
|
3024
|
+
const documentManager2 = getService$2("document-manager");
|
3025
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2808
3026
|
if (permissionChecker2.cannot.unpublish()) {
|
2809
3027
|
return ctx.forbidden();
|
2810
3028
|
}
|
@@ -2838,8 +3056,8 @@ const singleTypes = {
|
|
2838
3056
|
const { userAbility } = ctx.state;
|
2839
3057
|
const { model } = ctx.params;
|
2840
3058
|
const { body, query = {} } = ctx.request;
|
2841
|
-
const documentManager2 = getService$
|
2842
|
-
const permissionChecker2 = getService$
|
3059
|
+
const documentManager2 = getService$2("document-manager");
|
3060
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2843
3061
|
if (permissionChecker2.cannot.discard()) {
|
2844
3062
|
return ctx.forbidden();
|
2845
3063
|
}
|
@@ -2862,8 +3080,8 @@ const singleTypes = {
|
|
2862
3080
|
const { userAbility } = ctx.state;
|
2863
3081
|
const { model } = ctx.params;
|
2864
3082
|
const { query } = ctx.request;
|
2865
|
-
const documentManager2 = getService$
|
2866
|
-
const permissionChecker2 = getService$
|
3083
|
+
const documentManager2 = getService$2("document-manager");
|
3084
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2867
3085
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2868
3086
|
if (permissionChecker2.cannot.read()) {
|
2869
3087
|
return ctx.forbidden();
|
@@ -2887,7 +3105,7 @@ const uid$1 = {
|
|
2887
3105
|
const { query = {} } = ctx.request;
|
2888
3106
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2889
3107
|
await validateUIDField(contentTypeUID, field);
|
2890
|
-
const uidService = getService$
|
3108
|
+
const uidService = getService$2("uid");
|
2891
3109
|
ctx.body = {
|
2892
3110
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2893
3111
|
};
|
@@ -2899,7 +3117,7 @@ const uid$1 = {
|
|
2899
3117
|
const { query = {} } = ctx.request;
|
2900
3118
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2901
3119
|
await validateUIDField(contentTypeUID, field);
|
2902
|
-
const uidService = getService$
|
3120
|
+
const uidService = getService$2("uid");
|
2903
3121
|
const isAvailable = await uidService.checkUIDAvailability({
|
2904
3122
|
contentTypeUID,
|
2905
3123
|
field,
|
@@ -2920,7 +3138,8 @@ const controllers = {
|
|
2920
3138
|
relations,
|
2921
3139
|
"single-types": singleTypes,
|
2922
3140
|
uid: uid$1,
|
2923
|
-
...history.controllers ? history.controllers : {}
|
3141
|
+
...history.controllers ? history.controllers : {},
|
3142
|
+
...preview.controllers ? preview.controllers : {}
|
2924
3143
|
};
|
2925
3144
|
const keys = {
|
2926
3145
|
CONFIGURATION: "configuration"
|
@@ -3049,18 +3268,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3049
3268
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3050
3269
|
___default.default.set(acc, [key], updatedMeta);
|
3051
3270
|
}
|
3052
|
-
if (!___default.default.has(edit, "mainField"))
|
3053
|
-
return acc;
|
3271
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3054
3272
|
if (!isRelation$1(attr)) {
|
3055
3273
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3056
3274
|
___default.default.set(acc, [key], updatedMeta);
|
3057
3275
|
return acc;
|
3058
3276
|
}
|
3059
|
-
if (edit.mainField === "id")
|
3060
|
-
return acc;
|
3277
|
+
if (edit.mainField === "id") return acc;
|
3061
3278
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3062
|
-
if (!targetSchema)
|
3063
|
-
return acc;
|
3279
|
+
if (!targetSchema) return acc;
|
3064
3280
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3065
3281
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3066
3282
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3071,12 +3287,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3071
3287
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3072
3288
|
}
|
3073
3289
|
const getTargetSchema = (targetModel) => {
|
3074
|
-
return getService$
|
3290
|
+
return getService$2("content-types").findContentType(targetModel);
|
3075
3291
|
};
|
3076
3292
|
const DEFAULT_LIST_LENGTH = 4;
|
3077
3293
|
const MAX_ROW_SIZE = 12;
|
3078
3294
|
const isAllowedFieldSize = (type, size) => {
|
3079
|
-
const { getFieldSize } = getService$
|
3295
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3080
3296
|
const fieldSize = getFieldSize(type);
|
3081
3297
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3082
3298
|
return false;
|
@@ -3084,7 +3300,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3084
3300
|
return size <= MAX_ROW_SIZE;
|
3085
3301
|
};
|
3086
3302
|
const getDefaultFieldSize = (attribute) => {
|
3087
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3303
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3088
3304
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3089
3305
|
};
|
3090
3306
|
async function createDefaultLayouts(schema) {
|
@@ -3105,8 +3321,7 @@ function createDefaultEditLayout(schema) {
|
|
3105
3321
|
return appendToEditLayout([], keys2, schema);
|
3106
3322
|
}
|
3107
3323
|
function syncLayouts(configuration, schema) {
|
3108
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3109
|
-
return createDefaultLayouts(schema);
|
3324
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3110
3325
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3111
3326
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3112
3327
|
const cleanEditRelations = editRelations.filter(
|
@@ -3117,9 +3332,8 @@ function syncLayouts(configuration, schema) {
|
|
3117
3332
|
for (const row of edit) {
|
3118
3333
|
const newRow = [];
|
3119
3334
|
for (const el of row) {
|
3120
|
-
if (!hasEditableAttribute(schema, el.name))
|
3121
|
-
|
3122
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3335
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3336
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3123
3337
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3124
3338
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3125
3339
|
elementsToReAppend.push(el.name);
|
@@ -3149,8 +3363,7 @@ function syncLayouts(configuration, schema) {
|
|
3149
3363
|
};
|
3150
3364
|
}
|
3151
3365
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3152
|
-
if (keysToAppend.length === 0)
|
3153
|
-
return layout;
|
3366
|
+
if (keysToAppend.length === 0) return layout;
|
3154
3367
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3155
3368
|
if (!layout[currentRowIndex]) {
|
3156
3369
|
layout[currentRowIndex] = [];
|
@@ -3259,17 +3472,17 @@ const configurationService$1 = createConfigurationService({
|
|
3259
3472
|
isComponent: true,
|
3260
3473
|
prefix: STORE_KEY_PREFIX,
|
3261
3474
|
getModels() {
|
3262
|
-
const { toContentManagerModel } = getService$
|
3475
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3263
3476
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3264
3477
|
}
|
3265
3478
|
});
|
3266
3479
|
const components = ({ strapi: strapi2 }) => ({
|
3267
3480
|
findAllComponents() {
|
3268
|
-
const { toContentManagerModel } = getService$
|
3481
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3269
3482
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3270
3483
|
},
|
3271
3484
|
findComponent(uid2) {
|
3272
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3273
3486
|
const component = strapi2.components[uid2];
|
3274
3487
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3275
3488
|
},
|
@@ -3320,17 +3533,17 @@ const configurationService = createConfigurationService({
|
|
3320
3533
|
storeUtils,
|
3321
3534
|
prefix: "content_types",
|
3322
3535
|
getModels() {
|
3323
|
-
const { toContentManagerModel } = getService$
|
3536
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3324
3537
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3325
3538
|
}
|
3326
3539
|
});
|
3327
3540
|
const service = ({ strapi: strapi2 }) => ({
|
3328
3541
|
findAllContentTypes() {
|
3329
|
-
const { toContentManagerModel } = getService$
|
3542
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3330
3543
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3331
3544
|
},
|
3332
3545
|
findContentType(uid2) {
|
3333
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3334
3547
|
const contentType = strapi2.contentTypes[uid2];
|
3335
3548
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3336
3549
|
},
|
@@ -3359,7 +3572,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3359
3572
|
return this.findConfiguration(contentType);
|
3360
3573
|
},
|
3361
3574
|
findComponentsConfigurations(contentType) {
|
3362
|
-
return getService$
|
3575
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3363
3576
|
},
|
3364
3577
|
syncConfigurations() {
|
3365
3578
|
return configurationService.syncConfigurations();
|
@@ -3631,7 +3844,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3631
3844
|
return userAbility.can(action);
|
3632
3845
|
},
|
3633
3846
|
async registerPermissions() {
|
3634
|
-
const displayedContentTypes = getService$
|
3847
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3635
3848
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3636
3849
|
const actions = [
|
3637
3850
|
{
|
@@ -3716,6 +3929,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3716
3929
|
if (initialPopulate) {
|
3717
3930
|
return initialPopulate;
|
3718
3931
|
}
|
3932
|
+
if (attributeName === "localizations") {
|
3933
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3934
|
+
return {
|
3935
|
+
populate: validationPopulate.populate
|
3936
|
+
};
|
3937
|
+
}
|
3719
3938
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3720
3939
|
return true;
|
3721
3940
|
}
|
@@ -3775,6 +3994,9 @@ const getDeepPopulate = (uid2, {
|
|
3775
3994
|
return {};
|
3776
3995
|
}
|
3777
3996
|
const model = strapi.getModel(uid2);
|
3997
|
+
if (!model) {
|
3998
|
+
return {};
|
3999
|
+
}
|
3778
4000
|
return Object.keys(model.attributes).reduce(
|
3779
4001
|
(populateAcc, attributeName) => fp.merge(
|
3780
4002
|
populateAcc,
|
@@ -3794,40 +4016,46 @@ const getDeepPopulate = (uid2, {
|
|
3794
4016
|
{}
|
3795
4017
|
);
|
3796
4018
|
};
|
3797
|
-
const
|
3798
|
-
|
3799
|
-
|
3800
|
-
countOne = false,
|
3801
|
-
maxLevel = Infinity
|
3802
|
-
} = {}, level = 1) => {
|
3803
|
-
if (level > maxLevel) {
|
4019
|
+
const getPopulateForValidation = (uid2) => {
|
4020
|
+
const model = strapi.getModel(uid2);
|
4021
|
+
if (!model) {
|
3804
4022
|
return {};
|
3805
4023
|
}
|
3806
|
-
const model = strapi.getModel(uid2);
|
3807
4024
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3808
|
-
if (
|
4025
|
+
if (isScalarAttribute(attribute)) {
|
4026
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4027
|
+
populateAcc.fields = populateAcc.fields || [];
|
4028
|
+
populateAcc.fields.push(attributeName);
|
4029
|
+
}
|
3809
4030
|
return populateAcc;
|
3810
4031
|
}
|
3811
|
-
if (
|
3812
|
-
|
3813
|
-
|
3814
|
-
|
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;
|
3815
4040
|
}
|
3816
|
-
|
3817
|
-
|
3818
|
-
|
3819
|
-
|
3820
|
-
|
3821
|
-
|
3822
|
-
|
3823
|
-
|
3824
|
-
|
3825
|
-
countOne,
|
3826
|
-
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;
|
3827
4050
|
},
|
3828
|
-
|
3829
|
-
)
|
3830
|
-
|
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;
|
3831
4059
|
}, {});
|
3832
4060
|
};
|
3833
4061
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3907,7 +4135,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3907
4135
|
return populateQuery;
|
3908
4136
|
};
|
3909
4137
|
const buildDeepPopulate = (uid2) => {
|
3910
|
-
return getService$
|
4138
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3911
4139
|
};
|
3912
4140
|
const populateBuilder = (uid2) => {
|
3913
4141
|
let getInitialPopulate = async () => {
|
@@ -4069,7 +4297,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4069
4297
|
"locale",
|
4070
4298
|
"updatedAt",
|
4071
4299
|
"createdAt",
|
4072
|
-
"status",
|
4073
4300
|
"publishedAt",
|
4074
4301
|
"documentId"
|
4075
4302
|
];
|
@@ -4090,34 +4317,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4090
4317
|
/**
|
4091
4318
|
* Returns available locales of a document for the current status
|
4092
4319
|
*/
|
4093
|
-
async getAvailableLocales(uid2, version, allVersions
|
4320
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4094
4321
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4095
|
-
|
4322
|
+
if (version.locale) {
|
4323
|
+
delete versionsByLocale[version.locale];
|
4324
|
+
}
|
4096
4325
|
const model = strapi2.getModel(uid2);
|
4097
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4098
|
-
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4099
|
-
({ key }, { remove }) => {
|
4100
|
-
if (keysToKeep.includes(key)) {
|
4101
|
-
return;
|
4102
|
-
}
|
4103
|
-
remove(key);
|
4104
|
-
},
|
4105
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4106
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4107
|
-
localeVersion
|
4108
|
-
);
|
4109
4326
|
const mappingResult = await strapiUtils.async.map(
|
4110
4327
|
Object.values(versionsByLocale),
|
4111
4328
|
async (localeVersions) => {
|
4112
|
-
const mappedLocaleVersions = await strapiUtils.async.map(
|
4113
|
-
localeVersions,
|
4114
|
-
traversalFunction
|
4115
|
-
);
|
4116
4329
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4117
|
-
return
|
4330
|
+
return localeVersions[0];
|
4118
4331
|
}
|
4119
|
-
const draftVersion =
|
4120
|
-
const otherVersions =
|
4332
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4333
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4121
4334
|
if (!draftVersion) {
|
4122
4335
|
return;
|
4123
4336
|
}
|
@@ -4139,8 +4352,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4139
4352
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4140
4353
|
return matchLocale && matchStatus;
|
4141
4354
|
});
|
4142
|
-
if (!availableStatus)
|
4143
|
-
return availableStatus;
|
4355
|
+
if (!availableStatus) return availableStatus;
|
4144
4356
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4145
4357
|
},
|
4146
4358
|
/**
|
@@ -4150,18 +4362,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4150
4362
|
* @returns
|
4151
4363
|
*/
|
4152
4364
|
async getManyAvailableStatus(uid2, documents) {
|
4153
|
-
if (!documents.length)
|
4154
|
-
return [];
|
4365
|
+
if (!documents.length) return [];
|
4155
4366
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4156
|
-
const
|
4157
|
-
const
|
4158
|
-
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
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"]
|
4165
4378
|
});
|
4166
4379
|
},
|
4167
4380
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4178,10 +4391,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4178
4391
|
} else if (otherVersion) {
|
4179
4392
|
draftVersion = otherVersion;
|
4180
4393
|
}
|
4181
|
-
if (!draftVersion)
|
4182
|
-
|
4183
|
-
if (!publishedVersion)
|
4184
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4394
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4395
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4185
4396
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4186
4397
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4187
4398
|
},
|
@@ -4189,11 +4400,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4189
4400
|
// We could refactor this so the locales are only loaded when they're
|
4190
4401
|
// needed. e.g. in the bulk locale action modal.
|
4191
4402
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4192
|
-
const populate =
|
4193
|
-
const
|
4194
|
-
where: { documentId: version.documentId },
|
4403
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4404
|
+
const params = {
|
4195
4405
|
populate: {
|
4196
|
-
// Populate only fields that require validation for bulk locale actions
|
4197
4406
|
...populate,
|
4198
4407
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4199
4408
|
createdBy: {
|
@@ -4202,9 +4411,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4202
4411
|
updatedBy: {
|
4203
4412
|
select: ["id", "firstname", "lastname", "email"]
|
4204
4413
|
}
|
4414
|
+
},
|
4415
|
+
fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4416
|
+
filters: {
|
4417
|
+
documentId: version.documentId
|
4205
4418
|
}
|
4206
|
-
}
|
4207
|
-
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) : [];
|
4208
4423
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4209
4424
|
return {
|
4210
4425
|
availableLocales: availableLocalesResult,
|
@@ -4231,6 +4446,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4231
4446
|
opts.availableStatus = false;
|
4232
4447
|
}
|
4233
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
|
+
}
|
4234
4459
|
return {
|
4235
4460
|
data: {
|
4236
4461
|
...document,
|
@@ -4448,7 +4673,8 @@ const services = {
|
|
4448
4673
|
permission,
|
4449
4674
|
"populate-builder": populateBuilder$1,
|
4450
4675
|
uid,
|
4451
|
-
...history.services ? history.services : {}
|
4676
|
+
...history.services ? history.services : {},
|
4677
|
+
...preview.services ? preview.services : {}
|
4452
4678
|
};
|
4453
4679
|
const index = () => {
|
4454
4680
|
return {
|