@strapi/content-manager 0.0.0-experimental.fd379e4937e431407d784eaa5fe7f93cf2a53386 → 0.0.0-experimental.fd51913e4ee4e81a845e6f5bcfd4916cac70ca2e
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-CIjXcRAB.mjs → ComponentConfigurationPage-9_4yUE9L.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CIjXcRAB.mjs.map → ComponentConfigurationPage-9_4yUE9L.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-gsCd80MU.js → ComponentConfigurationPage-DBSh-kET.js} +4 -5
- package/dist/_chunks/{ComponentConfigurationPage-gsCd80MU.js.map → ComponentConfigurationPage-DBSh-kET.js.map} +1 -1
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
- package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
- package/dist/_chunks/{EditConfigurationPage-DHDQKBzw.js → EditConfigurationPage-Bl_U2JgH.js} +4 -5
- package/dist/_chunks/{EditConfigurationPage-DHDQKBzw.js.map → EditConfigurationPage-Bl_U2JgH.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BglmD_BF.mjs → EditConfigurationPage-COe6hjPC.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BglmD_BF.mjs.map → EditConfigurationPage-COe6hjPC.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-C4iTxUPU.js → EditViewPage-D4yFJET6.js} +23 -57
- package/dist/_chunks/EditViewPage-D4yFJET6.js.map +1 -0
- package/dist/_chunks/{EditViewPage-CiwVPMaK.mjs → EditViewPage-DrmVmYN0.mjs} +21 -54
- package/dist/_chunks/EditViewPage-DrmVmYN0.mjs.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-CwmJ4sWe.js → Form-C4rSaGsz.js} +5 -6
- package/dist/_chunks/{Form-CwmJ4sWe.js.map → Form-C4rSaGsz.js.map} +1 -1
- package/dist/_chunks/{Form-CmNesrvR.mjs → Form-DamaxNpG.mjs} +3 -3
- package/dist/_chunks/{Form-CmNesrvR.mjs.map → Form-DamaxNpG.mjs.map} +1 -1
- package/dist/_chunks/{History-D-99Wh30.mjs → History-D1PreDSY.mjs} +50 -96
- package/dist/_chunks/History-D1PreDSY.mjs.map +1 -0
- package/dist/_chunks/{History-BLCCNgCt.js → History-DTm8UCCQ.js} +61 -108
- package/dist/_chunks/History-DTm8UCCQ.js.map +1 -0
- package/dist/_chunks/{Field-DhXEK8y1.js → Input-B7sapvBG.js} +1293 -1271
- package/dist/_chunks/Input-B7sapvBG.js.map +1 -0
- package/dist/_chunks/{Field-DIjL1b5d.mjs → Input-CZ1YvjHR.mjs} +1332 -1310
- package/dist/_chunks/Input-CZ1YvjHR.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-JPWZz7Kg.mjs → ListConfigurationPage-Bbi32isk.mjs} +6 -5
- package/dist/_chunks/ListConfigurationPage-Bbi32isk.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxWpeZrO.js → ListConfigurationPage-ysFMjKI3.js} +6 -6
- package/dist/_chunks/ListConfigurationPage-ysFMjKI3.js.map +1 -0
- package/dist/_chunks/{ListViewPage-DSK3f0ST.mjs → ListViewPage-Bud_jBDQ.mjs} +68 -53
- package/dist/_chunks/ListViewPage-Bud_jBDQ.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CIQekSFz.js → ListViewPage-DTuuxU3n.js} +74 -60
- package/dist/_chunks/ListViewPage-DTuuxU3n.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-C5cxKvC2.js → NoContentTypePage-CL7VVeYs.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-C5cxKvC2.js.map → NoContentTypePage-CL7VVeYs.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-D99LU1YP.mjs → NoContentTypePage-DVhkugsf.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-D99LU1YP.mjs.map → NoContentTypePage-DVhkugsf.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DBrBw-0y.mjs → NoPermissionsPage-CMdM-dCo.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DBrBw-0y.mjs.map → NoPermissionsPage-CMdM-dCo.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Oy4tmUrW.js → NoPermissionsPage-v7I599vC.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Oy4tmUrW.js.map → NoPermissionsPage-v7I599vC.js.map} +1 -1
- package/dist/_chunks/Preview-BNuU0SuQ.mjs +287 -0
- package/dist/_chunks/Preview-BNuU0SuQ.mjs.map +1 -0
- package/dist/_chunks/Preview-Cxq-uI6D.js +305 -0
- package/dist/_chunks/Preview-Cxq-uI6D.js.map +1 -0
- package/dist/_chunks/{Relations-BBmhcWFV.mjs → Relations-C2Ahkrdg.mjs} +9 -8
- package/dist/_chunks/Relations-C2Ahkrdg.mjs.map +1 -0
- package/dist/_chunks/{Relations-eG-9p_qS.js → Relations-CWS79QQn.js} +10 -10
- package/dist/_chunks/Relations-CWS79QQn.js.map +1 -0
- package/dist/_chunks/{en-Bm0D0IWz.js → en-BR48D_RH.js} +23 -4
- package/dist/_chunks/{en-Bm0D0IWz.js.map → en-BR48D_RH.js.map} +1 -1
- package/dist/_chunks/{en-DKV44jRb.mjs → en-D65uIF6Y.mjs} +23 -4
- package/dist/_chunks/{en-DKV44jRb.mjs.map → en-D65uIF6Y.mjs.map} +1 -1
- package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
- package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
- package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
- package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-C43IbhA_.js} +16 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-C43IbhA_.js.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr-DBseuRuB.mjs} +16 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr-DBseuRuB.mjs.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-BIWDoFLK.js → index-DQsvBb_N.js} +604 -237
- package/dist/_chunks/index-DQsvBb_N.js.map +1 -0
- package/dist/_chunks/{index-BrUzbQ30.mjs → index-ZKrsjv-2.mjs} +621 -253
- package/dist/_chunks/index-ZKrsjv-2.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-lMc9i1-Z.js → layout-Cl0NhlQB.js} +5 -6
- package/dist/_chunks/{layout-lMc9i1-Z.js.map → layout-Cl0NhlQB.js.map} +1 -1
- package/dist/_chunks/{layout-_5-cXs34.mjs → layout-fQk1rMk9.mjs} +4 -4
- package/dist/_chunks/{layout-_5-cXs34.mjs.map → layout-fQk1rMk9.mjs.map} +1 -1
- package/dist/_chunks/objects-BcXOv6_9.js.map +1 -1
- package/dist/_chunks/objects-D6yBsdmx.mjs.map +1 -1
- package/dist/_chunks/{relations-BRHithi8.js → relations-BRfBxVbX.js} +6 -3
- package/dist/_chunks/relations-BRfBxVbX.js.map +1 -0
- package/dist/_chunks/{relations-B_VLk-DD.mjs → relations-BakOFl_1.mjs} +6 -3
- package/dist/_chunks/relations-BakOFl_1.mjs.map +1 -0
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
- package/dist/_chunks/{useDebounce-DmuSJIF3.mjs → usePrev-CZGy2Vjf.mjs} +11 -11
- package/dist/_chunks/usePrev-CZGy2Vjf.mjs.map +1 -0
- package/dist/_chunks/{useDebounce-CtcjDB3L.js → usePrev-D5J_2fEu.js} +8 -8
- package/dist/_chunks/usePrev-D5J_2fEu.js.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +6 -5
- package/dist/admin/src/content-manager.d.ts +3 -2
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +19 -2
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +3 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +4 -1
- package/dist/admin/src/pages/EditView/components/FormLayout.d.ts +27 -0
- package/dist/admin/src/pages/EditView/utils/data.d.ts +1 -0
- package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/index.d.ts +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/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +16 -19
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/server/index.js +465 -308
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +466 -308
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +1 -0
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts +1 -1
- package/dist/server/src/history/controllers/history-version.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts +3 -3
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +6 -11
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +3 -2
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/preview.d.ts +6 -2
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -1
- 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/services/index.d.ts +13 -1
- package/dist/server/src/preview/services/index.d.ts.map +1 -1
- 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 +7 -1
- package/dist/server/src/preview/services/preview.d.ts.map +1 -1
- package/dist/server/src/preview/utils.d.ts +13 -1
- package/dist/server/src/preview/utils.d.ts.map +1 -1
- package/dist/server/src/register.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 +4 -2
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +3 -2
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- 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/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 -12
- package/dist/_chunks/EditViewPage-C4iTxUPU.js.map +0 -1
- package/dist/_chunks/EditViewPage-CiwVPMaK.mjs.map +0 -1
- package/dist/_chunks/Field-DIjL1b5d.mjs.map +0 -1
- package/dist/_chunks/Field-DhXEK8y1.js.map +0 -1
- package/dist/_chunks/History-BLCCNgCt.js.map +0 -1
- package/dist/_chunks/History-D-99Wh30.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxWpeZrO.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-JPWZz7Kg.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CIQekSFz.js.map +0 -1
- package/dist/_chunks/ListViewPage-DSK3f0ST.mjs.map +0 -1
- package/dist/_chunks/Relations-BBmhcWFV.mjs.map +0 -1
- package/dist/_chunks/Relations-eG-9p_qS.js.map +0 -1
- package/dist/_chunks/index-BIWDoFLK.js.map +0 -1
- package/dist/_chunks/index-BrUzbQ30.mjs.map +0 -1
- package/dist/_chunks/relations-BRHithi8.js.map +0 -1
- package/dist/_chunks/relations-B_VLk-DD.mjs.map +0 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +0 -1
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.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 {
|
@@ -167,8 +166,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
167
166
|
};
|
168
167
|
const getRelationRestoreValue = async (versionRelationData, attribute) => {
|
169
168
|
if (Array.isArray(versionRelationData)) {
|
170
|
-
if (versionRelationData.length === 0)
|
171
|
-
return versionRelationData;
|
169
|
+
if (versionRelationData.length === 0) return versionRelationData;
|
172
170
|
const existingAndMissingRelations = await Promise.all(
|
173
171
|
versionRelationData.map((relation) => {
|
174
172
|
return strapi2.documents(attribute.target).findOne({
|
@@ -177,19 +175,16 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
177
175
|
});
|
178
176
|
})
|
179
177
|
);
|
180
|
-
return existingAndMissingRelations.filter(
|
181
|
-
(relation) => relation !== null
|
182
|
-
);
|
178
|
+
return existingAndMissingRelations.filter((relation) => relation !== null);
|
183
179
|
}
|
184
180
|
return strapi2.documents(attribute.target).findOne({
|
185
181
|
documentId: versionRelationData.documentId,
|
186
182
|
locale: versionRelationData.locale || void 0
|
187
183
|
});
|
188
184
|
};
|
189
|
-
const getMediaRestoreValue = async (versionRelationData
|
190
|
-
if (
|
185
|
+
const getMediaRestoreValue = async (versionRelationData) => {
|
186
|
+
if (Array.isArray(versionRelationData)) {
|
191
187
|
const existingAndMissingMedias = await Promise.all(
|
192
|
-
// @ts-expect-error Fix the type definitions so this isn't any
|
193
188
|
versionRelationData.map((media) => {
|
194
189
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: media.id } });
|
195
190
|
})
|
@@ -203,8 +198,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
203
198
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
199
|
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
205
200
|
const getLocaleDictionary = async () => {
|
206
|
-
if (!localesService)
|
207
|
-
return {};
|
201
|
+
if (!localesService) return {};
|
208
202
|
const locales = await localesService.find() || [];
|
209
203
|
return locales.reduce(
|
210
204
|
(acc, locale) => {
|
@@ -228,6 +222,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
228
222
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
229
223
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
230
224
|
};
|
225
|
+
const getComponentFields = (componentUID) => {
|
226
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
227
|
+
(fieldsAcc, [key, attribute]) => {
|
228
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
229
|
+
fieldsAcc.push(key);
|
230
|
+
}
|
231
|
+
return fieldsAcc;
|
232
|
+
},
|
233
|
+
[]
|
234
|
+
);
|
235
|
+
};
|
231
236
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
232
237
|
const model = strapi2.getModel(uid2);
|
233
238
|
const attributes = Object.entries(model.attributes);
|
@@ -251,13 +256,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
251
256
|
}
|
252
257
|
case "component": {
|
253
258
|
const populate = getDeepPopulate2(attribute.component);
|
254
|
-
acc[attributeName] = {
|
259
|
+
acc[attributeName] = {
|
260
|
+
populate,
|
261
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
262
|
+
};
|
255
263
|
break;
|
256
264
|
}
|
257
265
|
case "dynamiczone": {
|
258
266
|
const populatedComponents = (attribute.components || []).reduce(
|
259
267
|
(acc2, componentUID) => {
|
260
|
-
acc2[componentUID] = {
|
268
|
+
acc2[componentUID] = {
|
269
|
+
populate: getDeepPopulate2(componentUID),
|
270
|
+
[fieldSelector]: getComponentFields(componentUID)
|
271
|
+
};
|
261
272
|
return acc2;
|
262
273
|
},
|
263
274
|
{}
|
@@ -342,8 +353,8 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
342
353
|
});
|
343
354
|
},
|
344
355
|
async findVersionsPage(params) {
|
345
|
-
const
|
346
|
-
const isLocalizedContentType = serviceUtils.isLocalizedContentType(
|
356
|
+
const schema = strapi2.getModel(params.query.contentType);
|
357
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(schema);
|
347
358
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
348
359
|
let locale = null;
|
349
360
|
if (isLocalizedContentType) {
|
@@ -364,32 +375,20 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
364
375
|
}),
|
365
376
|
serviceUtils.getLocaleDictionary()
|
366
377
|
]);
|
367
|
-
const
|
368
|
-
|
369
|
-
async (
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
model: "plugin::upload.file"
|
376
|
-
});
|
377
|
-
const response = await serviceUtils.buildMediaResponse(attributeValues);
|
378
|
-
const sanitizedResults = await Promise.all(
|
379
|
-
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
380
|
-
);
|
381
|
-
return {
|
382
|
-
...await currentDataWithRelations,
|
383
|
-
[attributeKey]: {
|
384
|
-
results: sanitizedResults,
|
385
|
-
meta: response.meta
|
386
|
-
}
|
387
|
-
};
|
378
|
+
const populateEntry = async (entry) => {
|
379
|
+
return strapiUtils.traverseEntity(
|
380
|
+
async (options, utils) => {
|
381
|
+
if (!options.attribute) return;
|
382
|
+
if (!options.value) return;
|
383
|
+
const currentValue = Array.isArray(options.value) ? options.value : [options.value];
|
384
|
+
if (options.attribute.type === "component") {
|
385
|
+
utils.remove("id");
|
388
386
|
}
|
389
|
-
if (
|
390
|
-
|
387
|
+
if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
|
388
|
+
options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
|
389
|
+
if (options.attribute.target === "admin::user") {
|
391
390
|
const adminUsers = await Promise.all(
|
392
|
-
|
391
|
+
currentValue.map((userToPopulate) => {
|
393
392
|
if (userToPopulate == null) {
|
394
393
|
return null;
|
395
394
|
}
|
@@ -401,46 +400,51 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
401
400
|
});
|
402
401
|
})
|
403
402
|
);
|
404
|
-
|
405
|
-
...await currentDataWithRelations,
|
406
|
-
/**
|
407
|
-
* Ideally we would return the same "{results: [], meta: {}}" shape, however,
|
408
|
-
* when sanitizing the data as a whole in the controller before sending to the client,
|
409
|
-
* the data for admin relation user is completely sanitized if we return an object here as opposed to an array.
|
410
|
-
*/
|
411
|
-
[attributeKey]: adminUsers
|
412
|
-
};
|
403
|
+
utils.set(options.key, adminUsers);
|
413
404
|
}
|
414
|
-
const permissionChecker2 = getService$
|
405
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
415
406
|
userAbility: params.state.userAbility,
|
416
|
-
model:
|
407
|
+
model: options.attribute.target
|
417
408
|
});
|
418
409
|
const response = await serviceUtils.buildRelationReponse(
|
419
|
-
|
420
|
-
|
410
|
+
currentValue,
|
411
|
+
options.attribute
|
421
412
|
);
|
422
413
|
const sanitizedResults = await Promise.all(
|
423
414
|
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
424
415
|
);
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
416
|
+
utils.set(options.key, {
|
417
|
+
results: sanitizedResults,
|
418
|
+
meta: response.meta
|
419
|
+
});
|
420
|
+
}
|
421
|
+
if (options.attribute.type === "media") {
|
422
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
423
|
+
userAbility: params.state.userAbility,
|
424
|
+
model: "plugin::upload.file"
|
425
|
+
});
|
426
|
+
const response = await serviceUtils.buildMediaResponse(currentValue);
|
427
|
+
const sanitizedResults = await Promise.all(
|
428
|
+
response.results.map((media) => permissionChecker2.sanitizeOutput(media))
|
429
|
+
);
|
430
|
+
utils.set(options.key, {
|
431
|
+
results: sanitizedResults,
|
432
|
+
meta: response.meta
|
433
|
+
});
|
432
434
|
}
|
433
|
-
return currentDataWithRelations;
|
434
435
|
},
|
435
|
-
|
436
|
+
{
|
437
|
+
schema,
|
438
|
+
getModel: strapi2.getModel.bind(strapi2)
|
439
|
+
},
|
440
|
+
entry.data
|
436
441
|
);
|
437
|
-
return entryWithRelations;
|
438
442
|
};
|
439
443
|
const formattedResults = await Promise.all(
|
440
444
|
results.map(async (result) => {
|
441
445
|
return {
|
442
446
|
...result,
|
443
|
-
data: await
|
447
|
+
data: await populateEntry(result),
|
444
448
|
meta: {
|
445
449
|
unknownAttributes: serviceUtils.getSchemaAttributesDiff(
|
446
450
|
result.schema,
|
@@ -471,30 +475,44 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
471
475
|
// Clone to avoid mutating the original version data
|
472
476
|
structuredClone(version.data)
|
473
477
|
);
|
474
|
-
const
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
478
|
+
const schema = structuredClone(version.schema);
|
479
|
+
schema.attributes = fp.omit(FIELDS_TO_IGNORE, contentTypeSchemaAttributes);
|
480
|
+
const dataWithoutMissingRelations = await strapiUtils.traverseEntity(
|
481
|
+
async (options, utils) => {
|
482
|
+
if (!options.attribute) return;
|
483
|
+
if (options.attribute.type === "component") {
|
484
|
+
utils.remove("id");
|
485
|
+
if (options.attribute.repeatable && options.value === null) {
|
486
|
+
utils.set(options.key, []);
|
487
|
+
}
|
484
488
|
}
|
485
|
-
if (attribute.type === "
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
+
if (options.attribute.type === "dynamiczone") {
|
490
|
+
if (options.value === null) {
|
491
|
+
utils.set(options.key, []);
|
492
|
+
}
|
489
493
|
}
|
490
|
-
if (attribute.type === "
|
491
|
-
|
492
|
-
|
494
|
+
if (options.attribute.type === "relation" && // TODO: handle polymorphic relations
|
495
|
+
options.attribute.relation !== "morphToOne" && options.attribute.relation !== "morphToMany") {
|
496
|
+
if (!options.value) return;
|
497
|
+
const data2 = await serviceUtils.getRelationRestoreValue(
|
498
|
+
options.value,
|
499
|
+
options.attribute
|
500
|
+
);
|
501
|
+
utils.set(options.key, data2);
|
502
|
+
}
|
503
|
+
if (options.attribute.type === "media") {
|
504
|
+
if (!options.value) return;
|
505
|
+
const data2 = await serviceUtils.getMediaRestoreValue(
|
506
|
+
options.value
|
507
|
+
);
|
508
|
+
utils.set(options.key, data2);
|
493
509
|
}
|
494
|
-
return previousRelationAttributes;
|
495
510
|
},
|
496
|
-
|
497
|
-
|
511
|
+
{
|
512
|
+
schema,
|
513
|
+
getModel: strapi2.getModel.bind(strapi2)
|
514
|
+
},
|
515
|
+
dataWithoutAddedAttributes
|
498
516
|
);
|
499
517
|
const data = fp.omit(["id", ...Object.keys(schemaDiff.removed)], dataWithoutMissingRelations);
|
500
518
|
const restoredDocument = await strapi2.documents(version.contentType).update({
|
@@ -587,7 +605,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
587
605
|
onCommit(async () => {
|
588
606
|
for (const entry of localeEntries) {
|
589
607
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
-
await getService(strapi2, "history").createVersion({
|
608
|
+
await getService$1(strapi2, "history").createVersion({
|
591
609
|
contentType: uid2,
|
592
610
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
611
|
relatedDocumentId: documentId,
|
@@ -600,15 +618,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
600
618
|
});
|
601
619
|
return result;
|
602
620
|
});
|
603
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
621
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
604
622
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
605
623
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
606
624
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
607
625
|
where: {
|
608
626
|
created_at: {
|
609
|
-
$lt: expirationDate
|
627
|
+
$lt: expirationDate
|
610
628
|
}
|
611
629
|
}
|
630
|
+
}).catch((error) => {
|
631
|
+
if (error instanceof Error) {
|
632
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
633
|
+
}
|
612
634
|
});
|
613
635
|
});
|
614
636
|
state.isInitialized = true;
|
@@ -702,10 +724,10 @@ const getFeature$1 = () => {
|
|
702
724
|
strapi2.get("models").add(historyVersion);
|
703
725
|
},
|
704
726
|
bootstrap({ strapi: strapi2 }) {
|
705
|
-
getService(strapi2, "lifecycles").bootstrap();
|
727
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
706
728
|
},
|
707
729
|
destroy({ strapi: strapi2 }) {
|
708
|
-
getService(strapi2, "lifecycles").destroy();
|
730
|
+
getService$1(strapi2, "lifecycles").destroy();
|
709
731
|
},
|
710
732
|
controllers: controllers$2,
|
711
733
|
services: services$2,
|
@@ -719,14 +741,6 @@ const getFeature$1 = () => {
|
|
719
741
|
};
|
720
742
|
};
|
721
743
|
const history = getFeature$1();
|
722
|
-
const register = async ({ strapi: strapi2 }) => {
|
723
|
-
await history.register?.({ strapi: strapi2 });
|
724
|
-
};
|
725
|
-
const ALLOWED_WEBHOOK_EVENTS = {
|
726
|
-
ENTRY_PUBLISH: "entry.publish",
|
727
|
-
ENTRY_UNPUBLISH: "entry.unpublish"
|
728
|
-
};
|
729
|
-
const FEATURE_ID = "preview";
|
730
744
|
const info = { pluginName: "content-manager", type: "admin" };
|
731
745
|
const previewRouter = {
|
732
746
|
type: "admin",
|
@@ -735,7 +749,7 @@ const previewRouter = {
|
|
735
749
|
method: "GET",
|
736
750
|
info,
|
737
751
|
path: "/preview/url/:contentType",
|
738
|
-
handler: "preview.
|
752
|
+
handler: "preview.getPreviewUrl",
|
739
753
|
config: {
|
740
754
|
policies: ["admin::isAuthenticatedAdmin"]
|
741
755
|
}
|
@@ -745,12 +759,56 @@ const previewRouter = {
|
|
745
759
|
const routes$1 = {
|
746
760
|
preview: previewRouter
|
747
761
|
};
|
762
|
+
function getService(strapi2, name) {
|
763
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
764
|
+
}
|
765
|
+
const getPreviewUrlSchema = yup__namespace.object().shape({
|
766
|
+
// Will be undefined for single types
|
767
|
+
documentId: yup__namespace.string(),
|
768
|
+
locale: yup__namespace.string().nullable(),
|
769
|
+
status: yup__namespace.string()
|
770
|
+
}).required();
|
771
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
772
|
+
await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
|
773
|
+
const newParams = fp.pick(["documentId", "locale", "status"], params);
|
774
|
+
const model = strapi2.getModel(uid2);
|
775
|
+
if (!model || model.modelType !== "contentType") {
|
776
|
+
throw new strapiUtils.errors.ValidationError("Invalid content type");
|
777
|
+
}
|
778
|
+
const isSingleType = model?.kind === "singleType";
|
779
|
+
if (!isSingleType && !params.documentId) {
|
780
|
+
throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
|
781
|
+
}
|
782
|
+
if (isSingleType) {
|
783
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
784
|
+
if (!doc) {
|
785
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
786
|
+
}
|
787
|
+
newParams.documentId = doc?.documentId;
|
788
|
+
}
|
789
|
+
if (!newParams.status) {
|
790
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
791
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
792
|
+
}
|
793
|
+
return newParams;
|
794
|
+
};
|
748
795
|
const createPreviewController = () => {
|
749
796
|
return {
|
750
|
-
|
751
|
-
|
797
|
+
/**
|
798
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
799
|
+
* in the Content Manager.
|
800
|
+
*/
|
801
|
+
async getPreviewUrl(ctx) {
|
802
|
+
const uid2 = ctx.params.contentType;
|
803
|
+
const query = ctx.request.query;
|
804
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
805
|
+
const previewService = getService(strapi, "preview");
|
806
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
807
|
+
if (!url) {
|
808
|
+
ctx.status = 204;
|
809
|
+
}
|
752
810
|
return {
|
753
|
-
data: { url
|
811
|
+
data: { url }
|
754
812
|
};
|
755
813
|
}
|
756
814
|
};
|
@@ -762,19 +820,111 @@ const controllers$1 = {
|
|
762
820
|
* passing a controller factory as the value, instead of a controller object directly
|
763
821
|
*/
|
764
822
|
};
|
765
|
-
const createPreviewService = () => {
|
823
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
824
|
+
const config = getService(strapi2, "preview-config");
|
825
|
+
return {
|
826
|
+
async getPreviewUrl(uid2, params) {
|
827
|
+
const handler = config.getPreviewHandler();
|
828
|
+
try {
|
829
|
+
return handler(uid2, params);
|
830
|
+
} catch (error) {
|
831
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
832
|
+
throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
|
833
|
+
}
|
834
|
+
return;
|
835
|
+
}
|
836
|
+
};
|
837
|
+
};
|
838
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
839
|
+
const middlewares = strapi.config.get("middlewares");
|
840
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
841
|
+
if (currentMiddleware === middleware.name) {
|
842
|
+
return middleware;
|
843
|
+
}
|
844
|
+
if (currentMiddleware.name === middleware.name) {
|
845
|
+
return fp.mergeWith(
|
846
|
+
(objValue, srcValue) => {
|
847
|
+
if (Array.isArray(objValue)) {
|
848
|
+
return objValue.concat(srcValue);
|
849
|
+
}
|
850
|
+
return void 0;
|
851
|
+
},
|
852
|
+
currentMiddleware,
|
853
|
+
middleware
|
854
|
+
);
|
855
|
+
}
|
856
|
+
return currentMiddleware;
|
857
|
+
});
|
858
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
859
|
+
};
|
860
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
861
|
+
return {
|
862
|
+
register() {
|
863
|
+
if (!this.isEnabled()) {
|
864
|
+
return;
|
865
|
+
}
|
866
|
+
const config = strapi2.config.get("admin.preview");
|
867
|
+
if (config.config?.allowedOrigins) {
|
868
|
+
extendMiddlewareConfiguration({
|
869
|
+
name: "strapi::security",
|
870
|
+
config: {
|
871
|
+
contentSecurityPolicy: {
|
872
|
+
directives: {
|
873
|
+
"frame-src": config.config.allowedOrigins
|
874
|
+
}
|
875
|
+
}
|
876
|
+
}
|
877
|
+
});
|
878
|
+
}
|
879
|
+
},
|
880
|
+
isEnabled() {
|
881
|
+
const config = strapi2.config.get("admin.preview");
|
882
|
+
if (!config) {
|
883
|
+
return false;
|
884
|
+
}
|
885
|
+
return config?.enabled ?? true;
|
886
|
+
},
|
887
|
+
/**
|
888
|
+
* Validate if the configuration is valid
|
889
|
+
*/
|
890
|
+
validate() {
|
891
|
+
if (!this.isEnabled()) {
|
892
|
+
return;
|
893
|
+
}
|
894
|
+
const handler = this.getPreviewHandler();
|
895
|
+
if (typeof handler !== "function") {
|
896
|
+
throw new strapiUtils.errors.ValidationError(
|
897
|
+
"Preview configuration is invalid. Handler must be a function"
|
898
|
+
);
|
899
|
+
}
|
900
|
+
},
|
901
|
+
/**
|
902
|
+
* Utility to get the preview handler from the configuration
|
903
|
+
*/
|
904
|
+
getPreviewHandler() {
|
905
|
+
const config = strapi2.config.get("admin.preview");
|
906
|
+
const emptyHandler = () => {
|
907
|
+
return void 0;
|
908
|
+
};
|
909
|
+
if (!this.isEnabled()) {
|
910
|
+
return emptyHandler;
|
911
|
+
}
|
912
|
+
return config?.config?.handler || emptyHandler;
|
913
|
+
}
|
914
|
+
};
|
766
915
|
};
|
767
916
|
const services$1 = {
|
768
|
-
preview: createPreviewService
|
917
|
+
preview: createPreviewService,
|
918
|
+
"preview-config": createPreviewConfigService
|
769
919
|
};
|
770
920
|
const getFeature = () => {
|
771
|
-
if (!strapi.features.future.isEnabled(FEATURE_ID)) {
|
772
|
-
return {};
|
773
|
-
}
|
774
921
|
return {
|
922
|
+
register() {
|
923
|
+
const config = getService(strapi, "preview-config");
|
924
|
+
config.validate();
|
925
|
+
config.register();
|
926
|
+
},
|
775
927
|
bootstrap() {
|
776
|
-
console.log("Bootstrapping preview server");
|
777
|
-
strapi.config.get("admin.preview");
|
778
928
|
},
|
779
929
|
routes: routes$1,
|
780
930
|
controllers: controllers$1,
|
@@ -782,14 +932,22 @@ const getFeature = () => {
|
|
782
932
|
};
|
783
933
|
};
|
784
934
|
const preview = getFeature();
|
935
|
+
const register = async ({ strapi: strapi2 }) => {
|
936
|
+
await history.register?.({ strapi: strapi2 });
|
937
|
+
await preview.register?.({ strapi: strapi2 });
|
938
|
+
};
|
939
|
+
const ALLOWED_WEBHOOK_EVENTS = {
|
940
|
+
ENTRY_PUBLISH: "entry.publish",
|
941
|
+
ENTRY_UNPUBLISH: "entry.unpublish"
|
942
|
+
};
|
785
943
|
const bootstrap = async () => {
|
786
944
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
787
945
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
788
946
|
});
|
789
|
-
getService$
|
790
|
-
await getService$
|
791
|
-
await getService$
|
792
|
-
await getService$
|
947
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
948
|
+
await getService$2("components").syncConfigurations();
|
949
|
+
await getService$2("content-types").syncConfigurations();
|
950
|
+
await getService$2("permission").registerPermissions();
|
793
951
|
await history.bootstrap?.({ strapi });
|
794
952
|
await preview.bootstrap?.({ strapi });
|
795
953
|
};
|
@@ -1345,8 +1503,7 @@ const isSortable = (schema, name) => {
|
|
1345
1503
|
if (!___default.default.has(schema.attributes, name)) {
|
1346
1504
|
return false;
|
1347
1505
|
}
|
1348
|
-
if (schema.modelType === "component" && name === "id")
|
1349
|
-
return false;
|
1506
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1350
1507
|
const attribute = schema.attributes[name];
|
1351
1508
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1352
1509
|
return false;
|
@@ -1491,8 +1648,7 @@ const createDefaultSettings = async (schema) => {
|
|
1491
1648
|
};
|
1492
1649
|
};
|
1493
1650
|
const syncSettings = async (configuration, schema) => {
|
1494
|
-
if (fp.isEmpty(configuration.settings))
|
1495
|
-
return createDefaultSettings(schema);
|
1651
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1496
1652
|
const defaultField = getDefaultMainField(schema);
|
1497
1653
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1498
1654
|
return {
|
@@ -1539,7 +1695,7 @@ const createMetadasSchema = (schema) => {
|
|
1539
1695
|
if (!value) {
|
1540
1696
|
return strapiUtils.yup.string();
|
1541
1697
|
}
|
1542
|
-
const targetSchema = getService$
|
1698
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1543
1699
|
schema.attributes[key].targetModel
|
1544
1700
|
);
|
1545
1701
|
if (!targetSchema) {
|
@@ -1668,8 +1824,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1668
1824
|
}
|
1669
1825
|
switch (attribute.type) {
|
1670
1826
|
case "relation": {
|
1671
|
-
if (canCreate(attributePath))
|
1672
|
-
return body2;
|
1827
|
+
if (canCreate(attributePath)) return body2;
|
1673
1828
|
return fp.set(attributePath, { set: [] }, body2);
|
1674
1829
|
}
|
1675
1830
|
case "component": {
|
@@ -1679,8 +1834,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1679
1834
|
]);
|
1680
1835
|
}
|
1681
1836
|
default: {
|
1682
|
-
if (canCreate(attributePath))
|
1683
|
-
return body2;
|
1837
|
+
if (canCreate(attributePath)) return body2;
|
1684
1838
|
return fp.set(attributePath, null, body2);
|
1685
1839
|
}
|
1686
1840
|
}
|
@@ -1708,7 +1862,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1708
1862
|
}
|
1709
1863
|
};
|
1710
1864
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1711
|
-
const documentMetadata2 = getService$
|
1865
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1712
1866
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1713
1867
|
let {
|
1714
1868
|
meta: { availableLocales, availableStatus }
|
@@ -1734,8 +1888,8 @@ const createDocument = async (ctx, opts) => {
|
|
1734
1888
|
const { userAbility, user } = ctx.state;
|
1735
1889
|
const { model } = ctx.params;
|
1736
1890
|
const { body } = ctx.request;
|
1737
|
-
const documentManager2 = getService$
|
1738
|
-
const permissionChecker2 = getService$
|
1891
|
+
const documentManager2 = getService$2("document-manager");
|
1892
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1739
1893
|
if (permissionChecker2.cannot.create()) {
|
1740
1894
|
throw new strapiUtils.errors.ForbiddenError();
|
1741
1895
|
}
|
@@ -1755,13 +1909,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1755
1909
|
const { userAbility, user } = ctx.state;
|
1756
1910
|
const { id, model } = ctx.params;
|
1757
1911
|
const { body } = ctx.request;
|
1758
|
-
const documentManager2 = getService$
|
1759
|
-
const permissionChecker2 = getService$
|
1912
|
+
const documentManager2 = getService$2("document-manager");
|
1913
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1760
1914
|
if (permissionChecker2.cannot.update()) {
|
1761
1915
|
throw new strapiUtils.errors.ForbiddenError();
|
1762
1916
|
}
|
1763
1917
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1764
|
-
const populate = await getService$
|
1918
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1765
1919
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1766
1920
|
const [documentVersion, documentExists] = await Promise.all([
|
1767
1921
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1792,14 +1946,14 @@ const collectionTypes = {
|
|
1792
1946
|
const { userAbility } = ctx.state;
|
1793
1947
|
const { model } = ctx.params;
|
1794
1948
|
const { query } = ctx.request;
|
1795
|
-
const documentMetadata2 = getService$
|
1796
|
-
const documentManager2 = getService$
|
1797
|
-
const permissionChecker2 = getService$
|
1949
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1950
|
+
const documentManager2 = getService$2("document-manager");
|
1951
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1798
1952
|
if (permissionChecker2.cannot.read()) {
|
1799
1953
|
return ctx.forbidden();
|
1800
1954
|
}
|
1801
1955
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1802
|
-
const populate = await getService$
|
1956
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1803
1957
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1804
1958
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1805
1959
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1828,13 +1982,13 @@ const collectionTypes = {
|
|
1828
1982
|
async findOne(ctx) {
|
1829
1983
|
const { userAbility } = ctx.state;
|
1830
1984
|
const { model, id } = ctx.params;
|
1831
|
-
const documentManager2 = getService$
|
1832
|
-
const permissionChecker2 = getService$
|
1985
|
+
const documentManager2 = getService$2("document-manager");
|
1986
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1833
1987
|
if (permissionChecker2.cannot.read()) {
|
1834
1988
|
return ctx.forbidden();
|
1835
1989
|
}
|
1836
1990
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1837
|
-
const populate = await getService$
|
1991
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1838
1992
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1839
1993
|
const version = await documentManager2.findOne(id, model, {
|
1840
1994
|
populate,
|
@@ -1865,7 +2019,7 @@ const collectionTypes = {
|
|
1865
2019
|
async create(ctx) {
|
1866
2020
|
const { userAbility } = ctx.state;
|
1867
2021
|
const { model } = ctx.params;
|
1868
|
-
const permissionChecker2 = getService$
|
2022
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1869
2023
|
const [totalEntries, document] = await Promise.all([
|
1870
2024
|
strapi.db.query(model).count(),
|
1871
2025
|
createDocument(ctx)
|
@@ -1886,7 +2040,7 @@ const collectionTypes = {
|
|
1886
2040
|
async update(ctx) {
|
1887
2041
|
const { userAbility } = ctx.state;
|
1888
2042
|
const { model } = ctx.params;
|
1889
|
-
const permissionChecker2 = getService$
|
2043
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1890
2044
|
const updatedVersion = await updateDocument(ctx);
|
1891
2045
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1892
2046
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1895,13 +2049,13 @@ const collectionTypes = {
|
|
1895
2049
|
const { userAbility, user } = ctx.state;
|
1896
2050
|
const { model, sourceId: id } = ctx.params;
|
1897
2051
|
const { body } = ctx.request;
|
1898
|
-
const documentManager2 = getService$
|
1899
|
-
const permissionChecker2 = getService$
|
2052
|
+
const documentManager2 = getService$2("document-manager");
|
2053
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1900
2054
|
if (permissionChecker2.cannot.create()) {
|
1901
2055
|
return ctx.forbidden();
|
1902
2056
|
}
|
1903
2057
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1904
|
-
const populate = await getService$
|
2058
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1905
2059
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1906
2060
|
const document = await documentManager2.findOne(id, model, {
|
1907
2061
|
populate,
|
@@ -1940,13 +2094,13 @@ const collectionTypes = {
|
|
1940
2094
|
async delete(ctx) {
|
1941
2095
|
const { userAbility } = ctx.state;
|
1942
2096
|
const { id, model } = ctx.params;
|
1943
|
-
const documentManager2 = getService$
|
1944
|
-
const permissionChecker2 = getService$
|
2097
|
+
const documentManager2 = getService$2("document-manager");
|
2098
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1945
2099
|
if (permissionChecker2.cannot.delete()) {
|
1946
2100
|
return ctx.forbidden();
|
1947
2101
|
}
|
1948
2102
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1949
|
-
const populate = await getService$
|
2103
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1950
2104
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1951
2105
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1952
2106
|
if (documentLocales.length === 0) {
|
@@ -1968,14 +2122,14 @@ const collectionTypes = {
|
|
1968
2122
|
const { userAbility } = ctx.state;
|
1969
2123
|
const { id, model } = ctx.params;
|
1970
2124
|
const { body } = ctx.request;
|
1971
|
-
const documentManager2 = getService$
|
1972
|
-
const permissionChecker2 = getService$
|
2125
|
+
const documentManager2 = getService$2("document-manager");
|
2126
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1973
2127
|
if (permissionChecker2.cannot.publish()) {
|
1974
2128
|
return ctx.forbidden();
|
1975
2129
|
}
|
1976
2130
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1977
2131
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1978
|
-
const populate = await getService$
|
2132
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1979
2133
|
let document;
|
1980
2134
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1981
2135
|
const isCreate = fp.isNil(id);
|
@@ -2023,13 +2177,13 @@ const collectionTypes = {
|
|
2023
2177
|
const { body } = ctx.request;
|
2024
2178
|
const { documentIds } = body;
|
2025
2179
|
await validateBulkActionInput(body);
|
2026
|
-
const documentManager2 = getService$
|
2027
|
-
const permissionChecker2 = getService$
|
2180
|
+
const documentManager2 = getService$2("document-manager");
|
2181
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2028
2182
|
if (permissionChecker2.cannot.publish()) {
|
2029
2183
|
return ctx.forbidden();
|
2030
2184
|
}
|
2031
2185
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
2032
|
-
const populate = await getService$
|
2186
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
2033
2187
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2034
2188
|
allowMultipleLocales: true
|
2035
2189
|
});
|
@@ -2054,8 +2208,8 @@ const collectionTypes = {
|
|
2054
2208
|
const { body } = ctx.request;
|
2055
2209
|
const { documentIds } = body;
|
2056
2210
|
await validateBulkActionInput(body);
|
2057
|
-
const documentManager2 = getService$
|
2058
|
-
const permissionChecker2 = getService$
|
2211
|
+
const documentManager2 = getService$2("document-manager");
|
2212
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2059
2213
|
if (permissionChecker2.cannot.unpublish()) {
|
2060
2214
|
return ctx.forbidden();
|
2061
2215
|
}
|
@@ -2084,8 +2238,8 @@ const collectionTypes = {
|
|
2084
2238
|
const {
|
2085
2239
|
body: { discardDraft, ...body }
|
2086
2240
|
} = ctx.request;
|
2087
|
-
const documentManager2 = getService$
|
2088
|
-
const permissionChecker2 = getService$
|
2241
|
+
const documentManager2 = getService$2("document-manager");
|
2242
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2089
2243
|
if (permissionChecker2.cannot.unpublish()) {
|
2090
2244
|
return ctx.forbidden();
|
2091
2245
|
}
|
@@ -2093,7 +2247,7 @@ const collectionTypes = {
|
|
2093
2247
|
return ctx.forbidden();
|
2094
2248
|
}
|
2095
2249
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2096
|
-
const populate = await getService$
|
2250
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2097
2251
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2098
2252
|
const document = await documentManager2.findOne(id, model, {
|
2099
2253
|
populate,
|
@@ -2124,13 +2278,13 @@ const collectionTypes = {
|
|
2124
2278
|
const { userAbility } = ctx.state;
|
2125
2279
|
const { id, model } = ctx.params;
|
2126
2280
|
const { body } = ctx.request;
|
2127
|
-
const documentManager2 = getService$
|
2128
|
-
const permissionChecker2 = getService$
|
2281
|
+
const documentManager2 = getService$2("document-manager");
|
2282
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2129
2283
|
if (permissionChecker2.cannot.discard()) {
|
2130
2284
|
return ctx.forbidden();
|
2131
2285
|
}
|
2132
2286
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2133
|
-
const populate = await getService$
|
2287
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2134
2288
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2135
2289
|
const document = await documentManager2.findOne(id, model, {
|
2136
2290
|
populate,
|
@@ -2155,13 +2309,13 @@ const collectionTypes = {
|
|
2155
2309
|
const { query, body } = ctx.request;
|
2156
2310
|
const { documentIds } = body;
|
2157
2311
|
await validateBulkActionInput(body);
|
2158
|
-
const documentManager2 = getService$
|
2159
|
-
const permissionChecker2 = getService$
|
2312
|
+
const documentManager2 = getService$2("document-manager");
|
2313
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2160
2314
|
if (permissionChecker2.cannot.delete()) {
|
2161
2315
|
return ctx.forbidden();
|
2162
2316
|
}
|
2163
2317
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2164
|
-
const populate = await getService$
|
2318
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2165
2319
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2166
2320
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2167
2321
|
populate,
|
@@ -2182,13 +2336,13 @@ const collectionTypes = {
|
|
2182
2336
|
async countDraftRelations(ctx) {
|
2183
2337
|
const { userAbility } = ctx.state;
|
2184
2338
|
const { model, id } = ctx.params;
|
2185
|
-
const documentManager2 = getService$
|
2186
|
-
const permissionChecker2 = getService$
|
2339
|
+
const documentManager2 = getService$2("document-manager");
|
2340
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2187
2341
|
if (permissionChecker2.cannot.read()) {
|
2188
2342
|
return ctx.forbidden();
|
2189
2343
|
}
|
2190
2344
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2191
|
-
const populate = await getService$
|
2345
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2192
2346
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2193
2347
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2194
2348
|
if (!entity) {
|
@@ -2207,8 +2361,8 @@ const collectionTypes = {
|
|
2207
2361
|
const ids = ctx.request.query.documentIds;
|
2208
2362
|
const locale = ctx.request.query.locale;
|
2209
2363
|
const { model } = ctx.params;
|
2210
|
-
const documentManager2 = getService$
|
2211
|
-
const permissionChecker2 = getService$
|
2364
|
+
const documentManager2 = getService$2("document-manager");
|
2365
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2212
2366
|
if (permissionChecker2.cannot.read()) {
|
2213
2367
|
return ctx.forbidden();
|
2214
2368
|
}
|
@@ -2232,13 +2386,13 @@ const collectionTypes = {
|
|
2232
2386
|
};
|
2233
2387
|
const components$1 = {
|
2234
2388
|
findComponents(ctx) {
|
2235
|
-
const components2 = getService$
|
2236
|
-
const { toDto } = getService$
|
2389
|
+
const components2 = getService$2("components").findAllComponents();
|
2390
|
+
const { toDto } = getService$2("data-mapper");
|
2237
2391
|
ctx.body = { data: components2.map(toDto) };
|
2238
2392
|
},
|
2239
2393
|
async findComponentConfiguration(ctx) {
|
2240
2394
|
const { uid: uid2 } = ctx.params;
|
2241
|
-
const componentService = getService$
|
2395
|
+
const componentService = getService$2("components");
|
2242
2396
|
const component = componentService.findComponent(uid2);
|
2243
2397
|
if (!component) {
|
2244
2398
|
return ctx.notFound("component.notFound");
|
@@ -2255,7 +2409,7 @@ const components$1 = {
|
|
2255
2409
|
async updateComponentConfiguration(ctx) {
|
2256
2410
|
const { uid: uid2 } = ctx.params;
|
2257
2411
|
const { body } = ctx.request;
|
2258
|
-
const componentService = getService$
|
2412
|
+
const componentService = getService$2("components");
|
2259
2413
|
const component = componentService.findComponent(uid2);
|
2260
2414
|
if (!component) {
|
2261
2415
|
return ctx.notFound("component.notFound");
|
@@ -2289,12 +2443,12 @@ const contentTypes = {
|
|
2289
2443
|
} catch (error) {
|
2290
2444
|
return ctx.send({ error }, 400);
|
2291
2445
|
}
|
2292
|
-
const contentTypes2 = getService$
|
2293
|
-
const { toDto } = getService$
|
2446
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2447
|
+
const { toDto } = getService$2("data-mapper");
|
2294
2448
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2295
2449
|
},
|
2296
2450
|
async findContentTypesSettings(ctx) {
|
2297
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2451
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2298
2452
|
const contentTypes2 = await findAllContentTypes();
|
2299
2453
|
const configurations = await Promise.all(
|
2300
2454
|
contentTypes2.map(async (contentType) => {
|
@@ -2308,7 +2462,7 @@ const contentTypes = {
|
|
2308
2462
|
},
|
2309
2463
|
async findContentTypeConfiguration(ctx) {
|
2310
2464
|
const { uid: uid2 } = ctx.params;
|
2311
|
-
const contentTypeService = getService$
|
2465
|
+
const contentTypeService = getService$2("content-types");
|
2312
2466
|
const contentType = await contentTypeService.findContentType(uid2);
|
2313
2467
|
if (!contentType) {
|
2314
2468
|
return ctx.notFound("contentType.notFound");
|
@@ -2330,13 +2484,13 @@ const contentTypes = {
|
|
2330
2484
|
const { userAbility } = ctx.state;
|
2331
2485
|
const { uid: uid2 } = ctx.params;
|
2332
2486
|
const { body } = ctx.request;
|
2333
|
-
const contentTypeService = getService$
|
2334
|
-
const metricsService = getService$
|
2487
|
+
const contentTypeService = getService$2("content-types");
|
2488
|
+
const metricsService = getService$2("metrics");
|
2335
2489
|
const contentType = await contentTypeService.findContentType(uid2);
|
2336
2490
|
if (!contentType) {
|
2337
2491
|
return ctx.notFound("contentType.notFound");
|
2338
2492
|
}
|
2339
|
-
if (!getService$
|
2493
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2340
2494
|
return ctx.forbidden();
|
2341
2495
|
}
|
2342
2496
|
let input;
|
@@ -2369,10 +2523,10 @@ const contentTypes = {
|
|
2369
2523
|
};
|
2370
2524
|
const init = {
|
2371
2525
|
getInitData(ctx) {
|
2372
|
-
const { toDto } = getService$
|
2373
|
-
const { findAllComponents } = getService$
|
2374
|
-
const { getAllFieldSizes } = getService$
|
2375
|
-
const { findAllContentTypes } = getService$
|
2526
|
+
const { toDto } = getService$2("data-mapper");
|
2527
|
+
const { findAllComponents } = getService$2("components");
|
2528
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2529
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2376
2530
|
ctx.body = {
|
2377
2531
|
data: {
|
2378
2532
|
fieldSizes: getAllFieldSizes(),
|
@@ -2408,7 +2562,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2408
2562
|
params.filters.$and.push(filtersClause);
|
2409
2563
|
};
|
2410
2564
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2411
|
-
const permissionChecker2 = getService$
|
2565
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2412
2566
|
userAbility,
|
2413
2567
|
model: model.uid
|
2414
2568
|
});
|
@@ -2426,7 +2580,7 @@ const addStatusToRelations = async (targetUid, relations2) => {
|
|
2426
2580
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2427
2581
|
return relations2;
|
2428
2582
|
}
|
2429
|
-
const documentMetadata2 = getService$
|
2583
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2430
2584
|
if (!relations2.length) {
|
2431
2585
|
return relations2;
|
2432
2586
|
}
|
@@ -2473,8 +2627,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2473
2627
|
const sourceModel = strapi.getModel(sourceUid);
|
2474
2628
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2475
2629
|
const isSourceDP = isDP(sourceModel);
|
2476
|
-
if (!isSourceDP)
|
2477
|
-
return { status: void 0 };
|
2630
|
+
if (!isSourceDP) return { status: void 0 };
|
2478
2631
|
switch (status) {
|
2479
2632
|
case "published":
|
2480
2633
|
return { status: "published" };
|
@@ -2504,7 +2657,7 @@ const relations = {
|
|
2504
2657
|
ctx.request?.query?.locale
|
2505
2658
|
);
|
2506
2659
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2507
|
-
const permissionChecker2 = getService$
|
2660
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2508
2661
|
userAbility,
|
2509
2662
|
model
|
2510
2663
|
});
|
@@ -2529,7 +2682,7 @@ const relations = {
|
|
2529
2682
|
where.id = id;
|
2530
2683
|
}
|
2531
2684
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2532
|
-
const populate = await getService$
|
2685
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2533
2686
|
const currentEntity = await strapi.db.query(model).findOne({
|
2534
2687
|
where,
|
2535
2688
|
populate
|
@@ -2544,7 +2697,7 @@ const relations = {
|
|
2544
2697
|
}
|
2545
2698
|
entryId = currentEntity.id;
|
2546
2699
|
}
|
2547
|
-
const modelConfig = isComponent2 ? await getService$
|
2700
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2548
2701
|
const targetSchema = strapi.getModel(targetUid);
|
2549
2702
|
const mainField = fp.flow(
|
2550
2703
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2598,7 +2751,7 @@ const relations = {
|
|
2598
2751
|
}
|
2599
2752
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2600
2753
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2601
|
-
const permissionChecker2 = getService$
|
2754
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2602
2755
|
userAbility: ctx.state.userAbility,
|
2603
2756
|
model: targetUid
|
2604
2757
|
});
|
@@ -2677,7 +2830,7 @@ const relations = {
|
|
2677
2830
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2678
2831
|
const { uid: sourceUid } = sourceSchema;
|
2679
2832
|
const { uid: targetUid } = targetSchema;
|
2680
|
-
const permissionQuery = await getService$
|
2833
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2681
2834
|
const dbQuery = strapi.db.query(sourceUid);
|
2682
2835
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2683
2836
|
const filters = {};
|
@@ -2718,10 +2871,10 @@ const relations = {
|
|
2718
2871
|
}
|
2719
2872
|
};
|
2720
2873
|
const buildPopulateFromQuery = async (query, model) => {
|
2721
|
-
return getService$
|
2874
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2722
2875
|
};
|
2723
2876
|
const findDocument = async (query, uid2, opts = {}) => {
|
2724
|
-
const documentManager2 = getService$
|
2877
|
+
const documentManager2 = getService$2("document-manager");
|
2725
2878
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2726
2879
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2727
2880
|
};
|
@@ -2729,8 +2882,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2729
2882
|
const { user, userAbility } = ctx.state;
|
2730
2883
|
const { model } = ctx.params;
|
2731
2884
|
const { body, query } = ctx.request;
|
2732
|
-
const documentManager2 = getService$
|
2733
|
-
const permissionChecker2 = getService$
|
2885
|
+
const documentManager2 = getService$2("document-manager");
|
2886
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2734
2887
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2735
2888
|
throw new strapiUtils.errors.ForbiddenError();
|
2736
2889
|
}
|
@@ -2771,7 +2924,7 @@ const singleTypes = {
|
|
2771
2924
|
const { userAbility } = ctx.state;
|
2772
2925
|
const { model } = ctx.params;
|
2773
2926
|
const { query = {} } = ctx.request;
|
2774
|
-
const permissionChecker2 = getService$
|
2927
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2775
2928
|
if (permissionChecker2.cannot.read()) {
|
2776
2929
|
return ctx.forbidden();
|
2777
2930
|
}
|
@@ -2805,7 +2958,7 @@ const singleTypes = {
|
|
2805
2958
|
async createOrUpdate(ctx) {
|
2806
2959
|
const { userAbility } = ctx.state;
|
2807
2960
|
const { model } = ctx.params;
|
2808
|
-
const permissionChecker2 = getService$
|
2961
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2809
2962
|
const document = await createOrUpdateDocument(ctx);
|
2810
2963
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2811
2964
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2814,8 +2967,8 @@ const singleTypes = {
|
|
2814
2967
|
const { userAbility } = ctx.state;
|
2815
2968
|
const { model } = ctx.params;
|
2816
2969
|
const { query = {} } = ctx.request;
|
2817
|
-
const documentManager2 = getService$
|
2818
|
-
const permissionChecker2 = getService$
|
2970
|
+
const documentManager2 = getService$2("document-manager");
|
2971
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2819
2972
|
if (permissionChecker2.cannot.delete()) {
|
2820
2973
|
return ctx.forbidden();
|
2821
2974
|
}
|
@@ -2843,8 +2996,8 @@ const singleTypes = {
|
|
2843
2996
|
const { userAbility } = ctx.state;
|
2844
2997
|
const { model } = ctx.params;
|
2845
2998
|
const { query = {} } = ctx.request;
|
2846
|
-
const documentManager2 = getService$
|
2847
|
-
const permissionChecker2 = getService$
|
2999
|
+
const documentManager2 = getService$2("document-manager");
|
3000
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2848
3001
|
if (permissionChecker2.cannot.publish()) {
|
2849
3002
|
return ctx.forbidden();
|
2850
3003
|
}
|
@@ -2872,8 +3025,8 @@ const singleTypes = {
|
|
2872
3025
|
body: { discardDraft, ...body },
|
2873
3026
|
query = {}
|
2874
3027
|
} = ctx.request;
|
2875
|
-
const documentManager2 = getService$
|
2876
|
-
const permissionChecker2 = getService$
|
3028
|
+
const documentManager2 = getService$2("document-manager");
|
3029
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2877
3030
|
if (permissionChecker2.cannot.unpublish()) {
|
2878
3031
|
return ctx.forbidden();
|
2879
3032
|
}
|
@@ -2907,8 +3060,8 @@ const singleTypes = {
|
|
2907
3060
|
const { userAbility } = ctx.state;
|
2908
3061
|
const { model } = ctx.params;
|
2909
3062
|
const { body, query = {} } = ctx.request;
|
2910
|
-
const documentManager2 = getService$
|
2911
|
-
const permissionChecker2 = getService$
|
3063
|
+
const documentManager2 = getService$2("document-manager");
|
3064
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2912
3065
|
if (permissionChecker2.cannot.discard()) {
|
2913
3066
|
return ctx.forbidden();
|
2914
3067
|
}
|
@@ -2931,8 +3084,8 @@ const singleTypes = {
|
|
2931
3084
|
const { userAbility } = ctx.state;
|
2932
3085
|
const { model } = ctx.params;
|
2933
3086
|
const { query } = ctx.request;
|
2934
|
-
const documentManager2 = getService$
|
2935
|
-
const permissionChecker2 = getService$
|
3087
|
+
const documentManager2 = getService$2("document-manager");
|
3088
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2936
3089
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2937
3090
|
if (permissionChecker2.cannot.read()) {
|
2938
3091
|
return ctx.forbidden();
|
@@ -2956,7 +3109,7 @@ const uid$1 = {
|
|
2956
3109
|
const { query = {} } = ctx.request;
|
2957
3110
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2958
3111
|
await validateUIDField(contentTypeUID, field);
|
2959
|
-
const uidService = getService$
|
3112
|
+
const uidService = getService$2("uid");
|
2960
3113
|
ctx.body = {
|
2961
3114
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2962
3115
|
};
|
@@ -2968,7 +3121,7 @@ const uid$1 = {
|
|
2968
3121
|
const { query = {} } = ctx.request;
|
2969
3122
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2970
3123
|
await validateUIDField(contentTypeUID, field);
|
2971
|
-
const uidService = getService$
|
3124
|
+
const uidService = getService$2("uid");
|
2972
3125
|
const isAvailable = await uidService.checkUIDAvailability({
|
2973
3126
|
contentTypeUID,
|
2974
3127
|
field,
|
@@ -3119,18 +3272,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3119
3272
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3120
3273
|
___default.default.set(acc, [key], updatedMeta);
|
3121
3274
|
}
|
3122
|
-
if (!___default.default.has(edit, "mainField"))
|
3123
|
-
return acc;
|
3275
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3124
3276
|
if (!isRelation$1(attr)) {
|
3125
3277
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3126
3278
|
___default.default.set(acc, [key], updatedMeta);
|
3127
3279
|
return acc;
|
3128
3280
|
}
|
3129
|
-
if (edit.mainField === "id")
|
3130
|
-
return acc;
|
3281
|
+
if (edit.mainField === "id") return acc;
|
3131
3282
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3132
|
-
if (!targetSchema)
|
3133
|
-
return acc;
|
3283
|
+
if (!targetSchema) return acc;
|
3134
3284
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3135
3285
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3136
3286
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3141,12 +3291,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3141
3291
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3142
3292
|
}
|
3143
3293
|
const getTargetSchema = (targetModel) => {
|
3144
|
-
return getService$
|
3294
|
+
return getService$2("content-types").findContentType(targetModel);
|
3145
3295
|
};
|
3146
3296
|
const DEFAULT_LIST_LENGTH = 4;
|
3147
3297
|
const MAX_ROW_SIZE = 12;
|
3148
3298
|
const isAllowedFieldSize = (type, size) => {
|
3149
|
-
const { getFieldSize } = getService$
|
3299
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3150
3300
|
const fieldSize = getFieldSize(type);
|
3151
3301
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3152
3302
|
return false;
|
@@ -3154,7 +3304,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3154
3304
|
return size <= MAX_ROW_SIZE;
|
3155
3305
|
};
|
3156
3306
|
const getDefaultFieldSize = (attribute) => {
|
3157
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3307
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3158
3308
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3159
3309
|
};
|
3160
3310
|
async function createDefaultLayouts(schema) {
|
@@ -3175,8 +3325,7 @@ function createDefaultEditLayout(schema) {
|
|
3175
3325
|
return appendToEditLayout([], keys2, schema);
|
3176
3326
|
}
|
3177
3327
|
function syncLayouts(configuration, schema) {
|
3178
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3179
|
-
return createDefaultLayouts(schema);
|
3328
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3180
3329
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3181
3330
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3182
3331
|
const cleanEditRelations = editRelations.filter(
|
@@ -3187,9 +3336,8 @@ function syncLayouts(configuration, schema) {
|
|
3187
3336
|
for (const row of edit) {
|
3188
3337
|
const newRow = [];
|
3189
3338
|
for (const el of row) {
|
3190
|
-
if (!hasEditableAttribute(schema, el.name))
|
3191
|
-
|
3192
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3339
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3340
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3193
3341
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3194
3342
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3195
3343
|
elementsToReAppend.push(el.name);
|
@@ -3219,8 +3367,7 @@ function syncLayouts(configuration, schema) {
|
|
3219
3367
|
};
|
3220
3368
|
}
|
3221
3369
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3222
|
-
if (keysToAppend.length === 0)
|
3223
|
-
return layout;
|
3370
|
+
if (keysToAppend.length === 0) return layout;
|
3224
3371
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3225
3372
|
if (!layout[currentRowIndex]) {
|
3226
3373
|
layout[currentRowIndex] = [];
|
@@ -3329,17 +3476,17 @@ const configurationService$1 = createConfigurationService({
|
|
3329
3476
|
isComponent: true,
|
3330
3477
|
prefix: STORE_KEY_PREFIX,
|
3331
3478
|
getModels() {
|
3332
|
-
const { toContentManagerModel } = getService$
|
3479
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3333
3480
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3334
3481
|
}
|
3335
3482
|
});
|
3336
3483
|
const components = ({ strapi: strapi2 }) => ({
|
3337
3484
|
findAllComponents() {
|
3338
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3339
3486
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3340
3487
|
},
|
3341
3488
|
findComponent(uid2) {
|
3342
|
-
const { toContentManagerModel } = getService$
|
3489
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3343
3490
|
const component = strapi2.components[uid2];
|
3344
3491
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3345
3492
|
},
|
@@ -3390,17 +3537,17 @@ const configurationService = createConfigurationService({
|
|
3390
3537
|
storeUtils,
|
3391
3538
|
prefix: "content_types",
|
3392
3539
|
getModels() {
|
3393
|
-
const { toContentManagerModel } = getService$
|
3540
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3394
3541
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3395
3542
|
}
|
3396
3543
|
});
|
3397
3544
|
const service = ({ strapi: strapi2 }) => ({
|
3398
3545
|
findAllContentTypes() {
|
3399
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3400
3547
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3401
3548
|
},
|
3402
3549
|
findContentType(uid2) {
|
3403
|
-
const { toContentManagerModel } = getService$
|
3550
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3404
3551
|
const contentType = strapi2.contentTypes[uid2];
|
3405
3552
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3406
3553
|
},
|
@@ -3429,7 +3576,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3429
3576
|
return this.findConfiguration(contentType);
|
3430
3577
|
},
|
3431
3578
|
findComponentsConfigurations(contentType) {
|
3432
|
-
return getService$
|
3579
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3433
3580
|
},
|
3434
3581
|
syncConfigurations() {
|
3435
3582
|
return configurationService.syncConfigurations();
|
@@ -3701,7 +3848,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3701
3848
|
return userAbility.can(action);
|
3702
3849
|
},
|
3703
3850
|
async registerPermissions() {
|
3704
|
-
const displayedContentTypes = getService$
|
3851
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3705
3852
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3706
3853
|
const actions = [
|
3707
3854
|
{
|
@@ -3786,6 +3933,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3786
3933
|
if (initialPopulate) {
|
3787
3934
|
return initialPopulate;
|
3788
3935
|
}
|
3936
|
+
if (attributeName === "localizations") {
|
3937
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3938
|
+
return {
|
3939
|
+
populate: validationPopulate.populate
|
3940
|
+
};
|
3941
|
+
}
|
3789
3942
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3790
3943
|
return true;
|
3791
3944
|
}
|
@@ -3845,6 +3998,9 @@ const getDeepPopulate = (uid2, {
|
|
3845
3998
|
return {};
|
3846
3999
|
}
|
3847
4000
|
const model = strapi.getModel(uid2);
|
4001
|
+
if (!model) {
|
4002
|
+
return {};
|
4003
|
+
}
|
3848
4004
|
return Object.keys(model.attributes).reduce(
|
3849
4005
|
(populateAcc, attributeName) => fp.merge(
|
3850
4006
|
populateAcc,
|
@@ -3864,40 +4020,46 @@ const getDeepPopulate = (uid2, {
|
|
3864
4020
|
{}
|
3865
4021
|
);
|
3866
4022
|
};
|
3867
|
-
const
|
3868
|
-
|
3869
|
-
|
3870
|
-
countOne = false,
|
3871
|
-
maxLevel = Infinity
|
3872
|
-
} = {}, level = 1) => {
|
3873
|
-
if (level > maxLevel) {
|
4023
|
+
const getPopulateForValidation = (uid2) => {
|
4024
|
+
const model = strapi.getModel(uid2);
|
4025
|
+
if (!model) {
|
3874
4026
|
return {};
|
3875
4027
|
}
|
3876
|
-
const model = strapi.getModel(uid2);
|
3877
4028
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3878
|
-
if (
|
4029
|
+
if (isScalarAttribute(attribute)) {
|
4030
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4031
|
+
populateAcc.fields = populateAcc.fields || [];
|
4032
|
+
populateAcc.fields.push(attributeName);
|
4033
|
+
}
|
3879
4034
|
return populateAcc;
|
3880
4035
|
}
|
3881
|
-
if (
|
3882
|
-
|
3883
|
-
|
3884
|
-
|
4036
|
+
if (isComponent(attribute)) {
|
4037
|
+
const component = attribute.component;
|
4038
|
+
const componentResult = getPopulateForValidation(component);
|
4039
|
+
if (Object.keys(componentResult).length > 0) {
|
4040
|
+
populateAcc.populate = populateAcc.populate || {};
|
4041
|
+
populateAcc.populate[attributeName] = componentResult;
|
4042
|
+
}
|
4043
|
+
return populateAcc;
|
3885
4044
|
}
|
3886
|
-
|
3887
|
-
|
3888
|
-
|
3889
|
-
|
3890
|
-
|
3891
|
-
|
3892
|
-
|
3893
|
-
|
3894
|
-
|
3895
|
-
countOne,
|
3896
|
-
maxLevel
|
4045
|
+
if (isDynamicZone(attribute)) {
|
4046
|
+
const components2 = attribute.components;
|
4047
|
+
const componentsResult = (components2 || []).reduce(
|
4048
|
+
(acc, componentUID) => {
|
4049
|
+
const componentResult = getPopulateForValidation(componentUID);
|
4050
|
+
if (Object.keys(componentResult).length > 0) {
|
4051
|
+
acc[componentUID] = componentResult;
|
4052
|
+
}
|
4053
|
+
return acc;
|
3897
4054
|
},
|
3898
|
-
|
3899
|
-
)
|
3900
|
-
|
4055
|
+
{}
|
4056
|
+
);
|
4057
|
+
if (Object.keys(componentsResult).length > 0) {
|
4058
|
+
populateAcc.populate = populateAcc.populate || {};
|
4059
|
+
populateAcc.populate[attributeName] = { on: componentsResult };
|
4060
|
+
}
|
4061
|
+
}
|
4062
|
+
return populateAcc;
|
3901
4063
|
}, {});
|
3902
4064
|
};
|
3903
4065
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3977,7 +4139,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3977
4139
|
return populateQuery;
|
3978
4140
|
};
|
3979
4141
|
const buildDeepPopulate = (uid2) => {
|
3980
|
-
return getService$
|
4142
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3981
4143
|
};
|
3982
4144
|
const populateBuilder = (uid2) => {
|
3983
4145
|
let getInitialPopulate = async () => {
|
@@ -4139,7 +4301,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4139
4301
|
"locale",
|
4140
4302
|
"updatedAt",
|
4141
4303
|
"createdAt",
|
4142
|
-
"status",
|
4143
4304
|
"publishedAt",
|
4144
4305
|
"documentId"
|
4145
4306
|
];
|
@@ -4160,36 +4321,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4160
4321
|
/**
|
4161
4322
|
* Returns available locales of a document for the current status
|
4162
4323
|
*/
|
4163
|
-
async getAvailableLocales(uid2, version, allVersions
|
4324
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4164
4325
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4165
4326
|
if (version.locale) {
|
4166
4327
|
delete versionsByLocale[version.locale];
|
4167
4328
|
}
|
4168
4329
|
const model = strapi2.getModel(uid2);
|
4169
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4170
|
-
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4171
|
-
({ key }, { remove }) => {
|
4172
|
-
if (keysToKeep.includes(key)) {
|
4173
|
-
return;
|
4174
|
-
}
|
4175
|
-
remove(key);
|
4176
|
-
},
|
4177
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4178
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4179
|
-
localeVersion
|
4180
|
-
);
|
4181
4330
|
const mappingResult = await strapiUtils.async.map(
|
4182
4331
|
Object.values(versionsByLocale),
|
4183
4332
|
async (localeVersions) => {
|
4184
|
-
const mappedLocaleVersions = await strapiUtils.async.map(
|
4185
|
-
localeVersions,
|
4186
|
-
traversalFunction
|
4187
|
-
);
|
4188
4333
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4189
|
-
return
|
4334
|
+
return localeVersions[0];
|
4190
4335
|
}
|
4191
|
-
const draftVersion =
|
4192
|
-
const otherVersions =
|
4336
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4337
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4193
4338
|
if (!draftVersion) {
|
4194
4339
|
return;
|
4195
4340
|
}
|
@@ -4211,8 +4356,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4211
4356
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4212
4357
|
return matchLocale && matchStatus;
|
4213
4358
|
});
|
4214
|
-
if (!availableStatus)
|
4215
|
-
return availableStatus;
|
4359
|
+
if (!availableStatus) return availableStatus;
|
4216
4360
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4217
4361
|
},
|
4218
4362
|
/**
|
@@ -4222,18 +4366,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4222
4366
|
* @returns
|
4223
4367
|
*/
|
4224
4368
|
async getManyAvailableStatus(uid2, documents) {
|
4225
|
-
if (!documents.length)
|
4226
|
-
return [];
|
4369
|
+
if (!documents.length) return [];
|
4227
4370
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4228
|
-
const
|
4229
|
-
const
|
4230
|
-
|
4231
|
-
|
4232
|
-
|
4233
|
-
|
4234
|
-
|
4235
|
-
|
4236
|
-
|
4371
|
+
const locales = documents.map((d) => d.locale).filter(Boolean);
|
4372
|
+
const where = {
|
4373
|
+
documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
|
4374
|
+
publishedAt: { $null: status === "published" }
|
4375
|
+
};
|
4376
|
+
if (locales.length) {
|
4377
|
+
where.locale = { $in: locales };
|
4378
|
+
}
|
4379
|
+
return strapi2.query(uid2).findMany({
|
4380
|
+
where,
|
4381
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
|
4237
4382
|
});
|
4238
4383
|
},
|
4239
4384
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4250,10 +4395,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4250
4395
|
} else if (otherVersion) {
|
4251
4396
|
draftVersion = otherVersion;
|
4252
4397
|
}
|
4253
|
-
if (!draftVersion)
|
4254
|
-
|
4255
|
-
if (!publishedVersion)
|
4256
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4398
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4399
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4257
4400
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4258
4401
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4259
4402
|
},
|
@@ -4261,11 +4404,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4261
4404
|
// We could refactor this so the locales are only loaded when they're
|
4262
4405
|
// needed. e.g. in the bulk locale action modal.
|
4263
4406
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4264
|
-
const populate =
|
4265
|
-
const
|
4266
|
-
where: { documentId: version.documentId },
|
4407
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4408
|
+
const params = {
|
4267
4409
|
populate: {
|
4268
|
-
// Populate only fields that require validation for bulk locale actions
|
4269
4410
|
...populate,
|
4270
4411
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4271
4412
|
createdBy: {
|
@@ -4274,9 +4415,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4274
4415
|
updatedBy: {
|
4275
4416
|
select: ["id", "firstname", "lastname", "email"]
|
4276
4417
|
}
|
4418
|
+
},
|
4419
|
+
fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4420
|
+
filters: {
|
4421
|
+
documentId: version.documentId
|
4277
4422
|
}
|
4278
|
-
}
|
4279
|
-
const
|
4423
|
+
};
|
4424
|
+
const dbParams = strapi2.get("query-params").transform(uid2, params);
|
4425
|
+
const versions = await strapi2.db.query(uid2).findMany(dbParams);
|
4426
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
|
4280
4427
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4281
4428
|
return {
|
4282
4429
|
availableLocales: availableLocalesResult,
|
@@ -4303,6 +4450,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4303
4450
|
opts.availableStatus = false;
|
4304
4451
|
}
|
4305
4452
|
const meta = await this.getMetadata(uid2, document, opts);
|
4453
|
+
if (document.localizations) {
|
4454
|
+
const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
|
4455
|
+
document.localizations = document.localizations.map((d) => {
|
4456
|
+
const status = otherStatus.find((s) => s.documentId === d.documentId);
|
4457
|
+
return {
|
4458
|
+
...d,
|
4459
|
+
status: this.getStatus(d, status ? [status] : [])
|
4460
|
+
};
|
4461
|
+
});
|
4462
|
+
}
|
4306
4463
|
return {
|
4307
4464
|
data: {
|
4308
4465
|
...document,
|