@strapi/content-manager 0.0.0-experimental.f2351bcfa3965c60f063a492da51faa2c636eee8 → 0.0.0-experimental.f49f46a1c17445a39e8af3f63124bcccf73842e6
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/{ComponentConfigurationPage-BlAzljQ6.js → ComponentConfigurationPage-ClKl_TA2.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-BlAzljQ6.js.map → ComponentConfigurationPage-ClKl_TA2.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-Ccwb19Qj.mjs → ComponentConfigurationPage-D3ZWDAHG.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-Ccwb19Qj.mjs.map → ComponentConfigurationPage-D3ZWDAHG.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-C19b_9RL.mjs → EditConfigurationPage-BYCBSJxP.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-C19b_9RL.mjs.map → EditConfigurationPage-BYCBSJxP.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BPoOzhCM.js → EditConfigurationPage-OWez0Kxp.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-BPoOzhCM.js.map → EditConfigurationPage-OWez0Kxp.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-nmrHNiJ9.mjs → EditViewPage-5pdbvsO_.mjs} +50 -10
- package/dist/_chunks/EditViewPage-5pdbvsO_.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-D9xH8HYD.js → EditViewPage-BEs5iGDi.js} +49 -9
- package/dist/_chunks/EditViewPage-BEs5iGDi.js.map +1 -0
- package/dist/_chunks/{Field-BB_pHo6D.js → Field-DNHm4wHx.js} +107 -44
- package/dist/_chunks/Field-DNHm4wHx.js.map +1 -0
- package/dist/_chunks/{Field--kmlJuSb.mjs → Field-DcKuFHYK.mjs} +107 -44
- package/dist/_chunks/Field-DcKuFHYK.mjs.map +1 -0
- package/dist/_chunks/{Form-CUtOiC4S.mjs → Form-CGwM_-5c.mjs} +3 -3
- package/dist/_chunks/Form-CGwM_-5c.mjs.map +1 -0
- package/dist/_chunks/{Form-iwbkoaAF.js → Form-CoRxWJOz.js} +3 -3
- package/dist/_chunks/Form-CoRxWJOz.js.map +1 -0
- package/dist/_chunks/{History-guuZF4lR.js → History-BcUTQrfG.js} +40 -97
- package/dist/_chunks/History-BcUTQrfG.js.map +1 -0
- package/dist/_chunks/{History-BKR3KyU3.mjs → History-DEvr3Q_V.mjs} +42 -99
- package/dist/_chunks/History-DEvr3Q_V.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-Cu26t5sE.js → ListConfigurationPage-BE_Ho7tV.js} +5 -4
- package/dist/_chunks/ListConfigurationPage-BE_Ho7tV.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B_O3hiLT.mjs → ListConfigurationPage-BM4zZZcM.mjs} +6 -5
- package/dist/_chunks/ListConfigurationPage-BM4zZZcM.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-B4sTBfu6.mjs → ListViewPage-BK2mkrql.mjs} +29 -7
- package/dist/_chunks/{ListViewPage-B4sTBfu6.mjs.map → ListViewPage-BK2mkrql.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-DWqqGno8.js → ListViewPage-BkT8Eao0.js} +29 -7
- package/dist/_chunks/ListViewPage-BkT8Eao0.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Daktt4t9.mjs → NoContentTypePage-BvcAutu9.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Daktt4t9.mjs.map → NoContentTypePage-BvcAutu9.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-TTkwA8uk.js → NoContentTypePage-C8mtyc4H.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-TTkwA8uk.js.map → NoContentTypePage-C8mtyc4H.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-D8_k39Q0.js → NoPermissionsPage-B5Y9Y78B.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-D8_k39Q0.js.map → NoPermissionsPage-B5Y9Y78B.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CBUXY2Pt.mjs → NoPermissionsPage-BmbRz7PR.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CBUXY2Pt.mjs.map → NoPermissionsPage-BmbRz7PR.mjs.map} +1 -1
- package/dist/_chunks/Preview-BF8ZDYqS.js +286 -0
- package/dist/_chunks/Preview-BF8ZDYqS.js.map +1 -0
- package/dist/_chunks/Preview-DcexhKJE.mjs +267 -0
- package/dist/_chunks/Preview-DcexhKJE.mjs.map +1 -0
- package/dist/_chunks/{Relations-DjvmZ_XQ.js → Relations-BKnoK1R0.js} +71 -35
- package/dist/_chunks/Relations-BKnoK1R0.js.map +1 -0
- package/dist/_chunks/{Relations-HKmXF7eO.mjs → Relations-BjIzc4EK.mjs} +72 -36
- package/dist/_chunks/Relations-BjIzc4EK.mjs.map +1 -0
- package/dist/_chunks/{en-CPTj6CjC.mjs → en-CfIXaZf9.mjs} +21 -10
- package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-CfIXaZf9.mjs.map} +1 -1
- package/dist/_chunks/{en-BVzUkPxZ.js → en-DTWPCdTS.js} +21 -10
- package/dist/_chunks/{en-BVzUkPxZ.js.map → en-DTWPCdTS.js.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/{index-CB1AN26E.mjs → index-BW-rXkjn.mjs} +882 -721
- package/dist/_chunks/index-BW-rXkjn.mjs.map +1 -0
- package/dist/_chunks/{index-jDJgW_Lf.js → index-DOzAG2cq.js} +879 -717
- package/dist/_chunks/index-DOzAG2cq.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-BCzDsMgN.mjs → layout-DFVbgjp2.mjs} +3 -3
- package/dist/_chunks/{layout-BCzDsMgN.mjs.map → layout-DFVbgjp2.mjs.map} +1 -1
- package/dist/_chunks/{layout-D6A3K-ut.js → layout-RC3W2obV.js} +3 -3
- package/dist/_chunks/{layout-D6A3K-ut.js.map → layout-RC3W2obV.js.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-B5Jnw32V.mjs → relations-Dogh8HWI.mjs} +6 -7
- package/dist/_chunks/relations-Dogh8HWI.mjs.map +1 -0
- package/dist/_chunks/{relations-C10QoukP.js → relations-zam7-5H7.js} +6 -7
- package/dist/_chunks/relations-zam7-5H7.js.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +4 -3
- package/dist/admin/src/exports.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/Header.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/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/server/index.js +374 -160
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +374 -160
- 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 +2 -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/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 +15 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +30 -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 +18 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- 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/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/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 -13
- package/dist/_chunks/EditViewPage-D9xH8HYD.js.map +0 -1
- package/dist/_chunks/EditViewPage-nmrHNiJ9.mjs.map +0 -1
- package/dist/_chunks/Field--kmlJuSb.mjs.map +0 -1
- package/dist/_chunks/Field-BB_pHo6D.js.map +0 -1
- package/dist/_chunks/Form-CUtOiC4S.mjs.map +0 -1
- package/dist/_chunks/Form-iwbkoaAF.js.map +0 -1
- package/dist/_chunks/History-BKR3KyU3.mjs.map +0 -1
- package/dist/_chunks/History-guuZF4lR.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B_O3hiLT.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-Cu26t5sE.js.map +0 -1
- package/dist/_chunks/ListViewPage-DWqqGno8.js.map +0 -1
- package/dist/_chunks/Relations-DjvmZ_XQ.js.map +0 -1
- package/dist/_chunks/Relations-HKmXF7eO.mjs.map +0 -1
- package/dist/_chunks/index-CB1AN26E.mjs.map +0 -1
- package/dist/_chunks/index-jDJgW_Lf.js.map +0 -1
- package/dist/_chunks/relations-B5Jnw32V.mjs.map +0 -1
- package/dist/_chunks/relations-C10QoukP.js.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.mjs
CHANGED
@@ -7,10 +7,10 @@ import isNil from "lodash/isNil";
|
|
7
7
|
import _, { intersection as intersection$1, difference as difference$1 } from "lodash";
|
8
8
|
import qs from "qs";
|
9
9
|
import slugify from "@sindresorhus/slugify";
|
10
|
-
const getService$
|
10
|
+
const getService$2 = (name) => {
|
11
11
|
return strapi.plugin("content-manager").service(name);
|
12
12
|
};
|
13
|
-
function getService(strapi2, name) {
|
13
|
+
function getService$1(strapi2, name) {
|
14
14
|
return strapi2.service(`plugin::content-manager.${name}`);
|
15
15
|
}
|
16
16
|
const historyRestoreVersionSchema = yup.object().shape({
|
@@ -46,7 +46,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
46
46
|
if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
|
47
47
|
throw new errors.ForbiddenError("contentType and documentId are required");
|
48
48
|
}
|
49
|
-
const permissionChecker2 = getService$
|
49
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
50
50
|
userAbility: ctx.state.userAbility,
|
51
51
|
model: ctx.query.contentType
|
52
52
|
});
|
@@ -54,7 +54,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
54
54
|
return ctx.forbidden();
|
55
55
|
}
|
56
56
|
const query = await permissionChecker2.sanitizeQuery(ctx.query);
|
57
|
-
const { results, pagination: pagination2 } = await getService(strapi2, "history").findVersionsPage({
|
57
|
+
const { results, pagination: pagination2 } = await getService$1(strapi2, "history").findVersionsPage({
|
58
58
|
query: {
|
59
59
|
...query,
|
60
60
|
...getValidPagination({ page: query.page, pageSize: query.pageSize })
|
@@ -79,14 +79,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
79
79
|
async restoreVersion(ctx) {
|
80
80
|
const request = ctx.request;
|
81
81
|
await validateRestoreVersion(request.body, "contentType is required");
|
82
|
-
const permissionChecker2 = getService$
|
82
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
83
83
|
userAbility: ctx.state.userAbility,
|
84
84
|
model: request.body.contentType
|
85
85
|
});
|
86
86
|
if (permissionChecker2.cannot.update()) {
|
87
87
|
throw new errors.ForbiddenError();
|
88
88
|
}
|
89
|
-
const restoredDocument = await getService(strapi2, "history").restoreVersion(
|
89
|
+
const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
|
90
90
|
request.params.versionId
|
91
91
|
);
|
92
92
|
return {
|
@@ -95,7 +95,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
95
95
|
}
|
96
96
|
};
|
97
97
|
};
|
98
|
-
const controllers$
|
98
|
+
const controllers$2 = {
|
99
99
|
"history-version": createHistoryVersionController
|
100
100
|
/**
|
101
101
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -202,6 +202,17 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
202
202
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
203
203
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
204
204
|
};
|
205
|
+
const getComponentFields = (componentUID) => {
|
206
|
+
return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
|
207
|
+
(fieldsAcc, [key, attribute]) => {
|
208
|
+
if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
|
209
|
+
fieldsAcc.push(key);
|
210
|
+
}
|
211
|
+
return fieldsAcc;
|
212
|
+
},
|
213
|
+
[]
|
214
|
+
);
|
215
|
+
};
|
205
216
|
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
206
217
|
const model = strapi2.getModel(uid2);
|
207
218
|
const attributes = Object.entries(model.attributes);
|
@@ -225,13 +236,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
225
236
|
}
|
226
237
|
case "component": {
|
227
238
|
const populate = getDeepPopulate2(attribute.component);
|
228
|
-
acc[attributeName] = {
|
239
|
+
acc[attributeName] = {
|
240
|
+
populate,
|
241
|
+
[fieldSelector]: getComponentFields(attribute.component)
|
242
|
+
};
|
229
243
|
break;
|
230
244
|
}
|
231
245
|
case "dynamiczone": {
|
232
246
|
const populatedComponents = (attribute.components || []).reduce(
|
233
247
|
(acc2, componentUID) => {
|
234
|
-
acc2[componentUID] = {
|
248
|
+
acc2[componentUID] = {
|
249
|
+
populate: getDeepPopulate2(componentUID),
|
250
|
+
[fieldSelector]: getComponentFields(componentUID)
|
251
|
+
};
|
235
252
|
return acc2;
|
236
253
|
},
|
237
254
|
{}
|
@@ -344,7 +361,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
344
361
|
const attributeValue = entry.data[attributeKey];
|
345
362
|
const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
|
346
363
|
if (attributeSchema.type === "media") {
|
347
|
-
const permissionChecker2 = getService$
|
364
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
348
365
|
userAbility: params.state.userAbility,
|
349
366
|
model: "plugin::upload.file"
|
350
367
|
});
|
@@ -367,7 +384,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
367
384
|
if (userToPopulate == null) {
|
368
385
|
return null;
|
369
386
|
}
|
370
|
-
return strapi2.query("admin::user").findOne({
|
387
|
+
return strapi2.query("admin::user").findOne({
|
388
|
+
where: {
|
389
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
390
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
391
|
+
}
|
392
|
+
});
|
371
393
|
})
|
372
394
|
);
|
373
395
|
return {
|
@@ -380,7 +402,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
380
402
|
[attributeKey]: adminUsers
|
381
403
|
};
|
382
404
|
}
|
383
|
-
const permissionChecker2 = getService$
|
405
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
384
406
|
userAbility: params.state.userAbility,
|
385
407
|
model: attributeSchema.target
|
386
408
|
});
|
@@ -556,7 +578,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
556
578
|
onCommit(async () => {
|
557
579
|
for (const entry of localeEntries) {
|
558
580
|
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
559
|
-
await getService(strapi2, "history").createVersion({
|
581
|
+
await getService$1(strapi2, "history").createVersion({
|
560
582
|
contentType: uid2,
|
561
583
|
data: omit(FIELDS_TO_IGNORE, entry),
|
562
584
|
relatedDocumentId: documentId,
|
@@ -569,15 +591,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
569
591
|
});
|
570
592
|
return result;
|
571
593
|
});
|
572
|
-
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
594
|
+
state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
|
573
595
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
574
596
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
575
597
|
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
576
598
|
where: {
|
577
599
|
created_at: {
|
578
|
-
$lt: expirationDate
|
600
|
+
$lt: expirationDate
|
579
601
|
}
|
580
602
|
}
|
603
|
+
}).catch((error) => {
|
604
|
+
if (error instanceof Error) {
|
605
|
+
strapi2.log.error("Error deleting expired history versions", error.message);
|
606
|
+
}
|
581
607
|
});
|
582
608
|
});
|
583
609
|
state.isInitialized = true;
|
@@ -589,17 +615,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
589
615
|
}
|
590
616
|
};
|
591
617
|
};
|
592
|
-
const services$
|
618
|
+
const services$2 = {
|
593
619
|
history: createHistoryService,
|
594
620
|
lifecycles: createLifecyclesService
|
595
621
|
};
|
596
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
622
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
597
623
|
const historyVersionRouter = {
|
598
624
|
type: "admin",
|
599
625
|
routes: [
|
600
626
|
{
|
601
627
|
method: "GET",
|
602
|
-
info,
|
628
|
+
info: info$1,
|
603
629
|
path: "/history-versions",
|
604
630
|
handler: "history-version.findMany",
|
605
631
|
config: {
|
@@ -608,7 +634,7 @@ const historyVersionRouter = {
|
|
608
634
|
},
|
609
635
|
{
|
610
636
|
method: "PUT",
|
611
|
-
info,
|
637
|
+
info: info$1,
|
612
638
|
path: "/history-versions/:versionId/restore",
|
613
639
|
handler: "history-version.restoreVersion",
|
614
640
|
config: {
|
@@ -617,7 +643,7 @@ const historyVersionRouter = {
|
|
617
643
|
}
|
618
644
|
]
|
619
645
|
};
|
620
|
-
const routes$
|
646
|
+
const routes$2 = {
|
621
647
|
"history-version": historyVersionRouter
|
622
648
|
};
|
623
649
|
const historyVersion = {
|
@@ -664,21 +690,21 @@ const historyVersion = {
|
|
664
690
|
}
|
665
691
|
}
|
666
692
|
};
|
667
|
-
const getFeature = () => {
|
693
|
+
const getFeature$1 = () => {
|
668
694
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
669
695
|
return {
|
670
696
|
register({ strapi: strapi2 }) {
|
671
697
|
strapi2.get("models").add(historyVersion);
|
672
698
|
},
|
673
699
|
bootstrap({ strapi: strapi2 }) {
|
674
|
-
getService(strapi2, "lifecycles").bootstrap();
|
700
|
+
getService$1(strapi2, "lifecycles").bootstrap();
|
675
701
|
},
|
676
702
|
destroy({ strapi: strapi2 }) {
|
677
|
-
getService(strapi2, "lifecycles").destroy();
|
703
|
+
getService$1(strapi2, "lifecycles").destroy();
|
678
704
|
},
|
679
|
-
controllers: controllers$
|
680
|
-
services: services$
|
681
|
-
routes: routes$
|
705
|
+
controllers: controllers$2,
|
706
|
+
services: services$2,
|
707
|
+
routes: routes$2
|
682
708
|
};
|
683
709
|
}
|
684
710
|
return {
|
@@ -687,7 +713,7 @@ const getFeature = () => {
|
|
687
713
|
}
|
688
714
|
};
|
689
715
|
};
|
690
|
-
const history = getFeature();
|
716
|
+
const history = getFeature$1();
|
691
717
|
const register = async ({ strapi: strapi2 }) => {
|
692
718
|
await history.register?.({ strapi: strapi2 });
|
693
719
|
};
|
@@ -695,15 +721,165 @@ const ALLOWED_WEBHOOK_EVENTS = {
|
|
695
721
|
ENTRY_PUBLISH: "entry.publish",
|
696
722
|
ENTRY_UNPUBLISH: "entry.unpublish"
|
697
723
|
};
|
724
|
+
const FEATURE_ID = "preview";
|
725
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
726
|
+
const previewRouter = {
|
727
|
+
type: "admin",
|
728
|
+
routes: [
|
729
|
+
{
|
730
|
+
method: "GET",
|
731
|
+
info,
|
732
|
+
path: "/preview/url/:contentType",
|
733
|
+
handler: "preview.getPreviewUrl",
|
734
|
+
config: {
|
735
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
736
|
+
}
|
737
|
+
}
|
738
|
+
]
|
739
|
+
};
|
740
|
+
const routes$1 = {
|
741
|
+
preview: previewRouter
|
742
|
+
};
|
743
|
+
function getService(strapi2, name) {
|
744
|
+
return strapi2.service(`plugin::content-manager.${name}`);
|
745
|
+
}
|
746
|
+
const getPreviewUrlSchema = yup.object().shape({
|
747
|
+
// Will be undefined for single types
|
748
|
+
documentId: yup.string(),
|
749
|
+
locale: yup.string().nullable(),
|
750
|
+
status: yup.string()
|
751
|
+
}).required();
|
752
|
+
const validatePreviewUrl = async (strapi2, uid2, params) => {
|
753
|
+
await validateYupSchema(getPreviewUrlSchema)(params);
|
754
|
+
const newParams = pick(["documentId", "locale", "status"], params);
|
755
|
+
const model = strapi2.getModel(uid2);
|
756
|
+
if (!model || model.modelType !== "contentType") {
|
757
|
+
throw new errors.ValidationError("Invalid content type");
|
758
|
+
}
|
759
|
+
const isSingleType = model?.kind === "singleType";
|
760
|
+
if (!isSingleType && !params.documentId) {
|
761
|
+
throw new errors.ValidationError("documentId is required for Collection Types");
|
762
|
+
}
|
763
|
+
if (isSingleType) {
|
764
|
+
const doc = await strapi2.documents(uid2).findFirst();
|
765
|
+
if (!doc) {
|
766
|
+
throw new errors.NotFoundError("Document not found");
|
767
|
+
}
|
768
|
+
newParams.documentId = doc?.documentId;
|
769
|
+
}
|
770
|
+
return newParams;
|
771
|
+
};
|
772
|
+
const createPreviewController = () => {
|
773
|
+
return {
|
774
|
+
/**
|
775
|
+
* Transforms an entry into a preview URL, so that it can be previewed
|
776
|
+
* in the Content Manager.
|
777
|
+
*/
|
778
|
+
async getPreviewUrl(ctx) {
|
779
|
+
const uid2 = ctx.params.contentType;
|
780
|
+
const query = ctx.request.query;
|
781
|
+
const params = await validatePreviewUrl(strapi, uid2, query);
|
782
|
+
const previewService = getService(strapi, "preview");
|
783
|
+
const url = await previewService.getPreviewUrl(uid2, params);
|
784
|
+
if (!url) {
|
785
|
+
ctx.status = 204;
|
786
|
+
}
|
787
|
+
return {
|
788
|
+
data: { url }
|
789
|
+
};
|
790
|
+
}
|
791
|
+
};
|
792
|
+
};
|
793
|
+
const controllers$1 = {
|
794
|
+
preview: createPreviewController
|
795
|
+
/**
|
796
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
797
|
+
* passing a controller factory as the value, instead of a controller object directly
|
798
|
+
*/
|
799
|
+
};
|
800
|
+
const createPreviewService = ({ strapi: strapi2 }) => {
|
801
|
+
const config = getService(strapi2, "preview-config");
|
802
|
+
return {
|
803
|
+
async getPreviewUrl(uid2, params) {
|
804
|
+
const handler = config.getPreviewHandler();
|
805
|
+
try {
|
806
|
+
return handler(uid2, params);
|
807
|
+
} catch (error) {
|
808
|
+
strapi2.log.error(`Failed to get preview URL: ${error}`);
|
809
|
+
throw new errors.ApplicationError("Failed to get preview URL");
|
810
|
+
}
|
811
|
+
return;
|
812
|
+
}
|
813
|
+
};
|
814
|
+
};
|
815
|
+
const createPreviewConfigService = ({ strapi: strapi2 }) => {
|
816
|
+
return {
|
817
|
+
isEnabled() {
|
818
|
+
const config = strapi2.config.get("admin.preview");
|
819
|
+
if (!config) {
|
820
|
+
return false;
|
821
|
+
}
|
822
|
+
return config?.enabled ?? true;
|
823
|
+
},
|
824
|
+
/**
|
825
|
+
* Validate if the configuration is valid
|
826
|
+
*/
|
827
|
+
validate() {
|
828
|
+
if (!this.isEnabled()) {
|
829
|
+
return;
|
830
|
+
}
|
831
|
+
const handler = this.getPreviewHandler();
|
832
|
+
if (typeof handler !== "function") {
|
833
|
+
throw new errors.ValidationError(
|
834
|
+
"Preview configuration is invalid. Handler must be a function"
|
835
|
+
);
|
836
|
+
}
|
837
|
+
},
|
838
|
+
/**
|
839
|
+
* Utility to get the preview handler from the configuration
|
840
|
+
*/
|
841
|
+
getPreviewHandler() {
|
842
|
+
const config = strapi2.config.get("admin.preview");
|
843
|
+
const emptyHandler = () => {
|
844
|
+
return void 0;
|
845
|
+
};
|
846
|
+
if (!this.isEnabled()) {
|
847
|
+
return emptyHandler;
|
848
|
+
}
|
849
|
+
return config?.config?.handler || emptyHandler;
|
850
|
+
}
|
851
|
+
};
|
852
|
+
};
|
853
|
+
const services$1 = {
|
854
|
+
preview: createPreviewService,
|
855
|
+
"preview-config": createPreviewConfigService
|
856
|
+
};
|
857
|
+
const getFeature = () => {
|
858
|
+
if (!strapi.features.future.isEnabled(FEATURE_ID)) {
|
859
|
+
return {};
|
860
|
+
}
|
861
|
+
return {
|
862
|
+
bootstrap() {
|
863
|
+
console.log("Bootstrapping preview server");
|
864
|
+
const config = getService(strapi, "preview-config");
|
865
|
+
config.validate();
|
866
|
+
},
|
867
|
+
routes: routes$1,
|
868
|
+
controllers: controllers$1,
|
869
|
+
services: services$1
|
870
|
+
};
|
871
|
+
};
|
872
|
+
const preview = getFeature();
|
698
873
|
const bootstrap = async () => {
|
699
874
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
700
875
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
701
876
|
});
|
702
|
-
getService$
|
703
|
-
await getService$
|
704
|
-
await getService$
|
705
|
-
await getService$
|
877
|
+
getService$2("field-sizes").setCustomFieldInputSizes();
|
878
|
+
await getService$2("components").syncConfigurations();
|
879
|
+
await getService$2("content-types").syncConfigurations();
|
880
|
+
await getService$2("permission").registerPermissions();
|
706
881
|
await history.bootstrap?.({ strapi });
|
882
|
+
await preview.bootstrap?.({ strapi });
|
707
883
|
};
|
708
884
|
const destroy = async ({ strapi: strapi2 }) => {
|
709
885
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1193,7 +1369,8 @@ const admin = {
|
|
1193
1369
|
};
|
1194
1370
|
const routes = {
|
1195
1371
|
admin,
|
1196
|
-
...history.routes ? history.routes : {}
|
1372
|
+
...history.routes ? history.routes : {},
|
1373
|
+
...preview.routes ? preview.routes : {}
|
1197
1374
|
};
|
1198
1375
|
const hasPermissionsSchema = yup$1.object({
|
1199
1376
|
actions: yup$1.array().of(yup$1.string()),
|
@@ -1450,7 +1627,7 @@ const createMetadasSchema = (schema) => {
|
|
1450
1627
|
if (!value) {
|
1451
1628
|
return yup$1.string();
|
1452
1629
|
}
|
1453
|
-
const targetSchema = getService$
|
1630
|
+
const targetSchema = getService$2("content-types").findContentType(
|
1454
1631
|
schema.attributes[key].targetModel
|
1455
1632
|
);
|
1456
1633
|
if (!targetSchema) {
|
@@ -1619,7 +1796,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
|
|
1619
1796
|
}
|
1620
1797
|
};
|
1621
1798
|
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1622
|
-
const documentMetadata2 = getService$
|
1799
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1623
1800
|
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1624
1801
|
let {
|
1625
1802
|
meta: { availableLocales, availableStatus }
|
@@ -1645,8 +1822,8 @@ const createDocument = async (ctx, opts) => {
|
|
1645
1822
|
const { userAbility, user } = ctx.state;
|
1646
1823
|
const { model } = ctx.params;
|
1647
1824
|
const { body } = ctx.request;
|
1648
|
-
const documentManager2 = getService$
|
1649
|
-
const permissionChecker2 = getService$
|
1825
|
+
const documentManager2 = getService$2("document-manager");
|
1826
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1650
1827
|
if (permissionChecker2.cannot.create()) {
|
1651
1828
|
throw new errors.ForbiddenError();
|
1652
1829
|
}
|
@@ -1666,13 +1843,13 @@ const updateDocument = async (ctx, opts) => {
|
|
1666
1843
|
const { userAbility, user } = ctx.state;
|
1667
1844
|
const { id, model } = ctx.params;
|
1668
1845
|
const { body } = ctx.request;
|
1669
|
-
const documentManager2 = getService$
|
1670
|
-
const permissionChecker2 = getService$
|
1846
|
+
const documentManager2 = getService$2("document-manager");
|
1847
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1671
1848
|
if (permissionChecker2.cannot.update()) {
|
1672
1849
|
throw new errors.ForbiddenError();
|
1673
1850
|
}
|
1674
1851
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1675
|
-
const populate = await getService$
|
1852
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1676
1853
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1677
1854
|
const [documentVersion, documentExists] = await Promise.all([
|
1678
1855
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
@@ -1689,7 +1866,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1689
1866
|
throw new errors.ForbiddenError();
|
1690
1867
|
}
|
1691
1868
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1692
|
-
const setCreator = setCreatorFields({ user, isEdition: true });
|
1869
|
+
const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
|
1693
1870
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1694
1871
|
const sanitizedBody = await sanitizeFn(body);
|
1695
1872
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1703,14 +1880,14 @@ const collectionTypes = {
|
|
1703
1880
|
const { userAbility } = ctx.state;
|
1704
1881
|
const { model } = ctx.params;
|
1705
1882
|
const { query } = ctx.request;
|
1706
|
-
const documentMetadata2 = getService$
|
1707
|
-
const documentManager2 = getService$
|
1708
|
-
const permissionChecker2 = getService$
|
1883
|
+
const documentMetadata2 = getService$2("document-metadata");
|
1884
|
+
const documentManager2 = getService$2("document-manager");
|
1885
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1709
1886
|
if (permissionChecker2.cannot.read()) {
|
1710
1887
|
return ctx.forbidden();
|
1711
1888
|
}
|
1712
1889
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1713
|
-
const populate = await getService$
|
1890
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1714
1891
|
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1715
1892
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1716
1893
|
{ ...permissionQuery, populate, locale, status },
|
@@ -1739,13 +1916,13 @@ const collectionTypes = {
|
|
1739
1916
|
async findOne(ctx) {
|
1740
1917
|
const { userAbility } = ctx.state;
|
1741
1918
|
const { model, id } = ctx.params;
|
1742
|
-
const documentManager2 = getService$
|
1743
|
-
const permissionChecker2 = getService$
|
1919
|
+
const documentManager2 = getService$2("document-manager");
|
1920
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1744
1921
|
if (permissionChecker2.cannot.read()) {
|
1745
1922
|
return ctx.forbidden();
|
1746
1923
|
}
|
1747
1924
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1748
|
-
const populate = await getService$
|
1925
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1749
1926
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1750
1927
|
const version = await documentManager2.findOne(id, model, {
|
1751
1928
|
populate,
|
@@ -1776,7 +1953,7 @@ const collectionTypes = {
|
|
1776
1953
|
async create(ctx) {
|
1777
1954
|
const { userAbility } = ctx.state;
|
1778
1955
|
const { model } = ctx.params;
|
1779
|
-
const permissionChecker2 = getService$
|
1956
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1780
1957
|
const [totalEntries, document] = await Promise.all([
|
1781
1958
|
strapi.db.query(model).count(),
|
1782
1959
|
createDocument(ctx)
|
@@ -1797,7 +1974,7 @@ const collectionTypes = {
|
|
1797
1974
|
async update(ctx) {
|
1798
1975
|
const { userAbility } = ctx.state;
|
1799
1976
|
const { model } = ctx.params;
|
1800
|
-
const permissionChecker2 = getService$
|
1977
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1801
1978
|
const updatedVersion = await updateDocument(ctx);
|
1802
1979
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1803
1980
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
@@ -1806,13 +1983,13 @@ const collectionTypes = {
|
|
1806
1983
|
const { userAbility, user } = ctx.state;
|
1807
1984
|
const { model, sourceId: id } = ctx.params;
|
1808
1985
|
const { body } = ctx.request;
|
1809
|
-
const documentManager2 = getService$
|
1810
|
-
const permissionChecker2 = getService$
|
1986
|
+
const documentManager2 = getService$2("document-manager");
|
1987
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1811
1988
|
if (permissionChecker2.cannot.create()) {
|
1812
1989
|
return ctx.forbidden();
|
1813
1990
|
}
|
1814
1991
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1815
|
-
const populate = await getService$
|
1992
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1816
1993
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1817
1994
|
const document = await documentManager2.findOne(id, model, {
|
1818
1995
|
populate,
|
@@ -1851,13 +2028,13 @@ const collectionTypes = {
|
|
1851
2028
|
async delete(ctx) {
|
1852
2029
|
const { userAbility } = ctx.state;
|
1853
2030
|
const { id, model } = ctx.params;
|
1854
|
-
const documentManager2 = getService$
|
1855
|
-
const permissionChecker2 = getService$
|
2031
|
+
const documentManager2 = getService$2("document-manager");
|
2032
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1856
2033
|
if (permissionChecker2.cannot.delete()) {
|
1857
2034
|
return ctx.forbidden();
|
1858
2035
|
}
|
1859
2036
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1860
|
-
const populate = await getService$
|
2037
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1861
2038
|
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1862
2039
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1863
2040
|
if (documentLocales.length === 0) {
|
@@ -1879,14 +2056,14 @@ const collectionTypes = {
|
|
1879
2056
|
const { userAbility } = ctx.state;
|
1880
2057
|
const { id, model } = ctx.params;
|
1881
2058
|
const { body } = ctx.request;
|
1882
|
-
const documentManager2 = getService$
|
1883
|
-
const permissionChecker2 = getService$
|
2059
|
+
const documentManager2 = getService$2("document-manager");
|
2060
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1884
2061
|
if (permissionChecker2.cannot.publish()) {
|
1885
2062
|
return ctx.forbidden();
|
1886
2063
|
}
|
1887
2064
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1888
2065
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1889
|
-
const populate = await getService$
|
2066
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1890
2067
|
let document;
|
1891
2068
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1892
2069
|
const isCreate = isNil$1(id);
|
@@ -1898,11 +2075,17 @@ const collectionTypes = {
|
|
1898
2075
|
}
|
1899
2076
|
const isUpdate = !isCreate;
|
1900
2077
|
if (isUpdate) {
|
1901
|
-
|
1902
|
-
if (!
|
2078
|
+
const documentExists = documentManager2.exists(model, id);
|
2079
|
+
if (!documentExists) {
|
1903
2080
|
throw new errors.NotFoundError("Document not found");
|
1904
2081
|
}
|
1905
|
-
|
2082
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
2083
|
+
if (!document) {
|
2084
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
2085
|
+
throw new errors.ForbiddenError();
|
2086
|
+
}
|
2087
|
+
document = await updateDocument(ctx);
|
2088
|
+
} else if (permissionChecker2.can.update(document)) {
|
1906
2089
|
await updateDocument(ctx);
|
1907
2090
|
}
|
1908
2091
|
}
|
@@ -1928,13 +2111,13 @@ const collectionTypes = {
|
|
1928
2111
|
const { body } = ctx.request;
|
1929
2112
|
const { documentIds } = body;
|
1930
2113
|
await validateBulkActionInput(body);
|
1931
|
-
const documentManager2 = getService$
|
1932
|
-
const permissionChecker2 = getService$
|
2114
|
+
const documentManager2 = getService$2("document-manager");
|
2115
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1933
2116
|
if (permissionChecker2.cannot.publish()) {
|
1934
2117
|
return ctx.forbidden();
|
1935
2118
|
}
|
1936
2119
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1937
|
-
const populate = await getService$
|
2120
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1938
2121
|
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1939
2122
|
allowMultipleLocales: true
|
1940
2123
|
});
|
@@ -1959,8 +2142,8 @@ const collectionTypes = {
|
|
1959
2142
|
const { body } = ctx.request;
|
1960
2143
|
const { documentIds } = body;
|
1961
2144
|
await validateBulkActionInput(body);
|
1962
|
-
const documentManager2 = getService$
|
1963
|
-
const permissionChecker2 = getService$
|
2145
|
+
const documentManager2 = getService$2("document-manager");
|
2146
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1964
2147
|
if (permissionChecker2.cannot.unpublish()) {
|
1965
2148
|
return ctx.forbidden();
|
1966
2149
|
}
|
@@ -1989,8 +2172,8 @@ const collectionTypes = {
|
|
1989
2172
|
const {
|
1990
2173
|
body: { discardDraft, ...body }
|
1991
2174
|
} = ctx.request;
|
1992
|
-
const documentManager2 = getService$
|
1993
|
-
const permissionChecker2 = getService$
|
2175
|
+
const documentManager2 = getService$2("document-manager");
|
2176
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1994
2177
|
if (permissionChecker2.cannot.unpublish()) {
|
1995
2178
|
return ctx.forbidden();
|
1996
2179
|
}
|
@@ -1998,7 +2181,7 @@ const collectionTypes = {
|
|
1998
2181
|
return ctx.forbidden();
|
1999
2182
|
}
|
2000
2183
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
2001
|
-
const populate = await getService$
|
2184
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2002
2185
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2003
2186
|
const document = await documentManager2.findOne(id, model, {
|
2004
2187
|
populate,
|
@@ -2029,13 +2212,13 @@ const collectionTypes = {
|
|
2029
2212
|
const { userAbility } = ctx.state;
|
2030
2213
|
const { id, model } = ctx.params;
|
2031
2214
|
const { body } = ctx.request;
|
2032
|
-
const documentManager2 = getService$
|
2033
|
-
const permissionChecker2 = getService$
|
2215
|
+
const documentManager2 = getService$2("document-manager");
|
2216
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2034
2217
|
if (permissionChecker2.cannot.discard()) {
|
2035
2218
|
return ctx.forbidden();
|
2036
2219
|
}
|
2037
2220
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2038
|
-
const populate = await getService$
|
2221
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2039
2222
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2040
2223
|
const document = await documentManager2.findOne(id, model, {
|
2041
2224
|
populate,
|
@@ -2060,13 +2243,13 @@ const collectionTypes = {
|
|
2060
2243
|
const { query, body } = ctx.request;
|
2061
2244
|
const { documentIds } = body;
|
2062
2245
|
await validateBulkActionInput(body);
|
2063
|
-
const documentManager2 = getService$
|
2064
|
-
const permissionChecker2 = getService$
|
2246
|
+
const documentManager2 = getService$2("document-manager");
|
2247
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2065
2248
|
if (permissionChecker2.cannot.delete()) {
|
2066
2249
|
return ctx.forbidden();
|
2067
2250
|
}
|
2068
2251
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2069
|
-
const populate = await getService$
|
2252
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2070
2253
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2071
2254
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2072
2255
|
populate,
|
@@ -2087,13 +2270,13 @@ const collectionTypes = {
|
|
2087
2270
|
async countDraftRelations(ctx) {
|
2088
2271
|
const { userAbility } = ctx.state;
|
2089
2272
|
const { model, id } = ctx.params;
|
2090
|
-
const documentManager2 = getService$
|
2091
|
-
const permissionChecker2 = getService$
|
2273
|
+
const documentManager2 = getService$2("document-manager");
|
2274
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2092
2275
|
if (permissionChecker2.cannot.read()) {
|
2093
2276
|
return ctx.forbidden();
|
2094
2277
|
}
|
2095
2278
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2096
|
-
const populate = await getService$
|
2279
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2097
2280
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2098
2281
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2099
2282
|
if (!entity) {
|
@@ -2112,8 +2295,8 @@ const collectionTypes = {
|
|
2112
2295
|
const ids = ctx.request.query.documentIds;
|
2113
2296
|
const locale = ctx.request.query.locale;
|
2114
2297
|
const { model } = ctx.params;
|
2115
|
-
const documentManager2 = getService$
|
2116
|
-
const permissionChecker2 = getService$
|
2298
|
+
const documentManager2 = getService$2("document-manager");
|
2299
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2117
2300
|
if (permissionChecker2.cannot.read()) {
|
2118
2301
|
return ctx.forbidden();
|
2119
2302
|
}
|
@@ -2137,13 +2320,13 @@ const collectionTypes = {
|
|
2137
2320
|
};
|
2138
2321
|
const components$1 = {
|
2139
2322
|
findComponents(ctx) {
|
2140
|
-
const components2 = getService$
|
2141
|
-
const { toDto } = getService$
|
2323
|
+
const components2 = getService$2("components").findAllComponents();
|
2324
|
+
const { toDto } = getService$2("data-mapper");
|
2142
2325
|
ctx.body = { data: components2.map(toDto) };
|
2143
2326
|
},
|
2144
2327
|
async findComponentConfiguration(ctx) {
|
2145
2328
|
const { uid: uid2 } = ctx.params;
|
2146
|
-
const componentService = getService$
|
2329
|
+
const componentService = getService$2("components");
|
2147
2330
|
const component = componentService.findComponent(uid2);
|
2148
2331
|
if (!component) {
|
2149
2332
|
return ctx.notFound("component.notFound");
|
@@ -2160,7 +2343,7 @@ const components$1 = {
|
|
2160
2343
|
async updateComponentConfiguration(ctx) {
|
2161
2344
|
const { uid: uid2 } = ctx.params;
|
2162
2345
|
const { body } = ctx.request;
|
2163
|
-
const componentService = getService$
|
2346
|
+
const componentService = getService$2("components");
|
2164
2347
|
const component = componentService.findComponent(uid2);
|
2165
2348
|
if (!component) {
|
2166
2349
|
return ctx.notFound("component.notFound");
|
@@ -2194,12 +2377,12 @@ const contentTypes = {
|
|
2194
2377
|
} catch (error) {
|
2195
2378
|
return ctx.send({ error }, 400);
|
2196
2379
|
}
|
2197
|
-
const contentTypes2 = getService$
|
2198
|
-
const { toDto } = getService$
|
2380
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2381
|
+
const { toDto } = getService$2("data-mapper");
|
2199
2382
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2200
2383
|
},
|
2201
2384
|
async findContentTypesSettings(ctx) {
|
2202
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2385
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2203
2386
|
const contentTypes2 = await findAllContentTypes();
|
2204
2387
|
const configurations = await Promise.all(
|
2205
2388
|
contentTypes2.map(async (contentType) => {
|
@@ -2213,7 +2396,7 @@ const contentTypes = {
|
|
2213
2396
|
},
|
2214
2397
|
async findContentTypeConfiguration(ctx) {
|
2215
2398
|
const { uid: uid2 } = ctx.params;
|
2216
|
-
const contentTypeService = getService$
|
2399
|
+
const contentTypeService = getService$2("content-types");
|
2217
2400
|
const contentType = await contentTypeService.findContentType(uid2);
|
2218
2401
|
if (!contentType) {
|
2219
2402
|
return ctx.notFound("contentType.notFound");
|
@@ -2235,13 +2418,13 @@ const contentTypes = {
|
|
2235
2418
|
const { userAbility } = ctx.state;
|
2236
2419
|
const { uid: uid2 } = ctx.params;
|
2237
2420
|
const { body } = ctx.request;
|
2238
|
-
const contentTypeService = getService$
|
2239
|
-
const metricsService = getService$
|
2421
|
+
const contentTypeService = getService$2("content-types");
|
2422
|
+
const metricsService = getService$2("metrics");
|
2240
2423
|
const contentType = await contentTypeService.findContentType(uid2);
|
2241
2424
|
if (!contentType) {
|
2242
2425
|
return ctx.notFound("contentType.notFound");
|
2243
2426
|
}
|
2244
|
-
if (!getService$
|
2427
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2245
2428
|
return ctx.forbidden();
|
2246
2429
|
}
|
2247
2430
|
let input;
|
@@ -2274,10 +2457,10 @@ const contentTypes = {
|
|
2274
2457
|
};
|
2275
2458
|
const init = {
|
2276
2459
|
getInitData(ctx) {
|
2277
|
-
const { toDto } = getService$
|
2278
|
-
const { findAllComponents } = getService$
|
2279
|
-
const { getAllFieldSizes } = getService$
|
2280
|
-
const { findAllContentTypes } = getService$
|
2460
|
+
const { toDto } = getService$2("data-mapper");
|
2461
|
+
const { findAllComponents } = getService$2("components");
|
2462
|
+
const { getAllFieldSizes } = getService$2("field-sizes");
|
2463
|
+
const { findAllContentTypes } = getService$2("content-types");
|
2281
2464
|
ctx.body = {
|
2282
2465
|
data: {
|
2283
2466
|
fieldSizes: getAllFieldSizes(),
|
@@ -2313,7 +2496,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2313
2496
|
params.filters.$and.push(filtersClause);
|
2314
2497
|
};
|
2315
2498
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2316
|
-
const permissionChecker2 = getService$
|
2499
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2317
2500
|
userAbility,
|
2318
2501
|
model: model.uid
|
2319
2502
|
});
|
@@ -2327,15 +2510,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2327
2510
|
}
|
2328
2511
|
return mainField;
|
2329
2512
|
};
|
2330
|
-
const addStatusToRelations = async (
|
2331
|
-
if (!contentTypes$1.hasDraftAndPublish(strapi.
|
2513
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2514
|
+
if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2515
|
+
return relations2;
|
2516
|
+
}
|
2517
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2518
|
+
if (!relations2.length) {
|
2332
2519
|
return relations2;
|
2333
2520
|
}
|
2334
|
-
const
|
2335
|
-
const
|
2521
|
+
const firstRelation = relations2[0];
|
2522
|
+
const filters = {
|
2523
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2524
|
+
// NOTE: find the "opposite" status
|
2525
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2526
|
+
};
|
2527
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2528
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2529
|
+
filters
|
2530
|
+
});
|
2336
2531
|
return relations2.map((relation) => {
|
2337
|
-
const availableStatuses =
|
2338
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2532
|
+
const availableStatuses = availableStatus.filter(
|
2533
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2339
2534
|
);
|
2340
2535
|
return {
|
2341
2536
|
...relation,
|
@@ -2356,11 +2551,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2356
2551
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2357
2552
|
const isSourceLocalized = isLocalized(sourceModel);
|
2358
2553
|
const isTargetLocalized = isLocalized(targetModel);
|
2359
|
-
let validatedLocale = locale;
|
2360
|
-
if (!targetModel || !isTargetLocalized)
|
2361
|
-
validatedLocale = void 0;
|
2362
2554
|
return {
|
2363
|
-
locale
|
2555
|
+
locale,
|
2364
2556
|
isSourceLocalized,
|
2365
2557
|
isTargetLocalized
|
2366
2558
|
};
|
@@ -2400,7 +2592,7 @@ const relations = {
|
|
2400
2592
|
ctx.request?.query?.locale
|
2401
2593
|
);
|
2402
2594
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2403
|
-
const permissionChecker2 = getService$
|
2595
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2404
2596
|
userAbility,
|
2405
2597
|
model
|
2406
2598
|
});
|
@@ -2425,7 +2617,7 @@ const relations = {
|
|
2425
2617
|
where.id = id;
|
2426
2618
|
}
|
2427
2619
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2428
|
-
const populate = await getService$
|
2620
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2429
2621
|
const currentEntity = await strapi.db.query(model).findOne({
|
2430
2622
|
where,
|
2431
2623
|
populate
|
@@ -2440,7 +2632,7 @@ const relations = {
|
|
2440
2632
|
}
|
2441
2633
|
entryId = currentEntity.id;
|
2442
2634
|
}
|
2443
|
-
const modelConfig = isComponent2 ? await getService$
|
2635
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2444
2636
|
const targetSchema = strapi.getModel(targetUid);
|
2445
2637
|
const mainField = flow(
|
2446
2638
|
prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2463,7 +2655,7 @@ const relations = {
|
|
2463
2655
|
attribute,
|
2464
2656
|
fieldsToSelect,
|
2465
2657
|
mainField,
|
2466
|
-
source: { schema: sourceSchema },
|
2658
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2467
2659
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2468
2660
|
sourceSchema,
|
2469
2661
|
targetSchema,
|
@@ -2485,7 +2677,8 @@ const relations = {
|
|
2485
2677
|
fieldsToSelect,
|
2486
2678
|
mainField,
|
2487
2679
|
source: {
|
2488
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2680
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2681
|
+
isLocalized: isSourceLocalized
|
2489
2682
|
},
|
2490
2683
|
target: {
|
2491
2684
|
schema: { uid: targetUid },
|
@@ -2493,7 +2686,7 @@ const relations = {
|
|
2493
2686
|
}
|
2494
2687
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2495
2688
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2496
|
-
const permissionChecker2 = getService$
|
2689
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2497
2690
|
userAbility: ctx.state.userAbility,
|
2498
2691
|
model: targetUid
|
2499
2692
|
});
|
@@ -2523,12 +2716,16 @@ const relations = {
|
|
2523
2716
|
} else {
|
2524
2717
|
where.id = id;
|
2525
2718
|
}
|
2526
|
-
|
2527
|
-
|
2719
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2720
|
+
if (!isEmpty(publishedAt)) {
|
2721
|
+
where[`${alias}.published_at`] = publishedAt;
|
2528
2722
|
}
|
2529
|
-
if (
|
2723
|
+
if (isTargetLocalized && locale) {
|
2530
2724
|
where[`${alias}.locale`] = locale;
|
2531
2725
|
}
|
2726
|
+
if (isSourceLocalized && locale) {
|
2727
|
+
where.locale = locale;
|
2728
|
+
}
|
2532
2729
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2533
2730
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2534
2731
|
}
|
@@ -2546,7 +2743,8 @@ const relations = {
|
|
2546
2743
|
id: { $notIn: uniq(idsToOmit) }
|
2547
2744
|
});
|
2548
2745
|
}
|
2549
|
-
const
|
2746
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2747
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2550
2748
|
ctx.body = {
|
2551
2749
|
...res,
|
2552
2750
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2561,21 +2759,33 @@ const relations = {
|
|
2561
2759
|
attribute,
|
2562
2760
|
targetField,
|
2563
2761
|
fieldsToSelect,
|
2564
|
-
|
2565
|
-
|
2566
|
-
}
|
2567
|
-
target: {
|
2568
|
-
schema: { uid: targetUid }
|
2569
|
-
}
|
2762
|
+
status,
|
2763
|
+
source: { schema: sourceSchema },
|
2764
|
+
target: { schema: targetSchema }
|
2570
2765
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2571
|
-
const
|
2766
|
+
const { uid: sourceUid } = sourceSchema;
|
2767
|
+
const { uid: targetUid } = targetSchema;
|
2768
|
+
const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2572
2769
|
const dbQuery = strapi.db.query(sourceUid);
|
2573
2770
|
const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2771
|
+
const filters = {};
|
2772
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2773
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2774
|
+
if (status === "published") {
|
2775
|
+
filters.publishedAt = { $notNull: true };
|
2776
|
+
} else {
|
2777
|
+
filters.publishedAt = { $null: true };
|
2778
|
+
}
|
2779
|
+
}
|
2780
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2781
|
+
filters.publishedAt = { $null: true };
|
2782
|
+
}
|
2574
2783
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2575
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2784
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2576
2785
|
ordering: "desc",
|
2577
2786
|
page: ctx.request.query.page,
|
2578
|
-
pageSize: ctx.request.query.pageSize
|
2787
|
+
pageSize: ctx.request.query.pageSize,
|
2788
|
+
filters
|
2579
2789
|
});
|
2580
2790
|
const loadedIds = res.results.map((item) => item.id);
|
2581
2791
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2596,10 +2806,10 @@ const relations = {
|
|
2596
2806
|
}
|
2597
2807
|
};
|
2598
2808
|
const buildPopulateFromQuery = async (query, model) => {
|
2599
|
-
return getService$
|
2809
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2600
2810
|
};
|
2601
2811
|
const findDocument = async (query, uid2, opts = {}) => {
|
2602
|
-
const documentManager2 = getService$
|
2812
|
+
const documentManager2 = getService$2("document-manager");
|
2603
2813
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2604
2814
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2605
2815
|
};
|
@@ -2607,8 +2817,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2607
2817
|
const { user, userAbility } = ctx.state;
|
2608
2818
|
const { model } = ctx.params;
|
2609
2819
|
const { body, query } = ctx.request;
|
2610
|
-
const documentManager2 = getService$
|
2611
|
-
const permissionChecker2 = getService$
|
2820
|
+
const documentManager2 = getService$2("document-manager");
|
2821
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2612
2822
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2613
2823
|
throw new errors.ForbiddenError();
|
2614
2824
|
}
|
@@ -2649,7 +2859,7 @@ const singleTypes = {
|
|
2649
2859
|
const { userAbility } = ctx.state;
|
2650
2860
|
const { model } = ctx.params;
|
2651
2861
|
const { query = {} } = ctx.request;
|
2652
|
-
const permissionChecker2 = getService$
|
2862
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2653
2863
|
if (permissionChecker2.cannot.read()) {
|
2654
2864
|
return ctx.forbidden();
|
2655
2865
|
}
|
@@ -2668,7 +2878,7 @@ const singleTypes = {
|
|
2668
2878
|
permissionChecker2,
|
2669
2879
|
model,
|
2670
2880
|
// @ts-expect-error - fix types
|
2671
|
-
{
|
2881
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2672
2882
|
{ availableLocales: true, availableStatus: false }
|
2673
2883
|
);
|
2674
2884
|
ctx.body = { data: {}, meta };
|
@@ -2683,7 +2893,7 @@ const singleTypes = {
|
|
2683
2893
|
async createOrUpdate(ctx) {
|
2684
2894
|
const { userAbility } = ctx.state;
|
2685
2895
|
const { model } = ctx.params;
|
2686
|
-
const permissionChecker2 = getService$
|
2896
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2687
2897
|
const document = await createOrUpdateDocument(ctx);
|
2688
2898
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2689
2899
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2692,8 +2902,8 @@ const singleTypes = {
|
|
2692
2902
|
const { userAbility } = ctx.state;
|
2693
2903
|
const { model } = ctx.params;
|
2694
2904
|
const { query = {} } = ctx.request;
|
2695
|
-
const documentManager2 = getService$
|
2696
|
-
const permissionChecker2 = getService$
|
2905
|
+
const documentManager2 = getService$2("document-manager");
|
2906
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2697
2907
|
if (permissionChecker2.cannot.delete()) {
|
2698
2908
|
return ctx.forbidden();
|
2699
2909
|
}
|
@@ -2721,8 +2931,8 @@ const singleTypes = {
|
|
2721
2931
|
const { userAbility } = ctx.state;
|
2722
2932
|
const { model } = ctx.params;
|
2723
2933
|
const { query = {} } = ctx.request;
|
2724
|
-
const documentManager2 = getService$
|
2725
|
-
const permissionChecker2 = getService$
|
2934
|
+
const documentManager2 = getService$2("document-manager");
|
2935
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2726
2936
|
if (permissionChecker2.cannot.publish()) {
|
2727
2937
|
return ctx.forbidden();
|
2728
2938
|
}
|
@@ -2750,8 +2960,8 @@ const singleTypes = {
|
|
2750
2960
|
body: { discardDraft, ...body },
|
2751
2961
|
query = {}
|
2752
2962
|
} = ctx.request;
|
2753
|
-
const documentManager2 = getService$
|
2754
|
-
const permissionChecker2 = getService$
|
2963
|
+
const documentManager2 = getService$2("document-manager");
|
2964
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2755
2965
|
if (permissionChecker2.cannot.unpublish()) {
|
2756
2966
|
return ctx.forbidden();
|
2757
2967
|
}
|
@@ -2785,8 +2995,8 @@ const singleTypes = {
|
|
2785
2995
|
const { userAbility } = ctx.state;
|
2786
2996
|
const { model } = ctx.params;
|
2787
2997
|
const { body, query = {} } = ctx.request;
|
2788
|
-
const documentManager2 = getService$
|
2789
|
-
const permissionChecker2 = getService$
|
2998
|
+
const documentManager2 = getService$2("document-manager");
|
2999
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2790
3000
|
if (permissionChecker2.cannot.discard()) {
|
2791
3001
|
return ctx.forbidden();
|
2792
3002
|
}
|
@@ -2809,8 +3019,8 @@ const singleTypes = {
|
|
2809
3019
|
const { userAbility } = ctx.state;
|
2810
3020
|
const { model } = ctx.params;
|
2811
3021
|
const { query } = ctx.request;
|
2812
|
-
const documentManager2 = getService$
|
2813
|
-
const permissionChecker2 = getService$
|
3022
|
+
const documentManager2 = getService$2("document-manager");
|
3023
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2814
3024
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2815
3025
|
if (permissionChecker2.cannot.read()) {
|
2816
3026
|
return ctx.forbidden();
|
@@ -2834,7 +3044,7 @@ const uid$1 = {
|
|
2834
3044
|
const { query = {} } = ctx.request;
|
2835
3045
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2836
3046
|
await validateUIDField(contentTypeUID, field);
|
2837
|
-
const uidService = getService$
|
3047
|
+
const uidService = getService$2("uid");
|
2838
3048
|
ctx.body = {
|
2839
3049
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2840
3050
|
};
|
@@ -2846,7 +3056,7 @@ const uid$1 = {
|
|
2846
3056
|
const { query = {} } = ctx.request;
|
2847
3057
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2848
3058
|
await validateUIDField(contentTypeUID, field);
|
2849
|
-
const uidService = getService$
|
3059
|
+
const uidService = getService$2("uid");
|
2850
3060
|
const isAvailable = await uidService.checkUIDAvailability({
|
2851
3061
|
contentTypeUID,
|
2852
3062
|
field,
|
@@ -2867,7 +3077,8 @@ const controllers = {
|
|
2867
3077
|
relations,
|
2868
3078
|
"single-types": singleTypes,
|
2869
3079
|
uid: uid$1,
|
2870
|
-
...history.controllers ? history.controllers : {}
|
3080
|
+
...history.controllers ? history.controllers : {},
|
3081
|
+
...preview.controllers ? preview.controllers : {}
|
2871
3082
|
};
|
2872
3083
|
const keys = {
|
2873
3084
|
CONFIGURATION: "configuration"
|
@@ -3018,12 +3229,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3018
3229
|
return _.assign(metasWithDefaults, updatedMetas);
|
3019
3230
|
}
|
3020
3231
|
const getTargetSchema = (targetModel) => {
|
3021
|
-
return getService$
|
3232
|
+
return getService$2("content-types").findContentType(targetModel);
|
3022
3233
|
};
|
3023
3234
|
const DEFAULT_LIST_LENGTH = 4;
|
3024
3235
|
const MAX_ROW_SIZE = 12;
|
3025
3236
|
const isAllowedFieldSize = (type, size) => {
|
3026
|
-
const { getFieldSize } = getService$
|
3237
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3027
3238
|
const fieldSize = getFieldSize(type);
|
3028
3239
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3029
3240
|
return false;
|
@@ -3031,7 +3242,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3031
3242
|
return size <= MAX_ROW_SIZE;
|
3032
3243
|
};
|
3033
3244
|
const getDefaultFieldSize = (attribute) => {
|
3034
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3245
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3035
3246
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3036
3247
|
};
|
3037
3248
|
async function createDefaultLayouts(schema) {
|
@@ -3066,7 +3277,7 @@ function syncLayouts(configuration, schema) {
|
|
3066
3277
|
for (const el of row) {
|
3067
3278
|
if (!hasEditableAttribute(schema, el.name))
|
3068
3279
|
continue;
|
3069
|
-
const { hasFieldSize } = getService$
|
3280
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3070
3281
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3071
3282
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3072
3283
|
elementsToReAppend.push(el.name);
|
@@ -3206,17 +3417,17 @@ const configurationService$1 = createConfigurationService({
|
|
3206
3417
|
isComponent: true,
|
3207
3418
|
prefix: STORE_KEY_PREFIX,
|
3208
3419
|
getModels() {
|
3209
|
-
const { toContentManagerModel } = getService$
|
3420
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3210
3421
|
return mapValues(toContentManagerModel, strapi.components);
|
3211
3422
|
}
|
3212
3423
|
});
|
3213
3424
|
const components = ({ strapi: strapi2 }) => ({
|
3214
3425
|
findAllComponents() {
|
3215
|
-
const { toContentManagerModel } = getService$
|
3426
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3216
3427
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3217
3428
|
},
|
3218
3429
|
findComponent(uid2) {
|
3219
|
-
const { toContentManagerModel } = getService$
|
3430
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3220
3431
|
const component = strapi2.components[uid2];
|
3221
3432
|
return isNil$1(component) ? component : toContentManagerModel(component);
|
3222
3433
|
},
|
@@ -3267,17 +3478,17 @@ const configurationService = createConfigurationService({
|
|
3267
3478
|
storeUtils,
|
3268
3479
|
prefix: "content_types",
|
3269
3480
|
getModels() {
|
3270
|
-
const { toContentManagerModel } = getService$
|
3481
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3271
3482
|
return mapValues(toContentManagerModel, strapi.contentTypes);
|
3272
3483
|
}
|
3273
3484
|
});
|
3274
3485
|
const service = ({ strapi: strapi2 }) => ({
|
3275
3486
|
findAllContentTypes() {
|
3276
|
-
const { toContentManagerModel } = getService$
|
3487
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3277
3488
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3278
3489
|
},
|
3279
3490
|
findContentType(uid2) {
|
3280
|
-
const { toContentManagerModel } = getService$
|
3491
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3281
3492
|
const contentType = strapi2.contentTypes[uid2];
|
3282
3493
|
return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
|
3283
3494
|
},
|
@@ -3306,7 +3517,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3306
3517
|
return this.findConfiguration(contentType);
|
3307
3518
|
},
|
3308
3519
|
findComponentsConfigurations(contentType) {
|
3309
|
-
return getService$
|
3520
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3310
3521
|
},
|
3311
3522
|
syncConfigurations() {
|
3312
3523
|
return configurationService.syncConfigurations();
|
@@ -3578,7 +3789,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3578
3789
|
return userAbility.can(action);
|
3579
3790
|
},
|
3580
3791
|
async registerPermissions() {
|
3581
|
-
const displayedContentTypes = getService$
|
3792
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3582
3793
|
const contentTypesUids = displayedContentTypes.map(prop("uid"));
|
3583
3794
|
const actions = [
|
3584
3795
|
{
|
@@ -3854,7 +4065,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3854
4065
|
return populateQuery;
|
3855
4066
|
};
|
3856
4067
|
const buildDeepPopulate = (uid2) => {
|
3857
|
-
return getService$
|
4068
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3858
4069
|
};
|
3859
4070
|
const populateBuilder = (uid2) => {
|
3860
4071
|
let getInitialPopulate = async () => {
|
@@ -4039,7 +4250,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4039
4250
|
*/
|
4040
4251
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
4041
4252
|
const versionsByLocale = groupBy("locale", allVersions);
|
4042
|
-
|
4253
|
+
if (version.locale) {
|
4254
|
+
delete versionsByLocale[version.locale];
|
4255
|
+
}
|
4043
4256
|
const model = strapi2.getModel(uid2);
|
4044
4257
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4045
4258
|
const traversalFunction = async (localeVersion) => traverseEntity(
|
@@ -4395,7 +4608,8 @@ const services = {
|
|
4395
4608
|
permission,
|
4396
4609
|
"populate-builder": populateBuilder$1,
|
4397
4610
|
uid,
|
4398
|
-
...history.services ? history.services : {}
|
4611
|
+
...history.services ? history.services : {},
|
4612
|
+
...preview.services ? preview.services : {}
|
4399
4613
|
};
|
4400
4614
|
const index = () => {
|
4401
4615
|
return {
|