@strapi/content-manager 0.0.0-next.55dabf6295dfb7987fcab8a6b40212555f0e684c → 0.0.0-next.5d0cd5a1a7d80ae3da90f2331d25161b28f06910
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-FqfsxQ1j.js → ComponentConfigurationPage-CJPoOvy3.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-FqfsxQ1j.js.map → ComponentConfigurationPage-CJPoOvy3.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DfFSZQxe.mjs → ComponentConfigurationPage-CcRDqD0e.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DfFSZQxe.mjs.map → ComponentConfigurationPage-CcRDqD0e.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-DdPNAbl3.mjs → EditConfigurationPage-C1ddZ_zf.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DdPNAbl3.mjs.map → EditConfigurationPage-C1ddZ_zf.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Cn0e8t3I.js → EditConfigurationPage-CF3lxOy2.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-Cn0e8t3I.js.map → EditConfigurationPage-CF3lxOy2.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-B82x_x1b.mjs → EditViewPage-BPFcUbqi.mjs} +38 -8
- package/dist/_chunks/EditViewPage-BPFcUbqi.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-DlxEHhUt.js → EditViewPage-CDyTC6aU.js} +38 -9
- package/dist/_chunks/EditViewPage-CDyTC6aU.js.map +1 -0
- package/dist/_chunks/{Field-COL25JiC.js → Field-DuxAW9q2.js} +172 -120
- package/dist/_chunks/Field-DuxAW9q2.js.map +1 -0
- package/dist/_chunks/{Field-DufHXW17.mjs → Field-fBnTwgU4.mjs} +170 -118
- package/dist/_chunks/Field-fBnTwgU4.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-u_kAOhwB.mjs → Form-BGl7PhlZ.mjs} +3 -3
- package/dist/_chunks/{Form-u_kAOhwB.mjs.map → Form-BGl7PhlZ.mjs.map} +1 -1
- package/dist/_chunks/{Form-BssUwrTO.js → Form-DSGh_zkz.js} +5 -6
- package/dist/_chunks/{Form-BssUwrTO.js.map → Form-DSGh_zkz.js.map} +1 -1
- package/dist/_chunks/{History-DRwA3oMM.mjs → History-DTYB9CSB.mjs} +23 -93
- package/dist/_chunks/History-DTYB9CSB.mjs.map +1 -0
- package/dist/_chunks/{History-C9t9UqpO.js → History-DrDJv698.js} +23 -94
- package/dist/_chunks/History-DrDJv698.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BxfQJzPk.mjs → ListConfigurationPage-qWx8r4D_.mjs} +7 -6
- package/dist/_chunks/ListConfigurationPage-qWx8r4D_.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BXYPohh-.js → ListConfigurationPage-zurIlUZ7.js} +7 -7
- package/dist/_chunks/ListConfigurationPage-zurIlUZ7.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D2VD8Szg.js → ListViewPage-DTM2uO_S.js} +63 -41
- package/dist/_chunks/ListViewPage-DTM2uO_S.js.map +1 -0
- package/dist/_chunks/{ListViewPage-CELx2ysp.mjs → ListViewPage-GKpL5p8A.mjs} +62 -39
- package/dist/_chunks/ListViewPage-GKpL5p8A.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DtJ9jcfk.mjs → NoContentTypePage-B5Vc5Cal.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DtJ9jcfk.mjs.map → NoContentTypePage-B5Vc5Cal.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BV9IjJSM.js → NoContentTypePage-BuZlNroO.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BV9IjJSM.js.map → NoContentTypePage-BuZlNroO.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DWleVYK7.mjs → NoPermissionsPage-BAZlWgJ4.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DWleVYK7.mjs.map → NoPermissionsPage-BAZlWgJ4.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Dp8NpF9I.js → NoPermissionsPage-DLzkS4Hy.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Dp8NpF9I.js.map → NoPermissionsPage-DLzkS4Hy.js.map} +1 -1
- package/dist/_chunks/Preview-VOJ8RuQp.js +312 -0
- package/dist/_chunks/Preview-VOJ8RuQp.js.map +1 -0
- package/dist/_chunks/Preview-Zzjg2_K_.mjs +294 -0
- package/dist/_chunks/Preview-Zzjg2_K_.mjs.map +1 -0
- package/dist/_chunks/{Relations-BTcf5xaw.mjs → Relations-BVdRfDkW.mjs} +47 -22
- package/dist/_chunks/Relations-BVdRfDkW.mjs.map +1 -0
- package/dist/_chunks/{Relations-DR7EUgyC.js → Relations-Dsj0boFJ.js} +47 -23
- package/dist/_chunks/Relations-Dsj0boFJ.js.map +1 -0
- package/dist/_chunks/{en-Bm0D0IWz.js → en-BzQmavmK.js} +21 -4
- package/dist/_chunks/{en-Bm0D0IWz.js.map → en-BzQmavmK.js.map} +1 -1
- package/dist/_chunks/{en-DKV44jRb.mjs → en-CSxLmrh1.mjs} +21 -4
- package/dist/_chunks/{en-DKV44jRb.mjs.map → en-CSxLmrh1.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-wnqzm4Q8.mjs → index-Bu_-B7ZA.mjs} +390 -196
- package/dist/_chunks/index-Bu_-B7ZA.mjs.map +1 -0
- package/dist/_chunks/{index-BdMf2lfT.js → index-Ct-GZ0iV.js} +388 -194
- package/dist/_chunks/index-Ct-GZ0iV.js.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-B2MyZU-_.js → layout-CDBEgRsM.js} +5 -6
- package/dist/_chunks/{layout-B2MyZU-_.js.map → layout-CDBEgRsM.js.map} +1 -1
- package/dist/_chunks/{layout-2CfjL0T9.mjs → layout-COzAvgJh.mjs} +4 -4
- package/dist/_chunks/{layout-2CfjL0T9.mjs.map → layout-COzAvgJh.mjs.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-BH7JJGGe.js → relations-BjiF1Aad.js} +6 -7
- package/dist/_chunks/relations-BjiF1Aad.js.map +1 -0
- package/dist/_chunks/{relations-C0w0GcXi.mjs → relations-BtmMFBpM.mjs} +6 -7
- package/dist/_chunks/relations-BtmMFBpM.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 +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- 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/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/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
- package/dist/admin/src/preview/routes.d.ts +3 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- package/dist/admin/src/router.d.ts +1 -1
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +16 -19
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/server/index.js +482 -243
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +483 -243
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +16 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -3
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +7 -6
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +13 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +16 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +32 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +12 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +19 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +12 -10
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +7 -6
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/index.d.ts +1 -0
- package/dist/shared/contracts/index.d.ts.map +1 -1
- package/dist/shared/contracts/preview.d.ts +27 -0
- package/dist/shared/contracts/preview.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +4 -0
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +13 -11
- package/dist/_chunks/EditViewPage-B82x_x1b.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-DlxEHhUt.js.map +0 -1
- package/dist/_chunks/Field-COL25JiC.js.map +0 -1
- package/dist/_chunks/Field-DufHXW17.mjs.map +0 -1
- package/dist/_chunks/History-C9t9UqpO.js.map +0 -1
- package/dist/_chunks/History-DRwA3oMM.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-BXYPohh-.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-BxfQJzPk.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CELx2ysp.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-D2VD8Szg.js.map +0 -1
- package/dist/_chunks/Relations-BTcf5xaw.mjs.map +0 -1
- package/dist/_chunks/Relations-DR7EUgyC.js.map +0 -1
- package/dist/_chunks/index-BdMf2lfT.js.map +0 -1
- package/dist/_chunks/index-wnqzm4Q8.mjs.map +0 -1
- package/dist/_chunks/relations-BH7JJGGe.js.map +0 -1
- package/dist/_chunks/relations-C0w0GcXi.mjs.map +0 -1
package/dist/server/index.js
CHANGED
@@ -10,8 +10,7 @@ const qs = require("qs");
|
|
10
10
|
const slugify = require("@sindresorhus/slugify");
|
11
11
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
12
12
|
function _interopNamespace(e) {
|
13
|
-
if (e && e.__esModule)
|
14
|
-
return e;
|
13
|
+
if (e && e.__esModule) return e;
|
15
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
16
15
|
if (e) {
|
17
16
|
for (const k in e) {
|
@@ -33,10 +32,10 @@ const isNil__default = /* @__PURE__ */ _interopDefault(isNil);
|
|
33
32
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
34
33
|
const qs__default = /* @__PURE__ */ _interopDefault(qs);
|
35
34
|
const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
|
36
|
-
const getService$
|
35
|
+
const getService$2 = (name) => {
|
37
36
|
return strapi.plugin("content-manager").service(name);
|
38
37
|
};
|
39
|
-
function getService(strapi2, name) {
|
38
|
+
function getService$1(strapi2, name) {
|
40
39
|
return strapi2.service(`plugin::content-manager.${name}`);
|
41
40
|
}
|
42
41
|
const historyRestoreVersionSchema = yup__namespace.object().shape({
|
@@ -72,7 +71,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
72
71
|
if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
|
73
72
|
throw new strapiUtils.errors.ForbiddenError("contentType and documentId are required");
|
74
73
|
}
|
75
|
-
const permissionChecker2 = getService$
|
74
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
76
75
|
userAbility: ctx.state.userAbility,
|
77
76
|
model: ctx.query.contentType
|
78
77
|
});
|
@@ -80,7 +79,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
80
79
|
return ctx.forbidden();
|
81
80
|
}
|
82
81
|
const query = await permissionChecker2.sanitizeQuery(ctx.query);
|
83
|
-
const { results, pagination } = await getService(strapi2, "history").findVersionsPage({
|
82
|
+
const { results, pagination } = await getService$1(strapi2, "history").findVersionsPage({
|
84
83
|
query: {
|
85
84
|
...query,
|
86
85
|
...getValidPagination({ page: query.page, pageSize: query.pageSize })
|
@@ -105,14 +104,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
105
104
|
async restoreVersion(ctx) {
|
106
105
|
const request = ctx.request;
|
107
106
|
await validateRestoreVersion(request.body, "contentType is required");
|
108
|
-
const permissionChecker2 = getService$
|
107
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
109
108
|
userAbility: ctx.state.userAbility,
|
110
109
|
model: request.body.contentType
|
111
110
|
});
|
112
111
|
if (permissionChecker2.cannot.update()) {
|
113
112
|
throw new strapiUtils.errors.ForbiddenError();
|
114
113
|
}
|
115
|
-
const restoredDocument = await getService(strapi2, "history").restoreVersion(
|
114
|
+
const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
|
116
115
|
request.params.versionId
|
117
116
|
);
|
118
117
|
return {
|
@@ -121,7 +120,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
121
120
|
}
|
122
121
|
};
|
123
122
|
};
|
124
|
-
const controllers$
|
123
|
+
const controllers$2 = {
|
125
124
|
"history-version": createHistoryVersionController
|
126
125
|
/**
|
127
126
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -167,8 +166,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
167
166
|
};
|
168
167
|
const getRelationRestoreValue = async (versionRelationData, attribute) => {
|
169
168
|
if (Array.isArray(versionRelationData)) {
|
170
|
-
if (versionRelationData.length === 0)
|
171
|
-
return versionRelationData;
|
169
|
+
if (versionRelationData.length === 0) return versionRelationData;
|
172
170
|
const existingAndMissingRelations = await Promise.all(
|
173
171
|
versionRelationData.map((relation) => {
|
174
172
|
return strapi2.documents(attribute.target).findOne({
|
@@ -203,8 +201,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
203
201
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
202
|
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
205
203
|
const getLocaleDictionary = async () => {
|
206
|
-
if (!localesService)
|
207
|
-
return {};
|
204
|
+
if (!localesService) return {};
|
208
205
|
const locales = await localesService.find() || [];
|
209
206
|
return locales.reduce(
|
210
207
|
(acc, locale) => {
|
@@ -228,6 +225,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
228
225
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
229
226
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
230
227
|
};
|
228
|
+
const getComponentFields = (componentUID) => {
|
229
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
230
|
+
(fieldsAcc, [key, attribute]) => {
|
231
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
232
|
+
fieldsAcc.push(key);
|
233
|
+
}
|
234
|
+
return fieldsAcc;
|
235
|
+
},
|
236
|
+
[]
|
237
|
+
);
|
238
|
+
};
|
231
239
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
232
240
|
const model = strapi2.getModel(uid2);
|
233
241
|
const attributes = Object.entries(model.attributes);
|
@@ -251,13 +259,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
251
259
|
}
|
252
260
|
case "component": {
|
253
261
|
const populate = getDeepPopulate2(attribute.component);
|
254
|
-
acc[attributeName] = {
|
262
|
+
acc[attributeName] = {
|
263
|
+
populate,
|
264
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
265
|
+
};
|
255
266
|
break;
|
256
267
|
}
|
257
268
|
case "dynamiczone": {
|
258
269
|
const populatedComponents = (attribute.components || []).reduce(
|
259
270
|
(acc2, componentUID) => {
|
260
|
-
acc2[componentUID] = {
|
271
|
+
acc2[componentUID] = {
|
272
|
+
populate: getDeepPopulate2(componentUID),
|
273
|
+
[fieldSelector]: getComponentFields(componentUID)
|
274
|
+
};
|
261
275
|
return acc2;
|
262
276
|
},
|
263
277
|
{}
|
@@ -370,7 +384,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
370
384
|
const attributeValue = entry.data[attributeKey];
|
371
385
|
const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
|
372
386
|
if (attributeSchema.type === "media") {
|
373
|
-
const permissionChecker2 = getService$
|
387
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
374
388
|
userAbility: params.state.userAbility,
|
375
389
|
model: "plugin::upload.file"
|
376
390
|
});
|
@@ -411,7 +425,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
411
425
|
[attributeKey]: adminUsers
|
412
426
|
};
|
413
427
|
}
|
414
|
-
const permissionChecker2 = getService$
|
428
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
415
429
|
userAbility: params.state.userAbility,
|
416
430
|
model: attributeSchema.target
|
417
431
|
});
|
@@ -587,7 +601,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
587
601
|
onCommit(async () => {
|
588
602
|
for (const entry of localeEntries) {
|
589
603
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
-
await getService(strapi2, "history").createVersion({
|
604
|
+
await getService$1(strapi2, "history").createVersion({
|
591
605
|
contentType: uid2,
|
592
606
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
607
|
relatedDocumentId: documentId,
|
@@ -600,15 +614,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
600
614
|
});
|
601
615
|
return result;
|
602
616
|
});
|
603
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
617
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
604
618
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
605
619
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
606
620
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
607
621
|
where: {
|
608
622
|
created_at: {
|
609
|
-
$lt: expirationDate
|
623
|
+
$lt: expirationDate
|
610
624
|
}
|
611
625
|
}
|
626
|
+
}).catch((error) => {
|
627
|
+
if (error instanceof Error) {
|
628
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
629
|
+
}
|
612
630
|
});
|
613
631
|
});
|
614
632
|
state.isInitialized = true;
|
@@ -620,17 +638,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
620
638
|
}
|
621
639
|
};
|
622
640
|
};
|
623
|
-
const services$
|
641
|
+
const services$2 = {
|
624
642
|
history: createHistoryService,
|
625
643
|
lifecycles: createLifecyclesService
|
626
644
|
};
|
627
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
645
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
628
646
|
const historyVersionRouter = {
|
629
647
|
type: "admin",
|
630
648
|
routes: [
|
631
649
|
{
|
632
650
|
method: "GET",
|
633
|
-
info,
|
651
|
+
info: info$1,
|
634
652
|
path: "/history-versions",
|
635
653
|
handler: "history-version.findMany",
|
636
654
|
config: {
|
@@ -639,7 +657,7 @@ const historyVersionRouter = {
|
|
639
657
|
},
|
640
658
|
{
|
641
659
|
method: "PUT",
|
642
|
-
info,
|
660
|
+
info: info$1,
|
643
661
|
path: "/history-versions/:versionId/restore",
|
644
662
|
handler: "history-version.restoreVersion",
|
645
663
|
config: {
|
@@ -648,7 +666,7 @@ const historyVersionRouter = {
|
|
648
666
|
}
|
649
667
|
]
|
650
668
|
};
|
651
|
-
const routes$
|
669
|
+
const routes$2 = {
|
652
670
|
"history-version": historyVersionRouter
|
653
671
|
};
|
654
672
|
const historyVersion = {
|
@@ -695,21 +713,21 @@ const historyVersion = {
|
|
695
713
|
}
|
696
714
|
}
|
697
715
|
};
|
698
|
-
const getFeature = () => {
|
716
|
+
const getFeature$1 = () => {
|
699
717
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
700
718
|
return {
|
701
719
|
register({ strapi: strapi2 }) {
|
702
720
|
strapi2.get("models").add(historyVersion);
|
703
721
|
},
|
704
722
|
bootstrap({ strapi: strapi2 }) {
|
705
|
-
getService(strapi2, "lifecycles").bootstrap();
|
723
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
706
724
|
},
|
707
725
|
destroy({ strapi: strapi2 }) {
|
708
|
-
getService(strapi2, "lifecycles").destroy();
|
726
|
+
getService$1(strapi2, "lifecycles").destroy();
|
709
727
|
},
|
710
|
-
controllers: controllers$
|
711
|
-
services: services$
|
712
|
-
routes: routes$
|
728
|
+
controllers: controllers$2,
|
729
|
+
services: services$2,
|
730
|
+
routes: routes$2
|
713
731
|
};
|
714
732
|
}
|
715
733
|
return {
|
@@ -718,9 +736,201 @@ const getFeature = () => {
|
|
718
736
|
}
|
719
737
|
};
|
720
738
|
};
|
721
|
-
const history = getFeature();
|
739
|
+
const history = getFeature$1();
|
740
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
741
|
+
const previewRouter = {
|
742
|
+
type: "admin",
|
743
|
+
routes: [
|
744
|
+
{
|
745
|
+
method: "GET",
|
746
|
+
info,
|
747
|
+
path: "/preview/url/:contentType",
|
748
|
+
handler: "preview.getPreviewUrl",
|
749
|
+
config: {
|
750
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
751
|
+
}
|
752
|
+
}
|
753
|
+
]
|
754
|
+
};
|
755
|
+
const routes$1 = {
|
756
|
+
preview: previewRouter
|
757
|
+
};
|
758
|
+
function getService(strapi2, name) {
|
759
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
760
|
+
}
|
761
|
+
const getPreviewUrlSchema = yup__namespace.object().shape({
|
762
|
+
// Will be undefined for single types
|
763
|
+
documentId: yup__namespace.string(),
|
764
|
+
locale: yup__namespace.string().nullable(),
|
765
|
+
status: yup__namespace.string()
|
766
|
+
}).required();
|
767
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
768
|
+
await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
|
769
|
+
const newParams = fp.pick(["documentId", "locale", "status"], params);
|
770
|
+
const model = strapi2.getModel(uid2);
|
771
|
+
if (!model || model.modelType !== "contentType") {
|
772
|
+
throw new strapiUtils.errors.ValidationError("Invalid content type");
|
773
|
+
}
|
774
|
+
const isSingleType = model?.kind === "singleType";
|
775
|
+
if (!isSingleType && !params.documentId) {
|
776
|
+
throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
|
777
|
+
}
|
778
|
+
if (isSingleType) {
|
779
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
780
|
+
if (!doc) {
|
781
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
782
|
+
}
|
783
|
+
newParams.documentId = doc?.documentId;
|
784
|
+
}
|
785
|
+
if (!newParams.status) {
|
786
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
787
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
788
|
+
}
|
789
|
+
return newParams;
|
790
|
+
};
|
791
|
+
const createPreviewController = () => {
|
792
|
+
return {
|
793
|
+
/**
|
794
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
795
|
+
* in the Content Manager.
|
796
|
+
*/
|
797
|
+
async getPreviewUrl(ctx) {
|
798
|
+
const uid2 = ctx.params.contentType;
|
799
|
+
const query = ctx.request.query;
|
800
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
801
|
+
const previewService = getService(strapi, "preview");
|
802
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
803
|
+
if (!url) {
|
804
|
+
ctx.status = 204;
|
805
|
+
}
|
806
|
+
return {
|
807
|
+
data: { url }
|
808
|
+
};
|
809
|
+
}
|
810
|
+
};
|
811
|
+
};
|
812
|
+
const controllers$1 = {
|
813
|
+
preview: createPreviewController
|
814
|
+
/**
|
815
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
816
|
+
* passing a controller factory as the value, instead of a controller object directly
|
817
|
+
*/
|
818
|
+
};
|
819
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
820
|
+
const config = getService(strapi2, "preview-config");
|
821
|
+
return {
|
822
|
+
async getPreviewUrl(uid2, params) {
|
823
|
+
const handler = config.getPreviewHandler();
|
824
|
+
try {
|
825
|
+
return handler(uid2, params);
|
826
|
+
} catch (error) {
|
827
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
828
|
+
throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
|
829
|
+
}
|
830
|
+
return;
|
831
|
+
}
|
832
|
+
};
|
833
|
+
};
|
834
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
835
|
+
const middlewares = strapi.config.get("middlewares");
|
836
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
837
|
+
if (currentMiddleware === middleware.name) {
|
838
|
+
return middleware;
|
839
|
+
}
|
840
|
+
if (currentMiddleware.name === middleware.name) {
|
841
|
+
return fp.mergeWith(
|
842
|
+
(objValue, srcValue) => {
|
843
|
+
if (Array.isArray(objValue)) {
|
844
|
+
return objValue.concat(srcValue);
|
845
|
+
}
|
846
|
+
return void 0;
|
847
|
+
},
|
848
|
+
currentMiddleware,
|
849
|
+
middleware
|
850
|
+
);
|
851
|
+
}
|
852
|
+
return currentMiddleware;
|
853
|
+
});
|
854
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
855
|
+
};
|
856
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
857
|
+
return {
|
858
|
+
register() {
|
859
|
+
if (!this.isEnabled()) {
|
860
|
+
return;
|
861
|
+
}
|
862
|
+
const config = strapi2.config.get("admin.preview");
|
863
|
+
if (config.config?.allowedOrigins) {
|
864
|
+
extendMiddlewareConfiguration({
|
865
|
+
name: "strapi::security",
|
866
|
+
config: {
|
867
|
+
contentSecurityPolicy: {
|
868
|
+
directives: {
|
869
|
+
"frame-src": config.config.allowedOrigins
|
870
|
+
}
|
871
|
+
}
|
872
|
+
}
|
873
|
+
});
|
874
|
+
}
|
875
|
+
},
|
876
|
+
isEnabled() {
|
877
|
+
const config = strapi2.config.get("admin.preview");
|
878
|
+
if (!config) {
|
879
|
+
return false;
|
880
|
+
}
|
881
|
+
return config?.enabled ?? true;
|
882
|
+
},
|
883
|
+
/**
|
884
|
+
* Validate if the configuration is valid
|
885
|
+
*/
|
886
|
+
validate() {
|
887
|
+
if (!this.isEnabled()) {
|
888
|
+
return;
|
889
|
+
}
|
890
|
+
const handler = this.getPreviewHandler();
|
891
|
+
if (typeof handler !== "function") {
|
892
|
+
throw new strapiUtils.errors.ValidationError(
|
893
|
+
"Preview configuration is invalid. Handler must be a function"
|
894
|
+
);
|
895
|
+
}
|
896
|
+
},
|
897
|
+
/**
|
898
|
+
* Utility to get the preview handler from the configuration
|
899
|
+
*/
|
900
|
+
getPreviewHandler() {
|
901
|
+
const config = strapi2.config.get("admin.preview");
|
902
|
+
const emptyHandler = () => {
|
903
|
+
return void 0;
|
904
|
+
};
|
905
|
+
if (!this.isEnabled()) {
|
906
|
+
return emptyHandler;
|
907
|
+
}
|
908
|
+
return config?.config?.handler || emptyHandler;
|
909
|
+
}
|
910
|
+
};
|
911
|
+
};
|
912
|
+
const services$1 = {
|
913
|
+
preview: createPreviewService,
|
914
|
+
"preview-config": createPreviewConfigService
|
915
|
+
};
|
916
|
+
const getFeature = () => {
|
917
|
+
return {
|
918
|
+
register() {
|
919
|
+
const config = getService(strapi, "preview-config");
|
920
|
+
config.validate();
|
921
|
+
config.register();
|
922
|
+
},
|
923
|
+
bootstrap() {
|
924
|
+
},
|
925
|
+
routes: routes$1,
|
926
|
+
controllers: controllers$1,
|
927
|
+
services: services$1
|
928
|
+
};
|
929
|
+
};
|
930
|
+
const preview = getFeature();
|
722
931
|
const register = async ({ strapi: strapi2 }) => {
|
723
932
|
await history.register?.({ strapi: strapi2 });
|
933
|
+
await preview.register?.({ strapi: strapi2 });
|
724
934
|
};
|
725
935
|
const ALLOWED_WEBHOOK_EVENTS = {
|
726
936
|
ENTRY_PUBLISH: "entry.publish",
|
@@ -730,11 +940,12 @@ const bootstrap = async () => {
|
|
730
940
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
731
941
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
732
942
|
});
|
733
|
-
getService$
|
734
|
-
await getService$
|
735
|
-
await getService$
|
736
|
-
await getService$
|
943
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
944
|
+
await getService$2("components").syncConfigurations();
|
945
|
+
await getService$2("content-types").syncConfigurations();
|
946
|
+
await getService$2("permission").registerPermissions();
|
737
947
|
await history.bootstrap?.({ strapi });
|
948
|
+
await preview.bootstrap?.({ strapi });
|
738
949
|
};
|
739
950
|
const destroy = async ({ strapi: strapi2 }) => {
|
740
951
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1224,7 +1435,8 @@ const admin = {
|
|
1224
1435
|
};
|
1225
1436
|
const routes = {
|
1226
1437
|
admin,
|
1227
|
-
...history.routes ? history.routes : {}
|
1438
|
+
...history.routes ? history.routes : {},
|
1439
|
+
...preview.routes ? preview.routes : {}
|
1228
1440
|
};
|
1229
1441
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1230
1442
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1287,8 +1499,7 @@ const isSortable = (schema, name) => {
|
|
1287
1499
|
if (!___default.default.has(schema.attributes, name)) {
|
1288
1500
|
return false;
|
1289
1501
|
}
|
1290
|
-
if (schema.modelType === "component" && name === "id")
|
1291
|
-
return false;
|
1502
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1292
1503
|
const attribute = schema.attributes[name];
|
1293
1504
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1294
1505
|
return false;
|
@@ -1433,8 +1644,7 @@ const createDefaultSettings = async (schema) => {
|
|
1433
1644
|
};
|
1434
1645
|
};
|
1435
1646
|
const syncSettings = async (configuration, schema) => {
|
1436
|
-
if (fp.isEmpty(configuration.settings))
|
1437
|
-
return createDefaultSettings(schema);
|
1647
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1438
1648
|
const defaultField = getDefaultMainField(schema);
|
1439
1649
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1440
1650
|
return {
|
@@ -1481,7 +1691,7 @@ const createMetadasSchema = (schema) => {
|
|
1481
1691
|
if (!value) {
|
1482
1692
|
return strapiUtils.yup.string();
|
1483
1693
|
}
|
1484
|
-
const targetSchema = getService$
|
1694
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1485
1695
|
schema.attributes[key].targetModel
|
1486
1696
|
);
|
1487
1697
|
if (!targetSchema) {
|
@@ -1610,8 +1820,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1610
1820
|
}
|
1611
1821
|
switch (attribute.type) {
|
1612
1822
|
case "relation": {
|
1613
|
-
if (canCreate(attributePath))
|
1614
|
-
return body2;
|
1823
|
+
if (canCreate(attributePath)) return body2;
|
1615
1824
|
return fp.set(attributePath, { set: [] }, body2);
|
1616
1825
|
}
|
1617
1826
|
case "component": {
|
@@ -1621,8 +1830,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1621
1830
|
]);
|
1622
1831
|
}
|
1623
1832
|
default: {
|
1624
|
-
if (canCreate(attributePath))
|
1625
|
-
return body2;
|
1833
|
+
if (canCreate(attributePath)) return body2;
|
1626
1834
|
return fp.set(attributePath, null, body2);
|
1627
1835
|
}
|
1628
1836
|
}
|
@@ -1650,7 +1858,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1650
1858
|
}
|
1651
1859
|
};
|
1652
1860
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1653
|
-
const documentMetadata2 = getService$
|
1861
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1654
1862
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1655
1863
|
let {
|
1656
1864
|
meta: { availableLocales, availableStatus }
|
@@ -1676,8 +1884,8 @@ const createDocument = async (ctx, opts) => {
|
|
1676
1884
|
const { userAbility, user } = ctx.state;
|
1677
1885
|
const { model } = ctx.params;
|
1678
1886
|
const { body } = ctx.request;
|
1679
|
-
const documentManager2 = getService$
|
1680
|
-
const permissionChecker2 = getService$
|
1887
|
+
const documentManager2 = getService$2("document-manager");
|
1888
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1681
1889
|
if (permissionChecker2.cannot.create()) {
|
1682
1890
|
throw new strapiUtils.errors.ForbiddenError();
|
1683
1891
|
}
|
@@ -1697,13 +1905,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1697
1905
|
const { userAbility, user } = ctx.state;
|
1698
1906
|
const { id, model } = ctx.params;
|
1699
1907
|
const { body } = ctx.request;
|
1700
|
-
const documentManager2 = getService$
|
1701
|
-
const permissionChecker2 = getService$
|
1908
|
+
const documentManager2 = getService$2("document-manager");
|
1909
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1702
1910
|
if (permissionChecker2.cannot.update()) {
|
1703
1911
|
throw new strapiUtils.errors.ForbiddenError();
|
1704
1912
|
}
|
1705
1913
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1706
|
-
const populate = await getService$
|
1914
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1707
1915
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1708
1916
|
const [documentVersion, documentExists] = await Promise.all([
|
1709
1917
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1734,14 +1942,14 @@ const collectionTypes = {
|
|
1734
1942
|
const { userAbility } = ctx.state;
|
1735
1943
|
const { model } = ctx.params;
|
1736
1944
|
const { query } = ctx.request;
|
1737
|
-
const documentMetadata2 = getService$
|
1738
|
-
const documentManager2 = getService$
|
1739
|
-
const permissionChecker2 = getService$
|
1945
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1946
|
+
const documentManager2 = getService$2("document-manager");
|
1947
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1740
1948
|
if (permissionChecker2.cannot.read()) {
|
1741
1949
|
return ctx.forbidden();
|
1742
1950
|
}
|
1743
1951
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1744
|
-
const populate = await getService$
|
1952
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1745
1953
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1746
1954
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1747
1955
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1770,13 +1978,13 @@ const collectionTypes = {
|
|
1770
1978
|
async findOne(ctx) {
|
1771
1979
|
const { userAbility } = ctx.state;
|
1772
1980
|
const { model, id } = ctx.params;
|
1773
|
-
const documentManager2 = getService$
|
1774
|
-
const permissionChecker2 = getService$
|
1981
|
+
const documentManager2 = getService$2("document-manager");
|
1982
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1775
1983
|
if (permissionChecker2.cannot.read()) {
|
1776
1984
|
return ctx.forbidden();
|
1777
1985
|
}
|
1778
1986
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1779
|
-
const populate = await getService$
|
1987
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1780
1988
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1781
1989
|
const version = await documentManager2.findOne(id, model, {
|
1782
1990
|
populate,
|
@@ -1807,7 +2015,7 @@ const collectionTypes = {
|
|
1807
2015
|
async create(ctx) {
|
1808
2016
|
const { userAbility } = ctx.state;
|
1809
2017
|
const { model } = ctx.params;
|
1810
|
-
const permissionChecker2 = getService$
|
2018
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1811
2019
|
const [totalEntries, document] = await Promise.all([
|
1812
2020
|
strapi.db.query(model).count(),
|
1813
2021
|
createDocument(ctx)
|
@@ -1828,7 +2036,7 @@ const collectionTypes = {
|
|
1828
2036
|
async update(ctx) {
|
1829
2037
|
const { userAbility } = ctx.state;
|
1830
2038
|
const { model } = ctx.params;
|
1831
|
-
const permissionChecker2 = getService$
|
2039
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1832
2040
|
const updatedVersion = await updateDocument(ctx);
|
1833
2041
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1834
2042
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1837,13 +2045,13 @@ const collectionTypes = {
|
|
1837
2045
|
const { userAbility, user } = ctx.state;
|
1838
2046
|
const { model, sourceId: id } = ctx.params;
|
1839
2047
|
const { body } = ctx.request;
|
1840
|
-
const documentManager2 = getService$
|
1841
|
-
const permissionChecker2 = getService$
|
2048
|
+
const documentManager2 = getService$2("document-manager");
|
2049
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1842
2050
|
if (permissionChecker2.cannot.create()) {
|
1843
2051
|
return ctx.forbidden();
|
1844
2052
|
}
|
1845
2053
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1846
|
-
const populate = await getService$
|
2054
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1847
2055
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1848
2056
|
const document = await documentManager2.findOne(id, model, {
|
1849
2057
|
populate,
|
@@ -1882,13 +2090,13 @@ const collectionTypes = {
|
|
1882
2090
|
async delete(ctx) {
|
1883
2091
|
const { userAbility } = ctx.state;
|
1884
2092
|
const { id, model } = ctx.params;
|
1885
|
-
const documentManager2 = getService$
|
1886
|
-
const permissionChecker2 = getService$
|
2093
|
+
const documentManager2 = getService$2("document-manager");
|
2094
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1887
2095
|
if (permissionChecker2.cannot.delete()) {
|
1888
2096
|
return ctx.forbidden();
|
1889
2097
|
}
|
1890
2098
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1891
|
-
const populate = await getService$
|
2099
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1892
2100
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1893
2101
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1894
2102
|
if (documentLocales.length === 0) {
|
@@ -1910,14 +2118,14 @@ const collectionTypes = {
|
|
1910
2118
|
const { userAbility } = ctx.state;
|
1911
2119
|
const { id, model } = ctx.params;
|
1912
2120
|
const { body } = ctx.request;
|
1913
|
-
const documentManager2 = getService$
|
1914
|
-
const permissionChecker2 = getService$
|
2121
|
+
const documentManager2 = getService$2("document-manager");
|
2122
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1915
2123
|
if (permissionChecker2.cannot.publish()) {
|
1916
2124
|
return ctx.forbidden();
|
1917
2125
|
}
|
1918
2126
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1919
2127
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1920
|
-
const populate = await getService$
|
2128
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1921
2129
|
let document;
|
1922
2130
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1923
2131
|
const isCreate = fp.isNil(id);
|
@@ -1965,13 +2173,13 @@ const collectionTypes = {
|
|
1965
2173
|
const { body } = ctx.request;
|
1966
2174
|
const { documentIds } = body;
|
1967
2175
|
await validateBulkActionInput(body);
|
1968
|
-
const documentManager2 = getService$
|
1969
|
-
const permissionChecker2 = getService$
|
2176
|
+
const documentManager2 = getService$2("document-manager");
|
2177
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1970
2178
|
if (permissionChecker2.cannot.publish()) {
|
1971
2179
|
return ctx.forbidden();
|
1972
2180
|
}
|
1973
2181
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1974
|
-
const populate = await getService$
|
2182
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1975
2183
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1976
2184
|
allowMultipleLocales: true
|
1977
2185
|
});
|
@@ -1996,8 +2204,8 @@ const collectionTypes = {
|
|
1996
2204
|
const { body } = ctx.request;
|
1997
2205
|
const { documentIds } = body;
|
1998
2206
|
await validateBulkActionInput(body);
|
1999
|
-
const documentManager2 = getService$
|
2000
|
-
const permissionChecker2 = getService$
|
2207
|
+
const documentManager2 = getService$2("document-manager");
|
2208
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2001
2209
|
if (permissionChecker2.cannot.unpublish()) {
|
2002
2210
|
return ctx.forbidden();
|
2003
2211
|
}
|
@@ -2026,8 +2234,8 @@ const collectionTypes = {
|
|
2026
2234
|
const {
|
2027
2235
|
body: { discardDraft, ...body }
|
2028
2236
|
} = ctx.request;
|
2029
|
-
const documentManager2 = getService$
|
2030
|
-
const permissionChecker2 = getService$
|
2237
|
+
const documentManager2 = getService$2("document-manager");
|
2238
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2031
2239
|
if (permissionChecker2.cannot.unpublish()) {
|
2032
2240
|
return ctx.forbidden();
|
2033
2241
|
}
|
@@ -2035,7 +2243,7 @@ const collectionTypes = {
|
|
2035
2243
|
return ctx.forbidden();
|
2036
2244
|
}
|
2037
2245
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2038
|
-
const populate = await getService$
|
2246
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2039
2247
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2040
2248
|
const document = await documentManager2.findOne(id, model, {
|
2041
2249
|
populate,
|
@@ -2066,13 +2274,13 @@ const collectionTypes = {
|
|
2066
2274
|
const { userAbility } = ctx.state;
|
2067
2275
|
const { id, model } = ctx.params;
|
2068
2276
|
const { body } = ctx.request;
|
2069
|
-
const documentManager2 = getService$
|
2070
|
-
const permissionChecker2 = getService$
|
2277
|
+
const documentManager2 = getService$2("document-manager");
|
2278
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2071
2279
|
if (permissionChecker2.cannot.discard()) {
|
2072
2280
|
return ctx.forbidden();
|
2073
2281
|
}
|
2074
2282
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2075
|
-
const populate = await getService$
|
2283
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2076
2284
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2077
2285
|
const document = await documentManager2.findOne(id, model, {
|
2078
2286
|
populate,
|
@@ -2097,13 +2305,13 @@ const collectionTypes = {
|
|
2097
2305
|
const { query, body } = ctx.request;
|
2098
2306
|
const { documentIds } = body;
|
2099
2307
|
await validateBulkActionInput(body);
|
2100
|
-
const documentManager2 = getService$
|
2101
|
-
const permissionChecker2 = getService$
|
2308
|
+
const documentManager2 = getService$2("document-manager");
|
2309
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2102
2310
|
if (permissionChecker2.cannot.delete()) {
|
2103
2311
|
return ctx.forbidden();
|
2104
2312
|
}
|
2105
2313
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2106
|
-
const populate = await getService$
|
2314
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2107
2315
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2108
2316
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2109
2317
|
populate,
|
@@ -2124,13 +2332,13 @@ const collectionTypes = {
|
|
2124
2332
|
async countDraftRelations(ctx) {
|
2125
2333
|
const { userAbility } = ctx.state;
|
2126
2334
|
const { model, id } = ctx.params;
|
2127
|
-
const documentManager2 = getService$
|
2128
|
-
const permissionChecker2 = getService$
|
2335
|
+
const documentManager2 = getService$2("document-manager");
|
2336
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2129
2337
|
if (permissionChecker2.cannot.read()) {
|
2130
2338
|
return ctx.forbidden();
|
2131
2339
|
}
|
2132
2340
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2133
|
-
const populate = await getService$
|
2341
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2134
2342
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2135
2343
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2136
2344
|
if (!entity) {
|
@@ -2149,8 +2357,8 @@ const collectionTypes = {
|
|
2149
2357
|
const ids = ctx.request.query.documentIds;
|
2150
2358
|
const locale = ctx.request.query.locale;
|
2151
2359
|
const { model } = ctx.params;
|
2152
|
-
const documentManager2 = getService$
|
2153
|
-
const permissionChecker2 = getService$
|
2360
|
+
const documentManager2 = getService$2("document-manager");
|
2361
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2154
2362
|
if (permissionChecker2.cannot.read()) {
|
2155
2363
|
return ctx.forbidden();
|
2156
2364
|
}
|
@@ -2174,13 +2382,13 @@ const collectionTypes = {
|
|
2174
2382
|
};
|
2175
2383
|
const components$1 = {
|
2176
2384
|
findComponents(ctx) {
|
2177
|
-
const components2 = getService$
|
2178
|
-
const { toDto } = getService$
|
2385
|
+
const components2 = getService$2("components").findAllComponents();
|
2386
|
+
const { toDto } = getService$2("data-mapper");
|
2179
2387
|
ctx.body = { data: components2.map(toDto) };
|
2180
2388
|
},
|
2181
2389
|
async findComponentConfiguration(ctx) {
|
2182
2390
|
const { uid: uid2 } = ctx.params;
|
2183
|
-
const componentService = getService$
|
2391
|
+
const componentService = getService$2("components");
|
2184
2392
|
const component = componentService.findComponent(uid2);
|
2185
2393
|
if (!component) {
|
2186
2394
|
return ctx.notFound("component.notFound");
|
@@ -2197,7 +2405,7 @@ const components$1 = {
|
|
2197
2405
|
async updateComponentConfiguration(ctx) {
|
2198
2406
|
const { uid: uid2 } = ctx.params;
|
2199
2407
|
const { body } = ctx.request;
|
2200
|
-
const componentService = getService$
|
2408
|
+
const componentService = getService$2("components");
|
2201
2409
|
const component = componentService.findComponent(uid2);
|
2202
2410
|
if (!component) {
|
2203
2411
|
return ctx.notFound("component.notFound");
|
@@ -2231,12 +2439,12 @@ const contentTypes = {
|
|
2231
2439
|
} catch (error) {
|
2232
2440
|
return ctx.send({ error }, 400);
|
2233
2441
|
}
|
2234
|
-
const contentTypes2 = getService$
|
2235
|
-
const { toDto } = getService$
|
2442
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2443
|
+
const { toDto } = getService$2("data-mapper");
|
2236
2444
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2237
2445
|
},
|
2238
2446
|
async findContentTypesSettings(ctx) {
|
2239
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2447
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2240
2448
|
const contentTypes2 = await findAllContentTypes();
|
2241
2449
|
const configurations = await Promise.all(
|
2242
2450
|
contentTypes2.map(async (contentType) => {
|
@@ -2250,7 +2458,7 @@ const contentTypes = {
|
|
2250
2458
|
},
|
2251
2459
|
async findContentTypeConfiguration(ctx) {
|
2252
2460
|
const { uid: uid2 } = ctx.params;
|
2253
|
-
const contentTypeService = getService$
|
2461
|
+
const contentTypeService = getService$2("content-types");
|
2254
2462
|
const contentType = await contentTypeService.findContentType(uid2);
|
2255
2463
|
if (!contentType) {
|
2256
2464
|
return ctx.notFound("contentType.notFound");
|
@@ -2272,13 +2480,13 @@ const contentTypes = {
|
|
2272
2480
|
const { userAbility } = ctx.state;
|
2273
2481
|
const { uid: uid2 } = ctx.params;
|
2274
2482
|
const { body } = ctx.request;
|
2275
|
-
const contentTypeService = getService$
|
2276
|
-
const metricsService = getService$
|
2483
|
+
const contentTypeService = getService$2("content-types");
|
2484
|
+
const metricsService = getService$2("metrics");
|
2277
2485
|
const contentType = await contentTypeService.findContentType(uid2);
|
2278
2486
|
if (!contentType) {
|
2279
2487
|
return ctx.notFound("contentType.notFound");
|
2280
2488
|
}
|
2281
|
-
if (!getService$
|
2489
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2282
2490
|
return ctx.forbidden();
|
2283
2491
|
}
|
2284
2492
|
let input;
|
@@ -2311,10 +2519,10 @@ const contentTypes = {
|
|
2311
2519
|
};
|
2312
2520
|
const init = {
|
2313
2521
|
getInitData(ctx) {
|
2314
|
-
const { toDto } = getService$
|
2315
|
-
const { findAllComponents } = getService$
|
2316
|
-
const { getAllFieldSizes } = getService$
|
2317
|
-
const { findAllContentTypes } = getService$
|
2522
|
+
const { toDto } = getService$2("data-mapper");
|
2523
|
+
const { findAllComponents } = getService$2("components");
|
2524
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2525
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2318
2526
|
ctx.body = {
|
2319
2527
|
data: {
|
2320
2528
|
fieldSizes: getAllFieldSizes(),
|
@@ -2350,7 +2558,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2350
2558
|
params.filters.$and.push(filtersClause);
|
2351
2559
|
};
|
2352
2560
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2353
|
-
const permissionChecker2 = getService$
|
2561
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2354
2562
|
userAbility,
|
2355
2563
|
model: model.uid
|
2356
2564
|
});
|
@@ -2364,15 +2572,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2364
2572
|
}
|
2365
2573
|
return mainField;
|
2366
2574
|
};
|
2367
|
-
const addStatusToRelations = async (
|
2368
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2575
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2576
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2369
2577
|
return relations2;
|
2370
2578
|
}
|
2371
|
-
const documentMetadata2 = getService$
|
2372
|
-
|
2579
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2580
|
+
if (!relations2.length) {
|
2581
|
+
return relations2;
|
2582
|
+
}
|
2583
|
+
const firstRelation = relations2[0];
|
2584
|
+
const filters = {
|
2585
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2586
|
+
// NOTE: find the "opposite" status
|
2587
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2588
|
+
};
|
2589
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2590
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2591
|
+
filters
|
2592
|
+
});
|
2373
2593
|
return relations2.map((relation) => {
|
2374
|
-
const availableStatuses =
|
2375
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2594
|
+
const availableStatuses = availableStatus.filter(
|
2595
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2376
2596
|
);
|
2377
2597
|
return {
|
2378
2598
|
...relation,
|
@@ -2403,8 +2623,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2403
2623
|
const sourceModel = strapi.getModel(sourceUid);
|
2404
2624
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2405
2625
|
const isSourceDP = isDP(sourceModel);
|
2406
|
-
if (!isSourceDP)
|
2407
|
-
return { status: void 0 };
|
2626
|
+
if (!isSourceDP) return { status: void 0 };
|
2408
2627
|
switch (status) {
|
2409
2628
|
case "published":
|
2410
2629
|
return { status: "published" };
|
@@ -2434,7 +2653,7 @@ const relations = {
|
|
2434
2653
|
ctx.request?.query?.locale
|
2435
2654
|
);
|
2436
2655
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2437
|
-
const permissionChecker2 = getService$
|
2656
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2438
2657
|
userAbility,
|
2439
2658
|
model
|
2440
2659
|
});
|
@@ -2459,7 +2678,7 @@ const relations = {
|
|
2459
2678
|
where.id = id;
|
2460
2679
|
}
|
2461
2680
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2462
|
-
const populate = await getService$
|
2681
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2463
2682
|
const currentEntity = await strapi.db.query(model).findOne({
|
2464
2683
|
where,
|
2465
2684
|
populate
|
@@ -2474,7 +2693,7 @@ const relations = {
|
|
2474
2693
|
}
|
2475
2694
|
entryId = currentEntity.id;
|
2476
2695
|
}
|
2477
|
-
const modelConfig = isComponent2 ? await getService$
|
2696
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2478
2697
|
const targetSchema = strapi.getModel(targetUid);
|
2479
2698
|
const mainField = fp.flow(
|
2480
2699
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2528,7 +2747,7 @@ const relations = {
|
|
2528
2747
|
}
|
2529
2748
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2530
2749
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2531
|
-
const permissionChecker2 = getService$
|
2750
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2532
2751
|
userAbility: ctx.state.userAbility,
|
2533
2752
|
model: targetUid
|
2534
2753
|
});
|
@@ -2601,21 +2820,33 @@ const relations = {
|
|
2601
2820
|
attribute,
|
2602
2821
|
targetField,
|
2603
2822
|
fieldsToSelect,
|
2604
|
-
|
2605
|
-
|
2606
|
-
}
|
2607
|
-
target: {
|
2608
|
-
schema: { uid: targetUid }
|
2609
|
-
}
|
2823
|
+
status,
|
2824
|
+
source: { schema: sourceSchema },
|
2825
|
+
target: { schema: targetSchema }
|
2610
2826
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2611
|
-
const
|
2827
|
+
const { uid: sourceUid } = sourceSchema;
|
2828
|
+
const { uid: targetUid } = targetSchema;
|
2829
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2612
2830
|
const dbQuery = strapi.db.query(sourceUid);
|
2613
2831
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2832
|
+
const filters = {};
|
2833
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2834
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2835
|
+
if (status === "published") {
|
2836
|
+
filters.publishedAt = { $notNull: true };
|
2837
|
+
} else {
|
2838
|
+
filters.publishedAt = { $null: true };
|
2839
|
+
}
|
2840
|
+
}
|
2841
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2842
|
+
filters.publishedAt = { $null: true };
|
2843
|
+
}
|
2614
2844
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2615
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2845
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2616
2846
|
ordering: "desc",
|
2617
2847
|
page: ctx.request.query.page,
|
2618
|
-
pageSize: ctx.request.query.pageSize
|
2848
|
+
pageSize: ctx.request.query.pageSize,
|
2849
|
+
filters
|
2619
2850
|
});
|
2620
2851
|
const loadedIds = res.results.map((item) => item.id);
|
2621
2852
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2636,10 +2867,10 @@ const relations = {
|
|
2636
2867
|
}
|
2637
2868
|
};
|
2638
2869
|
const buildPopulateFromQuery = async (query, model) => {
|
2639
|
-
return getService$
|
2870
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2640
2871
|
};
|
2641
2872
|
const findDocument = async (query, uid2, opts = {}) => {
|
2642
|
-
const documentManager2 = getService$
|
2873
|
+
const documentManager2 = getService$2("document-manager");
|
2643
2874
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2644
2875
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2645
2876
|
};
|
@@ -2647,8 +2878,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2647
2878
|
const { user, userAbility } = ctx.state;
|
2648
2879
|
const { model } = ctx.params;
|
2649
2880
|
const { body, query } = ctx.request;
|
2650
|
-
const documentManager2 = getService$
|
2651
|
-
const permissionChecker2 = getService$
|
2881
|
+
const documentManager2 = getService$2("document-manager");
|
2882
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2652
2883
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2653
2884
|
throw new strapiUtils.errors.ForbiddenError();
|
2654
2885
|
}
|
@@ -2689,7 +2920,7 @@ const singleTypes = {
|
|
2689
2920
|
const { userAbility } = ctx.state;
|
2690
2921
|
const { model } = ctx.params;
|
2691
2922
|
const { query = {} } = ctx.request;
|
2692
|
-
const permissionChecker2 = getService$
|
2923
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2693
2924
|
if (permissionChecker2.cannot.read()) {
|
2694
2925
|
return ctx.forbidden();
|
2695
2926
|
}
|
@@ -2723,7 +2954,7 @@ const singleTypes = {
|
|
2723
2954
|
async createOrUpdate(ctx) {
|
2724
2955
|
const { userAbility } = ctx.state;
|
2725
2956
|
const { model } = ctx.params;
|
2726
|
-
const permissionChecker2 = getService$
|
2957
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2727
2958
|
const document = await createOrUpdateDocument(ctx);
|
2728
2959
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2729
2960
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2732,8 +2963,8 @@ const singleTypes = {
|
|
2732
2963
|
const { userAbility } = ctx.state;
|
2733
2964
|
const { model } = ctx.params;
|
2734
2965
|
const { query = {} } = ctx.request;
|
2735
|
-
const documentManager2 = getService$
|
2736
|
-
const permissionChecker2 = getService$
|
2966
|
+
const documentManager2 = getService$2("document-manager");
|
2967
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2737
2968
|
if (permissionChecker2.cannot.delete()) {
|
2738
2969
|
return ctx.forbidden();
|
2739
2970
|
}
|
@@ -2761,8 +2992,8 @@ const singleTypes = {
|
|
2761
2992
|
const { userAbility } = ctx.state;
|
2762
2993
|
const { model } = ctx.params;
|
2763
2994
|
const { query = {} } = ctx.request;
|
2764
|
-
const documentManager2 = getService$
|
2765
|
-
const permissionChecker2 = getService$
|
2995
|
+
const documentManager2 = getService$2("document-manager");
|
2996
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2766
2997
|
if (permissionChecker2.cannot.publish()) {
|
2767
2998
|
return ctx.forbidden();
|
2768
2999
|
}
|
@@ -2790,8 +3021,8 @@ const singleTypes = {
|
|
2790
3021
|
body: { discardDraft, ...body },
|
2791
3022
|
query = {}
|
2792
3023
|
} = ctx.request;
|
2793
|
-
const documentManager2 = getService$
|
2794
|
-
const permissionChecker2 = getService$
|
3024
|
+
const documentManager2 = getService$2("document-manager");
|
3025
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2795
3026
|
if (permissionChecker2.cannot.unpublish()) {
|
2796
3027
|
return ctx.forbidden();
|
2797
3028
|
}
|
@@ -2825,8 +3056,8 @@ const singleTypes = {
|
|
2825
3056
|
const { userAbility } = ctx.state;
|
2826
3057
|
const { model } = ctx.params;
|
2827
3058
|
const { body, query = {} } = ctx.request;
|
2828
|
-
const documentManager2 = getService$
|
2829
|
-
const permissionChecker2 = getService$
|
3059
|
+
const documentManager2 = getService$2("document-manager");
|
3060
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2830
3061
|
if (permissionChecker2.cannot.discard()) {
|
2831
3062
|
return ctx.forbidden();
|
2832
3063
|
}
|
@@ -2849,8 +3080,8 @@ const singleTypes = {
|
|
2849
3080
|
const { userAbility } = ctx.state;
|
2850
3081
|
const { model } = ctx.params;
|
2851
3082
|
const { query } = ctx.request;
|
2852
|
-
const documentManager2 = getService$
|
2853
|
-
const permissionChecker2 = getService$
|
3083
|
+
const documentManager2 = getService$2("document-manager");
|
3084
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2854
3085
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2855
3086
|
if (permissionChecker2.cannot.read()) {
|
2856
3087
|
return ctx.forbidden();
|
@@ -2874,7 +3105,7 @@ const uid$1 = {
|
|
2874
3105
|
const { query = {} } = ctx.request;
|
2875
3106
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2876
3107
|
await validateUIDField(contentTypeUID, field);
|
2877
|
-
const uidService = getService$
|
3108
|
+
const uidService = getService$2("uid");
|
2878
3109
|
ctx.body = {
|
2879
3110
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2880
3111
|
};
|
@@ -2886,7 +3117,7 @@ const uid$1 = {
|
|
2886
3117
|
const { query = {} } = ctx.request;
|
2887
3118
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2888
3119
|
await validateUIDField(contentTypeUID, field);
|
2889
|
-
const uidService = getService$
|
3120
|
+
const uidService = getService$2("uid");
|
2890
3121
|
const isAvailable = await uidService.checkUIDAvailability({
|
2891
3122
|
contentTypeUID,
|
2892
3123
|
field,
|
@@ -2907,7 +3138,8 @@ const controllers = {
|
|
2907
3138
|
relations,
|
2908
3139
|
"single-types": singleTypes,
|
2909
3140
|
uid: uid$1,
|
2910
|
-
...history.controllers ? history.controllers : {}
|
3141
|
+
...history.controllers ? history.controllers : {},
|
3142
|
+
...preview.controllers ? preview.controllers : {}
|
2911
3143
|
};
|
2912
3144
|
const keys = {
|
2913
3145
|
CONFIGURATION: "configuration"
|
@@ -3036,18 +3268,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3036
3268
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3037
3269
|
___default.default.set(acc, [key], updatedMeta);
|
3038
3270
|
}
|
3039
|
-
if (!___default.default.has(edit, "mainField"))
|
3040
|
-
return acc;
|
3271
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3041
3272
|
if (!isRelation$1(attr)) {
|
3042
3273
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3043
3274
|
___default.default.set(acc, [key], updatedMeta);
|
3044
3275
|
return acc;
|
3045
3276
|
}
|
3046
|
-
if (edit.mainField === "id")
|
3047
|
-
return acc;
|
3277
|
+
if (edit.mainField === "id") return acc;
|
3048
3278
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3049
|
-
if (!targetSchema)
|
3050
|
-
return acc;
|
3279
|
+
if (!targetSchema) return acc;
|
3051
3280
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3052
3281
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3053
3282
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3058,12 +3287,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3058
3287
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3059
3288
|
}
|
3060
3289
|
const getTargetSchema = (targetModel) => {
|
3061
|
-
return getService$
|
3290
|
+
return getService$2("content-types").findContentType(targetModel);
|
3062
3291
|
};
|
3063
3292
|
const DEFAULT_LIST_LENGTH = 4;
|
3064
3293
|
const MAX_ROW_SIZE = 12;
|
3065
3294
|
const isAllowedFieldSize = (type, size) => {
|
3066
|
-
const { getFieldSize } = getService$
|
3295
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3067
3296
|
const fieldSize = getFieldSize(type);
|
3068
3297
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3069
3298
|
return false;
|
@@ -3071,7 +3300,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3071
3300
|
return size <= MAX_ROW_SIZE;
|
3072
3301
|
};
|
3073
3302
|
const getDefaultFieldSize = (attribute) => {
|
3074
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3303
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3075
3304
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3076
3305
|
};
|
3077
3306
|
async function createDefaultLayouts(schema) {
|
@@ -3092,8 +3321,7 @@ function createDefaultEditLayout(schema) {
|
|
3092
3321
|
return appendToEditLayout([], keys2, schema);
|
3093
3322
|
}
|
3094
3323
|
function syncLayouts(configuration, schema) {
|
3095
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3096
|
-
return createDefaultLayouts(schema);
|
3324
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3097
3325
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3098
3326
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3099
3327
|
const cleanEditRelations = editRelations.filter(
|
@@ -3104,9 +3332,8 @@ function syncLayouts(configuration, schema) {
|
|
3104
3332
|
for (const row of edit) {
|
3105
3333
|
const newRow = [];
|
3106
3334
|
for (const el of row) {
|
3107
|
-
if (!hasEditableAttribute(schema, el.name))
|
3108
|
-
|
3109
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3335
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3336
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3110
3337
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3111
3338
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3112
3339
|
elementsToReAppend.push(el.name);
|
@@ -3136,8 +3363,7 @@ function syncLayouts(configuration, schema) {
|
|
3136
3363
|
};
|
3137
3364
|
}
|
3138
3365
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3139
|
-
if (keysToAppend.length === 0)
|
3140
|
-
return layout;
|
3366
|
+
if (keysToAppend.length === 0) return layout;
|
3141
3367
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3142
3368
|
if (!layout[currentRowIndex]) {
|
3143
3369
|
layout[currentRowIndex] = [];
|
@@ -3246,17 +3472,17 @@ const configurationService$1 = createConfigurationService({
|
|
3246
3472
|
isComponent: true,
|
3247
3473
|
prefix: STORE_KEY_PREFIX,
|
3248
3474
|
getModels() {
|
3249
|
-
const { toContentManagerModel } = getService$
|
3475
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3250
3476
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3251
3477
|
}
|
3252
3478
|
});
|
3253
3479
|
const components = ({ strapi: strapi2 }) => ({
|
3254
3480
|
findAllComponents() {
|
3255
|
-
const { toContentManagerModel } = getService$
|
3481
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3256
3482
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3257
3483
|
},
|
3258
3484
|
findComponent(uid2) {
|
3259
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3260
3486
|
const component = strapi2.components[uid2];
|
3261
3487
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3262
3488
|
},
|
@@ -3307,17 +3533,17 @@ const configurationService = createConfigurationService({
|
|
3307
3533
|
storeUtils,
|
3308
3534
|
prefix: "content_types",
|
3309
3535
|
getModels() {
|
3310
|
-
const { toContentManagerModel } = getService$
|
3536
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3311
3537
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3312
3538
|
}
|
3313
3539
|
});
|
3314
3540
|
const service = ({ strapi: strapi2 }) => ({
|
3315
3541
|
findAllContentTypes() {
|
3316
|
-
const { toContentManagerModel } = getService$
|
3542
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3317
3543
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3318
3544
|
},
|
3319
3545
|
findContentType(uid2) {
|
3320
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3321
3547
|
const contentType = strapi2.contentTypes[uid2];
|
3322
3548
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3323
3549
|
},
|
@@ -3346,7 +3572,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3346
3572
|
return this.findConfiguration(contentType);
|
3347
3573
|
},
|
3348
3574
|
findComponentsConfigurations(contentType) {
|
3349
|
-
return getService$
|
3575
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3350
3576
|
},
|
3351
3577
|
syncConfigurations() {
|
3352
3578
|
return configurationService.syncConfigurations();
|
@@ -3618,7 +3844,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3618
3844
|
return userAbility.can(action);
|
3619
3845
|
},
|
3620
3846
|
async registerPermissions() {
|
3621
|
-
const displayedContentTypes = getService$
|
3847
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3622
3848
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3623
3849
|
const actions = [
|
3624
3850
|
{
|
@@ -3703,6 +3929,12 @@ function getPopulateForRelation(attribute, model, attributeName, { countMany, co
|
|
3703
3929
|
if (initialPopulate) {
|
3704
3930
|
return initialPopulate;
|
3705
3931
|
}
|
3932
|
+
if (attributeName === "localizations") {
|
3933
|
+
const validationPopulate = getPopulateForValidation(model.uid);
|
3934
|
+
return {
|
3935
|
+
populate: validationPopulate.populate
|
3936
|
+
};
|
3937
|
+
}
|
3706
3938
|
if (!isVisibleAttribute$1(model, attributeName)) {
|
3707
3939
|
return true;
|
3708
3940
|
}
|
@@ -3762,6 +3994,9 @@ const getDeepPopulate = (uid2, {
|
|
3762
3994
|
return {};
|
3763
3995
|
}
|
3764
3996
|
const model = strapi.getModel(uid2);
|
3997
|
+
if (!model) {
|
3998
|
+
return {};
|
3999
|
+
}
|
3765
4000
|
return Object.keys(model.attributes).reduce(
|
3766
4001
|
(populateAcc, attributeName) => fp.merge(
|
3767
4002
|
populateAcc,
|
@@ -3781,40 +4016,46 @@ const getDeepPopulate = (uid2, {
|
|
3781
4016
|
{}
|
3782
4017
|
);
|
3783
4018
|
};
|
3784
|
-
const
|
3785
|
-
|
3786
|
-
|
3787
|
-
countOne = false,
|
3788
|
-
maxLevel = Infinity
|
3789
|
-
} = {}, level = 1) => {
|
3790
|
-
if (level > maxLevel) {
|
4019
|
+
const getPopulateForValidation = (uid2) => {
|
4020
|
+
const model = strapi.getModel(uid2);
|
4021
|
+
if (!model) {
|
3791
4022
|
return {};
|
3792
4023
|
}
|
3793
|
-
const model = strapi.getModel(uid2);
|
3794
4024
|
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3795
|
-
if (
|
4025
|
+
if (isScalarAttribute(attribute)) {
|
4026
|
+
if (getDoesAttributeRequireValidation(attribute)) {
|
4027
|
+
populateAcc.fields = populateAcc.fields || [];
|
4028
|
+
populateAcc.fields.push(attributeName);
|
4029
|
+
}
|
3796
4030
|
return populateAcc;
|
3797
4031
|
}
|
3798
|
-
if (
|
3799
|
-
|
3800
|
-
|
3801
|
-
|
4032
|
+
if (isComponent(attribute)) {
|
4033
|
+
const component = attribute.component;
|
4034
|
+
const componentResult = getPopulateForValidation(component);
|
4035
|
+
if (Object.keys(componentResult).length > 0) {
|
4036
|
+
populateAcc.populate = populateAcc.populate || {};
|
4037
|
+
populateAcc.populate[attributeName] = componentResult;
|
4038
|
+
}
|
4039
|
+
return populateAcc;
|
3802
4040
|
}
|
3803
|
-
|
3804
|
-
|
3805
|
-
|
3806
|
-
|
3807
|
-
|
3808
|
-
|
3809
|
-
|
3810
|
-
|
3811
|
-
|
3812
|
-
countOne,
|
3813
|
-
maxLevel
|
4041
|
+
if (isDynamicZone(attribute)) {
|
4042
|
+
const components2 = attribute.components;
|
4043
|
+
const componentsResult = (components2 || []).reduce(
|
4044
|
+
(acc, componentUID) => {
|
4045
|
+
const componentResult = getPopulateForValidation(componentUID);
|
4046
|
+
if (Object.keys(componentResult).length > 0) {
|
4047
|
+
acc[componentUID] = componentResult;
|
4048
|
+
}
|
4049
|
+
return acc;
|
3814
4050
|
},
|
3815
|
-
|
3816
|
-
)
|
3817
|
-
|
4051
|
+
{}
|
4052
|
+
);
|
4053
|
+
if (Object.keys(componentsResult).length > 0) {
|
4054
|
+
populateAcc.populate = populateAcc.populate || {};
|
4055
|
+
populateAcc.populate[attributeName] = { on: componentsResult };
|
4056
|
+
}
|
4057
|
+
}
|
4058
|
+
return populateAcc;
|
3818
4059
|
}, {});
|
3819
4060
|
};
|
3820
4061
|
const getDeepPopulateDraftCount = (uid2) => {
|
@@ -3894,7 +4135,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3894
4135
|
return populateQuery;
|
3895
4136
|
};
|
3896
4137
|
const buildDeepPopulate = (uid2) => {
|
3897
|
-
return getService$
|
4138
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3898
4139
|
};
|
3899
4140
|
const populateBuilder = (uid2) => {
|
3900
4141
|
let getInitialPopulate = async () => {
|
@@ -4056,7 +4297,6 @@ const AVAILABLE_LOCALES_FIELDS = [
|
|
4056
4297
|
"locale",
|
4057
4298
|
"updatedAt",
|
4058
4299
|
"createdAt",
|
4059
|
-
"status",
|
4060
4300
|
"publishedAt",
|
4061
4301
|
"documentId"
|
4062
4302
|
];
|
@@ -4077,34 +4317,20 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4077
4317
|
/**
|
4078
4318
|
* Returns available locales of a document for the current status
|
4079
4319
|
*/
|
4080
|
-
async getAvailableLocales(uid2, version, allVersions
|
4320
|
+
async getAvailableLocales(uid2, version, allVersions) {
|
4081
4321
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4082
|
-
|
4322
|
+
if (version.locale) {
|
4323
|
+
delete versionsByLocale[version.locale];
|
4324
|
+
}
|
4083
4325
|
const model = strapi2.getModel(uid2);
|
4084
|
-
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4085
|
-
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4086
|
-
({ key }, { remove }) => {
|
4087
|
-
if (keysToKeep.includes(key)) {
|
4088
|
-
return;
|
4089
|
-
}
|
4090
|
-
remove(key);
|
4091
|
-
},
|
4092
|
-
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4093
|
-
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4094
|
-
localeVersion
|
4095
|
-
);
|
4096
4326
|
const mappingResult = await strapiUtils.async.map(
|
4097
4327
|
Object.values(versionsByLocale),
|
4098
4328
|
async (localeVersions) => {
|
4099
|
-
const mappedLocaleVersions = await strapiUtils.async.map(
|
4100
|
-
localeVersions,
|
4101
|
-
traversalFunction
|
4102
|
-
);
|
4103
4329
|
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4104
|
-
return
|
4330
|
+
return localeVersions[0];
|
4105
4331
|
}
|
4106
|
-
const draftVersion =
|
4107
|
-
const otherVersions =
|
4332
|
+
const draftVersion = localeVersions.find((v) => v.publishedAt === null);
|
4333
|
+
const otherVersions = localeVersions.filter((v) => v.id !== draftVersion?.id);
|
4108
4334
|
if (!draftVersion) {
|
4109
4335
|
return;
|
4110
4336
|
}
|
@@ -4126,8 +4352,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4126
4352
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4127
4353
|
return matchLocale && matchStatus;
|
4128
4354
|
});
|
4129
|
-
if (!availableStatus)
|
4130
|
-
return availableStatus;
|
4355
|
+
if (!availableStatus) return availableStatus;
|
4131
4356
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4132
4357
|
},
|
4133
4358
|
/**
|
@@ -4137,18 +4362,19 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4137
4362
|
* @returns
|
4138
4363
|
*/
|
4139
4364
|
async getManyAvailableStatus(uid2, documents) {
|
4140
|
-
if (!documents.length)
|
4141
|
-
return [];
|
4365
|
+
if (!documents.length) return [];
|
4142
4366
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4143
|
-
const
|
4144
|
-
const
|
4145
|
-
|
4146
|
-
|
4147
|
-
|
4148
|
-
|
4149
|
-
|
4150
|
-
|
4151
|
-
|
4367
|
+
const locales = documents.map((d) => d.locale).filter(Boolean);
|
4368
|
+
const where = {
|
4369
|
+
documentId: { $in: documents.map((d) => d.documentId).filter(Boolean) },
|
4370
|
+
publishedAt: { $null: status === "published" }
|
4371
|
+
};
|
4372
|
+
if (locales.length) {
|
4373
|
+
where.locale = { $in: locales };
|
4374
|
+
}
|
4375
|
+
return strapi2.query(uid2).findMany({
|
4376
|
+
where,
|
4377
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"]
|
4152
4378
|
});
|
4153
4379
|
},
|
4154
4380
|
getStatus(version, otherDocumentStatuses) {
|
@@ -4165,10 +4391,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4165
4391
|
} else if (otherVersion) {
|
4166
4392
|
draftVersion = otherVersion;
|
4167
4393
|
}
|
4168
|
-
if (!draftVersion)
|
4169
|
-
|
4170
|
-
if (!publishedVersion)
|
4171
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4394
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4395
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4172
4396
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4173
4397
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4174
4398
|
},
|
@@ -4176,11 +4400,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4176
4400
|
// We could refactor this so the locales are only loaded when they're
|
4177
4401
|
// needed. e.g. in the bulk locale action modal.
|
4178
4402
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4179
|
-
const populate =
|
4180
|
-
const
|
4181
|
-
where: { documentId: version.documentId },
|
4403
|
+
const { populate = {}, fields = [] } = getPopulateForValidation(uid2);
|
4404
|
+
const params = {
|
4182
4405
|
populate: {
|
4183
|
-
// Populate only fields that require validation for bulk locale actions
|
4184
4406
|
...populate,
|
4185
4407
|
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
4186
4408
|
createdBy: {
|
@@ -4189,9 +4411,15 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4189
4411
|
updatedBy: {
|
4190
4412
|
select: ["id", "firstname", "lastname", "email"]
|
4191
4413
|
}
|
4414
|
+
},
|
4415
|
+
fields: fp.uniq([...AVAILABLE_LOCALES_FIELDS, ...fields]),
|
4416
|
+
filters: {
|
4417
|
+
documentId: version.documentId
|
4192
4418
|
}
|
4193
|
-
}
|
4194
|
-
const
|
4419
|
+
};
|
4420
|
+
const dbParams = strapi2.get("query-params").transform(uid2, params);
|
4421
|
+
const versions = await strapi2.db.query(uid2).findMany(dbParams);
|
4422
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions) : [];
|
4195
4423
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
4196
4424
|
return {
|
4197
4425
|
availableLocales: availableLocalesResult,
|
@@ -4218,6 +4446,16 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4218
4446
|
opts.availableStatus = false;
|
4219
4447
|
}
|
4220
4448
|
const meta = await this.getMetadata(uid2, document, opts);
|
4449
|
+
if (document.localizations) {
|
4450
|
+
const otherStatus = await this.getManyAvailableStatus(uid2, document.localizations);
|
4451
|
+
document.localizations = document.localizations.map((d) => {
|
4452
|
+
const status = otherStatus.find((s) => s.documentId === d.documentId);
|
4453
|
+
return {
|
4454
|
+
...d,
|
4455
|
+
status: this.getStatus(d, status ? [status] : [])
|
4456
|
+
};
|
4457
|
+
});
|
4458
|
+
}
|
4221
4459
|
return {
|
4222
4460
|
data: {
|
4223
4461
|
...document,
|
@@ -4435,7 +4673,8 @@ const services = {
|
|
4435
4673
|
permission,
|
4436
4674
|
"populate-builder": populateBuilder$1,
|
4437
4675
|
uid,
|
4438
|
-
...history.services ? history.services : {}
|
4676
|
+
...history.services ? history.services : {},
|
4677
|
+
...preview.services ? preview.services : {}
|
4439
4678
|
};
|
4440
4679
|
const index = () => {
|
4441
4680
|
return {
|