@strapi/content-manager 0.0.0-experimental.cb311d9fcfbd8e441f790aea232f0a39bdd90e16 → 0.0.0-experimental.cb74730ce5154c26404d4dccca14976a22319002
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-D0dyDTwq.mjs → ComponentConfigurationPage-BgCLcjXO.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-D0dyDTwq.mjs.map → ComponentConfigurationPage-BgCLcjXO.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DL1MHO8i.js → ComponentConfigurationPage-DywpTZeV.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-DL1MHO8i.js.map → ComponentConfigurationPage-DywpTZeV.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-13b7S5Cq.mjs → EditConfigurationPage-BNjOAHNS.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-13b7S5Cq.mjs.map → EditConfigurationPage-BNjOAHNS.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CMaOf-A-.js → EditConfigurationPage-CxRlP5if.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-CMaOf-A-.js.map → EditConfigurationPage-CxRlP5if.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-BSVmMpRd.js → EditViewPage-BRewdTqE.js} +63 -13
- package/dist/_chunks/EditViewPage-BRewdTqE.js.map +1 -0
- package/dist/_chunks/{EditViewPage-C3tIZ8F5.mjs → EditViewPage-CD_hqc1J.mjs} +63 -12
- package/dist/_chunks/EditViewPage-CD_hqc1J.mjs.map +1 -0
- package/dist/_chunks/{Field-BvuT8cGL.mjs → Field-BPkQ-3Ku.mjs} +230 -158
- package/dist/_chunks/Field-BPkQ-3Ku.mjs.map +1 -0
- package/dist/_chunks/{Field-DUCVth4C.js → Field-DwvmENVf.js} +233 -162
- package/dist/_chunks/Field-DwvmENVf.js.map +1 -0
- package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
- package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
- package/dist/_chunks/{Form-Cpl4W1ak.js → Form-C_Gwv8P_.js} +39 -21
- package/dist/_chunks/Form-C_Gwv8P_.js.map +1 -0
- package/dist/_chunks/{Form-BZmDNVr9.mjs → Form-Czi0cf_2.mjs} +37 -18
- package/dist/_chunks/Form-Czi0cf_2.mjs.map +1 -0
- package/dist/_chunks/{History-D4U2YISB.js → History-C1TKAig-.js} +42 -100
- package/dist/_chunks/History-C1TKAig-.js.map +1 -0
- package/dist/_chunks/{History-Cq_Hrzuu.mjs → History-CIQHyi4T.mjs} +43 -100
- package/dist/_chunks/History-CIQHyi4T.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-Bny6CdWe.js → ListConfigurationPage-D-NGRLYu.js} +19 -9
- package/dist/_chunks/ListConfigurationPage-D-NGRLYu.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-W-KQHmBv.mjs → ListConfigurationPage-DcZsfyEL.mjs} +19 -8
- package/dist/_chunks/ListConfigurationPage-DcZsfyEL.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-HBBnJa8K.mjs → ListViewPage-C10McTK1.mjs} +99 -72
- package/dist/_chunks/ListViewPage-C10McTK1.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-O8F1pBJo.js → ListViewPage-xv5IQoZp.js} +103 -77
- package/dist/_chunks/ListViewPage-xv5IQoZp.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-B-gIhHWM.mjs → NoContentTypePage-CPc0Cd3S.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-B-gIhHWM.mjs.map → NoContentTypePage-CPc0Cd3S.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CQWChGPw.js → NoContentTypePage-Dzw5Yj5u.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-CQWChGPw.js.map → NoContentTypePage-Dzw5Yj5u.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CY46zxnM.js → NoPermissionsPage-DAe5CDCC.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CY46zxnM.js.map → NoPermissionsPage-DAe5CDCC.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-XhOPl8wx.mjs → NoPermissionsPage-wfPBh2_0.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-XhOPl8wx.mjs.map → NoPermissionsPage-wfPBh2_0.mjs.map} +1 -1
- package/dist/_chunks/Preview-B7LyGT_b.js +290 -0
- package/dist/_chunks/Preview-B7LyGT_b.js.map +1 -0
- package/dist/_chunks/Preview-BVFFm7uB.mjs +272 -0
- package/dist/_chunks/Preview-BVFFm7uB.mjs.map +1 -0
- package/dist/_chunks/{Relations-C4gGfZRv.js → Relations-BmYR1AjY.js} +76 -43
- package/dist/_chunks/Relations-BmYR1AjY.js.map +1 -0
- package/dist/_chunks/{Relations-vFZ6Wasg.mjs → Relations-JPhWxk-s.mjs} +76 -42
- package/dist/_chunks/Relations-JPhWxk-s.mjs.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-BK8Xyl5I.js} +28 -15
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BK8Xyl5I.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-Dtk_ot79.mjs} +28 -15
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-Dtk_ot79.mjs.map} +1 -1
- package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
- package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
- package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
- package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-5EMXLEM_.js → index-C2Q_PLWj.js} +1199 -927
- package/dist/_chunks/index-C2Q_PLWj.js.map +1 -0
- package/dist/_chunks/{index-Dpxg3ctD.mjs → index-DLIkNVnQ.mjs} +1217 -945
- package/dist/_chunks/index-DLIkNVnQ.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-P3eKO1Qy.js → layout-7AsWJzZJ.js} +10 -10
- package/dist/_chunks/layout-7AsWJzZJ.js.map +1 -0
- package/dist/_chunks/{layout-C0INpKap.mjs → layout-qE8qkNH_.mjs} +9 -8
- package/dist/_chunks/layout-qE8qkNH_.mjs.map +1 -0
- 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-FBRRBWeO.mjs → relations-BjHH_1Am.mjs} +6 -7
- package/dist/_chunks/relations-BjHH_1Am.mjs.map +1 -0
- package/dist/_chunks/{relations-B1y0K6LE.js → relations-EifVzf_2.js} +6 -7
- package/dist/_chunks/relations-EifVzf_2.js.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/constants.d.ts +1 -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 +19 -20
- 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/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +486 -219
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +486 -218
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +3 -3
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- 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 +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.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/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.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 +15 -15
- package/dist/_chunks/EditViewPage-BSVmMpRd.js.map +0 -1
- package/dist/_chunks/EditViewPage-C3tIZ8F5.mjs.map +0 -1
- package/dist/_chunks/Field-BvuT8cGL.mjs.map +0 -1
- package/dist/_chunks/Field-DUCVth4C.js.map +0 -1
- package/dist/_chunks/Form-BZmDNVr9.mjs.map +0 -1
- package/dist/_chunks/Form-Cpl4W1ak.js.map +0 -1
- package/dist/_chunks/History-Cq_Hrzuu.mjs.map +0 -1
- package/dist/_chunks/History-D4U2YISB.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-Bny6CdWe.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-W-KQHmBv.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-HBBnJa8K.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-O8F1pBJo.js.map +0 -1
- package/dist/_chunks/Relations-C4gGfZRv.js.map +0 -1
- package/dist/_chunks/Relations-vFZ6Wasg.mjs.map +0 -1
- package/dist/_chunks/index-5EMXLEM_.js.map +0 -1
- package/dist/_chunks/index-Dpxg3ctD.mjs.map +0 -1
- package/dist/_chunks/layout-C0INpKap.mjs.map +0 -1
- package/dist/_chunks/layout-P3eKO1Qy.js.map +0 -1
- package/dist/_chunks/relations-B1y0K6LE.js.map +0 -1
- package/dist/_chunks/relations-FBRRBWeO.mjs.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.js
CHANGED
@@ -10,8 +10,7 @@ const qs = require("qs");
|
|
10
10
|
const slugify = require("@sindresorhus/slugify");
|
11
11
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
12
12
|
function _interopNamespace(e) {
|
13
|
-
if (e && e.__esModule)
|
14
|
-
return e;
|
13
|
+
if (e && e.__esModule) return e;
|
15
14
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
16
15
|
if (e) {
|
17
16
|
for (const k in e) {
|
@@ -33,10 +32,10 @@ const isNil__default = /* @__PURE__ */ _interopDefault(isNil);
|
|
33
32
|
const ___default = /* @__PURE__ */ _interopDefault(_);
|
34
33
|
const qs__default = /* @__PURE__ */ _interopDefault(qs);
|
35
34
|
const slugify__default = /* @__PURE__ */ _interopDefault(slugify);
|
36
|
-
const getService$
|
35
|
+
const getService$2 = (name) => {
|
37
36
|
return strapi.plugin("content-manager").service(name);
|
38
37
|
};
|
39
|
-
function getService(strapi2, name) {
|
38
|
+
function getService$1(strapi2, name) {
|
40
39
|
return strapi2.service(`plugin::content-manager.${name}`);
|
41
40
|
}
|
42
41
|
const historyRestoreVersionSchema = yup__namespace.object().shape({
|
@@ -72,7 +71,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
72
71
|
if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
|
73
72
|
throw new strapiUtils.errors.ForbiddenError("contentType and documentId are required");
|
74
73
|
}
|
75
|
-
const permissionChecker2 = getService$
|
74
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
76
75
|
userAbility: ctx.state.userAbility,
|
77
76
|
model: ctx.query.contentType
|
78
77
|
});
|
@@ -80,7 +79,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
80
79
|
return ctx.forbidden();
|
81
80
|
}
|
82
81
|
const query = await permissionChecker2.sanitizeQuery(ctx.query);
|
83
|
-
const { results, pagination } = await getService(strapi2, "history").findVersionsPage({
|
82
|
+
const { results, pagination } = await getService$1(strapi2, "history").findVersionsPage({
|
84
83
|
query: {
|
85
84
|
...query,
|
86
85
|
...getValidPagination({ page: query.page, pageSize: query.pageSize })
|
@@ -105,14 +104,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
105
104
|
async restoreVersion(ctx) {
|
106
105
|
const request = ctx.request;
|
107
106
|
await validateRestoreVersion(request.body, "contentType is required");
|
108
|
-
const permissionChecker2 = getService$
|
107
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
109
108
|
userAbility: ctx.state.userAbility,
|
110
109
|
model: request.body.contentType
|
111
110
|
});
|
112
111
|
if (permissionChecker2.cannot.update()) {
|
113
112
|
throw new strapiUtils.errors.ForbiddenError();
|
114
113
|
}
|
115
|
-
const restoredDocument = await getService(strapi2, "history").restoreVersion(
|
114
|
+
const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
|
116
115
|
request.params.versionId
|
117
116
|
);
|
118
117
|
return {
|
@@ -121,7 +120,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
121
120
|
}
|
122
121
|
};
|
123
122
|
};
|
124
|
-
const controllers$
|
123
|
+
const controllers$2 = {
|
125
124
|
"history-version": createHistoryVersionController
|
126
125
|
/**
|
127
126
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -167,8 +166,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
167
166
|
};
|
168
167
|
const getRelationRestoreValue = async (versionRelationData, attribute) => {
|
169
168
|
if (Array.isArray(versionRelationData)) {
|
170
|
-
if (versionRelationData.length === 0)
|
171
|
-
return versionRelationData;
|
169
|
+
if (versionRelationData.length === 0) return versionRelationData;
|
172
170
|
const existingAndMissingRelations = await Promise.all(
|
173
171
|
versionRelationData.map((relation) => {
|
174
172
|
return strapi2.documents(attribute.target).findOne({
|
@@ -199,10 +197,11 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
199
197
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
|
200
198
|
};
|
201
199
|
const localesService = strapi2.plugin("i18n")?.service("locales");
|
200
|
+
const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
|
202
201
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
202
|
+
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
203
203
|
const getLocaleDictionary = async () => {
|
204
|
-
if (!localesService)
|
205
|
-
return {};
|
204
|
+
if (!localesService) return {};
|
206
205
|
const locales = await localesService.find() || [];
|
207
206
|
return locales.reduce(
|
208
207
|
(acc, locale) => {
|
@@ -226,6 +225,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
226
225
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
227
226
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
228
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
|
+
};
|
229
239
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
230
240
|
const model = strapi2.getModel(uid2);
|
231
241
|
const attributes = Object.entries(model.attributes);
|
@@ -249,13 +259,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
249
259
|
}
|
250
260
|
case "component": {
|
251
261
|
const populate = getDeepPopulate2(attribute.component);
|
252
|
-
acc[attributeName] = {
|
262
|
+
acc[attributeName] = {
|
263
|
+
populate,
|
264
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
265
|
+
};
|
253
266
|
break;
|
254
267
|
}
|
255
268
|
case "dynamiczone": {
|
256
269
|
const populatedComponents = (attribute.components || []).reduce(
|
257
270
|
(acc2, componentUID) => {
|
258
|
-
acc2[componentUID] = {
|
271
|
+
acc2[componentUID] = {
|
272
|
+
populate: getDeepPopulate2(componentUID),
|
273
|
+
[fieldSelector]: getComponentFields(componentUID)
|
274
|
+
};
|
259
275
|
return acc2;
|
260
276
|
},
|
261
277
|
{}
|
@@ -317,6 +333,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
317
333
|
getRelationRestoreValue,
|
318
334
|
getMediaRestoreValue,
|
319
335
|
getDefaultLocale,
|
336
|
+
isLocalizedContentType,
|
320
337
|
getLocaleDictionary,
|
321
338
|
getRetentionDays,
|
322
339
|
getVersionStatus,
|
@@ -339,7 +356,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
339
356
|
});
|
340
357
|
},
|
341
358
|
async findVersionsPage(params) {
|
342
|
-
const
|
359
|
+
const model = strapi2.getModel(params.query.contentType);
|
360
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
361
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
362
|
+
let locale = null;
|
363
|
+
if (isLocalizedContentType) {
|
364
|
+
locale = params.query.locale || defaultLocale;
|
365
|
+
}
|
343
366
|
const [{ results, pagination }, localeDictionary] = await Promise.all([
|
344
367
|
query.findPage({
|
345
368
|
...params.query,
|
@@ -361,7 +384,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
361
384
|
const attributeValue = entry.data[attributeKey];
|
362
385
|
const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
|
363
386
|
if (attributeSchema.type === "media") {
|
364
|
-
const permissionChecker2 = getService$
|
387
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
365
388
|
userAbility: params.state.userAbility,
|
366
389
|
model: "plugin::upload.file"
|
367
390
|
});
|
@@ -384,7 +407,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
384
407
|
if (userToPopulate == null) {
|
385
408
|
return null;
|
386
409
|
}
|
387
|
-
return strapi2.query("admin::user").findOne({
|
410
|
+
return strapi2.query("admin::user").findOne({
|
411
|
+
where: {
|
412
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
413
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
414
|
+
}
|
415
|
+
});
|
388
416
|
})
|
389
417
|
);
|
390
418
|
return {
|
@@ -397,7 +425,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
397
425
|
[attributeKey]: adminUsers
|
398
426
|
};
|
399
427
|
}
|
400
|
-
const permissionChecker2 = getService$
|
428
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
401
429
|
userAbility: params.state.userAbility,
|
402
430
|
model: attributeSchema.target
|
403
431
|
});
|
@@ -555,11 +583,13 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
555
583
|
}
|
556
584
|
const uid2 = context.contentType.uid;
|
557
585
|
const schemas = getSchemas(uid2);
|
586
|
+
const model = strapi2.getModel(uid2);
|
587
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
558
588
|
const localeEntries = await strapi2.db.query(uid2).findMany({
|
559
589
|
where: {
|
560
590
|
documentId,
|
561
|
-
locale: { $in: locales },
|
562
|
-
publishedAt: null
|
591
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
592
|
+
...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
563
593
|
},
|
564
594
|
populate: serviceUtils.getDeepPopulate(
|
565
595
|
uid2,
|
@@ -571,7 +601,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
571
601
|
onCommit(async () => {
|
572
602
|
for (const entry of localeEntries) {
|
573
603
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
574
|
-
await getService(strapi2, "history").createVersion({
|
604
|
+
await getService$1(strapi2, "history").createVersion({
|
575
605
|
contentType: uid2,
|
576
606
|
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
577
607
|
relatedDocumentId: documentId,
|
@@ -584,15 +614,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
584
614
|
});
|
585
615
|
return result;
|
586
616
|
});
|
587
|
-
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
617
|
+
state.deleteExpiredJob = nodeSchedule.scheduleJob("historyDaily", "0 0 * * *", () => {
|
588
618
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
589
619
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
590
620
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
591
621
|
where: {
|
592
622
|
created_at: {
|
593
|
-
$lt: expirationDate
|
623
|
+
$lt: expirationDate
|
594
624
|
}
|
595
625
|
}
|
626
|
+
}).catch((error) => {
|
627
|
+
if (error instanceof Error) {
|
628
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
629
|
+
}
|
596
630
|
});
|
597
631
|
});
|
598
632
|
state.isInitialized = true;
|
@@ -604,17 +638,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
604
638
|
}
|
605
639
|
};
|
606
640
|
};
|
607
|
-
const services$
|
641
|
+
const services$2 = {
|
608
642
|
history: createHistoryService,
|
609
643
|
lifecycles: createLifecyclesService
|
610
644
|
};
|
611
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
645
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
612
646
|
const historyVersionRouter = {
|
613
647
|
type: "admin",
|
614
648
|
routes: [
|
615
649
|
{
|
616
650
|
method: "GET",
|
617
|
-
info,
|
651
|
+
info: info$1,
|
618
652
|
path: "/history-versions",
|
619
653
|
handler: "history-version.findMany",
|
620
654
|
config: {
|
@@ -623,7 +657,7 @@ const historyVersionRouter = {
|
|
623
657
|
},
|
624
658
|
{
|
625
659
|
method: "PUT",
|
626
|
-
info,
|
660
|
+
info: info$1,
|
627
661
|
path: "/history-versions/:versionId/restore",
|
628
662
|
handler: "history-version.restoreVersion",
|
629
663
|
config: {
|
@@ -632,7 +666,7 @@ const historyVersionRouter = {
|
|
632
666
|
}
|
633
667
|
]
|
634
668
|
};
|
635
|
-
const routes$
|
669
|
+
const routes$2 = {
|
636
670
|
"history-version": historyVersionRouter
|
637
671
|
};
|
638
672
|
const historyVersion = {
|
@@ -679,21 +713,21 @@ const historyVersion = {
|
|
679
713
|
}
|
680
714
|
}
|
681
715
|
};
|
682
|
-
const getFeature = () => {
|
716
|
+
const getFeature$1 = () => {
|
683
717
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
684
718
|
return {
|
685
719
|
register({ strapi: strapi2 }) {
|
686
720
|
strapi2.get("models").add(historyVersion);
|
687
721
|
},
|
688
722
|
bootstrap({ strapi: strapi2 }) {
|
689
|
-
getService(strapi2, "lifecycles").bootstrap();
|
723
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
690
724
|
},
|
691
725
|
destroy({ strapi: strapi2 }) {
|
692
|
-
getService(strapi2, "lifecycles").destroy();
|
726
|
+
getService$1(strapi2, "lifecycles").destroy();
|
693
727
|
},
|
694
|
-
controllers: controllers$
|
695
|
-
services: services$
|
696
|
-
routes: routes$
|
728
|
+
controllers: controllers$2,
|
729
|
+
services: services$2,
|
730
|
+
routes: routes$2
|
697
731
|
};
|
698
732
|
}
|
699
733
|
return {
|
@@ -702,9 +736,205 @@ const getFeature = () => {
|
|
702
736
|
}
|
703
737
|
};
|
704
738
|
};
|
705
|
-
const history = getFeature();
|
739
|
+
const history = getFeature$1();
|
740
|
+
const FEATURE_ID = "preview";
|
741
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
742
|
+
const previewRouter = {
|
743
|
+
type: "admin",
|
744
|
+
routes: [
|
745
|
+
{
|
746
|
+
method: "GET",
|
747
|
+
info,
|
748
|
+
path: "/preview/url/:contentType",
|
749
|
+
handler: "preview.getPreviewUrl",
|
750
|
+
config: {
|
751
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
752
|
+
}
|
753
|
+
}
|
754
|
+
]
|
755
|
+
};
|
756
|
+
const routes$1 = {
|
757
|
+
preview: previewRouter
|
758
|
+
};
|
759
|
+
function getService(strapi2, name) {
|
760
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
761
|
+
}
|
762
|
+
const getPreviewUrlSchema = yup__namespace.object().shape({
|
763
|
+
// Will be undefined for single types
|
764
|
+
documentId: yup__namespace.string(),
|
765
|
+
locale: yup__namespace.string().nullable(),
|
766
|
+
status: yup__namespace.string()
|
767
|
+
}).required();
|
768
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
769
|
+
await strapiUtils.validateYupSchema(getPreviewUrlSchema)(params);
|
770
|
+
const newParams = fp.pick(["documentId", "locale", "status"], params);
|
771
|
+
const model = strapi2.getModel(uid2);
|
772
|
+
if (!model || model.modelType !== "contentType") {
|
773
|
+
throw new strapiUtils.errors.ValidationError("Invalid content type");
|
774
|
+
}
|
775
|
+
const isSingleType = model?.kind === "singleType";
|
776
|
+
if (!isSingleType && !params.documentId) {
|
777
|
+
throw new strapiUtils.errors.ValidationError("documentId is required for Collection Types");
|
778
|
+
}
|
779
|
+
if (isSingleType) {
|
780
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
781
|
+
if (!doc) {
|
782
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
783
|
+
}
|
784
|
+
newParams.documentId = doc?.documentId;
|
785
|
+
}
|
786
|
+
if (!newParams.status) {
|
787
|
+
const isDPEnabled = model?.options?.draftAndPublish;
|
788
|
+
newParams.status = isDPEnabled ? "draft" : "published";
|
789
|
+
}
|
790
|
+
return newParams;
|
791
|
+
};
|
792
|
+
const createPreviewController = () => {
|
793
|
+
return {
|
794
|
+
/**
|
795
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
796
|
+
* in the Content Manager.
|
797
|
+
*/
|
798
|
+
async getPreviewUrl(ctx) {
|
799
|
+
const uid2 = ctx.params.contentType;
|
800
|
+
const query = ctx.request.query;
|
801
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
802
|
+
const previewService = getService(strapi, "preview");
|
803
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
804
|
+
if (!url) {
|
805
|
+
ctx.status = 204;
|
806
|
+
}
|
807
|
+
return {
|
808
|
+
data: { url }
|
809
|
+
};
|
810
|
+
}
|
811
|
+
};
|
812
|
+
};
|
813
|
+
const controllers$1 = {
|
814
|
+
preview: createPreviewController
|
815
|
+
/**
|
816
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
817
|
+
* passing a controller factory as the value, instead of a controller object directly
|
818
|
+
*/
|
819
|
+
};
|
820
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
821
|
+
const config = getService(strapi2, "preview-config");
|
822
|
+
return {
|
823
|
+
async getPreviewUrl(uid2, params) {
|
824
|
+
const handler = config.getPreviewHandler();
|
825
|
+
try {
|
826
|
+
return handler(uid2, params);
|
827
|
+
} catch (error) {
|
828
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
829
|
+
throw new strapiUtils.errors.ApplicationError("Failed to get preview URL");
|
830
|
+
}
|
831
|
+
return;
|
832
|
+
}
|
833
|
+
};
|
834
|
+
};
|
835
|
+
const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
|
836
|
+
const middlewares = strapi.config.get("middlewares");
|
837
|
+
const configuredMiddlewares = middlewares.map((currentMiddleware) => {
|
838
|
+
if (currentMiddleware === middleware.name) {
|
839
|
+
return middleware;
|
840
|
+
}
|
841
|
+
if (currentMiddleware.name === middleware.name) {
|
842
|
+
return fp.mergeWith(
|
843
|
+
(objValue, srcValue) => {
|
844
|
+
if (Array.isArray(objValue)) {
|
845
|
+
return objValue.concat(srcValue);
|
846
|
+
}
|
847
|
+
return void 0;
|
848
|
+
},
|
849
|
+
currentMiddleware,
|
850
|
+
middleware
|
851
|
+
);
|
852
|
+
}
|
853
|
+
return currentMiddleware;
|
854
|
+
});
|
855
|
+
strapi.config.set("middlewares", configuredMiddlewares);
|
856
|
+
};
|
857
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
858
|
+
return {
|
859
|
+
register() {
|
860
|
+
if (!this.isEnabled()) {
|
861
|
+
return;
|
862
|
+
}
|
863
|
+
const config = strapi2.config.get("admin.preview");
|
864
|
+
if (config.config?.allowedOrigins) {
|
865
|
+
extendMiddlewareConfiguration({
|
866
|
+
name: "strapi::security",
|
867
|
+
config: {
|
868
|
+
contentSecurityPolicy: {
|
869
|
+
directives: {
|
870
|
+
"frame-src": config.config.allowedOrigins
|
871
|
+
}
|
872
|
+
}
|
873
|
+
}
|
874
|
+
});
|
875
|
+
}
|
876
|
+
},
|
877
|
+
isEnabled() {
|
878
|
+
const config = strapi2.config.get("admin.preview");
|
879
|
+
if (!config) {
|
880
|
+
return false;
|
881
|
+
}
|
882
|
+
return config?.enabled ?? true;
|
883
|
+
},
|
884
|
+
/**
|
885
|
+
* Validate if the configuration is valid
|
886
|
+
*/
|
887
|
+
validate() {
|
888
|
+
if (!this.isEnabled()) {
|
889
|
+
return;
|
890
|
+
}
|
891
|
+
const handler = this.getPreviewHandler();
|
892
|
+
if (typeof handler !== "function") {
|
893
|
+
throw new strapiUtils.errors.ValidationError(
|
894
|
+
"Preview configuration is invalid. Handler must be a function"
|
895
|
+
);
|
896
|
+
}
|
897
|
+
},
|
898
|
+
/**
|
899
|
+
* Utility to get the preview handler from the configuration
|
900
|
+
*/
|
901
|
+
getPreviewHandler() {
|
902
|
+
const config = strapi2.config.get("admin.preview");
|
903
|
+
const emptyHandler = () => {
|
904
|
+
return void 0;
|
905
|
+
};
|
906
|
+
if (!this.isEnabled()) {
|
907
|
+
return emptyHandler;
|
908
|
+
}
|
909
|
+
return config?.config?.handler || emptyHandler;
|
910
|
+
}
|
911
|
+
};
|
912
|
+
};
|
913
|
+
const services$1 = {
|
914
|
+
preview: createPreviewService,
|
915
|
+
"preview-config": createPreviewConfigService
|
916
|
+
};
|
917
|
+
const getFeature = () => {
|
918
|
+
if (!strapi.features.future.isEnabled(FEATURE_ID)) {
|
919
|
+
return {};
|
920
|
+
}
|
921
|
+
return {
|
922
|
+
register() {
|
923
|
+
const config = getService(strapi, "preview-config");
|
924
|
+
config.validate();
|
925
|
+
config.register();
|
926
|
+
},
|
927
|
+
bootstrap() {
|
928
|
+
},
|
929
|
+
routes: routes$1,
|
930
|
+
controllers: controllers$1,
|
931
|
+
services: services$1
|
932
|
+
};
|
933
|
+
};
|
934
|
+
const preview = getFeature();
|
706
935
|
const register = async ({ strapi: strapi2 }) => {
|
707
936
|
await history.register?.({ strapi: strapi2 });
|
937
|
+
await preview.register?.({ strapi: strapi2 });
|
708
938
|
};
|
709
939
|
const ALLOWED_WEBHOOK_EVENTS = {
|
710
940
|
ENTRY_PUBLISH: "entry.publish",
|
@@ -714,11 +944,12 @@ const bootstrap = async () => {
|
|
714
944
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
715
945
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
716
946
|
});
|
717
|
-
getService$
|
718
|
-
await getService$
|
719
|
-
await getService$
|
720
|
-
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();
|
721
951
|
await history.bootstrap?.({ strapi });
|
952
|
+
await preview.bootstrap?.({ strapi });
|
722
953
|
};
|
723
954
|
const destroy = async ({ strapi: strapi2 }) => {
|
724
955
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1208,7 +1439,8 @@ const admin = {
|
|
1208
1439
|
};
|
1209
1440
|
const routes = {
|
1210
1441
|
admin,
|
1211
|
-
...history.routes ? history.routes : {}
|
1442
|
+
...history.routes ? history.routes : {},
|
1443
|
+
...preview.routes ? preview.routes : {}
|
1212
1444
|
};
|
1213
1445
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1214
1446
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1219,6 +1451,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1219
1451
|
const hasPermissions = createPolicy({
|
1220
1452
|
name: "plugin::content-manager.hasPermissions",
|
1221
1453
|
validator: validateHasPermissionsInput,
|
1454
|
+
/**
|
1455
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1456
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1457
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1458
|
+
*/
|
1222
1459
|
handler(ctx, config = {}) {
|
1223
1460
|
const { actions = [], hasAtLeastOne = false } = config;
|
1224
1461
|
const { userAbility } = ctx.state;
|
@@ -1266,8 +1503,7 @@ const isSortable = (schema, name) => {
|
|
1266
1503
|
if (!___default.default.has(schema.attributes, name)) {
|
1267
1504
|
return false;
|
1268
1505
|
}
|
1269
|
-
if (schema.modelType === "component" && name === "id")
|
1270
|
-
return false;
|
1506
|
+
if (schema.modelType === "component" && name === "id") return false;
|
1271
1507
|
const attribute = schema.attributes[name];
|
1272
1508
|
if (NON_SORTABLES.includes(attribute.type)) {
|
1273
1509
|
return false;
|
@@ -1412,8 +1648,7 @@ const createDefaultSettings = async (schema) => {
|
|
1412
1648
|
};
|
1413
1649
|
};
|
1414
1650
|
const syncSettings = async (configuration, schema) => {
|
1415
|
-
if (fp.isEmpty(configuration.settings))
|
1416
|
-
return createDefaultSettings(schema);
|
1651
|
+
if (fp.isEmpty(configuration.settings)) return createDefaultSettings(schema);
|
1417
1652
|
const defaultField = getDefaultMainField(schema);
|
1418
1653
|
const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
|
1419
1654
|
return {
|
@@ -1460,7 +1695,7 @@ const createMetadasSchema = (schema) => {
|
|
1460
1695
|
if (!value) {
|
1461
1696
|
return strapiUtils.yup.string();
|
1462
1697
|
}
|
1463
|
-
const targetSchema = getService$
|
1698
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1464
1699
|
schema.attributes[key].targetModel
|
1465
1700
|
);
|
1466
1701
|
if (!targetSchema) {
|
@@ -1589,8 +1824,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1589
1824
|
}
|
1590
1825
|
switch (attribute.type) {
|
1591
1826
|
case "relation": {
|
1592
|
-
if (canCreate(attributePath))
|
1593
|
-
return body2;
|
1827
|
+
if (canCreate(attributePath)) return body2;
|
1594
1828
|
return fp.set(attributePath, { set: [] }, body2);
|
1595
1829
|
}
|
1596
1830
|
case "component": {
|
@@ -1600,8 +1834,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1600
1834
|
]);
|
1601
1835
|
}
|
1602
1836
|
default: {
|
1603
|
-
if (canCreate(attributePath))
|
1604
|
-
return body2;
|
1837
|
+
if (canCreate(attributePath)) return body2;
|
1605
1838
|
return fp.set(attributePath, null, body2);
|
1606
1839
|
}
|
1607
1840
|
}
|
@@ -1629,7 +1862,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1629
1862
|
}
|
1630
1863
|
};
|
1631
1864
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1632
|
-
const documentMetadata2 = getService$
|
1865
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1633
1866
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1634
1867
|
let {
|
1635
1868
|
meta: { availableLocales, availableStatus }
|
@@ -1655,8 +1888,8 @@ const createDocument = async (ctx, opts) => {
|
|
1655
1888
|
const { userAbility, user } = ctx.state;
|
1656
1889
|
const { model } = ctx.params;
|
1657
1890
|
const { body } = ctx.request;
|
1658
|
-
const documentManager2 = getService$
|
1659
|
-
const permissionChecker2 = getService$
|
1891
|
+
const documentManager2 = getService$2("document-manager");
|
1892
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1660
1893
|
if (permissionChecker2.cannot.create()) {
|
1661
1894
|
throw new strapiUtils.errors.ForbiddenError();
|
1662
1895
|
}
|
@@ -1676,13 +1909,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1676
1909
|
const { userAbility, user } = ctx.state;
|
1677
1910
|
const { id, model } = ctx.params;
|
1678
1911
|
const { body } = ctx.request;
|
1679
|
-
const documentManager2 = getService$
|
1680
|
-
const permissionChecker2 = getService$
|
1912
|
+
const documentManager2 = getService$2("document-manager");
|
1913
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1681
1914
|
if (permissionChecker2.cannot.update()) {
|
1682
1915
|
throw new strapiUtils.errors.ForbiddenError();
|
1683
1916
|
}
|
1684
1917
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1685
|
-
const populate = await getService$
|
1918
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1686
1919
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1687
1920
|
const [documentVersion, documentExists] = await Promise.all([
|
1688
1921
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1699,7 +1932,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1699
1932
|
throw new strapiUtils.errors.ForbiddenError();
|
1700
1933
|
}
|
1701
1934
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1702
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1935
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1703
1936
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1704
1937
|
const sanitizedBody = await sanitizeFn(body);
|
1705
1938
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1713,14 +1946,14 @@ const collectionTypes = {
|
|
1713
1946
|
const { userAbility } = ctx.state;
|
1714
1947
|
const { model } = ctx.params;
|
1715
1948
|
const { query } = ctx.request;
|
1716
|
-
const documentMetadata2 = getService$
|
1717
|
-
const documentManager2 = getService$
|
1718
|
-
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 });
|
1719
1952
|
if (permissionChecker2.cannot.read()) {
|
1720
1953
|
return ctx.forbidden();
|
1721
1954
|
}
|
1722
1955
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1723
|
-
const populate = await getService$
|
1956
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1724
1957
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1725
1958
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1726
1959
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1749,13 +1982,13 @@ const collectionTypes = {
|
|
1749
1982
|
async findOne(ctx) {
|
1750
1983
|
const { userAbility } = ctx.state;
|
1751
1984
|
const { model, id } = ctx.params;
|
1752
|
-
const documentManager2 = getService$
|
1753
|
-
const permissionChecker2 = getService$
|
1985
|
+
const documentManager2 = getService$2("document-manager");
|
1986
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1754
1987
|
if (permissionChecker2.cannot.read()) {
|
1755
1988
|
return ctx.forbidden();
|
1756
1989
|
}
|
1757
1990
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1758
|
-
const populate = await getService$
|
1991
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1759
1992
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1760
1993
|
const version = await documentManager2.findOne(id, model, {
|
1761
1994
|
populate,
|
@@ -1771,7 +2004,7 @@ const collectionTypes = {
|
|
1771
2004
|
permissionChecker2,
|
1772
2005
|
model,
|
1773
2006
|
// @ts-expect-error TODO: fix
|
1774
|
-
{ id, locale, publishedAt: null },
|
2007
|
+
{ documentId: id, locale, publishedAt: null },
|
1775
2008
|
{ availableLocales: true, availableStatus: false }
|
1776
2009
|
);
|
1777
2010
|
ctx.body = { data: {}, meta };
|
@@ -1786,7 +2019,7 @@ const collectionTypes = {
|
|
1786
2019
|
async create(ctx) {
|
1787
2020
|
const { userAbility } = ctx.state;
|
1788
2021
|
const { model } = ctx.params;
|
1789
|
-
const permissionChecker2 = getService$
|
2022
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1790
2023
|
const [totalEntries, document] = await Promise.all([
|
1791
2024
|
strapi.db.query(model).count(),
|
1792
2025
|
createDocument(ctx)
|
@@ -1807,7 +2040,7 @@ const collectionTypes = {
|
|
1807
2040
|
async update(ctx) {
|
1808
2041
|
const { userAbility } = ctx.state;
|
1809
2042
|
const { model } = ctx.params;
|
1810
|
-
const permissionChecker2 = getService$
|
2043
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1811
2044
|
const updatedVersion = await updateDocument(ctx);
|
1812
2045
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1813
2046
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1816,13 +2049,13 @@ const collectionTypes = {
|
|
1816
2049
|
const { userAbility, user } = ctx.state;
|
1817
2050
|
const { model, sourceId: id } = ctx.params;
|
1818
2051
|
const { body } = ctx.request;
|
1819
|
-
const documentManager2 = getService$
|
1820
|
-
const permissionChecker2 = getService$
|
2052
|
+
const documentManager2 = getService$2("document-manager");
|
2053
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1821
2054
|
if (permissionChecker2.cannot.create()) {
|
1822
2055
|
return ctx.forbidden();
|
1823
2056
|
}
|
1824
2057
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1825
|
-
const populate = await getService$
|
2058
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1826
2059
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1827
2060
|
const document = await documentManager2.findOne(id, model, {
|
1828
2061
|
populate,
|
@@ -1861,13 +2094,13 @@ const collectionTypes = {
|
|
1861
2094
|
async delete(ctx) {
|
1862
2095
|
const { userAbility } = ctx.state;
|
1863
2096
|
const { id, model } = ctx.params;
|
1864
|
-
const documentManager2 = getService$
|
1865
|
-
const permissionChecker2 = getService$
|
2097
|
+
const documentManager2 = getService$2("document-manager");
|
2098
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1866
2099
|
if (permissionChecker2.cannot.delete()) {
|
1867
2100
|
return ctx.forbidden();
|
1868
2101
|
}
|
1869
2102
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1870
|
-
const populate = await getService$
|
2103
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1871
2104
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1872
2105
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1873
2106
|
if (documentLocales.length === 0) {
|
@@ -1889,14 +2122,14 @@ const collectionTypes = {
|
|
1889
2122
|
const { userAbility } = ctx.state;
|
1890
2123
|
const { id, model } = ctx.params;
|
1891
2124
|
const { body } = ctx.request;
|
1892
|
-
const documentManager2 = getService$
|
1893
|
-
const permissionChecker2 = getService$
|
2125
|
+
const documentManager2 = getService$2("document-manager");
|
2126
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1894
2127
|
if (permissionChecker2.cannot.publish()) {
|
1895
2128
|
return ctx.forbidden();
|
1896
2129
|
}
|
1897
2130
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1898
2131
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1899
|
-
const populate = await getService$
|
2132
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1900
2133
|
let document;
|
1901
2134
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1902
2135
|
const isCreate = fp.isNil(id);
|
@@ -1908,11 +2141,17 @@ const collectionTypes = {
|
|
1908
2141
|
}
|
1909
2142
|
const isUpdate = !isCreate;
|
1910
2143
|
if (isUpdate) {
|
1911
|
-
|
1912
|
-
if (!
|
2144
|
+
const documentExists = documentManager2.exists(model, id);
|
2145
|
+
if (!documentExists) {
|
1913
2146
|
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1914
2147
|
}
|
1915
|
-
|
2148
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
2149
|
+
if (!document) {
|
2150
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
2151
|
+
throw new strapiUtils.errors.ForbiddenError();
|
2152
|
+
}
|
2153
|
+
document = await updateDocument(ctx);
|
2154
|
+
} else if (permissionChecker2.can.update(document)) {
|
1916
2155
|
await updateDocument(ctx);
|
1917
2156
|
}
|
1918
2157
|
}
|
@@ -1938,13 +2177,13 @@ const collectionTypes = {
|
|
1938
2177
|
const { body } = ctx.request;
|
1939
2178
|
const { documentIds } = body;
|
1940
2179
|
await validateBulkActionInput(body);
|
1941
|
-
const documentManager2 = getService$
|
1942
|
-
const permissionChecker2 = getService$
|
2180
|
+
const documentManager2 = getService$2("document-manager");
|
2181
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1943
2182
|
if (permissionChecker2.cannot.publish()) {
|
1944
2183
|
return ctx.forbidden();
|
1945
2184
|
}
|
1946
2185
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1947
|
-
const populate = await getService$
|
2186
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1948
2187
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1949
2188
|
allowMultipleLocales: true
|
1950
2189
|
});
|
@@ -1969,12 +2208,14 @@ const collectionTypes = {
|
|
1969
2208
|
const { body } = ctx.request;
|
1970
2209
|
const { documentIds } = body;
|
1971
2210
|
await validateBulkActionInput(body);
|
1972
|
-
const documentManager2 = getService$
|
1973
|
-
const permissionChecker2 = getService$
|
2211
|
+
const documentManager2 = getService$2("document-manager");
|
2212
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1974
2213
|
if (permissionChecker2.cannot.unpublish()) {
|
1975
2214
|
return ctx.forbidden();
|
1976
2215
|
}
|
1977
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
2216
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2217
|
+
allowMultipleLocales: true
|
2218
|
+
});
|
1978
2219
|
const entityPromises = documentIds.map(
|
1979
2220
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1980
2221
|
);
|
@@ -1997,8 +2238,8 @@ const collectionTypes = {
|
|
1997
2238
|
const {
|
1998
2239
|
body: { discardDraft, ...body }
|
1999
2240
|
} = ctx.request;
|
2000
|
-
const documentManager2 = getService$
|
2001
|
-
const permissionChecker2 = getService$
|
2241
|
+
const documentManager2 = getService$2("document-manager");
|
2242
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2002
2243
|
if (permissionChecker2.cannot.unpublish()) {
|
2003
2244
|
return ctx.forbidden();
|
2004
2245
|
}
|
@@ -2006,7 +2247,7 @@ const collectionTypes = {
|
|
2006
2247
|
return ctx.forbidden();
|
2007
2248
|
}
|
2008
2249
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2009
|
-
const populate = await getService$
|
2250
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2010
2251
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2011
2252
|
const document = await documentManager2.findOne(id, model, {
|
2012
2253
|
populate,
|
@@ -2037,13 +2278,13 @@ const collectionTypes = {
|
|
2037
2278
|
const { userAbility } = ctx.state;
|
2038
2279
|
const { id, model } = ctx.params;
|
2039
2280
|
const { body } = ctx.request;
|
2040
|
-
const documentManager2 = getService$
|
2041
|
-
const permissionChecker2 = getService$
|
2281
|
+
const documentManager2 = getService$2("document-manager");
|
2282
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2042
2283
|
if (permissionChecker2.cannot.discard()) {
|
2043
2284
|
return ctx.forbidden();
|
2044
2285
|
}
|
2045
2286
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2046
|
-
const populate = await getService$
|
2287
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2047
2288
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2048
2289
|
const document = await documentManager2.findOne(id, model, {
|
2049
2290
|
populate,
|
@@ -2068,13 +2309,13 @@ const collectionTypes = {
|
|
2068
2309
|
const { query, body } = ctx.request;
|
2069
2310
|
const { documentIds } = body;
|
2070
2311
|
await validateBulkActionInput(body);
|
2071
|
-
const documentManager2 = getService$
|
2072
|
-
const permissionChecker2 = getService$
|
2312
|
+
const documentManager2 = getService$2("document-manager");
|
2313
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2073
2314
|
if (permissionChecker2.cannot.delete()) {
|
2074
2315
|
return ctx.forbidden();
|
2075
2316
|
}
|
2076
2317
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2077
|
-
const populate = await getService$
|
2318
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2078
2319
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2079
2320
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2080
2321
|
populate,
|
@@ -2095,13 +2336,13 @@ const collectionTypes = {
|
|
2095
2336
|
async countDraftRelations(ctx) {
|
2096
2337
|
const { userAbility } = ctx.state;
|
2097
2338
|
const { model, id } = ctx.params;
|
2098
|
-
const documentManager2 = getService$
|
2099
|
-
const permissionChecker2 = getService$
|
2339
|
+
const documentManager2 = getService$2("document-manager");
|
2340
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2100
2341
|
if (permissionChecker2.cannot.read()) {
|
2101
2342
|
return ctx.forbidden();
|
2102
2343
|
}
|
2103
2344
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2104
|
-
const populate = await getService$
|
2345
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2105
2346
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2106
2347
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2107
2348
|
if (!entity) {
|
@@ -2120,8 +2361,8 @@ const collectionTypes = {
|
|
2120
2361
|
const ids = ctx.request.query.documentIds;
|
2121
2362
|
const locale = ctx.request.query.locale;
|
2122
2363
|
const { model } = ctx.params;
|
2123
|
-
const documentManager2 = getService$
|
2124
|
-
const permissionChecker2 = getService$
|
2364
|
+
const documentManager2 = getService$2("document-manager");
|
2365
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2125
2366
|
if (permissionChecker2.cannot.read()) {
|
2126
2367
|
return ctx.forbidden();
|
2127
2368
|
}
|
@@ -2145,13 +2386,13 @@ const collectionTypes = {
|
|
2145
2386
|
};
|
2146
2387
|
const components$1 = {
|
2147
2388
|
findComponents(ctx) {
|
2148
|
-
const components2 = getService$
|
2149
|
-
const { toDto } = getService$
|
2389
|
+
const components2 = getService$2("components").findAllComponents();
|
2390
|
+
const { toDto } = getService$2("data-mapper");
|
2150
2391
|
ctx.body = { data: components2.map(toDto) };
|
2151
2392
|
},
|
2152
2393
|
async findComponentConfiguration(ctx) {
|
2153
2394
|
const { uid: uid2 } = ctx.params;
|
2154
|
-
const componentService = getService$
|
2395
|
+
const componentService = getService$2("components");
|
2155
2396
|
const component = componentService.findComponent(uid2);
|
2156
2397
|
if (!component) {
|
2157
2398
|
return ctx.notFound("component.notFound");
|
@@ -2168,7 +2409,7 @@ const components$1 = {
|
|
2168
2409
|
async updateComponentConfiguration(ctx) {
|
2169
2410
|
const { uid: uid2 } = ctx.params;
|
2170
2411
|
const { body } = ctx.request;
|
2171
|
-
const componentService = getService$
|
2412
|
+
const componentService = getService$2("components");
|
2172
2413
|
const component = componentService.findComponent(uid2);
|
2173
2414
|
if (!component) {
|
2174
2415
|
return ctx.notFound("component.notFound");
|
@@ -2202,12 +2443,12 @@ const contentTypes = {
|
|
2202
2443
|
} catch (error) {
|
2203
2444
|
return ctx.send({ error }, 400);
|
2204
2445
|
}
|
2205
|
-
const contentTypes2 = getService$
|
2206
|
-
const { toDto } = getService$
|
2446
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2447
|
+
const { toDto } = getService$2("data-mapper");
|
2207
2448
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2208
2449
|
},
|
2209
2450
|
async findContentTypesSettings(ctx) {
|
2210
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2451
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2211
2452
|
const contentTypes2 = await findAllContentTypes();
|
2212
2453
|
const configurations = await Promise.all(
|
2213
2454
|
contentTypes2.map(async (contentType) => {
|
@@ -2221,7 +2462,7 @@ const contentTypes = {
|
|
2221
2462
|
},
|
2222
2463
|
async findContentTypeConfiguration(ctx) {
|
2223
2464
|
const { uid: uid2 } = ctx.params;
|
2224
|
-
const contentTypeService = getService$
|
2465
|
+
const contentTypeService = getService$2("content-types");
|
2225
2466
|
const contentType = await contentTypeService.findContentType(uid2);
|
2226
2467
|
if (!contentType) {
|
2227
2468
|
return ctx.notFound("contentType.notFound");
|
@@ -2243,13 +2484,13 @@ const contentTypes = {
|
|
2243
2484
|
const { userAbility } = ctx.state;
|
2244
2485
|
const { uid: uid2 } = ctx.params;
|
2245
2486
|
const { body } = ctx.request;
|
2246
|
-
const contentTypeService = getService$
|
2247
|
-
const metricsService = getService$
|
2487
|
+
const contentTypeService = getService$2("content-types");
|
2488
|
+
const metricsService = getService$2("metrics");
|
2248
2489
|
const contentType = await contentTypeService.findContentType(uid2);
|
2249
2490
|
if (!contentType) {
|
2250
2491
|
return ctx.notFound("contentType.notFound");
|
2251
2492
|
}
|
2252
|
-
if (!getService$
|
2493
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2253
2494
|
return ctx.forbidden();
|
2254
2495
|
}
|
2255
2496
|
let input;
|
@@ -2282,10 +2523,10 @@ const contentTypes = {
|
|
2282
2523
|
};
|
2283
2524
|
const init = {
|
2284
2525
|
getInitData(ctx) {
|
2285
|
-
const { toDto } = getService$
|
2286
|
-
const { findAllComponents } = getService$
|
2287
|
-
const { getAllFieldSizes } = getService$
|
2288
|
-
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");
|
2289
2530
|
ctx.body = {
|
2290
2531
|
data: {
|
2291
2532
|
fieldSizes: getAllFieldSizes(),
|
@@ -2321,36 +2562,41 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2321
2562
|
params.filters.$and.push(filtersClause);
|
2322
2563
|
};
|
2323
2564
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2324
|
-
const permissionChecker2 = getService$
|
2565
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2325
2566
|
userAbility,
|
2326
2567
|
model: model.uid
|
2327
2568
|
});
|
2328
|
-
|
2569
|
+
const isMainFieldListable = isListable(model, mainField);
|
2570
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2571
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2329
2572
|
return "id";
|
2330
2573
|
}
|
2331
|
-
if (
|
2332
|
-
|
2333
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2334
|
-
userAbility,
|
2335
|
-
model: "plugin::users-permissions.user"
|
2336
|
-
});
|
2337
|
-
if (userPermissionChecker.can.read()) {
|
2338
|
-
return "name";
|
2339
|
-
}
|
2340
|
-
}
|
2341
|
-
return "id";
|
2574
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2575
|
+
return "name";
|
2342
2576
|
}
|
2343
2577
|
return mainField;
|
2344
2578
|
};
|
2345
|
-
const addStatusToRelations = async (
|
2346
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2579
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2580
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2347
2581
|
return relations2;
|
2348
2582
|
}
|
2349
|
-
const documentMetadata2 = getService$
|
2350
|
-
|
2583
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2584
|
+
if (!relations2.length) {
|
2585
|
+
return relations2;
|
2586
|
+
}
|
2587
|
+
const firstRelation = relations2[0];
|
2588
|
+
const filters = {
|
2589
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2590
|
+
// NOTE: find the "opposite" status
|
2591
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2592
|
+
};
|
2593
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2594
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2595
|
+
filters
|
2596
|
+
});
|
2351
2597
|
return relations2.map((relation) => {
|
2352
|
-
const availableStatuses =
|
2353
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2598
|
+
const availableStatuses = availableStatus.filter(
|
2599
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2354
2600
|
);
|
2355
2601
|
return {
|
2356
2602
|
...relation,
|
@@ -2371,11 +2617,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2371
2617
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2372
2618
|
const isSourceLocalized = isLocalized(sourceModel);
|
2373
2619
|
const isTargetLocalized = isLocalized(targetModel);
|
2374
|
-
let validatedLocale = locale;
|
2375
|
-
if (!targetModel || !isTargetLocalized)
|
2376
|
-
validatedLocale = void 0;
|
2377
2620
|
return {
|
2378
|
-
locale
|
2621
|
+
locale,
|
2379
2622
|
isSourceLocalized,
|
2380
2623
|
isTargetLocalized
|
2381
2624
|
};
|
@@ -2384,8 +2627,7 @@ const validateStatus = (sourceUid, status) => {
|
|
2384
2627
|
const sourceModel = strapi.getModel(sourceUid);
|
2385
2628
|
const isDP = strapiUtils.contentTypes.hasDraftAndPublish;
|
2386
2629
|
const isSourceDP = isDP(sourceModel);
|
2387
|
-
if (!isSourceDP)
|
2388
|
-
return { status: void 0 };
|
2630
|
+
if (!isSourceDP) return { status: void 0 };
|
2389
2631
|
switch (status) {
|
2390
2632
|
case "published":
|
2391
2633
|
return { status: "published" };
|
@@ -2415,7 +2657,7 @@ const relations = {
|
|
2415
2657
|
ctx.request?.query?.locale
|
2416
2658
|
);
|
2417
2659
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2418
|
-
const permissionChecker2 = getService$
|
2660
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2419
2661
|
userAbility,
|
2420
2662
|
model
|
2421
2663
|
});
|
@@ -2440,7 +2682,7 @@ const relations = {
|
|
2440
2682
|
where.id = id;
|
2441
2683
|
}
|
2442
2684
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2443
|
-
const populate = await getService$
|
2685
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2444
2686
|
const currentEntity = await strapi.db.query(model).findOne({
|
2445
2687
|
where,
|
2446
2688
|
populate
|
@@ -2455,7 +2697,7 @@ const relations = {
|
|
2455
2697
|
}
|
2456
2698
|
entryId = currentEntity.id;
|
2457
2699
|
}
|
2458
|
-
const modelConfig = isComponent2 ? await getService$
|
2700
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2459
2701
|
const targetSchema = strapi.getModel(targetUid);
|
2460
2702
|
const mainField = fp.flow(
|
2461
2703
|
fp.prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2478,7 +2720,7 @@ const relations = {
|
|
2478
2720
|
attribute,
|
2479
2721
|
fieldsToSelect,
|
2480
2722
|
mainField,
|
2481
|
-
source: { schema: sourceSchema },
|
2723
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2482
2724
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2483
2725
|
sourceSchema,
|
2484
2726
|
targetSchema,
|
@@ -2500,7 +2742,8 @@ const relations = {
|
|
2500
2742
|
fieldsToSelect,
|
2501
2743
|
mainField,
|
2502
2744
|
source: {
|
2503
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2745
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2746
|
+
isLocalized: isSourceLocalized
|
2504
2747
|
},
|
2505
2748
|
target: {
|
2506
2749
|
schema: { uid: targetUid },
|
@@ -2508,7 +2751,7 @@ const relations = {
|
|
2508
2751
|
}
|
2509
2752
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2510
2753
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2511
|
-
const permissionChecker2 = getService$
|
2754
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2512
2755
|
userAbility: ctx.state.userAbility,
|
2513
2756
|
model: targetUid
|
2514
2757
|
});
|
@@ -2538,12 +2781,16 @@ const relations = {
|
|
2538
2781
|
} else {
|
2539
2782
|
where.id = id;
|
2540
2783
|
}
|
2541
|
-
|
2542
|
-
|
2784
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2785
|
+
if (!fp.isEmpty(publishedAt)) {
|
2786
|
+
where[`${alias}.published_at`] = publishedAt;
|
2543
2787
|
}
|
2544
|
-
if (
|
2788
|
+
if (isTargetLocalized && locale) {
|
2545
2789
|
where[`${alias}.locale`] = locale;
|
2546
2790
|
}
|
2791
|
+
if (isSourceLocalized && locale) {
|
2792
|
+
where.locale = locale;
|
2793
|
+
}
|
2547
2794
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2548
2795
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2549
2796
|
}
|
@@ -2561,7 +2808,8 @@ const relations = {
|
|
2561
2808
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2562
2809
|
});
|
2563
2810
|
}
|
2564
|
-
const
|
2811
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2812
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2565
2813
|
ctx.body = {
|
2566
2814
|
...res,
|
2567
2815
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2576,29 +2824,39 @@ const relations = {
|
|
2576
2824
|
attribute,
|
2577
2825
|
targetField,
|
2578
2826
|
fieldsToSelect,
|
2579
|
-
|
2580
|
-
|
2581
|
-
}
|
2582
|
-
target: {
|
2583
|
-
schema: { uid: targetUid }
|
2584
|
-
}
|
2827
|
+
status,
|
2828
|
+
source: { schema: sourceSchema },
|
2829
|
+
target: { schema: targetSchema }
|
2585
2830
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2586
|
-
const
|
2831
|
+
const { uid: sourceUid } = sourceSchema;
|
2832
|
+
const { uid: targetUid } = targetSchema;
|
2833
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2587
2834
|
const dbQuery = strapi.db.query(sourceUid);
|
2588
2835
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2836
|
+
const filters = {};
|
2837
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2838
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2839
|
+
if (status === "published") {
|
2840
|
+
filters.publishedAt = { $notNull: true };
|
2841
|
+
} else {
|
2842
|
+
filters.publishedAt = { $null: true };
|
2843
|
+
}
|
2844
|
+
}
|
2845
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2846
|
+
filters.publishedAt = { $null: true };
|
2847
|
+
}
|
2589
2848
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2590
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2849
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2591
2850
|
ordering: "desc",
|
2592
2851
|
page: ctx.request.query.page,
|
2593
|
-
pageSize: ctx.request.query.pageSize
|
2852
|
+
pageSize: ctx.request.query.pageSize,
|
2853
|
+
filters
|
2594
2854
|
});
|
2595
2855
|
const loadedIds = res.results.map((item) => item.id);
|
2596
2856
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2597
2857
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2598
2858
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2599
|
-
ordering: "desc"
|
2600
|
-
page: ctx.request.query.page,
|
2601
|
-
pageSize: ctx.request.query.pageSize
|
2859
|
+
ordering: "desc"
|
2602
2860
|
});
|
2603
2861
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2604
2862
|
ctx.body = {
|
@@ -2613,10 +2871,10 @@ const relations = {
|
|
2613
2871
|
}
|
2614
2872
|
};
|
2615
2873
|
const buildPopulateFromQuery = async (query, model) => {
|
2616
|
-
return getService$
|
2874
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2617
2875
|
};
|
2618
2876
|
const findDocument = async (query, uid2, opts = {}) => {
|
2619
|
-
const documentManager2 = getService$
|
2877
|
+
const documentManager2 = getService$2("document-manager");
|
2620
2878
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2621
2879
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2622
2880
|
};
|
@@ -2624,8 +2882,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2624
2882
|
const { user, userAbility } = ctx.state;
|
2625
2883
|
const { model } = ctx.params;
|
2626
2884
|
const { body, query } = ctx.request;
|
2627
|
-
const documentManager2 = getService$
|
2628
|
-
const permissionChecker2 = getService$
|
2885
|
+
const documentManager2 = getService$2("document-manager");
|
2886
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2629
2887
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2630
2888
|
throw new strapiUtils.errors.ForbiddenError();
|
2631
2889
|
}
|
@@ -2666,7 +2924,7 @@ const singleTypes = {
|
|
2666
2924
|
const { userAbility } = ctx.state;
|
2667
2925
|
const { model } = ctx.params;
|
2668
2926
|
const { query = {} } = ctx.request;
|
2669
|
-
const permissionChecker2 = getService$
|
2927
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2670
2928
|
if (permissionChecker2.cannot.read()) {
|
2671
2929
|
return ctx.forbidden();
|
2672
2930
|
}
|
@@ -2685,7 +2943,7 @@ const singleTypes = {
|
|
2685
2943
|
permissionChecker2,
|
2686
2944
|
model,
|
2687
2945
|
// @ts-expect-error - fix types
|
2688
|
-
{
|
2946
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2689
2947
|
{ availableLocales: true, availableStatus: false }
|
2690
2948
|
);
|
2691
2949
|
ctx.body = { data: {}, meta };
|
@@ -2700,7 +2958,7 @@ const singleTypes = {
|
|
2700
2958
|
async createOrUpdate(ctx) {
|
2701
2959
|
const { userAbility } = ctx.state;
|
2702
2960
|
const { model } = ctx.params;
|
2703
|
-
const permissionChecker2 = getService$
|
2961
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2704
2962
|
const document = await createOrUpdateDocument(ctx);
|
2705
2963
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2706
2964
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2709,8 +2967,8 @@ const singleTypes = {
|
|
2709
2967
|
const { userAbility } = ctx.state;
|
2710
2968
|
const { model } = ctx.params;
|
2711
2969
|
const { query = {} } = ctx.request;
|
2712
|
-
const documentManager2 = getService$
|
2713
|
-
const permissionChecker2 = getService$
|
2970
|
+
const documentManager2 = getService$2("document-manager");
|
2971
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2714
2972
|
if (permissionChecker2.cannot.delete()) {
|
2715
2973
|
return ctx.forbidden();
|
2716
2974
|
}
|
@@ -2738,8 +2996,8 @@ const singleTypes = {
|
|
2738
2996
|
const { userAbility } = ctx.state;
|
2739
2997
|
const { model } = ctx.params;
|
2740
2998
|
const { query = {} } = ctx.request;
|
2741
|
-
const documentManager2 = getService$
|
2742
|
-
const permissionChecker2 = getService$
|
2999
|
+
const documentManager2 = getService$2("document-manager");
|
3000
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2743
3001
|
if (permissionChecker2.cannot.publish()) {
|
2744
3002
|
return ctx.forbidden();
|
2745
3003
|
}
|
@@ -2767,8 +3025,8 @@ const singleTypes = {
|
|
2767
3025
|
body: { discardDraft, ...body },
|
2768
3026
|
query = {}
|
2769
3027
|
} = ctx.request;
|
2770
|
-
const documentManager2 = getService$
|
2771
|
-
const permissionChecker2 = getService$
|
3028
|
+
const documentManager2 = getService$2("document-manager");
|
3029
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2772
3030
|
if (permissionChecker2.cannot.unpublish()) {
|
2773
3031
|
return ctx.forbidden();
|
2774
3032
|
}
|
@@ -2802,8 +3060,8 @@ const singleTypes = {
|
|
2802
3060
|
const { userAbility } = ctx.state;
|
2803
3061
|
const { model } = ctx.params;
|
2804
3062
|
const { body, query = {} } = ctx.request;
|
2805
|
-
const documentManager2 = getService$
|
2806
|
-
const permissionChecker2 = getService$
|
3063
|
+
const documentManager2 = getService$2("document-manager");
|
3064
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2807
3065
|
if (permissionChecker2.cannot.discard()) {
|
2808
3066
|
return ctx.forbidden();
|
2809
3067
|
}
|
@@ -2826,8 +3084,8 @@ const singleTypes = {
|
|
2826
3084
|
const { userAbility } = ctx.state;
|
2827
3085
|
const { model } = ctx.params;
|
2828
3086
|
const { query } = ctx.request;
|
2829
|
-
const documentManager2 = getService$
|
2830
|
-
const permissionChecker2 = getService$
|
3087
|
+
const documentManager2 = getService$2("document-manager");
|
3088
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2831
3089
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2832
3090
|
if (permissionChecker2.cannot.read()) {
|
2833
3091
|
return ctx.forbidden();
|
@@ -2851,7 +3109,7 @@ const uid$1 = {
|
|
2851
3109
|
const { query = {} } = ctx.request;
|
2852
3110
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2853
3111
|
await validateUIDField(contentTypeUID, field);
|
2854
|
-
const uidService = getService$
|
3112
|
+
const uidService = getService$2("uid");
|
2855
3113
|
ctx.body = {
|
2856
3114
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2857
3115
|
};
|
@@ -2863,7 +3121,7 @@ const uid$1 = {
|
|
2863
3121
|
const { query = {} } = ctx.request;
|
2864
3122
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2865
3123
|
await validateUIDField(contentTypeUID, field);
|
2866
|
-
const uidService = getService$
|
3124
|
+
const uidService = getService$2("uid");
|
2867
3125
|
const isAvailable = await uidService.checkUIDAvailability({
|
2868
3126
|
contentTypeUID,
|
2869
3127
|
field,
|
@@ -2884,7 +3142,8 @@ const controllers = {
|
|
2884
3142
|
relations,
|
2885
3143
|
"single-types": singleTypes,
|
2886
3144
|
uid: uid$1,
|
2887
|
-
...history.controllers ? history.controllers : {}
|
3145
|
+
...history.controllers ? history.controllers : {},
|
3146
|
+
...preview.controllers ? preview.controllers : {}
|
2888
3147
|
};
|
2889
3148
|
const keys = {
|
2890
3149
|
CONFIGURATION: "configuration"
|
@@ -3013,18 +3272,15 @@ async function syncMetadatas(configuration, schema) {
|
|
3013
3272
|
___default.default.set(updatedMeta, ["list", "searchable"], false);
|
3014
3273
|
___default.default.set(acc, [key], updatedMeta);
|
3015
3274
|
}
|
3016
|
-
if (!___default.default.has(edit, "mainField"))
|
3017
|
-
return acc;
|
3275
|
+
if (!___default.default.has(edit, "mainField")) return acc;
|
3018
3276
|
if (!isRelation$1(attr)) {
|
3019
3277
|
___default.default.set(updatedMeta, "edit", ___default.default.omit(edit, ["mainField"]));
|
3020
3278
|
___default.default.set(acc, [key], updatedMeta);
|
3021
3279
|
return acc;
|
3022
3280
|
}
|
3023
|
-
if (edit.mainField === "id")
|
3024
|
-
return acc;
|
3281
|
+
if (edit.mainField === "id") return acc;
|
3025
3282
|
const targetSchema = getTargetSchema(attr.targetModel);
|
3026
|
-
if (!targetSchema)
|
3027
|
-
return acc;
|
3283
|
+
if (!targetSchema) return acc;
|
3028
3284
|
if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
|
3029
3285
|
___default.default.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
|
3030
3286
|
___default.default.set(acc, [key], updatedMeta);
|
@@ -3035,12 +3291,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3035
3291
|
return ___default.default.assign(metasWithDefaults, updatedMetas);
|
3036
3292
|
}
|
3037
3293
|
const getTargetSchema = (targetModel) => {
|
3038
|
-
return getService$
|
3294
|
+
return getService$2("content-types").findContentType(targetModel);
|
3039
3295
|
};
|
3040
3296
|
const DEFAULT_LIST_LENGTH = 4;
|
3041
3297
|
const MAX_ROW_SIZE = 12;
|
3042
3298
|
const isAllowedFieldSize = (type, size) => {
|
3043
|
-
const { getFieldSize } = getService$
|
3299
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3044
3300
|
const fieldSize = getFieldSize(type);
|
3045
3301
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3046
3302
|
return false;
|
@@ -3048,7 +3304,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3048
3304
|
return size <= MAX_ROW_SIZE;
|
3049
3305
|
};
|
3050
3306
|
const getDefaultFieldSize = (attribute) => {
|
3051
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3307
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3052
3308
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3053
3309
|
};
|
3054
3310
|
async function createDefaultLayouts(schema) {
|
@@ -3069,8 +3325,7 @@ function createDefaultEditLayout(schema) {
|
|
3069
3325
|
return appendToEditLayout([], keys2, schema);
|
3070
3326
|
}
|
3071
3327
|
function syncLayouts(configuration, schema) {
|
3072
|
-
if (___default.default.isEmpty(configuration.layouts))
|
3073
|
-
return createDefaultLayouts(schema);
|
3328
|
+
if (___default.default.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
|
3074
3329
|
const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
|
3075
3330
|
let cleanList = list.filter((attr) => isListable(schema, attr));
|
3076
3331
|
const cleanEditRelations = editRelations.filter(
|
@@ -3081,9 +3336,8 @@ function syncLayouts(configuration, schema) {
|
|
3081
3336
|
for (const row of edit) {
|
3082
3337
|
const newRow = [];
|
3083
3338
|
for (const el of row) {
|
3084
|
-
if (!hasEditableAttribute(schema, el.name))
|
3085
|
-
|
3086
|
-
const { hasFieldSize } = getService$1("field-sizes");
|
3339
|
+
if (!hasEditableAttribute(schema, el.name)) continue;
|
3340
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3087
3341
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3088
3342
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3089
3343
|
elementsToReAppend.push(el.name);
|
@@ -3113,8 +3367,7 @@ function syncLayouts(configuration, schema) {
|
|
3113
3367
|
};
|
3114
3368
|
}
|
3115
3369
|
const appendToEditLayout = (layout = [], keysToAppend, schema) => {
|
3116
|
-
if (keysToAppend.length === 0)
|
3117
|
-
return layout;
|
3370
|
+
if (keysToAppend.length === 0) return layout;
|
3118
3371
|
let currentRowIndex = Math.max(layout.length - 1, 0);
|
3119
3372
|
if (!layout[currentRowIndex]) {
|
3120
3373
|
layout[currentRowIndex] = [];
|
@@ -3223,17 +3476,17 @@ const configurationService$1 = createConfigurationService({
|
|
3223
3476
|
isComponent: true,
|
3224
3477
|
prefix: STORE_KEY_PREFIX,
|
3225
3478
|
getModels() {
|
3226
|
-
const { toContentManagerModel } = getService$
|
3479
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3227
3480
|
return fp.mapValues(toContentManagerModel, strapi.components);
|
3228
3481
|
}
|
3229
3482
|
});
|
3230
3483
|
const components = ({ strapi: strapi2 }) => ({
|
3231
3484
|
findAllComponents() {
|
3232
|
-
const { toContentManagerModel } = getService$
|
3485
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3233
3486
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3234
3487
|
},
|
3235
3488
|
findComponent(uid2) {
|
3236
|
-
const { toContentManagerModel } = getService$
|
3489
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3237
3490
|
const component = strapi2.components[uid2];
|
3238
3491
|
return fp.isNil(component) ? component : toContentManagerModel(component);
|
3239
3492
|
},
|
@@ -3284,17 +3537,17 @@ const configurationService = createConfigurationService({
|
|
3284
3537
|
storeUtils,
|
3285
3538
|
prefix: "content_types",
|
3286
3539
|
getModels() {
|
3287
|
-
const { toContentManagerModel } = getService$
|
3540
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3288
3541
|
return fp.mapValues(toContentManagerModel, strapi.contentTypes);
|
3289
3542
|
}
|
3290
3543
|
});
|
3291
3544
|
const service = ({ strapi: strapi2 }) => ({
|
3292
3545
|
findAllContentTypes() {
|
3293
|
-
const { toContentManagerModel } = getService$
|
3546
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3294
3547
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3295
3548
|
},
|
3296
3549
|
findContentType(uid2) {
|
3297
|
-
const { toContentManagerModel } = getService$
|
3550
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3298
3551
|
const contentType = strapi2.contentTypes[uid2];
|
3299
3552
|
return fp.isNil(contentType) ? contentType : toContentManagerModel(contentType);
|
3300
3553
|
},
|
@@ -3323,7 +3576,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3323
3576
|
return this.findConfiguration(contentType);
|
3324
3577
|
},
|
3325
3578
|
findComponentsConfigurations(contentType) {
|
3326
|
-
return getService$
|
3579
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3327
3580
|
},
|
3328
3581
|
syncConfigurations() {
|
3329
3582
|
return configurationService.syncConfigurations();
|
@@ -3504,12 +3757,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3504
3757
|
ability: userAbility,
|
3505
3758
|
model
|
3506
3759
|
});
|
3507
|
-
const
|
3760
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3761
|
+
const toSubject = (entity) => {
|
3762
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3763
|
+
};
|
3508
3764
|
const can = (action, entity, field) => {
|
3509
|
-
|
3765
|
+
const subject = toSubject(entity);
|
3766
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3767
|
+
return (
|
3768
|
+
// Test the original action to see if it passes
|
3769
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3770
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3771
|
+
);
|
3510
3772
|
};
|
3511
3773
|
const cannot = (action, entity, field) => {
|
3512
|
-
|
3774
|
+
const subject = toSubject(entity);
|
3775
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3776
|
+
return (
|
3777
|
+
// Test both the original action
|
3778
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3779
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3780
|
+
);
|
3513
3781
|
};
|
3514
3782
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3515
3783
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3580,7 +3848,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3580
3848
|
return userAbility.can(action);
|
3581
3849
|
},
|
3582
3850
|
async registerPermissions() {
|
3583
|
-
const displayedContentTypes = getService$
|
3851
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3584
3852
|
const contentTypesUids = displayedContentTypes.map(fp.prop("uid"));
|
3585
3853
|
const actions = [
|
3586
3854
|
{
|
@@ -3856,7 +4124,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3856
4124
|
return populateQuery;
|
3857
4125
|
};
|
3858
4126
|
const buildDeepPopulate = (uid2) => {
|
3859
|
-
return getService$
|
4127
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3860
4128
|
};
|
3861
4129
|
const populateBuilder = (uid2) => {
|
3862
4130
|
let getInitialPopulate = async () => {
|
@@ -4041,7 +4309,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4041
4309
|
*/
|
4042
4310
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
4043
4311
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4044
|
-
|
4312
|
+
if (version.locale) {
|
4313
|
+
delete versionsByLocale[version.locale];
|
4314
|
+
}
|
4045
4315
|
const model = strapi2.getModel(uid2);
|
4046
4316
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4047
4317
|
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
@@ -4088,8 +4358,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4088
4358
|
const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
|
4089
4359
|
return matchLocale && matchStatus;
|
4090
4360
|
});
|
4091
|
-
if (!availableStatus)
|
4092
|
-
return availableStatus;
|
4361
|
+
if (!availableStatus) return availableStatus;
|
4093
4362
|
return fp.pick(AVAILABLE_STATUS_FIELDS, availableStatus);
|
4094
4363
|
},
|
4095
4364
|
/**
|
@@ -4099,8 +4368,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4099
4368
|
* @returns
|
4100
4369
|
*/
|
4101
4370
|
async getManyAvailableStatus(uid2, documents) {
|
4102
|
-
if (!documents.length)
|
4103
|
-
return [];
|
4371
|
+
if (!documents.length) return [];
|
4104
4372
|
const status = documents[0].publishedAt !== null ? "published" : "draft";
|
4105
4373
|
const locale = documents[0]?.locale;
|
4106
4374
|
const otherStatus = status === "published" ? "draft" : "published";
|
@@ -4127,10 +4395,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4127
4395
|
} else if (otherVersion) {
|
4128
4396
|
draftVersion = otherVersion;
|
4129
4397
|
}
|
4130
|
-
if (!draftVersion)
|
4131
|
-
|
4132
|
-
if (!publishedVersion)
|
4133
|
-
return CONTENT_MANAGER_STATUS.DRAFT;
|
4398
|
+
if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
|
4399
|
+
if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
|
4134
4400
|
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4135
4401
|
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
4136
4402
|
},
|
@@ -4397,7 +4663,8 @@ const services = {
|
|
4397
4663
|
permission,
|
4398
4664
|
"populate-builder": populateBuilder$1,
|
4399
4665
|
uid,
|
4400
|
-
...history.services ? history.services : {}
|
4666
|
+
...history.services ? history.services : {},
|
4667
|
+
...preview.services ? preview.services : {}
|
4401
4668
|
};
|
4402
4669
|
const index = () => {
|
4403
4670
|
return {
|