@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.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1,
|
2
|
-
import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
|
1
|
+
import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, pagination } from "@strapi/utils";
|
2
|
+
import { pick, omit, difference, castArray, mergeWith, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
|
3
3
|
import "@strapi/types";
|
4
4
|
import * as yup from "yup";
|
5
5
|
import { scheduleJob } from "node-schedule";
|
@@ -7,10 +7,10 @@ import isNil from "lodash/isNil";
|
|
7
7
|
import _, { intersection as intersection$1, difference as difference$1 } from "lodash";
|
8
8
|
import qs from "qs";
|
9
9
|
import slugify from "@sindresorhus/slugify";
|
10
|
-
const getService$
|
10
|
+
const getService$2 = (name) => {
|
11
11
|
return strapi.plugin("content-manager").service(name);
|
12
12
|
};
|
13
|
-
function getService(strapi2, name) {
|
13
|
+
function getService$1(strapi2, name) {
|
14
14
|
return strapi2.service(`plugin::content-manager.${name}`);
|
15
15
|
}
|
16
16
|
const historyRestoreVersionSchema = yup.object().shape({
|
@@ -46,7 +46,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
46
46
|
if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
|
47
47
|
throw new errors.ForbiddenError("contentType and documentId are required");
|
48
48
|
}
|
49
|
-
const permissionChecker2 = getService$
|
49
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
50
50
|
userAbility: ctx.state.userAbility,
|
51
51
|
model: ctx.query.contentType
|
52
52
|
});
|
@@ -54,7 +54,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
54
54
|
return ctx.forbidden();
|
55
55
|
}
|
56
56
|
const query = await permissionChecker2.sanitizeQuery(ctx.query);
|
57
|
-
const { results, pagination: pagination2 } = await getService(strapi2, "history").findVersionsPage({
|
57
|
+
const { results, pagination: pagination2 } = await getService$1(strapi2, "history").findVersionsPage({
|
58
58
|
query: {
|
59
59
|
...query,
|
60
60
|
...getValidPagination({ page: query.page, pageSize: query.pageSize })
|
@@ -79,14 +79,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
79
79
|
async restoreVersion(ctx) {
|
80
80
|
const request = ctx.request;
|
81
81
|
await validateRestoreVersion(request.body, "contentType is required");
|
82
|
-
const permissionChecker2 = getService$
|
82
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
83
83
|
userAbility: ctx.state.userAbility,
|
84
84
|
model: request.body.contentType
|
85
85
|
});
|
86
86
|
if (permissionChecker2.cannot.update()) {
|
87
87
|
throw new errors.ForbiddenError();
|
88
88
|
}
|
89
|
-
const restoredDocument = await getService(strapi2, "history").restoreVersion(
|
89
|
+
const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
|
90
90
|
request.params.versionId
|
91
91
|
);
|
92
92
|
return {
|
@@ -95,7 +95,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
95
95
|
}
|
96
96
|
};
|
97
97
|
};
|
98
|
-
const controllers$
|
98
|
+
const controllers$2 = {
|
99
99
|
"history-version": createHistoryVersionController
|
100
100
|
/**
|
101
101
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -141,8 +141,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
141
141
|
};
|
142
142
|
const getRelationRestoreValue = async (versionRelationData, attribute) => {
|
143
143
|
if (Array.isArray(versionRelationData)) {
|
144
|
-
if (versionRelationData.length === 0)
|
145
|
-
return versionRelationData;
|
144
|
+
if (versionRelationData.length === 0) return versionRelationData;
|
146
145
|
const existingAndMissingRelations = await Promise.all(
|
147
146
|
versionRelationData.map((relation) => {
|
148
147
|
return strapi2.documents(attribute.target).findOne({
|
@@ -177,8 +176,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
177
176
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
178
177
|
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
179
178
|
const getLocaleDictionary = async () => {
|
180
|
-
if (!localesService)
|
181
|
-
return {};
|
179
|
+
if (!localesService) return {};
|
182
180
|
const locales = await localesService.find() || [];
|
183
181
|
return locales.reduce(
|
184
182
|
(acc, locale) => {
|
@@ -202,6 +200,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
202
200
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
203
201
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
204
202
|
};
|
203
|
+
const getComponentFields = (componentUID) => {
|
204
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
205
|
+
(fieldsAcc, [key, attribute]) => {
|
206
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
207
|
+
fieldsAcc.push(key);
|
208
|
+
}
|
209
|
+
return fieldsAcc;
|
210
|
+
},
|
211
|
+
[]
|
212
|
+
);
|
213
|
+
};
|
205
214
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
206
215
|
const model = strapi2.getModel(uid2);
|
207
216
|
const attributes = Object.entries(model.attributes);
|
@@ -225,13 +234,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
225
234
|
}
|
226
235
|
case "component": {
|
227
236
|
const populate = getDeepPopulate2(attribute.component);
|
228
|
-
acc[attributeName] = {
|
237
|
+
acc[attributeName] = {
|
238
|
+
populate,
|
239
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
240
|
+
};
|
229
241
|
break;
|
230
242
|
}
|
231
243
|
case "dynamiczone": {
|
232
244
|
const populatedComponents = (attribute.components || []).reduce(
|
233
245
|
(acc2, componentUID) => {
|
234
|
-
acc2[componentUID] = {
|
246
|
+
acc2[componentUID] = {
|
247
|
+
populate: getDeepPopulate2(componentUID),
|
248
|
+
[fieldSelector]: getComponentFields(componentUID)
|
249
|
+
};
|
235
250
|
return acc2;
|
236
251
|
},
|
237
252
|
{}
|
@@ -344,7 +359,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
344
359
|
const attributeValue = entry.data[attributeKey];
|
345
360
|
const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
|
346
361
|
if (attributeSchema.type === "media") {
|
347
|
-
const permissionChecker2 = getService$
|
362
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
348
363
|
userAbility: params.state.userAbility,
|
349
364
|
model: "plugin::upload.file"
|
350
365
|
});
|
@@ -385,7 +400,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
385
400
|
[attributeKey]: adminUsers
|
386
401
|
};
|
387
402
|
}
|
388
|
-
const permissionChecker2 = getService$
|
403
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
389
404
|
userAbility: params.state.userAbility,
|
390
405
|
model: attributeSchema.target
|
391
406
|
});
|
@@ -561,7 +576,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
561
576
|
onCommit(async () => {
|
562
577
|
for (const entry of localeEntries) {
|
563
578
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
564
|
-
await getService(strapi2, "history").createVersion({
|
579
|
+
await getService$1(strapi2, "history").createVersion({
|
565
580
|
contentType: uid2,
|
566
581
|
data: omit(FIELDS_TO_IGNORE, entry),
|
567
582
|
relatedDocumentId: documentId,
|
@@ -574,15 +589,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
574
589
|
});
|
575
590
|
return result;
|
576
591
|
});
|
577
|
-
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
592
|
+
state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
|
578
593
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
579
594
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
580
595
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
581
596
|
where: {
|
582
597
|
created_at: {
|
583
|
-
$lt: expirationDate
|
598
|
+
$lt: expirationDate
|
584
599
|
}
|
585
600
|
}
|
601
|
+
}).catch((error) => {
|
602
|
+
if (error instanceof Error) {
|
603
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
604
|
+
}
|
586
605
|
});
|
587
606
|
});
|
588
607
|
state.isInitialized = true;
|
@@ -594,17 +613,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
594
613
|
}
|
595
614
|
};
|
596
615
|
};
|
597
|
-
const services$
|
616
|
+
const services$2 = {
|
598
617
|
history: createHistoryService,
|
599
618
|
lifecycles: createLifecyclesService
|
600
619
|
};
|
601
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
620
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
602
621
|
const historyVersionRouter = {
|
603
622
|
type: "admin",
|
604
623
|
routes: [
|
605
624
|
{
|
606
625
|
method: "GET",
|
607
|
-
info,
|
626
|
+
info: info$1,
|
608
627
|
path: "/history-versions",
|
609
628
|
handler: "history-version.findMany",
|
610
629
|
config: {
|
@@ -613,7 +632,7 @@ const historyVersionRouter = {
|
|
613
632
|
},
|
614
633
|
{
|
615
634
|
method: "PUT",
|
616
|
-
info,
|
635
|
+
info: info$1,
|
617
636
|
path: "/history-versions/:versionId/restore",
|
618
637
|
handler: "history-version.restoreVersion",
|
619
638
|
config: {
|
@@ -622,7 +641,7 @@ const historyVersionRouter = {
|
|
622
641
|
}
|
623
642
|
]
|
624
643
|
};
|
625
|
-
const routes$
|
644
|
+
const routes$2 = {
|
626
645
|
"history-version": historyVersionRouter
|
627
646
|
};
|
628
647
|
const historyVersion = {
|
@@ -676,14 +695,14 @@ const getFeature$1 = () => {
|
|
676
695
|
strapi2.get("models").add(historyVersion);
|
677
696
|
},
|
678
697
|
bootstrap({ strapi: strapi2 }) {
|
679
|
-
getService(strapi2, "lifecycles").bootstrap();
|
698
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
680
699
|
},
|
681
700
|
destroy({ strapi: strapi2 }) {
|
682
|
-
getService(strapi2, "lifecycles").destroy();
|
701
|
+
getService$1(strapi2, "lifecycles").destroy();
|
683
702
|
},
|
684
|
-
controllers: controllers$
|
685
|
-
services: services$
|
686
|
-
routes: routes$
|
703
|
+
controllers: controllers$2,
|
704
|
+
services: services$2,
|
705
|
+
routes: routes$2
|
687
706
|
};
|
688
707
|
}
|
689
708
|
return {
|
@@ -693,33 +712,213 @@ const getFeature$1 = () => {
|
|
693
712
|
};
|
694
713
|
};
|
695
714
|
const history = getFeature$1();
|
696
|
-
const
|
697
|
-
|
715
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
716
|
+
const previewRouter = {
|
717
|
+
type: "admin",
|
718
|
+
routes: [
|
719
|
+
{
|
720
|
+
method: "GET",
|
721
|
+
info,
|
722
|
+
path: "/preview/url/:contentType",
|
723
|
+
handler: "preview.getPreviewUrl",
|
724
|
+
config: {
|
725
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
726
|
+
}
|
727
|
+
}
|
728
|
+
]
|
698
729
|
};
|
699
|
-
const
|
700
|
-
|
701
|
-
ENTRY_UNPUBLISH: "entry.unpublish"
|
730
|
+
const routes$1 = {
|
731
|
+
preview: previewRouter
|
702
732
|
};
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
733
|
+
function getService(strapi2, name) {
|
734
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
735
|
+
}
|
736
|
+
const getPreviewUrlSchema = yup.object().shape({
|
737
|
+
// Will be undefined for single types
|
738
|
+
documentId: yup.string(),
|
739
|
+
locale: yup.string().nullable(),
|
740
|
+
status: yup.string()
|
741
|
+
}).required();
|
742
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
743
|
+
await validateYupSchema(getPreviewUrlSchema)(params);
|
744
|
+
const newParams = pick(["documentId", "locale", "status"], params);
|
745
|
+
const model = strapi2.getModel(uid2);
|
746
|
+
if (!model || model.modelType !== "contentType") {
|
747
|
+
throw new errors.ValidationError("Invalid content type");
|
748
|
+
}
|
749
|
+
const isSingleType = model?.kind === "singleType";
|
750
|
+
if (!isSingleType && !params.documentId) {
|
751
|
+
throw new errors.ValidationError("documentId is required for Collection Types");
|
752
|
+
}
|
753
|
+
if (isSingleType) {
|
754
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
755
|
+
if (!doc) {
|
756
|
+
throw new errors.NotFoundError("Document not found");
|
757
|
+
}
|
758
|
+
newParams.documentId = doc?.documentId;
|
759
|
+
}
|
760
|
+
if (!newParams.status) {
|
761
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
762
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
707
763
|
}
|
764
|
+
return newParams;
|
765
|
+
};
|
766
|
+
const createPreviewController = () => {
|
708
767
|
return {
|
709
|
-
|
710
|
-
|
768
|
+
/**
|
769
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
770
|
+
* in the Content Manager.
|
771
|
+
*/
|
772
|
+
async getPreviewUrl(ctx) {
|
773
|
+
const uid2 = ctx.params.contentType;
|
774
|
+
const query = ctx.request.query;
|
775
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
776
|
+
const previewService = getService(strapi, "preview");
|
777
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
778
|
+
if (!url) {
|
779
|
+
ctx.status = 204;
|
780
|
+
}
|
781
|
+
return {
|
782
|
+
data: { url }
|
783
|
+
};
|
784
|
+
}
|
785
|
+
};
|
786
|
+
};
|
787
|
+
const controllers$1 = {
|
788
|
+
preview: createPreviewController
|
789
|
+
/**
|
790
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
791
|
+
* passing a controller factory as the value, instead of a controller object directly
|
792
|
+
*/
|
793
|
+
};
|
794
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
795
|
+
const config = getService(strapi2, "preview-config");
|
796
|
+
return {
|
797
|
+
async getPreviewUrl(uid2, params) {
|
798
|
+
const handler = config.getPreviewHandler();
|
799
|
+
try {
|
800
|
+
return handler(uid2, params);
|
801
|
+
} catch (error) {
|
802
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
803
|
+
throw new errors.ApplicationError("Failed to get preview URL");
|
804
|
+
}
|
805
|
+
return;
|
711
806
|
}
|
712
807
|
};
|
713
808
|
};
|
809
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
810
|
+
const middlewares = strapi.config.get("middlewares");
|
811
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
812
|
+
if (currentMiddleware === middleware.name) {
|
813
|
+
return middleware;
|
814
|
+
}
|
815
|
+
if (currentMiddleware.name === middleware.name) {
|
816
|
+
return mergeWith(
|
817
|
+
(objValue, srcValue) => {
|
818
|
+
if (Array.isArray(objValue)) {
|
819
|
+
return objValue.concat(srcValue);
|
820
|
+
}
|
821
|
+
return void 0;
|
822
|
+
},
|
823
|
+
currentMiddleware,
|
824
|
+
middleware
|
825
|
+
);
|
826
|
+
}
|
827
|
+
return currentMiddleware;
|
828
|
+
});
|
829
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
830
|
+
};
|
831
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
832
|
+
return {
|
833
|
+
register() {
|
834
|
+
if (!this.isEnabled()) {
|
835
|
+
return;
|
836
|
+
}
|
837
|
+
const config = strapi2.config.get("admin.preview");
|
838
|
+
if (config.config?.allowedOrigins) {
|
839
|
+
extendMiddlewareConfiguration({
|
840
|
+
name: "strapi::security",
|
841
|
+
config: {
|
842
|
+
contentSecurityPolicy: {
|
843
|
+
directives: {
|
844
|
+
"frame-src": config.config.allowedOrigins
|
845
|
+
}
|
846
|
+
}
|
847
|
+
}
|
848
|
+
});
|
849
|
+
}
|
850
|
+
},
|
851
|
+
isEnabled() {
|
852
|
+
const config = strapi2.config.get("admin.preview");
|
853
|
+
if (!config) {
|
854
|
+
return false;
|
855
|
+
}
|
856
|
+
return config?.enabled ?? true;
|
857
|
+
},
|
858
|
+
/**
|
859
|
+
* Validate if the configuration is valid
|
860
|
+
*/
|
861
|
+
validate() {
|
862
|
+
if (!this.isEnabled()) {
|
863
|
+
return;
|
864
|
+
}
|
865
|
+
const handler = this.getPreviewHandler();
|
866
|
+
if (typeof handler !== "function") {
|
867
|
+
throw new errors.ValidationError(
|
868
|
+
"Preview configuration is invalid. Handler must be a function"
|
869
|
+
);
|
870
|
+
}
|
871
|
+
},
|
872
|
+
/**
|
873
|
+
* Utility to get the preview handler from the configuration
|
874
|
+
*/
|
875
|
+
getPreviewHandler() {
|
876
|
+
const config = strapi2.config.get("admin.preview");
|
877
|
+
const emptyHandler = () => {
|
878
|
+
return void 0;
|
879
|
+
};
|
880
|
+
if (!this.isEnabled()) {
|
881
|
+
return emptyHandler;
|
882
|
+
}
|
883
|
+
return config?.config?.handler || emptyHandler;
|
884
|
+
}
|
885
|
+
};
|
886
|
+
};
|
887
|
+
const services$1 = {
|
888
|
+
preview: createPreviewService,
|
889
|
+
"preview-config": createPreviewConfigService
|
890
|
+
};
|
891
|
+
const getFeature = () => {
|
892
|
+
return {
|
893
|
+
register() {
|
894
|
+
const config = getService(strapi, "preview-config");
|
895
|
+
config.validate();
|
896
|
+
config.register();
|
897
|
+
},
|
898
|
+
bootstrap() {
|
899
|
+
},
|
900
|
+
routes: routes$1,
|
901
|
+
controllers: controllers$1,
|
902
|
+
services: services$1
|
903
|
+
};
|
904
|
+
};
|
714
905
|
const preview = getFeature();
|
906
|
+
const register = async ({ strapi: strapi2 }) => {
|
907
|
+
await history.register?.({ strapi: strapi2 });
|
908
|
+
await preview.register?.({ strapi: strapi2 });
|
909
|
+
};
|
910
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
911
|
+
ENTRY_PUBLISH: "entry.publish",
|
912
|
+
ENTRY_UNPUBLISH: "entry.unpublish"
|
913
|
+
};
|
715
914
|
const bootstrap = async () => {
|
716
915
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
717
916
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
718
917
|
});
|
719
|
-
getService$
|
720
|
-
await getService$
|
721
|
-
await getService$
|
722
|
-
await getService$
|
918
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
919
|
+
await getService$2("components").syncConfigurations();
|
920
|
+
await getService$2("content-types").syncConfigurations();
|
921
|
+
await getService$2("permission").registerPermissions();
|
723
922
|
await history.bootstrap?.({ strapi });
|
724
923
|
await preview.bootstrap?.({ strapi });
|
725
924
|
};
|
@@ -1211,7 +1410,8 @@ const admin = {
|
|
1211
1410
|
};
|
1212
1411
|
const routes = {
|
1213
1412
|
admin,
|
1214
|
-
...history.routes ? history.routes : {}
|
1413
|
+
...history.routes ? history.routes : {},
|
1414
|
+
...preview.routes ? preview.routes : {}
|
1215
1415
|
};
|
1216
1416
|
const hasPermissionsSchema = yup$1.object({
|
1217
1417
|
actions: yup$1.array().of(yup$1.string()),
|
@@ -1274,8 +1474,7 @@ const isSortable = (schema, name) => {
|
|
1274
1474
|
if (!_.has(schema.attributes, name)) {
|
1275
1475
|
return false;
|
1276
1476
|
}
|
1277
|
-
if (schema.modelType === "component" && name === "id")
|
1278
|
-
return false;
|
1477
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1279
1478
|
const attribute = schema.attributes[name];
|
1280
1479
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1281
1480
|
return false;
|
@@ -1420,8 +1619,7 @@ const createDefaultSettings = async (schema) => {
|
|
1420
1619
|
};
|
1421
1620
|
};
|
1422
1621
|
const syncSettings = async (configuration, schema) => {
|
1423
|
-
if (isEmpty(configuration.settings))
|
1424
|
-
return createDefaultSettings(schema);
|
1622
|
+
if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1425
1623
|
const defaultField = getDefaultMainField(schema);
|
1426
1624
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1427
1625
|
return {
|
@@ -1468,7 +1666,7 @@ const createMetadasSchema = (schema) => {
|
|
1468
1666
|
if (!value) {
|
1469
1667
|
return yup$1.string();
|
1470
1668
|
}
|
1471
|
-
const targetSchema = getService$
|
1669
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1472
1670
|
schema.attributes[key].targetModel
|
1473
1671
|
);
|
1474
1672
|
if (!targetSchema) {
|
@@ -1597,8 +1795,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1597
1795
|
}
|
1598
1796
|
switch (attribute.type) {
|
1599
1797
|
case "relation": {
|
1600
|
-
if (canCreate(attributePath))
|
1601
|
-
return body2;
|
1798
|
+
if (canCreate(attributePath)) return body2;
|
1602
1799
|
return set(attributePath, { set: [] }, body2);
|
1603
1800
|
}
|
1604
1801
|
case "component": {
|
@@ -1608,8 +1805,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1608
1805
|
]);
|
1609
1806
|
}
|
1610
1807
|
default: {
|
1611
|
-
if (canCreate(attributePath))
|
1612
|
-
return body2;
|
1808
|
+
if (canCreate(attributePath)) return body2;
|
1613
1809
|
return set(attributePath, null, body2);
|
1614
1810
|
}
|
1615
1811
|
}
|
@@ -1637,7 +1833,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1637
1833
|
}
|
1638
1834
|
};
|
1639
1835
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1640
|
-
const documentMetadata2 = getService$
|
1836
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1641
1837
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1642
1838
|
let {
|
1643
1839
|
meta: { availableLocales, availableStatus }
|
@@ -1663,8 +1859,8 @@ const createDocument = async (ctx, opts) => {
|
|
1663
1859
|
const { userAbility, user } = ctx.state;
|
1664
1860
|
const { model } = ctx.params;
|
1665
1861
|
const { body } = ctx.request;
|
1666
|
-
const documentManager2 = getService$
|
1667
|
-
const permissionChecker2 = getService$
|
1862
|
+
const documentManager2 = getService$2("document-manager");
|
1863
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1668
1864
|
if (permissionChecker2.cannot.create()) {
|
1669
1865
|
throw new errors.ForbiddenError();
|
1670
1866
|
}
|
@@ -1684,13 +1880,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1684
1880
|
const { userAbility, user } = ctx.state;
|
1685
1881
|
const { id, model } = ctx.params;
|
1686
1882
|
const { body } = ctx.request;
|
1687
|
-
const documentManager2 = getService$
|
1688
|
-
const permissionChecker2 = getService$
|
1883
|
+
const documentManager2 = getService$2("document-manager");
|
1884
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1689
1885
|
if (permissionChecker2.cannot.update()) {
|
1690
1886
|
throw new errors.ForbiddenError();
|
1691
1887
|
}
|
1692
1888
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1693
|
-
const populate = await getService$
|
1889
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1694
1890
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1695
1891
|
const [documentVersion, documentExists] = await Promise.all([
|
1696
1892
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1721,14 +1917,14 @@ const collectionTypes = {
|
|
1721
1917
|
const { userAbility } = ctx.state;
|
1722
1918
|
const { model } = ctx.params;
|
1723
1919
|
const { query } = ctx.request;
|
1724
|
-
const documentMetadata2 = getService$
|
1725
|
-
const documentManager2 = getService$
|
1726
|
-
const permissionChecker2 = getService$
|
1920
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1921
|
+
const documentManager2 = getService$2("document-manager");
|
1922
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1727
1923
|
if (permissionChecker2.cannot.read()) {
|
1728
1924
|
return ctx.forbidden();
|
1729
1925
|
}
|
1730
1926
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1731
|
-
const populate = await getService$
|
1927
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1732
1928
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1733
1929
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1734
1930
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1757,13 +1953,13 @@ const collectionTypes = {
|
|
1757
1953
|
async findOne(ctx) {
|
1758
1954
|
const { userAbility } = ctx.state;
|
1759
1955
|
const { model, id } = ctx.params;
|
1760
|
-
const documentManager2 = getService$
|
1761
|
-
const permissionChecker2 = getService$
|
1956
|
+
const documentManager2 = getService$2("document-manager");
|
1957
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1762
1958
|
if (permissionChecker2.cannot.read()) {
|
1763
1959
|
return ctx.forbidden();
|
1764
1960
|
}
|
1765
1961
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1766
|
-
const populate = await getService$
|
1962
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1767
1963
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1768
1964
|
const version = await documentManager2.findOne(id, model, {
|
1769
1965
|
populate,
|
@@ -1794,7 +1990,7 @@ const collectionTypes = {
|
|
1794
1990
|
async create(ctx) {
|
1795
1991
|
const { userAbility } = ctx.state;
|
1796
1992
|
const { model } = ctx.params;
|
1797
|
-
const permissionChecker2 = getService$
|
1993
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1798
1994
|
const [totalEntries, document] = await Promise.all([
|
1799
1995
|
strapi.db.query(model).count(),
|
1800
1996
|
createDocument(ctx)
|
@@ -1815,7 +2011,7 @@ const collectionTypes = {
|
|
1815
2011
|
async update(ctx) {
|
1816
2012
|
const { userAbility } = ctx.state;
|
1817
2013
|
const { model } = ctx.params;
|
1818
|
-
const permissionChecker2 = getService$
|
2014
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1819
2015
|
const updatedVersion = await updateDocument(ctx);
|
1820
2016
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1821
2017
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1824,13 +2020,13 @@ const collectionTypes = {
|
|
1824
2020
|
const { userAbility, user } = ctx.state;
|
1825
2021
|
const { model, sourceId: id } = ctx.params;
|
1826
2022
|
const { body } = ctx.request;
|
1827
|
-
const documentManager2 = getService$
|
1828
|
-
const permissionChecker2 = getService$
|
2023
|
+
const documentManager2 = getService$2("document-manager");
|
2024
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1829
2025
|
if (permissionChecker2.cannot.create()) {
|
1830
2026
|
return ctx.forbidden();
|
1831
2027
|
}
|
1832
2028
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1833
|
-
const populate = await getService$
|
2029
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1834
2030
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1835
2031
|
const document = await documentManager2.findOne(id, model, {
|
1836
2032
|
populate,
|
@@ -1869,13 +2065,13 @@ const collectionTypes = {
|
|
1869
2065
|
async delete(ctx) {
|
1870
2066
|
const { userAbility } = ctx.state;
|
1871
2067
|
const { id, model } = ctx.params;
|
1872
|
-
const documentManager2 = getService$
|
1873
|
-
const permissionChecker2 = getService$
|
2068
|
+
const documentManager2 = getService$2("document-manager");
|
2069
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1874
2070
|
if (permissionChecker2.cannot.delete()) {
|
1875
2071
|
return ctx.forbidden();
|
1876
2072
|
}
|
1877
2073
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1878
|
-
const populate = await getService$
|
2074
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1879
2075
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1880
2076
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1881
2077
|
if (documentLocales.length === 0) {
|
@@ -1897,14 +2093,14 @@ const collectionTypes = {
|
|
1897
2093
|
const { userAbility } = ctx.state;
|
1898
2094
|
const { id, model } = ctx.params;
|
1899
2095
|
const { body } = ctx.request;
|
1900
|
-
const documentManager2 = getService$
|
1901
|
-
const permissionChecker2 = getService$
|
2096
|
+
const documentManager2 = getService$2("document-manager");
|
2097
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1902
2098
|
if (permissionChecker2.cannot.publish()) {
|
1903
2099
|
return ctx.forbidden();
|
1904
2100
|
}
|
1905
2101
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1906
2102
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1907
|
-
const populate = await getService$
|
2103
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1908
2104
|
let document;
|
1909
2105
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1910
2106
|
const isCreate = isNil$1(id);
|
@@ -1952,13 +2148,13 @@ const collectionTypes = {
|
|
1952
2148
|
const { body } = ctx.request;
|
1953
2149
|
const { documentIds } = body;
|
1954
2150
|
await validateBulkActionInput(body);
|
1955
|
-
const documentManager2 = getService$
|
1956
|
-
const permissionChecker2 = getService$
|
2151
|
+
const documentManager2 = getService$2("document-manager");
|
2152
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1957
2153
|
if (permissionChecker2.cannot.publish()) {
|
1958
2154
|
return ctx.forbidden();
|
1959
2155
|
}
|
1960
2156
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1961
|
-
const populate = await getService$
|
2157
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1962
2158
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1963
2159
|
allowMultipleLocales: true
|
1964
2160
|
});
|
@@ -1983,8 +2179,8 @@ const collectionTypes = {
|
|
1983
2179
|
const { body } = ctx.request;
|
1984
2180
|
const { documentIds } = body;
|
1985
2181
|
await validateBulkActionInput(body);
|
1986
|
-
const documentManager2 = getService$
|
1987
|
-
const permissionChecker2 = getService$
|
2182
|
+
const documentManager2 = getService$2("document-manager");
|
2183
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1988
2184
|
if (permissionChecker2.cannot.unpublish()) {
|
1989
2185
|
return ctx.forbidden();
|
1990
2186
|
}
|
@@ -2013,8 +2209,8 @@ const collectionTypes = {
|
|
2013
2209
|
const {
|
2014
2210
|
body: { discardDraft, ...body }
|
2015
2211
|
} = ctx.request;
|
2016
|
-
const documentManager2 = getService$
|
2017
|
-
const permissionChecker2 = getService$
|
2212
|
+
const documentManager2 = getService$2("document-manager");
|
2213
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2018
2214
|
if (permissionChecker2.cannot.unpublish()) {
|
2019
2215
|
return ctx.forbidden();
|
2020
2216
|
}
|
@@ -2022,7 +2218,7 @@ const collectionTypes = {
|
|
2022
2218
|
return ctx.forbidden();
|
2023
2219
|
}
|
2024
2220
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2025
|
-
const populate = await getService$
|
2221
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2026
2222
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2027
2223
|
const document = await documentManager2.findOne(id, model, {
|
2028
2224
|
populate,
|
@@ -2053,13 +2249,13 @@ const collectionTypes = {
|
|
2053
2249
|
const { userAbility } = ctx.state;
|
2054
2250
|
const { id, model } = ctx.params;
|
2055
2251
|
const { body } = ctx.request;
|
2056
|
-
const documentManager2 = getService$
|
2057
|
-
const permissionChecker2 = getService$
|
2252
|
+
const documentManager2 = getService$2("document-manager");
|
2253
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2058
2254
|
if (permissionChecker2.cannot.discard()) {
|
2059
2255
|
return ctx.forbidden();
|
2060
2256
|
}
|
2061
2257
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2062
|
-
const populate = await getService$
|
2258
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2063
2259
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2064
2260
|
const document = await documentManager2.findOne(id, model, {
|
2065
2261
|
populate,
|
@@ -2084,13 +2280,13 @@ const collectionTypes = {
|
|
2084
2280
|
const { query, body } = ctx.request;
|
2085
2281
|
const { documentIds } = body;
|
2086
2282
|
await validateBulkActionInput(body);
|
2087
|
-
const documentManager2 = getService$
|
2088
|
-
const permissionChecker2 = getService$
|
2283
|
+
const documentManager2 = getService$2("document-manager");
|
2284
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2089
2285
|
if (permissionChecker2.cannot.delete()) {
|
2090
2286
|
return ctx.forbidden();
|
2091
2287
|
}
|
2092
2288
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2093
|
-
const populate = await getService$
|
2289
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2094
2290
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2095
2291
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2096
2292
|
populate,
|
@@ -2111,13 +2307,13 @@ const collectionTypes = {
|
|
2111
2307
|
async countDraftRelations(ctx) {
|
2112
2308
|
const { userAbility } = ctx.state;
|
2113
2309
|
const { model, id } = ctx.params;
|
2114
|
-
const documentManager2 = getService$
|
2115
|
-
const permissionChecker2 = getService$
|
2310
|
+
const documentManager2 = getService$2("document-manager");
|
2311
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2116
2312
|
if (permissionChecker2.cannot.read()) {
|
2117
2313
|
return ctx.forbidden();
|
2118
2314
|
}
|
2119
2315
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2120
|
-
const populate = await getService$
|
2316
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2121
2317
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2122
2318
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2123
2319
|
if (!entity) {
|
@@ -2136,8 +2332,8 @@ const collectionTypes = {
|
|
2136
2332
|
const ids = ctx.request.query.documentIds;
|
2137
2333
|
const locale = ctx.request.query.locale;
|
2138
2334
|
const { model } = ctx.params;
|
2139
|
-
const documentManager2 = getService$
|
2140
|
-
const permissionChecker2 = getService$
|
2335
|
+
const documentManager2 = getService$2("document-manager");
|
2336
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2141
2337
|
if (permissionChecker2.cannot.read()) {
|
2142
2338
|
return ctx.forbidden();
|
2143
2339
|
}
|
@@ -2161,13 +2357,13 @@ const collectionTypes = {
|
|
2161
2357
|
};
|
2162
2358
|
const components$1 = {
|
2163
2359
|
findComponents(ctx) {
|
2164
|
-
const components2 = getService$
|
2165
|
-
const { toDto } = getService$
|
2360
|
+
const components2 = getService$2("components").findAllComponents();
|
2361
|
+
const { toDto } = getService$2("data-mapper");
|
2166
2362
|
ctx.body = { data: components2.map(toDto) };
|
2167
2363
|
},
|
2168
2364
|
async findComponentConfiguration(ctx) {
|
2169
2365
|
const { uid: uid2 } = ctx.params;
|
2170
|
-
const componentService = getService$
|
2366
|
+
const componentService = getService$2("components");
|
2171
2367
|
const component = componentService.findComponent(uid2);
|
2172
2368
|
if (!component) {
|
2173
2369
|
return ctx.notFound("component.notFound");
|
@@ -2184,7 +2380,7 @@ const components$1 = {
|
|
2184
2380
|
async updateComponentConfiguration(ctx) {
|
2185
2381
|
const { uid: uid2 } = ctx.params;
|
2186
2382
|
const { body } = ctx.request;
|
2187
|
-
const componentService = getService$
|
2383
|
+
const componentService = getService$2("components");
|
2188
2384
|
const component = componentService.findComponent(uid2);
|
2189
2385
|
if (!component) {
|
2190
2386
|
return ctx.notFound("component.notFound");
|
@@ -2218,12 +2414,12 @@ const contentTypes = {
|
|
2218
2414
|
} catch (error) {
|
2219
2415
|
return ctx.send({ error }, 400);
|
2220
2416
|
}
|
2221
|
-
const contentTypes2 = getService$
|
2222
|
-
const { toDto } = getService$
|
2417
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2418
|
+
const { toDto } = getService$2("data-mapper");
|
2223
2419
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2224
2420
|
},
|
2225
2421
|
async findContentTypesSettings(ctx) {
|
2226
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2422
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2227
2423
|
const contentTypes2 = await findAllContentTypes();
|
2228
2424
|
const configurations = await Promise.all(
|
2229
2425
|
contentTypes2.map(async (contentType) => {
|
@@ -2237,7 +2433,7 @@ const contentTypes = {
|
|
2237
2433
|
},
|
2238
2434
|
async findContentTypeConfiguration(ctx) {
|
2239
2435
|
const { uid: uid2 } = ctx.params;
|
2240
|
-
const contentTypeService = getService$
|
2436
|
+
const contentTypeService = getService$2("content-types");
|
2241
2437
|
const contentType = await contentTypeService.findContentType(uid2);
|
2242
2438
|
if (!contentType) {
|
2243
2439
|
return ctx.notFound("contentType.notFound");
|
@@ -2259,13 +2455,13 @@ const contentTypes = {
|
|
2259
2455
|
const { userAbility } = ctx.state;
|
2260
2456
|
const { uid: uid2 } = ctx.params;
|
2261
2457
|
const { body } = ctx.request;
|
2262
|
-
const contentTypeService = getService$
|
2263
|
-
const metricsService = getService$
|
2458
|
+
const contentTypeService = getService$2("content-types");
|
2459
|
+
const metricsService = getService$2("metrics");
|
2264
2460
|
const contentType = await contentTypeService.findContentType(uid2);
|
2265
2461
|
if (!contentType) {
|
2266
2462
|
return ctx.notFound("contentType.notFound");
|
2267
2463
|
}
|
2268
|
-
if (!getService$
|
2464
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2269
2465
|
return ctx.forbidden();
|
2270
2466
|
}
|
2271
2467
|
let input;
|
@@ -2298,10 +2494,10 @@ const contentTypes = {
|
|
2298
2494
|
};
|
2299
2495
|
const init = {
|
2300
2496
|
getInitData(ctx) {
|
2301
|
-
const { toDto } = getService$
|
2302
|
-
const { findAllComponents } = getService$
|
2303
|
-
const { getAllFieldSizes } = getService$
|
2304
|
-
const { findAllContentTypes } = getService$
|
2497
|
+
const { toDto } = getService$2("data-mapper");
|
2498
|
+
const { findAllComponents } = getService$2("components");
|
2499
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2500
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2305
2501
|
ctx.body = {
|
2306
2502
|
data: {
|
2307
2503
|
fieldSizes: getAllFieldSizes(),
|
@@ -2337,7 +2533,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2337
2533
|
params.filters.$and.push(filtersClause);
|
2338
2534
|
};
|
2339
2535
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2340
|
-
const permissionChecker2 = getService$
|
2536
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2341
2537
|
userAbility,
|
2342
2538
|
model: model.uid
|
2343
2539
|
});
|
@@ -2351,15 +2547,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2351
2547
|
}
|
2352
2548
|
return mainField;
|
2353
2549
|
};
|
2354
|
-
const addStatusToRelations = async (
|
2355
|
-
if (!contentTypes$1.hasDraftAndPublish(strapi.
|
2550
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2551
|
+
if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2552
|
+
return relations2;
|
2553
|
+
}
|
2554
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2555
|
+
if (!relations2.length) {
|
2356
2556
|
return relations2;
|
2357
2557
|
}
|
2358
|
-
const
|
2359
|
-
const
|
2558
|
+
const firstRelation = relations2[0];
|
2559
|
+
const filters = {
|
2560
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2561
|
+
// NOTE: find the "opposite" status
|
2562
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2563
|
+
};
|
2564
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2565
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2566
|
+
filters
|
2567
|
+
});
|
2360
2568
|
return relations2.map((relation) => {
|
2361
|
-
const availableStatuses =
|
2362
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2569
|
+
const availableStatuses = availableStatus.filter(
|
2570
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2363
2571
|
);
|
2364
2572
|
return {
|
2365
2573
|
...relation,
|
@@ -2390,8 +2598,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2390
2598
|
const sourceModel = strapi.getModel(sourceUid);
|
2391
2599
|
const isDP = contentTypes$1.hasDraftAndPublish;
|
2392
2600
|
const isSourceDP = isDP(sourceModel);
|
2393
|
-
if (!isSourceDP)
|
2394
|
-
return { status: void 0 };
|
2601
|
+
if (!isSourceDP) return { status: void 0 };
|
2395
2602
|
switch (status) {
|
2396
2603
|
case "published":
|
2397
2604
|
return { status: "published" };
|
@@ -2421,7 +2628,7 @@ const relations = {
|
|
2421
2628
|
ctx.request?.query?.locale
|
2422
2629
|
);
|
2423
2630
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2424
|
-
const permissionChecker2 = getService$
|
2631
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2425
2632
|
userAbility,
|
2426
2633
|
model
|
2427
2634
|
});
|
@@ -2446,7 +2653,7 @@ const relations = {
|
|
2446
2653
|
where.id = id;
|
2447
2654
|
}
|
2448
2655
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2449
|
-
const populate = await getService$
|
2656
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2450
2657
|
const currentEntity = await strapi.db.query(model).findOne({
|
2451
2658
|
where,
|
2452
2659
|
populate
|
@@ -2461,7 +2668,7 @@ const relations = {
|
|
2461
2668
|
}
|
2462
2669
|
entryId = currentEntity.id;
|
2463
2670
|
}
|
2464
|
-
const modelConfig = isComponent2 ? await getService$
|
2671
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2465
2672
|
const targetSchema = strapi.getModel(targetUid);
|
2466
2673
|
const mainField = flow(
|
2467
2674
|
prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2515,7 +2722,7 @@ const relations = {
|
|
2515
2722
|
}
|
2516
2723
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2517
2724
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2518
|
-
const permissionChecker2 = getService$
|
2725
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2519
2726
|
userAbility: ctx.state.userAbility,
|
2520
2727
|
model: targetUid
|
2521
2728
|
});
|
@@ -2588,21 +2795,33 @@ const relations = {
|
|
2588
2795
|
attribute,
|
2589
2796
|
targetField,
|
2590
2797
|
fieldsToSelect,
|
2591
|
-
|
2592
|
-
|
2593
|
-
}
|
2594
|
-
target: {
|
2595
|
-
schema: { uid: targetUid }
|
2596
|
-
}
|
2798
|
+
status,
|
2799
|
+
source: { schema: sourceSchema },
|
2800
|
+
target: { schema: targetSchema }
|
2597
2801
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2598
|
-
const
|
2802
|
+
const { uid: sourceUid } = sourceSchema;
|
2803
|
+
const { uid: targetUid } = targetSchema;
|
2804
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2599
2805
|
const dbQuery = strapi.db.query(sourceUid);
|
2600
2806
|
const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2807
|
+
const filters = {};
|
2808
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2809
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2810
|
+
if (status === "published") {
|
2811
|
+
filters.publishedAt = { $notNull: true };
|
2812
|
+
} else {
|
2813
|
+
filters.publishedAt = { $null: true };
|
2814
|
+
}
|
2815
|
+
}
|
2816
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2817
|
+
filters.publishedAt = { $null: true };
|
2818
|
+
}
|
2601
2819
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2602
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2820
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2603
2821
|
ordering: "desc",
|
2604
2822
|
page: ctx.request.query.page,
|
2605
|
-
pageSize: ctx.request.query.pageSize
|
2823
|
+
pageSize: ctx.request.query.pageSize,
|
2824
|
+
filters
|
2606
2825
|
});
|
2607
2826
|
const loadedIds = res.results.map((item) => item.id);
|
2608
2827
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2623,10 +2842,10 @@ const relations = {
|
|
2623
2842
|
}
|
2624
2843
|
};
|
2625
2844
|
const buildPopulateFromQuery = async (query, model) => {
|
2626
|
-
return getService$
|
2845
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2627
2846
|
};
|
2628
2847
|
const findDocument = async (query, uid2, opts = {}) => {
|
2629
|
-
const documentManager2 = getService$
|
2848
|
+
const documentManager2 = getService$2("document-manager");
|
2630
2849
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2631
2850
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2632
2851
|
};
|
@@ -2634,8 +2853,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2634
2853
|
const { user, userAbility } = ctx.state;
|
2635
2854
|
const { model } = ctx.params;
|
2636
2855
|
const { body, query } = ctx.request;
|
2637
|
-
const documentManager2 = getService$
|
2638
|
-
const permissionChecker2 = getService$
|
2856
|
+
const documentManager2 = getService$2("document-manager");
|
2857
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2639
2858
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2640
2859
|
throw new errors.ForbiddenError();
|
2641
2860
|
}
|
@@ -2676,7 +2895,7 @@ const singleTypes = {
|
|
2676
2895
|
const { userAbility } = ctx.state;
|
2677
2896
|
const { model } = ctx.params;
|
2678
2897
|
const { query = {} } = ctx.request;
|
2679
|
-
const permissionChecker2 = getService$
|
2898
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2680
2899
|
if (permissionChecker2.cannot.read()) {
|
2681
2900
|
return ctx.forbidden();
|
2682
2901
|
}
|
@@ -2710,7 +2929,7 @@ const singleTypes = {
|
|
2710
2929
|
async createOrUpdate(ctx) {
|
2711
2930
|
const { userAbility } = ctx.state;
|
2712
2931
|
const { model } = ctx.params;
|
2713
|
-
const permissionChecker2 = getService$
|
2932
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2714
2933
|
const document = await createOrUpdateDocument(ctx);
|
2715
2934
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2716
2935
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2719,8 +2938,8 @@ const singleTypes = {
|
|
2719
2938
|
const { userAbility } = ctx.state;
|
2720
2939
|
const { model } = ctx.params;
|
2721
2940
|
const { query = {} } = ctx.request;
|
2722
|
-
const documentManager2 = getService$
|
2723
|
-
const permissionChecker2 = getService$
|
2941
|
+
const documentManager2 = getService$2("document-manager");
|
2942
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2724
2943
|
if (permissionChecker2.cannot.delete()) {
|
2725
2944
|
return ctx.forbidden();
|
2726
2945
|
}
|
@@ -2748,8 +2967,8 @@ const singleTypes = {
|
|
2748
2967
|
const { userAbility } = ctx.state;
|
2749
2968
|
const { model } = ctx.params;
|
2750
2969
|
const { query = {} } = ctx.request;
|
2751
|
-
const documentManager2 = getService$
|
2752
|
-
const permissionChecker2 = getService$
|
2970
|
+
const documentManager2 = getService$2("document-manager");
|
2971
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2753
2972
|
if (permissionChecker2.cannot.publish()) {
|
2754
2973
|
return ctx.forbidden();
|
2755
2974
|
}
|
@@ -2777,8 +2996,8 @@ const singleTypes = {
|
|
2777
2996
|
body: { discardDraft, ...body },
|
2778
2997
|
query = {}
|
2779
2998
|
} = ctx.request;
|
2780
|
-
const documentManager2 = getService$
|
2781
|
-
const permissionChecker2 = getService$
|
2999
|
+
const documentManager2 = getService$2("document-manager");
|
3000
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2782
3001
|
if (permissionChecker2.cannot.unpublish()) {
|
2783
3002
|
return ctx.forbidden();
|
2784
3003
|
}
|
@@ -2812,8 +3031,8 @@ const singleTypes = {
|
|
2812
3031
|
const { userAbility } = ctx.state;
|
2813
3032
|
const { model } = ctx.params;
|
2814
3033
|
const { body, query = {} } = ctx.request;
|
2815
|
-
const documentManager2 = getService$
|
2816
|
-
const permissionChecker2 = getService$
|
3034
|
+
const documentManager2 = getService$2("document-manager");
|
3035
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2817
3036
|
if (permissionChecker2.cannot.discard()) {
|
2818
3037
|
return ctx.forbidden();
|
2819
3038
|
}
|
@@ -2836,8 +3055,8 @@ const singleTypes = {
|
|
2836
3055
|
const { userAbility } = ctx.state;
|
2837
3056
|
const { model } = ctx.params;
|
2838
3057
|
const { query } = ctx.request;
|
2839
|
-
const documentManager2 = getService$
|
2840
|
-
const permissionChecker2 = getService$
|
3058
|
+
const documentManager2 = getService$2("document-manager");
|
3059
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2841
3060
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2842
3061
|
if (permissionChecker2.cannot.read()) {
|
2843
3062
|
return ctx.forbidden();
|
@@ -2861,7 +3080,7 @@ const uid$1 = {
|
|
2861
3080
|
const { query = {} } = ctx.request;
|
2862
3081
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2863
3082
|
await validateUIDField(contentTypeUID, field);
|
2864
|
-
const uidService = getService$
|
3083
|
+
const uidService = getService$2("uid");
|
2865
3084
|
ctx.body = {
|
2866
3085
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2867
3086
|
};
|
@@ -2873,7 +3092,7 @@ const uid$1 = {
|
|
2873
3092
|
const { query = {} } = ctx.request;
|
2874
3093
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2875
3094
|
await validateUIDField(contentTypeUID, field);
|
2876
|
-
const uidService = getService$
|
3095
|
+
const uidService = getService$2("uid");
|
2877
3096
|
const isAvailable = await uidService.checkUIDAvailability({
|
2878
3097
|
contentTypeUID,
|
2879
3098
|
field,
|
@@ -2894,7 +3113,8 @@ const controllers = {
|
|
2894
3113
|
relations,
|
2895
3114
|
"single-types": singleTypes,
|
2896
3115
|
uid: uid$1,
|
2897
|
-
...history.controllers ? history.controllers : {}
|
3116
|
+
...history.controllers ? history.controllers : {},
|
3117
|
+
...preview.controllers ? preview.controllers : {}
|
2898
3118
|
};
|
2899
3119
|
const keys = {
|
2900
3120
|
CONFIGURATION: "configuration"
|
@@ -3023,18 +3243,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3023
3243
|
_.set(updatedMeta, ["list", "searchable"], false);
|
3024
3244
|
_.set(acc, [key], updatedMeta);
|
3025
3245
|
}
|
3026
|
-
if (!_.has(edit, "mainField"))
|
3027
|
-
return acc;
|
3246
|
+
if (!_.has(edit, "mainField")) return acc;
|
3028
3247
|
if (!isRelation$1(attr)) {
|
3029
3248
|
_.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
|
3030
3249
|
_.set(acc, [key], updatedMeta);
|
3031
3250
|
return acc;
|
3032
3251
|
}
|
3033
|
-
if (edit.mainField === "id")
|
3034
|
-
return acc;
|
3252
|
+
if (edit.mainField === "id") return acc;
|
3035
3253
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3036
|
-
if (!targetSchema)
|
3037
|
-
return acc;
|
3254
|
+
if (!targetSchema) return acc;
|
3038
3255
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3039
3256
|
_.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3040
3257
|
_.set(acc, [key], updatedMeta);
|
@@ -3045,12 +3262,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3045
3262
|
return _.assign(metasWithDefaults, updatedMetas);
|
3046
3263
|
}
|
3047
3264
|
const getTargetSchema = (targetModel) => {
|
3048
|
-
return getService$
|
3265
|
+
return getService$2("content-types").findContentType(targetModel);
|
3049
3266
|
};
|
3050
3267
|
const DEFAULT_LIST_LENGTH = 4;
|
3051
3268
|
const MAX_ROW_SIZE = 12;
|
3052
3269
|
const isAllowedFieldSize = (type, size) => {
|
3053
|
-
const { getFieldSize } = getService$
|
3270
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3054
3271
|
const fieldSize = getFieldSize(type);
|
3055
3272
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3056
3273
|
return false;
|
@@ -3058,7 +3275,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3058
3275
|
return size <= MAX_ROW_SIZE;
|
3059
3276
|
};
|
3060
3277
|
const getDefaultFieldSize = (attribute) => {
|
3061
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3278
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3062
3279
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3063
3280
|
};
|
3064
3281
|
async function createDefaultLayouts(schema) {
|
@@ -3079,8 +3296,7 @@ function createDefaultEditLayout(schema) {
|
|
3079
3296
|
return appendToEditLayout([], keys2, schema);
|
3080
3297
|
}
|
3081
3298
|
function syncLayouts(configuration, schema) {
|
3082
|
-
if (_.isEmpty(configuration.layouts))
|
3083
|
-
return createDefaultLayouts(schema);
|
3299
|
+
if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3084
3300
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3085
3301
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3086
3302
|
const cleanEditRelations = editRelations.filter(
|
@@ -3091,9 +3307,8 @@ function syncLayouts(configuration, schema) {
|
|
3091
3307
|
for (const row of edit) {
|
3092
3308
|
const newRow = [];
|
3093
3309
|
for (const el of row) {
|
3094
|
-
if (!hasEditableAttribute(schema, el.name))
|
3095
|
-
|
3096
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3310
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3311
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3097
3312
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3098
3313
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3099
3314
|
elementsToReAppend.push(el.name);
|
@@ -3123,8 +3338,7 @@ function syncLayouts(configuration, schema) {
|
|
3123
3338
|
};
|
3124
3339
|
}
|
3125
3340
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3126
|
-
if (keysToAppend.length === 0)
|
3127
|
-
return layout;
|
3341
|
+
if (keysToAppend.length === 0) return layout;
|
3128
3342
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3129
3343
|
if (!layout[currentRowIndex]) {
|
3130
3344
|
layout[currentRowIndex] = [];
|
@@ -3233,17 +3447,17 @@ const configurationService$1 = createConfigurationService({
|
|
3233
3447
|
isComponent: true,
|
3234
3448
|
prefix: STORE_KEY_PREFIX,
|
3235
3449
|
getModels() {
|
3236
|
-
const { toContentManagerModel } = getService$
|
3450
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3237
3451
|
return mapValues(toContentManagerModel, strapi.components);
|
3238
3452
|
}
|
3239
3453
|
});
|
3240
3454
|
const components = ({ strapi: strapi2 }) => ({
|
3241
3455
|
findAllComponents() {
|
3242
|
-
const { toContentManagerModel } = getService$
|
3456
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3243
3457
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3244
3458
|
},
|
3245
3459
|
findComponent(uid2) {
|
3246
|
-
const { toContentManagerModel } = getService$
|
3460
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3247
3461
|
const component = strapi2.components[uid2];
|
3248
3462
|
return isNil$1(component) ? component : toContentManagerModel(component);
|
3249
3463
|
},
|
@@ -3294,17 +3508,17 @@ const configurationService = createConfigurationService({
|
|
3294
3508
|
storeUtils,
|
3295
3509
|
prefix: "content_types",
|
3296
3510
|
getModels() {
|
3297
|
-
const { toContentManagerModel } = getService$
|
3511
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3298
3512
|
return mapValues(toContentManagerModel, strapi.contentTypes);
|
3299
3513
|
}
|
3300
3514
|
});
|
3301
3515
|
const service = ({ strapi: strapi2 }) => ({
|
3302
3516
|
findAllContentTypes() {
|
3303
|
-
const { toContentManagerModel } = getService$
|
3517
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3304
3518
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3305
3519
|
},
|
3306
3520
|
findContentType(uid2) {
|
3307
|
-
const { toContentManagerModel } = getService$
|
3521
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3308
3522
|
const contentType = strapi2.contentTypes[uid2];
|
3309
3523
|
return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
|
3310
3524
|
},
|
@@ -3333,7 +3547,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3333
3547
|
return this.findConfiguration(contentType);
|
3334
3548
|
},
|
3335
3549
|
findComponentsConfigurations(contentType) {
|
3336
|
-
return getService$
|
3550
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3337
3551
|
},
|
3338
3552
|
syncConfigurations() {
|
3339
3553
|
return configurationService.syncConfigurations();
|
@@ -3605,7 +3819,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3605
3819
|
return userAbility.can(action);
|
3606
3820
|
},
|
3607
3821
|
async registerPermissions() {
|
3608
|
-
const displayedContentTypes = getService$
|
3822
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3609
3823
|
const contentTypesUids = displayedContentTypes.map(prop("uid"));
|
3610
3824
|
const actions = [
|
3611
3825
|
{
|
@@ -3690,6 +3904,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3690
3904
|
if (initialPopulate) {
|
3691
3905
|
return initialPopulate;
|
3692
3906
|
}
|
3907
|
+
if (attributeName === "localizations") {
|
3908
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3909
|
+
return {
|
3910
|
+
populate: validationPopulate.populate
|
3911
|
+
};
|
3912
|
+
}
|
3693
3913
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3694
3914
|
return true;
|
3695
3915
|
}
|
@@ -3749,6 +3969,9 @@ const getDeepPopulate = (uid2, {
|
|
3749
3969
|
return {};
|
3750
3970
|
}
|
3751
3971
|
const model = strapi.getModel(uid2);
|
3972
|
+
if (!model) {
|
3973
|
+
return {};
|
3974
|
+
}
|
3752
3975
|
return Object.keys(model.attributes).reduce(
|
3753
3976
|
(populateAcc, attributeName) => merge(
|
3754
3977
|
populateAcc,
|
@@ -3768,40 +3991,46 @@ const getDeepPopulate = (uid2, {
|
|
3768
3991
|
{}
|
3769
3992
|
);
|
3770
3993
|
};
|
3771
|
-
const
|
3772
|
-
|
3773
|
-
|
3774
|
-
countOne = false,
|
3775
|
-
maxLevel = Infinity
|
3776
|
-
} = {}, level = 1) => {
|
3777
|
-
if (level > maxLevel) {
|
3994
|
+
const getPopulateForValidation = (uid2) => {
|
3995
|
+
const model = strapi.getModel(uid2);
|
3996
|
+
if (!model) {
|
3778
3997
|
return {};
|
3779
3998
|
}
|
3780
|
-
const model = strapi.getModel(uid2);
|
3781
3999
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3782
|
-
if (
|
4000
|
+
if (isScalarAttribute(attribute)) {
|
4001
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4002
|
+
populateAcc.fields = populateAcc.fields || [];
|
4003
|
+
populateAcc.fields.push(attributeName);
|
4004
|
+
}
|
3783
4005
|
return populateAcc;
|
3784
4006
|
}
|
3785
|
-
if (
|
3786
|
-
|
3787
|
-
|
3788
|
-
|
4007
|
+
if (isComponent(attribute)) {
|
4008
|
+
const component = attribute.component;
|
4009
|
+
const componentResult = getPopulateForValidation(component);
|
4010
|
+
if (Object.keys(componentResult).length > 0) {
|
4011
|
+
populateAcc.populate = populateAcc.populate || {};
|
4012
|
+
populateAcc.populate[attributeName] = componentResult;
|
4013
|
+
}
|
4014
|
+
return populateAcc;
|
3789
4015
|
}
|
3790
|
-
|
3791
|
-
|
3792
|
-
|
3793
|
-
|
3794
|
-
|
3795
|
-
|
3796
|
-
|
3797
|
-
|
3798
|
-
|
3799
|
-
countOne,
|
3800
|
-
maxLevel
|
4016
|
+
if (isDynamicZone(attribute)) {
|
4017
|
+
const components2 = attribute.components;
|
4018
|
+
const componentsResult = (components2 || []).reduce(
|
4019
|
+
(acc, componentUID) => {
|
4020
|
+
const componentResult = getPopulateForValidation(componentUID);
|
4021
|
+
if (Object.keys(componentResult).length > 0) {
|
4022
|
+
acc[componentUID] = componentResult;
|
4023
|
+
}
|
4024
|
+
return acc;
|
3801
4025
|
},
|
3802
|
-
|
3803
|
-
)
|
3804
|
-
|
4026
|
+
{}
|
4027
|
+
);
|
4028
|
+
if (Object.keys(componentsResult).length > 0) {
|
4029
|
+
populateAcc.populate = populateAcc.populate || {};
|
4030
|
+
populateAcc.populate[attributeName] = { on: componentsResult };
|
4031
|
+
}
|
4032
|
+
}
|
4033
|
+
return populateAcc;
|
3805
4034
|
}, {});
|
3806
4035
|
};
|
3807
4036
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3881,7 +4110,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3881
4110
|
return populateQuery;
|
3882
4111
|
};
|
3883
4112
|
const buildDeepPopulate = (uid2) => {
|
3884
|
-
return getService$
|
4113
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3885
4114
|
};
|
3886
4115
|
const populateBuilder = (uid2) => {
|
3887
4116
|
let getInitialPopulate = async () => {
|
@@ -4043,7 +4272,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4043
4272
|
"locale",
|
4044
4273
|
"updatedAt",
|
4045
4274
|
"createdAt",
|
4046
|
-
"status",
|
4047
4275
|
"publishedAt",
|
4048
4276
|
"documentId"
|
4049
4277
|
];
|
@@ -4064,34 +4292,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4064
4292
|
/**
|
4065
4293
|
* Returns available locales of a document for the current status
|
4066
4294
|
*/
|
4067
|
-
async getAvailableLocales(uid2, version, allVersions
|
4295
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4068
4296
|
const versionsByLocale = groupBy("locale", allVersions);
|
4069
|
-
|
4297
|
+
if (version.locale) {
|
4298
|
+
delete versionsByLocale[version.locale];
|
4299
|
+
}
|
4070
4300
|
const model = strapi2.getModel(uid2);
|
4071
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4072
|
-
const traversalFunction = async (localeVersion) => traverseEntity(
|
4073
|
-
({ key }, { remove }) => {
|
4074
|
-
if (keysToKeep.includes(key)) {
|
4075
|
-
return;
|
4076
|
-
}
|
4077
|
-
remove(key);
|
4078
|
-
},
|
4079
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4080
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4081
|
-
localeVersion
|
4082
|
-
);
|
4083
4301
|
const mappingResult = await async.map(
|
4084
4302
|
Object.values(versionsByLocale),
|
4085
4303
|
async (localeVersions) => {
|
4086
|
-
const mappedLocaleVersions = await async.map(
|
4087
|
-
localeVersions,
|
4088
|
-
traversalFunction
|
4089
|
-
);
|
4090
4304
|
if (!contentTypes$1.hasDraftAndPublish(model)) {
|
4091
|
-
return
|
4305
|
+
return localeVersions[0];
|
4092
4306
|
}
|
4093
|
-
const draftVersion =
|
4094
|
-
const otherVersions =
|
4307
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4308
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4095
4309
|
if (!draftVersion) {
|
4096
4310
|
return;
|
4097
4311
|
}
|
@@ -4113,8 +4327,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4113
4327
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4114
4328
|
return matchLocale && matchStatus;
|
4115
4329
|
});
|
4116
|
-
if (!availableStatus)
|
4117
|
-
return availableStatus;
|
4330
|
+
if (!availableStatus) return availableStatus;
|
4118
4331
|
return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4119
4332
|
},
|
4120
4333
|
/**
|
@@ -4124,18 +4337,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4124
4337
|
* @returns
|
4125
4338
|
*/
|
4126
4339
|
async getManyAvailableStatus(uid2, documents) {
|
4127
|
-
if (!documents.length)
|
4128
|
-
return [];
|
4340
|
+
if (!documents.length) return [];
|
4129
4341
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4130
|
-
const
|
4131
|
-
const
|
4132
|
-
|
4133
|
-
|
4134
|
-
|
4135
|
-
|
4136
|
-
|
4137
|
-
|
4138
|
-
|
4342
|
+
const locales = documents.map((d) => d.locale).filter(Boolean);
|
4343
|
+
const where = {
|
4344
|
+
documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
|
4345
|
+
publishedAt: { $null: status === "published" }
|
4346
|
+
};
|
4347
|
+
if (locales.length) {
|
4348
|
+
where.locale = { $in: locales };
|
4349
|
+
}
|
4350
|
+
return strapi2.query(uid2).findMany({
|
4351
|
+
where,
|
4352
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
|
4139
4353
|
});
|
4140
4354
|
},
|
4141
4355
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4152,10 +4366,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4152
4366
|
} else if (otherVersion) {
|
4153
4367
|
draftVersion = otherVersion;
|
4154
4368
|
}
|
4155
|
-
if (!draftVersion)
|
4156
|
-
|
4157
|
-
if (!publishedVersion)
|
4158
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4369
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4370
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4159
4371
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4160
4372
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4161
4373
|
},
|
@@ -4163,11 +4375,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4163
4375
|
// We could refactor this so the locales are only loaded when they're
|
4164
4376
|
// needed. e.g. in the bulk locale action modal.
|
4165
4377
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4166
|
-
const populate =
|
4167
|
-
const
|
4168
|
-
where: { documentId: version.documentId },
|
4378
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4379
|
+
const params = {
|
4169
4380
|
populate: {
|
4170
|
-
// Populate only fields that require validation for bulk locale actions
|
4171
4381
|
...populate,
|
4172
4382
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4173
4383
|
createdBy: {
|
@@ -4176,9 +4386,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4176
4386
|
updatedBy: {
|
4177
4387
|
select: ["id", "firstname", "lastname", "email"]
|
4178
4388
|
}
|
4389
|
+
},
|
4390
|
+
fields: uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4391
|
+
filters: {
|
4392
|
+
documentId: version.documentId
|
4179
4393
|
}
|
4180
|
-
}
|
4181
|
-
const
|
4394
|
+
};
|
4395
|
+
const dbParams = strapi2.get("query-params").transform(uid2, params);
|
4396
|
+
const versions = await strapi2.db.query(uid2).findMany(dbParams);
|
4397
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
|
4182
4398
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4183
4399
|
return {
|
4184
4400
|
availableLocales: availableLocalesResult,
|
@@ -4205,6 +4421,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4205
4421
|
opts.availableStatus = false;
|
4206
4422
|
}
|
4207
4423
|
const meta = await this.getMetadata(uid2, document, opts);
|
4424
|
+
if (document.localizations) {
|
4425
|
+
const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
|
4426
|
+
document.localizations = document.localizations.map((d) => {
|
4427
|
+
const status = otherStatus.find((s) => s.documentId === d.documentId);
|
4428
|
+
return {
|
4429
|
+
...d,
|
4430
|
+
status: this.getStatus(d, status ? [status] : [])
|
4431
|
+
};
|
4432
|
+
});
|
4433
|
+
}
|
4208
4434
|
return {
|
4209
4435
|
data: {
|
4210
4436
|
...document,
|
@@ -4422,7 +4648,8 @@ const services = {
|
|
4422
4648
|
permission,
|
4423
4649
|
"populate-builder": populateBuilder$1,
|
4424
4650
|
uid,
|
4425
|
-
...history.services ? history.services : {}
|
4651
|
+
...history.services ? history.services : {},
|
4652
|
+
...preview.services ? preview.services : {}
|
4426
4653
|
};
|
4427
4654
|
const index = () => {
|
4428
4655
|
return {
|