@strapi/content-manager 0.0.0-experimental.da85533897155e719d784f0271223c866d2f69ab → 0.0.0-experimental.dd1d47ef78ef6cfec4ed62576108500bd9f13740
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-9lRmRdIr.mjs → ComponentConfigurationPage-BpM_Hc7r.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-9lRmRdIr.mjs.map → ComponentConfigurationPage-BpM_Hc7r.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js → ComponentConfigurationPage-CL9CAMaL.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-DyDkPajU.js.map → ComponentConfigurationPage-CL9CAMaL.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DValmA0m.js → EditConfigurationPage-ILWo0h1e.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DValmA0m.js.map → EditConfigurationPage-ILWo0h1e.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs → EditConfigurationPage-_prbqpTM.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-Bk893vVY.mjs.map → EditConfigurationPage-_prbqpTM.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-Dk7Eaft4.js → EditViewPage-BqZvBN4s.js} +15 -5
- package/dist/_chunks/EditViewPage-BqZvBN4s.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DiNFdFqP.mjs → EditViewPage-DAtscabN.mjs} +15 -5
- package/dist/_chunks/EditViewPage-DAtscabN.mjs.map +1 -0
- package/dist/_chunks/{Field-DH2OaqUP.js → Field-CcoQiiz1.js} +78 -44
- package/dist/_chunks/Field-CcoQiiz1.js.map +1 -0
- package/dist/_chunks/{Field-Dv_HTFTa.mjs → Field-D-mgn1tH.mjs} +74 -40
- package/dist/_chunks/Field-D-mgn1tH.mjs.map +1 -0
- package/dist/_chunks/{Form-Dy6P4HgH.mjs → Form-BxyeWiXW.mjs} +16 -8
- package/dist/_chunks/Form-BxyeWiXW.mjs.map +1 -0
- package/dist/_chunks/{Form-B_dUDizM.js → Form-CmLbZDfi.js} +16 -8
- package/dist/_chunks/Form-CmLbZDfi.js.map +1 -0
- package/dist/_chunks/{History-DrwsD1Vc.mjs → History-BOhLaq_g.mjs} +38 -41
- package/dist/_chunks/History-BOhLaq_g.mjs.map +1 -0
- package/dist/_chunks/{History-BT4w83Oa.js → History-uECUbCZB.js} +37 -40
- package/dist/_chunks/History-uECUbCZB.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs → ListConfigurationPage-D0vQez6F.mjs} +3 -3
- package/dist/_chunks/{ListConfigurationPage-BxIP0jRy.mjs.map → ListConfigurationPage-D0vQez6F.mjs.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js → ListConfigurationPage-D_bBSFNW.js} +3 -3
- package/dist/_chunks/{ListConfigurationPage-CuYrMcW3.js.map → ListConfigurationPage-D_bBSFNW.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-BvpwNur7.js → ListViewPage-BkZ83b1A.js} +40 -17
- package/dist/_chunks/ListViewPage-BkZ83b1A.js.map +1 -0
- package/dist/_chunks/{ListViewPage-5a1vw-OK.mjs → ListViewPage-ns-bmy5C.mjs} +36 -13
- package/dist/_chunks/ListViewPage-ns-bmy5C.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs → NoContentTypePage-BA5ZKMDR.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Bm6tRcd3.mjs.map → NoContentTypePage-BA5ZKMDR.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js → NoContentTypePage-C1439s4s.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-UqEiWKkM.js.map → NoContentTypePage-C1439s4s.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs → NoPermissionsPage-B0GdMw1Q.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BHPqn_tQ.mjs.map → NoPermissionsPage-B0GdMw1Q.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js → NoPermissionsPage-CPGwsVfb.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-C_vGRo8Q.js.map → NoPermissionsPage-CPGwsVfb.js.map} +1 -1
- package/dist/_chunks/{Relations-C7fPyh5P.mjs → Relations-BIGPMSW4.mjs} +72 -36
- package/dist/_chunks/Relations-BIGPMSW4.mjs.map +1 -0
- package/dist/_chunks/{Relations-CznVF6LS.js → Relations-d-8Uef_-.js} +71 -35
- package/dist/_chunks/Relations-d-8Uef_-.js.map +1 -0
- package/dist/_chunks/{en-otD_UBJi.js → en-Bdpa50w3.js} +17 -12
- package/dist/_chunks/{en-otD_UBJi.js.map → en-Bdpa50w3.js.map} +1 -1
- package/dist/_chunks/{en-CbaIuYoB.mjs → en-CZw4xdPY.mjs} +17 -12
- package/dist/_chunks/{en-CbaIuYoB.mjs.map → en-CZw4xdPY.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/{index-BJ6uTqLL.mjs → index-3_WeHXYp.mjs} +890 -685
- package/dist/_chunks/index-3_WeHXYp.mjs.map +1 -0
- package/dist/_chunks/{index-D9UmmBcM.js → index-BgaeYWIy.js} +887 -681
- package/dist/_chunks/index-BgaeYWIy.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-kfu5Wtix.js → layout-ByFyQRDH.js} +5 -4
- package/dist/_chunks/{layout-kfu5Wtix.js.map → layout-ByFyQRDH.js.map} +1 -1
- package/dist/_chunks/{layout-uomiIGbG.mjs → layout-CrTxOnCy.mjs} +5 -4
- package/dist/_chunks/{layout-uomiIGbG.mjs.map → layout-CrTxOnCy.mjs.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-DiDufGSA.mjs → relations-BlpLgngh.mjs} +3 -7
- package/dist/_chunks/relations-BlpLgngh.mjs.map +1 -0
- package/dist/_chunks/{relations-DKENrxko.js → relations-C5RSW926.js} +3 -7
- package/dist/_chunks/relations-C5RSW926.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/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +3 -2
- 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/components/Header.d.ts +11 -11
- 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/services/preview.d.ts +3 -0
- package/dist/admin/src/services/documents.d.ts +3 -1
- package/dist/server/index.js +378 -162
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +378 -162
- 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-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/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 +13 -13
- package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +0 -1
- package/dist/_chunks/Field-DH2OaqUP.js.map +0 -1
- package/dist/_chunks/Field-Dv_HTFTa.mjs.map +0 -1
- package/dist/_chunks/Form-B_dUDizM.js.map +0 -1
- package/dist/_chunks/Form-Dy6P4HgH.mjs.map +0 -1
- package/dist/_chunks/History-BT4w83Oa.js.map +0 -1
- package/dist/_chunks/History-DrwsD1Vc.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BvpwNur7.js.map +0 -1
- package/dist/_chunks/Relations-C7fPyh5P.mjs.map +0 -1
- package/dist/_chunks/Relations-CznVF6LS.js.map +0 -1
- package/dist/_chunks/index-BJ6uTqLL.mjs.map +0 -1
- package/dist/_chunks/index-D9UmmBcM.js.map +0 -1
- package/dist/_chunks/relations-DKENrxko.js.map +0 -1
- package/dist/_chunks/relations-DiDufGSA.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.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,
|
@@ -1761,7 +1938,7 @@ const collectionTypes = {
|
|
1761
1938
|
permissionChecker2,
|
1762
1939
|
model,
|
1763
1940
|
// @ts-expect-error TODO: fix
|
1764
|
-
{ id, locale, publishedAt: null },
|
1941
|
+
{ documentId: id, locale, publishedAt: null },
|
1765
1942
|
{ availableLocales: true, availableStatus: false }
|
1766
1943
|
);
|
1767
1944
|
ctx.body = { data: {}, meta };
|
@@ -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,12 +2142,14 @@ 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
|
}
|
1967
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
2150
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2151
|
+
allowMultipleLocales: true
|
2152
|
+
});
|
1968
2153
|
const entityPromises = documentIds.map(
|
1969
2154
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1970
2155
|
);
|
@@ -1987,8 +2172,8 @@ const collectionTypes = {
|
|
1987
2172
|
const {
|
1988
2173
|
body: { discardDraft, ...body }
|
1989
2174
|
} = ctx.request;
|
1990
|
-
const documentManager2 = getService$
|
1991
|
-
const permissionChecker2 = getService$
|
2175
|
+
const documentManager2 = getService$2("document-manager");
|
2176
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
1992
2177
|
if (permissionChecker2.cannot.unpublish()) {
|
1993
2178
|
return ctx.forbidden();
|
1994
2179
|
}
|
@@ -1996,7 +2181,7 @@ const collectionTypes = {
|
|
1996
2181
|
return ctx.forbidden();
|
1997
2182
|
}
|
1998
2183
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1999
|
-
const populate = await getService$
|
2184
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2000
2185
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2001
2186
|
const document = await documentManager2.findOne(id, model, {
|
2002
2187
|
populate,
|
@@ -2027,13 +2212,13 @@ const collectionTypes = {
|
|
2027
2212
|
const { userAbility } = ctx.state;
|
2028
2213
|
const { id, model } = ctx.params;
|
2029
2214
|
const { body } = ctx.request;
|
2030
|
-
const documentManager2 = getService$
|
2031
|
-
const permissionChecker2 = getService$
|
2215
|
+
const documentManager2 = getService$2("document-manager");
|
2216
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2032
2217
|
if (permissionChecker2.cannot.discard()) {
|
2033
2218
|
return ctx.forbidden();
|
2034
2219
|
}
|
2035
2220
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2036
|
-
const populate = await getService$
|
2221
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2037
2222
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2038
2223
|
const document = await documentManager2.findOne(id, model, {
|
2039
2224
|
populate,
|
@@ -2058,13 +2243,13 @@ const collectionTypes = {
|
|
2058
2243
|
const { query, body } = ctx.request;
|
2059
2244
|
const { documentIds } = body;
|
2060
2245
|
await validateBulkActionInput(body);
|
2061
|
-
const documentManager2 = getService$
|
2062
|
-
const permissionChecker2 = getService$
|
2246
|
+
const documentManager2 = getService$2("document-manager");
|
2247
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2063
2248
|
if (permissionChecker2.cannot.delete()) {
|
2064
2249
|
return ctx.forbidden();
|
2065
2250
|
}
|
2066
2251
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2067
|
-
const populate = await getService$
|
2252
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2068
2253
|
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2069
2254
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2070
2255
|
populate,
|
@@ -2085,13 +2270,13 @@ const collectionTypes = {
|
|
2085
2270
|
async countDraftRelations(ctx) {
|
2086
2271
|
const { userAbility } = ctx.state;
|
2087
2272
|
const { model, id } = ctx.params;
|
2088
|
-
const documentManager2 = getService$
|
2089
|
-
const permissionChecker2 = getService$
|
2273
|
+
const documentManager2 = getService$2("document-manager");
|
2274
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2090
2275
|
if (permissionChecker2.cannot.read()) {
|
2091
2276
|
return ctx.forbidden();
|
2092
2277
|
}
|
2093
2278
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2094
|
-
const populate = await getService$
|
2279
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2095
2280
|
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2096
2281
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2097
2282
|
if (!entity) {
|
@@ -2110,8 +2295,8 @@ const collectionTypes = {
|
|
2110
2295
|
const ids = ctx.request.query.documentIds;
|
2111
2296
|
const locale = ctx.request.query.locale;
|
2112
2297
|
const { model } = ctx.params;
|
2113
|
-
const documentManager2 = getService$
|
2114
|
-
const permissionChecker2 = getService$
|
2298
|
+
const documentManager2 = getService$2("document-manager");
|
2299
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2115
2300
|
if (permissionChecker2.cannot.read()) {
|
2116
2301
|
return ctx.forbidden();
|
2117
2302
|
}
|
@@ -2135,13 +2320,13 @@ const collectionTypes = {
|
|
2135
2320
|
};
|
2136
2321
|
const components$1 = {
|
2137
2322
|
findComponents(ctx) {
|
2138
|
-
const components2 = getService$
|
2139
|
-
const { toDto } = getService$
|
2323
|
+
const components2 = getService$2("components").findAllComponents();
|
2324
|
+
const { toDto } = getService$2("data-mapper");
|
2140
2325
|
ctx.body = { data: components2.map(toDto) };
|
2141
2326
|
},
|
2142
2327
|
async findComponentConfiguration(ctx) {
|
2143
2328
|
const { uid: uid2 } = ctx.params;
|
2144
|
-
const componentService = getService$
|
2329
|
+
const componentService = getService$2("components");
|
2145
2330
|
const component = componentService.findComponent(uid2);
|
2146
2331
|
if (!component) {
|
2147
2332
|
return ctx.notFound("component.notFound");
|
@@ -2158,7 +2343,7 @@ const components$1 = {
|
|
2158
2343
|
async updateComponentConfiguration(ctx) {
|
2159
2344
|
const { uid: uid2 } = ctx.params;
|
2160
2345
|
const { body } = ctx.request;
|
2161
|
-
const componentService = getService$
|
2346
|
+
const componentService = getService$2("components");
|
2162
2347
|
const component = componentService.findComponent(uid2);
|
2163
2348
|
if (!component) {
|
2164
2349
|
return ctx.notFound("component.notFound");
|
@@ -2192,12 +2377,12 @@ const contentTypes = {
|
|
2192
2377
|
} catch (error) {
|
2193
2378
|
return ctx.send({ error }, 400);
|
2194
2379
|
}
|
2195
|
-
const contentTypes2 = getService$
|
2196
|
-
const { toDto } = getService$
|
2380
|
+
const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
|
2381
|
+
const { toDto } = getService$2("data-mapper");
|
2197
2382
|
ctx.body = { data: contentTypes2.map(toDto) };
|
2198
2383
|
},
|
2199
2384
|
async findContentTypesSettings(ctx) {
|
2200
|
-
const { findAllContentTypes, findConfiguration } = getService$
|
2385
|
+
const { findAllContentTypes, findConfiguration } = getService$2("content-types");
|
2201
2386
|
const contentTypes2 = await findAllContentTypes();
|
2202
2387
|
const configurations = await Promise.all(
|
2203
2388
|
contentTypes2.map(async (contentType) => {
|
@@ -2211,7 +2396,7 @@ const contentTypes = {
|
|
2211
2396
|
},
|
2212
2397
|
async findContentTypeConfiguration(ctx) {
|
2213
2398
|
const { uid: uid2 } = ctx.params;
|
2214
|
-
const contentTypeService = getService$
|
2399
|
+
const contentTypeService = getService$2("content-types");
|
2215
2400
|
const contentType = await contentTypeService.findContentType(uid2);
|
2216
2401
|
if (!contentType) {
|
2217
2402
|
return ctx.notFound("contentType.notFound");
|
@@ -2233,13 +2418,13 @@ const contentTypes = {
|
|
2233
2418
|
const { userAbility } = ctx.state;
|
2234
2419
|
const { uid: uid2 } = ctx.params;
|
2235
2420
|
const { body } = ctx.request;
|
2236
|
-
const contentTypeService = getService$
|
2237
|
-
const metricsService = getService$
|
2421
|
+
const contentTypeService = getService$2("content-types");
|
2422
|
+
const metricsService = getService$2("metrics");
|
2238
2423
|
const contentType = await contentTypeService.findContentType(uid2);
|
2239
2424
|
if (!contentType) {
|
2240
2425
|
return ctx.notFound("contentType.notFound");
|
2241
2426
|
}
|
2242
|
-
if (!getService$
|
2427
|
+
if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
|
2243
2428
|
return ctx.forbidden();
|
2244
2429
|
}
|
2245
2430
|
let input;
|
@@ -2272,10 +2457,10 @@ const contentTypes = {
|
|
2272
2457
|
};
|
2273
2458
|
const init = {
|
2274
2459
|
getInitData(ctx) {
|
2275
|
-
const { toDto } = getService$
|
2276
|
-
const { findAllComponents } = getService$
|
2277
|
-
const { getAllFieldSizes } = getService$
|
2278
|
-
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");
|
2279
2464
|
ctx.body = {
|
2280
2465
|
data: {
|
2281
2466
|
fieldSizes: getAllFieldSizes(),
|
@@ -2311,7 +2496,7 @@ const addFiltersClause = (params, filtersClause) => {
|
|
2311
2496
|
params.filters.$and.push(filtersClause);
|
2312
2497
|
};
|
2313
2498
|
const sanitizeMainField = (model, mainField, userAbility) => {
|
2314
|
-
const permissionChecker2 = getService$
|
2499
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2315
2500
|
userAbility,
|
2316
2501
|
model: model.uid
|
2317
2502
|
});
|
@@ -2325,15 +2510,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2325
2510
|
}
|
2326
2511
|
return mainField;
|
2327
2512
|
};
|
2328
|
-
const addStatusToRelations = async (
|
2329
|
-
if (!contentTypes$1.hasDraftAndPublish(strapi.
|
2513
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2514
|
+
if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2330
2515
|
return relations2;
|
2331
2516
|
}
|
2332
|
-
const documentMetadata2 = getService$
|
2333
|
-
|
2517
|
+
const documentMetadata2 = getService$2("document-metadata");
|
2518
|
+
if (!relations2.length) {
|
2519
|
+
return relations2;
|
2520
|
+
}
|
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
|
+
});
|
2334
2531
|
return relations2.map((relation) => {
|
2335
|
-
const availableStatuses =
|
2336
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2532
|
+
const availableStatuses = availableStatus.filter(
|
2533
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2337
2534
|
);
|
2338
2535
|
return {
|
2339
2536
|
...relation,
|
@@ -2354,11 +2551,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2354
2551
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2355
2552
|
const isSourceLocalized = isLocalized(sourceModel);
|
2356
2553
|
const isTargetLocalized = isLocalized(targetModel);
|
2357
|
-
let validatedLocale = locale;
|
2358
|
-
if (!targetModel || !isTargetLocalized)
|
2359
|
-
validatedLocale = void 0;
|
2360
2554
|
return {
|
2361
|
-
locale
|
2555
|
+
locale,
|
2362
2556
|
isSourceLocalized,
|
2363
2557
|
isTargetLocalized
|
2364
2558
|
};
|
@@ -2398,7 +2592,7 @@ const relations = {
|
|
2398
2592
|
ctx.request?.query?.locale
|
2399
2593
|
);
|
2400
2594
|
const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
|
2401
|
-
const permissionChecker2 = getService$
|
2595
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2402
2596
|
userAbility,
|
2403
2597
|
model
|
2404
2598
|
});
|
@@ -2423,7 +2617,7 @@ const relations = {
|
|
2423
2617
|
where.id = id;
|
2424
2618
|
}
|
2425
2619
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2426
|
-
const populate = await getService$
|
2620
|
+
const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2427
2621
|
const currentEntity = await strapi.db.query(model).findOne({
|
2428
2622
|
where,
|
2429
2623
|
populate
|
@@ -2438,7 +2632,7 @@ const relations = {
|
|
2438
2632
|
}
|
2439
2633
|
entryId = currentEntity.id;
|
2440
2634
|
}
|
2441
|
-
const modelConfig = isComponent2 ? await getService$
|
2635
|
+
const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
|
2442
2636
|
const targetSchema = strapi.getModel(targetUid);
|
2443
2637
|
const mainField = flow(
|
2444
2638
|
prop(`metadatas.${targetField}.edit.mainField`),
|
@@ -2461,7 +2655,7 @@ const relations = {
|
|
2461
2655
|
attribute,
|
2462
2656
|
fieldsToSelect,
|
2463
2657
|
mainField,
|
2464
|
-
source: { schema: sourceSchema },
|
2658
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2465
2659
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2466
2660
|
sourceSchema,
|
2467
2661
|
targetSchema,
|
@@ -2483,7 +2677,8 @@ const relations = {
|
|
2483
2677
|
fieldsToSelect,
|
2484
2678
|
mainField,
|
2485
2679
|
source: {
|
2486
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2680
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2681
|
+
isLocalized: isSourceLocalized
|
2487
2682
|
},
|
2488
2683
|
target: {
|
2489
2684
|
schema: { uid: targetUid },
|
@@ -2491,7 +2686,7 @@ const relations = {
|
|
2491
2686
|
}
|
2492
2687
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2493
2688
|
const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
|
2494
|
-
const permissionChecker2 = getService$
|
2689
|
+
const permissionChecker2 = getService$2("permission-checker").create({
|
2495
2690
|
userAbility: ctx.state.userAbility,
|
2496
2691
|
model: targetUid
|
2497
2692
|
});
|
@@ -2521,12 +2716,16 @@ const relations = {
|
|
2521
2716
|
} else {
|
2522
2717
|
where.id = id;
|
2523
2718
|
}
|
2524
|
-
|
2525
|
-
|
2719
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2720
|
+
if (!isEmpty(publishedAt)) {
|
2721
|
+
where[`${alias}.published_at`] = publishedAt;
|
2526
2722
|
}
|
2527
|
-
if (
|
2723
|
+
if (isTargetLocalized && locale) {
|
2528
2724
|
where[`${alias}.locale`] = locale;
|
2529
2725
|
}
|
2726
|
+
if (isSourceLocalized && locale) {
|
2727
|
+
where.locale = locale;
|
2728
|
+
}
|
2530
2729
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2531
2730
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2532
2731
|
}
|
@@ -2544,7 +2743,8 @@ const relations = {
|
|
2544
2743
|
id: { $notIn: uniq(idsToOmit) }
|
2545
2744
|
});
|
2546
2745
|
}
|
2547
|
-
const
|
2746
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2747
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2548
2748
|
ctx.body = {
|
2549
2749
|
...res,
|
2550
2750
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2559,21 +2759,33 @@ const relations = {
|
|
2559
2759
|
attribute,
|
2560
2760
|
targetField,
|
2561
2761
|
fieldsToSelect,
|
2562
|
-
|
2563
|
-
|
2564
|
-
}
|
2565
|
-
target: {
|
2566
|
-
schema: { uid: targetUid }
|
2567
|
-
}
|
2762
|
+
status,
|
2763
|
+
source: { schema: sourceSchema },
|
2764
|
+
target: { schema: targetSchema }
|
2568
2765
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2569
|
-
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 });
|
2570
2769
|
const dbQuery = strapi.db.query(sourceUid);
|
2571
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
|
+
}
|
2572
2783
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2573
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2784
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2574
2785
|
ordering: "desc",
|
2575
2786
|
page: ctx.request.query.page,
|
2576
|
-
pageSize: ctx.request.query.pageSize
|
2787
|
+
pageSize: ctx.request.query.pageSize,
|
2788
|
+
filters
|
2577
2789
|
});
|
2578
2790
|
const loadedIds = res.results.map((item) => item.id);
|
2579
2791
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
@@ -2594,10 +2806,10 @@ const relations = {
|
|
2594
2806
|
}
|
2595
2807
|
};
|
2596
2808
|
const buildPopulateFromQuery = async (query, model) => {
|
2597
|
-
return getService$
|
2809
|
+
return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
|
2598
2810
|
};
|
2599
2811
|
const findDocument = async (query, uid2, opts = {}) => {
|
2600
|
-
const documentManager2 = getService$
|
2812
|
+
const documentManager2 = getService$2("document-manager");
|
2601
2813
|
const populate = await buildPopulateFromQuery(query, uid2);
|
2602
2814
|
return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
|
2603
2815
|
};
|
@@ -2605,8 +2817,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2605
2817
|
const { user, userAbility } = ctx.state;
|
2606
2818
|
const { model } = ctx.params;
|
2607
2819
|
const { body, query } = ctx.request;
|
2608
|
-
const documentManager2 = getService$
|
2609
|
-
const permissionChecker2 = getService$
|
2820
|
+
const documentManager2 = getService$2("document-manager");
|
2821
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2610
2822
|
if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
|
2611
2823
|
throw new errors.ForbiddenError();
|
2612
2824
|
}
|
@@ -2647,7 +2859,7 @@ const singleTypes = {
|
|
2647
2859
|
const { userAbility } = ctx.state;
|
2648
2860
|
const { model } = ctx.params;
|
2649
2861
|
const { query = {} } = ctx.request;
|
2650
|
-
const permissionChecker2 = getService$
|
2862
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2651
2863
|
if (permissionChecker2.cannot.read()) {
|
2652
2864
|
return ctx.forbidden();
|
2653
2865
|
}
|
@@ -2666,7 +2878,7 @@ const singleTypes = {
|
|
2666
2878
|
permissionChecker2,
|
2667
2879
|
model,
|
2668
2880
|
// @ts-expect-error - fix types
|
2669
|
-
{
|
2881
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2670
2882
|
{ availableLocales: true, availableStatus: false }
|
2671
2883
|
);
|
2672
2884
|
ctx.body = { data: {}, meta };
|
@@ -2681,7 +2893,7 @@ const singleTypes = {
|
|
2681
2893
|
async createOrUpdate(ctx) {
|
2682
2894
|
const { userAbility } = ctx.state;
|
2683
2895
|
const { model } = ctx.params;
|
2684
|
-
const permissionChecker2 = getService$
|
2896
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2685
2897
|
const document = await createOrUpdateDocument(ctx);
|
2686
2898
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2687
2899
|
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
@@ -2690,8 +2902,8 @@ const singleTypes = {
|
|
2690
2902
|
const { userAbility } = ctx.state;
|
2691
2903
|
const { model } = ctx.params;
|
2692
2904
|
const { query = {} } = ctx.request;
|
2693
|
-
const documentManager2 = getService$
|
2694
|
-
const permissionChecker2 = getService$
|
2905
|
+
const documentManager2 = getService$2("document-manager");
|
2906
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2695
2907
|
if (permissionChecker2.cannot.delete()) {
|
2696
2908
|
return ctx.forbidden();
|
2697
2909
|
}
|
@@ -2719,8 +2931,8 @@ const singleTypes = {
|
|
2719
2931
|
const { userAbility } = ctx.state;
|
2720
2932
|
const { model } = ctx.params;
|
2721
2933
|
const { query = {} } = ctx.request;
|
2722
|
-
const documentManager2 = getService$
|
2723
|
-
const permissionChecker2 = getService$
|
2934
|
+
const documentManager2 = getService$2("document-manager");
|
2935
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2724
2936
|
if (permissionChecker2.cannot.publish()) {
|
2725
2937
|
return ctx.forbidden();
|
2726
2938
|
}
|
@@ -2748,8 +2960,8 @@ const singleTypes = {
|
|
2748
2960
|
body: { discardDraft, ...body },
|
2749
2961
|
query = {}
|
2750
2962
|
} = ctx.request;
|
2751
|
-
const documentManager2 = getService$
|
2752
|
-
const permissionChecker2 = getService$
|
2963
|
+
const documentManager2 = getService$2("document-manager");
|
2964
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2753
2965
|
if (permissionChecker2.cannot.unpublish()) {
|
2754
2966
|
return ctx.forbidden();
|
2755
2967
|
}
|
@@ -2783,8 +2995,8 @@ const singleTypes = {
|
|
2783
2995
|
const { userAbility } = ctx.state;
|
2784
2996
|
const { model } = ctx.params;
|
2785
2997
|
const { body, query = {} } = ctx.request;
|
2786
|
-
const documentManager2 = getService$
|
2787
|
-
const permissionChecker2 = getService$
|
2998
|
+
const documentManager2 = getService$2("document-manager");
|
2999
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2788
3000
|
if (permissionChecker2.cannot.discard()) {
|
2789
3001
|
return ctx.forbidden();
|
2790
3002
|
}
|
@@ -2807,8 +3019,8 @@ const singleTypes = {
|
|
2807
3019
|
const { userAbility } = ctx.state;
|
2808
3020
|
const { model } = ctx.params;
|
2809
3021
|
const { query } = ctx.request;
|
2810
|
-
const documentManager2 = getService$
|
2811
|
-
const permissionChecker2 = getService$
|
3022
|
+
const documentManager2 = getService$2("document-manager");
|
3023
|
+
const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
|
2812
3024
|
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2813
3025
|
if (permissionChecker2.cannot.read()) {
|
2814
3026
|
return ctx.forbidden();
|
@@ -2832,7 +3044,7 @@ const uid$1 = {
|
|
2832
3044
|
const { query = {} } = ctx.request;
|
2833
3045
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2834
3046
|
await validateUIDField(contentTypeUID, field);
|
2835
|
-
const uidService = getService$
|
3047
|
+
const uidService = getService$2("uid");
|
2836
3048
|
ctx.body = {
|
2837
3049
|
data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
|
2838
3050
|
};
|
@@ -2844,7 +3056,7 @@ const uid$1 = {
|
|
2844
3056
|
const { query = {} } = ctx.request;
|
2845
3057
|
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2846
3058
|
await validateUIDField(contentTypeUID, field);
|
2847
|
-
const uidService = getService$
|
3059
|
+
const uidService = getService$2("uid");
|
2848
3060
|
const isAvailable = await uidService.checkUIDAvailability({
|
2849
3061
|
contentTypeUID,
|
2850
3062
|
field,
|
@@ -2865,7 +3077,8 @@ const controllers = {
|
|
2865
3077
|
relations,
|
2866
3078
|
"single-types": singleTypes,
|
2867
3079
|
uid: uid$1,
|
2868
|
-
...history.controllers ? history.controllers : {}
|
3080
|
+
...history.controllers ? history.controllers : {},
|
3081
|
+
...preview.controllers ? preview.controllers : {}
|
2869
3082
|
};
|
2870
3083
|
const keys = {
|
2871
3084
|
CONFIGURATION: "configuration"
|
@@ -3016,12 +3229,12 @@ async function syncMetadatas(configuration, schema) {
|
|
3016
3229
|
return _.assign(metasWithDefaults, updatedMetas);
|
3017
3230
|
}
|
3018
3231
|
const getTargetSchema = (targetModel) => {
|
3019
|
-
return getService$
|
3232
|
+
return getService$2("content-types").findContentType(targetModel);
|
3020
3233
|
};
|
3021
3234
|
const DEFAULT_LIST_LENGTH = 4;
|
3022
3235
|
const MAX_ROW_SIZE = 12;
|
3023
3236
|
const isAllowedFieldSize = (type, size) => {
|
3024
|
-
const { getFieldSize } = getService$
|
3237
|
+
const { getFieldSize } = getService$2("field-sizes");
|
3025
3238
|
const fieldSize = getFieldSize(type);
|
3026
3239
|
if (!fieldSize.isResizable && size !== fieldSize.default) {
|
3027
3240
|
return false;
|
@@ -3029,7 +3242,7 @@ const isAllowedFieldSize = (type, size) => {
|
|
3029
3242
|
return size <= MAX_ROW_SIZE;
|
3030
3243
|
};
|
3031
3244
|
const getDefaultFieldSize = (attribute) => {
|
3032
|
-
const { hasFieldSize, getFieldSize } = getService$
|
3245
|
+
const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
|
3033
3246
|
return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
|
3034
3247
|
};
|
3035
3248
|
async function createDefaultLayouts(schema) {
|
@@ -3064,7 +3277,7 @@ function syncLayouts(configuration, schema) {
|
|
3064
3277
|
for (const el of row) {
|
3065
3278
|
if (!hasEditableAttribute(schema, el.name))
|
3066
3279
|
continue;
|
3067
|
-
const { hasFieldSize } = getService$
|
3280
|
+
const { hasFieldSize } = getService$2("field-sizes");
|
3068
3281
|
const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
|
3069
3282
|
if (!isAllowedFieldSize(fieldType, el.size)) {
|
3070
3283
|
elementsToReAppend.push(el.name);
|
@@ -3204,17 +3417,17 @@ const configurationService$1 = createConfigurationService({
|
|
3204
3417
|
isComponent: true,
|
3205
3418
|
prefix: STORE_KEY_PREFIX,
|
3206
3419
|
getModels() {
|
3207
|
-
const { toContentManagerModel } = getService$
|
3420
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3208
3421
|
return mapValues(toContentManagerModel, strapi.components);
|
3209
3422
|
}
|
3210
3423
|
});
|
3211
3424
|
const components = ({ strapi: strapi2 }) => ({
|
3212
3425
|
findAllComponents() {
|
3213
|
-
const { toContentManagerModel } = getService$
|
3426
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3214
3427
|
return Object.values(strapi2.components).map(toContentManagerModel);
|
3215
3428
|
},
|
3216
3429
|
findComponent(uid2) {
|
3217
|
-
const { toContentManagerModel } = getService$
|
3430
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3218
3431
|
const component = strapi2.components[uid2];
|
3219
3432
|
return isNil$1(component) ? component : toContentManagerModel(component);
|
3220
3433
|
},
|
@@ -3265,17 +3478,17 @@ const configurationService = createConfigurationService({
|
|
3265
3478
|
storeUtils,
|
3266
3479
|
prefix: "content_types",
|
3267
3480
|
getModels() {
|
3268
|
-
const { toContentManagerModel } = getService$
|
3481
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3269
3482
|
return mapValues(toContentManagerModel, strapi.contentTypes);
|
3270
3483
|
}
|
3271
3484
|
});
|
3272
3485
|
const service = ({ strapi: strapi2 }) => ({
|
3273
3486
|
findAllContentTypes() {
|
3274
|
-
const { toContentManagerModel } = getService$
|
3487
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3275
3488
|
return Object.values(strapi2.contentTypes).map(toContentManagerModel);
|
3276
3489
|
},
|
3277
3490
|
findContentType(uid2) {
|
3278
|
-
const { toContentManagerModel } = getService$
|
3491
|
+
const { toContentManagerModel } = getService$2("data-mapper");
|
3279
3492
|
const contentType = strapi2.contentTypes[uid2];
|
3280
3493
|
return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
|
3281
3494
|
},
|
@@ -3304,7 +3517,7 @@ const service = ({ strapi: strapi2 }) => ({
|
|
3304
3517
|
return this.findConfiguration(contentType);
|
3305
3518
|
},
|
3306
3519
|
findComponentsConfigurations(contentType) {
|
3307
|
-
return getService$
|
3520
|
+
return getService$2("components").findComponentsConfigurations(contentType);
|
3308
3521
|
},
|
3309
3522
|
syncConfigurations() {
|
3310
3523
|
return configurationService.syncConfigurations();
|
@@ -3576,7 +3789,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3576
3789
|
return userAbility.can(action);
|
3577
3790
|
},
|
3578
3791
|
async registerPermissions() {
|
3579
|
-
const displayedContentTypes = getService$
|
3792
|
+
const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
|
3580
3793
|
const contentTypesUids = displayedContentTypes.map(prop("uid"));
|
3581
3794
|
const actions = [
|
3582
3795
|
{
|
@@ -3852,7 +4065,7 @@ const getQueryPopulate = async (uid2, query) => {
|
|
3852
4065
|
return populateQuery;
|
3853
4066
|
};
|
3854
4067
|
const buildDeepPopulate = (uid2) => {
|
3855
|
-
return getService$
|
4068
|
+
return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
|
3856
4069
|
};
|
3857
4070
|
const populateBuilder = (uid2) => {
|
3858
4071
|
let getInitialPopulate = async () => {
|
@@ -4037,7 +4250,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4037
4250
|
*/
|
4038
4251
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
4039
4252
|
const versionsByLocale = groupBy("locale", allVersions);
|
4040
|
-
|
4253
|
+
if (version.locale) {
|
4254
|
+
delete versionsByLocale[version.locale];
|
4255
|
+
}
|
4041
4256
|
const model = strapi2.getModel(uid2);
|
4042
4257
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4043
4258
|
const traversalFunction = async (localeVersion) => traverseEntity(
|
@@ -4393,7 +4608,8 @@ const services = {
|
|
4393
4608
|
permission,
|
4394
4609
|
"populate-builder": populateBuilder$1,
|
4395
4610
|
uid,
|
4396
|
-
...history.services ? history.services : {}
|
4611
|
+
...history.services ? history.services : {},
|
4612
|
+
...preview.services ? preview.services : {}
|
4397
4613
|
};
|
4398
4614
|
const index = () => {
|
4399
4615
|
return {
|