@strapi/content-manager 0.0.0-experimental.a9a5a36dd73072c19eadeff5f387e8286b2a4d22 → 0.0.0-experimental.ae69a6ec6a65b1061cd6a00b2608abeeff436042
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-B1bIXVuX.mjs → ComponentConfigurationPage-DH3rgf1K.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs.map → ComponentConfigurationPage-DH3rgf1K.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js → ComponentConfigurationPage-DRh2GoZx.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js.map → ComponentConfigurationPage-DRh2GoZx.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js → EditConfigurationPage-BOAqRJUV.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js.map → EditConfigurationPage-BOAqRJUV.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs → EditConfigurationPage-C1HHivAz.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs.map → EditConfigurationPage-C1HHivAz.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DA95Ha6J.js → EditViewPage-CgfL33yw.js} +30 -9
- package/dist/_chunks/EditViewPage-CgfL33yw.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DlLEyUL6.mjs → EditViewPage-DBV7CZVf.mjs} +30 -9
- package/dist/_chunks/EditViewPage-DBV7CZVf.mjs.map +1 -0
- package/dist/_chunks/{Field-Dq7bDnuh.mjs → Field-BQFK_H87.mjs} +178 -106
- package/dist/_chunks/Field-BQFK_H87.mjs.map +1 -0
- package/dist/_chunks/{Field-CnK8dO8N.js → Field-C647fIuP.js} +180 -108
- package/dist/_chunks/Field-C647fIuP.js.map +1 -0
- package/dist/_chunks/{Form-B_JE0dbz.mjs → Form--31reETM.mjs} +36 -17
- package/dist/_chunks/Form--31reETM.mjs.map +1 -0
- package/dist/_chunks/{Form-BpiR4piS.js → Form-CsYUrVEA.js} +36 -17
- package/dist/_chunks/Form-CsYUrVEA.js.map +1 -0
- package/dist/_chunks/{History-CBNGU7a-.mjs → History-8tQaor_-.mjs} +42 -19
- package/dist/_chunks/History-8tQaor_-.mjs.map +1 -0
- package/dist/_chunks/{History-DdIstl8b.js → History-Dl6wOm0V.js} +41 -18
- package/dist/_chunks/History-Dl6wOm0V.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DkKRparB.js → ListConfigurationPage-BedUJnmo.js} +15 -5
- package/dist/_chunks/ListConfigurationPage-BedUJnmo.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-5dr4qpue.mjs → ListConfigurationPage-_WWIGpVT.mjs} +15 -5
- package/dist/_chunks/ListConfigurationPage-_WWIGpVT.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-wE0lXqoD.js → ListViewPage-5QzoAtAo.js} +61 -41
- package/dist/_chunks/ListViewPage-5QzoAtAo.js.map +1 -0
- package/dist/_chunks/{ListViewPage-DecLrYV6.mjs → ListViewPage-CZfw9OW9.mjs} +59 -39
- package/dist/_chunks/ListViewPage-CZfw9OW9.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs → NoContentTypePage-D-RqshUI.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs.map → NoContentTypePage-D-RqshUI.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js → NoContentTypePage-DBIyA7hd.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js.map → NoContentTypePage-DBIyA7hd.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js → NoPermissionsPage-CCAreseM.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js.map → NoPermissionsPage-CCAreseM.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs → NoPermissionsPage-m7GAd26r.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs.map → NoPermissionsPage-m7GAd26r.mjs.map} +1 -1
- package/dist/_chunks/{Relations-Dqz0C1fz.mjs → Relations-Dq52hb_u.mjs} +70 -37
- package/dist/_chunks/Relations-Dq52hb_u.mjs.map +1 -0
- package/dist/_chunks/{Relations-L0xYRoSQ.js → Relations-SRwPhmo7.js} +69 -36
- package/dist/_chunks/Relations-SRwPhmo7.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-BSn97i8U.mjs → index-1Bdj-6ls.mjs} +914 -710
- package/dist/_chunks/index-1Bdj-6ls.mjs.map +1 -0
- package/dist/_chunks/{index-DyvUPg1a.js → index-CsrCnNa3.js} +895 -690
- package/dist/_chunks/index-CsrCnNa3.js.map +1 -0
- package/dist/_chunks/{layout-TPqF2oJ5.js → layout-B33V9Tdu.js} +21 -8
- package/dist/_chunks/layout-B33V9Tdu.js.map +1 -0
- package/dist/_chunks/{layout-DPaHUusj.mjs → layout-ByD1cQSW.mjs} +22 -9
- package/dist/_chunks/layout-ByD1cQSW.mjs.map +1 -0
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-BWYS9gkn.js → relations-BBHlo3qQ.js} +3 -7
- package/dist/_chunks/relations-BBHlo3qQ.js.map +1 -0
- package/dist/_chunks/{relations-Ck7-ecDT.mjs → relations-DFwbNLZ0.mjs} +3 -7
- package/dist/_chunks/relations-DFwbNLZ0.mjs.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 +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +256 -134
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +257 -135
- 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/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/uid.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/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.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 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- 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/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +13 -13
- package/dist/_chunks/EditViewPage-DA95Ha6J.js.map +0 -1
- package/dist/_chunks/EditViewPage-DlLEyUL6.mjs.map +0 -1
- package/dist/_chunks/Field-CnK8dO8N.js.map +0 -1
- package/dist/_chunks/Field-Dq7bDnuh.mjs.map +0 -1
- package/dist/_chunks/Form-B_JE0dbz.mjs.map +0 -1
- package/dist/_chunks/Form-BpiR4piS.js.map +0 -1
- package/dist/_chunks/History-CBNGU7a-.mjs.map +0 -1
- package/dist/_chunks/History-DdIstl8b.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-5dr4qpue.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DkKRparB.js.map +0 -1
- package/dist/_chunks/ListViewPage-DecLrYV6.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-wE0lXqoD.js.map +0 -1
- package/dist/_chunks/Relations-Dqz0C1fz.mjs.map +0 -1
- package/dist/_chunks/Relations-L0xYRoSQ.js.map +0 -1
- package/dist/_chunks/index-BSn97i8U.mjs.map +0 -1
- package/dist/_chunks/index-DyvUPg1a.js.map +0 -1
- package/dist/_chunks/layout-DPaHUusj.mjs.map +0 -1
- package/dist/_chunks/layout-TPqF2oJ5.js.map +0 -1
- package/dist/_chunks/relations-BWYS9gkn.js.map +0 -1
- package/dist/_chunks/relations-Ck7-ecDT.mjs.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.js
CHANGED
@@ -199,7 +199,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
199
199
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
|
200
200
|
};
|
201
201
|
const localesService = strapi2.plugin("i18n")?.service("locales");
|
202
|
+
const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
|
202
203
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
|
+
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
203
205
|
const getLocaleDictionary = async () => {
|
204
206
|
if (!localesService)
|
205
207
|
return {};
|
@@ -226,9 +228,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
226
228
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
227
229
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
228
230
|
};
|
229
|
-
const getDeepPopulate2 = (uid2) => {
|
231
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
230
232
|
const model = strapi2.getModel(uid2);
|
231
233
|
const attributes = Object.entries(model.attributes);
|
234
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
232
235
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
233
236
|
switch (attribute.type) {
|
234
237
|
case "relation": {
|
@@ -238,12 +241,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
238
241
|
}
|
239
242
|
const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
240
243
|
if (isVisible2) {
|
241
|
-
acc[attributeName] = {
|
244
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
242
245
|
}
|
243
246
|
break;
|
244
247
|
}
|
245
248
|
case "media": {
|
246
|
-
acc[attributeName] = {
|
249
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
247
250
|
break;
|
248
251
|
}
|
249
252
|
case "component": {
|
@@ -316,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
316
319
|
getRelationRestoreValue,
|
317
320
|
getMediaRestoreValue,
|
318
321
|
getDefaultLocale,
|
322
|
+
isLocalizedContentType,
|
319
323
|
getLocaleDictionary,
|
320
324
|
getRetentionDays,
|
321
325
|
getVersionStatus,
|
@@ -338,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
338
342
|
});
|
339
343
|
},
|
340
344
|
async findVersionsPage(params) {
|
341
|
-
const
|
345
|
+
const model = strapi2.getModel(params.query.contentType);
|
346
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
347
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
348
|
+
let locale = null;
|
349
|
+
if (isLocalizedContentType) {
|
350
|
+
locale = params.query.locale || defaultLocale;
|
351
|
+
}
|
342
352
|
const [{ results, pagination }, localeDictionary] = await Promise.all([
|
343
353
|
query.findPage({
|
344
354
|
...params.query,
|
@@ -383,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
383
393
|
if (userToPopulate == null) {
|
384
394
|
return null;
|
385
395
|
}
|
386
|
-
return strapi2.query("admin::user").findOne({
|
396
|
+
return strapi2.query("admin::user").findOne({
|
397
|
+
where: {
|
398
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
399
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
400
|
+
}
|
401
|
+
});
|
387
402
|
})
|
388
403
|
);
|
389
404
|
return {
|
@@ -494,6 +509,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
494
509
|
}
|
495
510
|
};
|
496
511
|
};
|
512
|
+
const shouldCreateHistoryVersion = (context) => {
|
513
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
514
|
+
return false;
|
515
|
+
}
|
516
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
517
|
+
return false;
|
518
|
+
}
|
519
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
520
|
+
return false;
|
521
|
+
}
|
522
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
523
|
+
return false;
|
524
|
+
}
|
525
|
+
return true;
|
526
|
+
};
|
527
|
+
const getSchemas = (uid2) => {
|
528
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
529
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
530
|
+
(currentComponentSchemas, key) => {
|
531
|
+
const fieldSchema = attributesSchema[key];
|
532
|
+
if (fieldSchema.type === "component") {
|
533
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
534
|
+
return {
|
535
|
+
...currentComponentSchemas,
|
536
|
+
[fieldSchema.component]: componentSchema
|
537
|
+
};
|
538
|
+
}
|
539
|
+
return currentComponentSchemas;
|
540
|
+
},
|
541
|
+
{}
|
542
|
+
);
|
543
|
+
return {
|
544
|
+
schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
|
545
|
+
componentsSchemas
|
546
|
+
};
|
547
|
+
};
|
497
548
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
498
549
|
const state = {
|
499
550
|
deleteExpiredJob: null,
|
@@ -506,63 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
506
557
|
return;
|
507
558
|
}
|
508
559
|
strapi2.documents.use(async (context, next) => {
|
509
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
510
|
-
return next();
|
511
|
-
}
|
512
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
513
|
-
return next();
|
514
|
-
}
|
515
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
516
|
-
return next();
|
517
|
-
}
|
518
|
-
const contentTypeUid = context.contentType.uid;
|
519
|
-
if (!contentTypeUid.startsWith("api::")) {
|
520
|
-
return next();
|
521
|
-
}
|
522
560
|
const result = await next();
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
561
|
+
if (!shouldCreateHistoryVersion(context)) {
|
562
|
+
return result;
|
563
|
+
}
|
564
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
527
565
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
528
|
-
const
|
529
|
-
if (
|
530
|
-
|
531
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
532
|
-
);
|
533
|
-
return next();
|
566
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
567
|
+
if (!locales.length) {
|
568
|
+
return result;
|
534
569
|
}
|
535
|
-
const
|
536
|
-
|
537
|
-
|
538
|
-
|
570
|
+
const uid2 = context.contentType.uid;
|
571
|
+
const schemas = getSchemas(uid2);
|
572
|
+
const model = strapi2.getModel(uid2);
|
573
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
574
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
575
|
+
where: {
|
576
|
+
documentId,
|
577
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
578
|
+
...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
579
|
+
},
|
580
|
+
populate: serviceUtils.getDeepPopulate(
|
581
|
+
uid2,
|
582
|
+
true
|
583
|
+
/* use database syntax */
|
584
|
+
)
|
539
585
|
});
|
540
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
541
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
542
|
-
const componentsSchemas = Object.keys(
|
543
|
-
attributesSchema
|
544
|
-
).reduce((currentComponentSchemas, key) => {
|
545
|
-
const fieldSchema = attributesSchema[key];
|
546
|
-
if (fieldSchema.type === "component") {
|
547
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
548
|
-
return {
|
549
|
-
...currentComponentSchemas,
|
550
|
-
[fieldSchema.component]: componentSchema
|
551
|
-
};
|
552
|
-
}
|
553
|
-
return currentComponentSchemas;
|
554
|
-
}, {});
|
555
586
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
556
|
-
onCommit(() => {
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
587
|
+
onCommit(async () => {
|
588
|
+
for (const entry of localeEntries) {
|
589
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
+
await getService(strapi2, "history").createVersion({
|
591
|
+
contentType: uid2,
|
592
|
+
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
|
+
relatedDocumentId: documentId,
|
594
|
+
locale: entry.locale,
|
595
|
+
status,
|
596
|
+
...schemas
|
597
|
+
});
|
598
|
+
}
|
566
599
|
});
|
567
600
|
});
|
568
601
|
return result;
|
@@ -662,7 +695,7 @@ const historyVersion = {
|
|
662
695
|
}
|
663
696
|
}
|
664
697
|
};
|
665
|
-
const getFeature = () => {
|
698
|
+
const getFeature$1 = () => {
|
666
699
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
667
700
|
return {
|
668
701
|
register({ strapi: strapi2 }) {
|
@@ -685,7 +718,7 @@ const getFeature = () => {
|
|
685
718
|
}
|
686
719
|
};
|
687
720
|
};
|
688
|
-
const history = getFeature();
|
721
|
+
const history = getFeature$1();
|
689
722
|
const register = async ({ strapi: strapi2 }) => {
|
690
723
|
await history.register?.({ strapi: strapi2 });
|
691
724
|
};
|
@@ -693,6 +726,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
|
|
693
726
|
ENTRY_PUBLISH: "entry.publish",
|
694
727
|
ENTRY_UNPUBLISH: "entry.unpublish"
|
695
728
|
};
|
729
|
+
const FEATURE_ID = "preview";
|
730
|
+
const getFeature = () => {
|
731
|
+
if (!strapi.features.future.isEnabled(FEATURE_ID)) {
|
732
|
+
return {};
|
733
|
+
}
|
734
|
+
return {
|
735
|
+
bootstrap() {
|
736
|
+
console.log("Bootstrapping preview server");
|
737
|
+
}
|
738
|
+
};
|
739
|
+
};
|
740
|
+
const preview = getFeature();
|
696
741
|
const bootstrap = async () => {
|
697
742
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
698
743
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
@@ -702,6 +747,7 @@ const bootstrap = async () => {
|
|
702
747
|
await getService$1("content-types").syncConfigurations();
|
703
748
|
await getService$1("permission").registerPermissions();
|
704
749
|
await history.bootstrap?.({ strapi });
|
750
|
+
await preview.bootstrap?.({ strapi });
|
705
751
|
};
|
706
752
|
const destroy = async ({ strapi: strapi2 }) => {
|
707
753
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1202,6 +1248,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1202
1248
|
const hasPermissions = createPolicy({
|
1203
1249
|
name: "plugin::content-manager.hasPermissions",
|
1204
1250
|
validator: validateHasPermissionsInput,
|
1251
|
+
/**
|
1252
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1253
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1254
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1255
|
+
*/
|
1205
1256
|
handler(ctx, config = {}) {
|
1206
1257
|
const { actions = [], hasAtLeastOne = false } = config;
|
1207
1258
|
const { userAbility } = ctx.state;
|
@@ -1595,9 +1646,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1595
1646
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1596
1647
|
);
|
1597
1648
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1598
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1649
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1599
1650
|
const { allowMultipleLocales } = opts;
|
1600
|
-
const { locale, status, ...rest } = request || {};
|
1651
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1652
|
+
const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1653
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1601
1654
|
const schema = strapiUtils.yup.object().shape({
|
1602
1655
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1603
1656
|
status: statusSchema
|
@@ -1645,7 +1698,7 @@ const createDocument = async (ctx, opts) => {
|
|
1645
1698
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1646
1699
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1647
1700
|
const sanitizedBody = await sanitizeFn(body);
|
1648
|
-
const { locale, status
|
1701
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1649
1702
|
return documentManager2.create(model, {
|
1650
1703
|
data: sanitizedBody,
|
1651
1704
|
locale,
|
@@ -1664,7 +1717,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1664
1717
|
}
|
1665
1718
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1666
1719
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1667
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1720
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1668
1721
|
const [documentVersion, documentExists] = await Promise.all([
|
1669
1722
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1670
1723
|
documentManager2.exists(model, id)
|
@@ -1680,7 +1733,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1680
1733
|
throw new strapiUtils.errors.ForbiddenError();
|
1681
1734
|
}
|
1682
1735
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1683
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1736
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1684
1737
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1685
1738
|
const sanitizedBody = await sanitizeFn(body);
|
1686
1739
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1702,7 +1755,7 @@ const collectionTypes = {
|
|
1702
1755
|
}
|
1703
1756
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1704
1757
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1705
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1758
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1706
1759
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1707
1760
|
{ ...permissionQuery, populate, locale, status },
|
1708
1761
|
model
|
@@ -1737,7 +1790,7 @@ const collectionTypes = {
|
|
1737
1790
|
}
|
1738
1791
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1739
1792
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1740
|
-
const { locale, status
|
1793
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1741
1794
|
const version = await documentManager2.findOne(id, model, {
|
1742
1795
|
populate,
|
1743
1796
|
locale,
|
@@ -1752,7 +1805,7 @@ const collectionTypes = {
|
|
1752
1805
|
permissionChecker2,
|
1753
1806
|
model,
|
1754
1807
|
// @ts-expect-error TODO: fix
|
1755
|
-
{ id, locale, publishedAt: null },
|
1808
|
+
{ documentId: id, locale, publishedAt: null },
|
1756
1809
|
{ availableLocales: true, availableStatus: false }
|
1757
1810
|
);
|
1758
1811
|
ctx.body = { data: {}, meta };
|
@@ -1804,7 +1857,7 @@ const collectionTypes = {
|
|
1804
1857
|
}
|
1805
1858
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1806
1859
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1807
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1860
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1808
1861
|
const document = await documentManager2.findOne(id, model, {
|
1809
1862
|
populate,
|
1810
1863
|
locale,
|
@@ -1849,7 +1902,7 @@ const collectionTypes = {
|
|
1849
1902
|
}
|
1850
1903
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1851
1904
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1852
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1905
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1853
1906
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1854
1907
|
if (documentLocales.length === 0) {
|
1855
1908
|
return ctx.notFound();
|
@@ -1878,11 +1931,34 @@ const collectionTypes = {
|
|
1878
1931
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1879
1932
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1880
1933
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1881
|
-
|
1934
|
+
let document;
|
1935
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1936
|
+
const isCreate = fp.isNil(id);
|
1937
|
+
if (isCreate) {
|
1938
|
+
if (permissionChecker2.cannot.create()) {
|
1939
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1940
|
+
}
|
1941
|
+
document = await createDocument(ctx, { populate });
|
1942
|
+
}
|
1943
|
+
const isUpdate = !isCreate;
|
1944
|
+
if (isUpdate) {
|
1945
|
+
const documentExists = documentManager2.exists(model, id);
|
1946
|
+
if (!documentExists) {
|
1947
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1948
|
+
}
|
1949
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1950
|
+
if (!document) {
|
1951
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
1952
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1953
|
+
}
|
1954
|
+
document = await updateDocument(ctx);
|
1955
|
+
} else if (permissionChecker2.can.update(document)) {
|
1956
|
+
await updateDocument(ctx);
|
1957
|
+
}
|
1958
|
+
}
|
1882
1959
|
if (permissionChecker2.cannot.publish(document)) {
|
1883
1960
|
throw new strapiUtils.errors.ForbiddenError();
|
1884
1961
|
}
|
1885
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1886
1962
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1887
1963
|
locale
|
1888
1964
|
// TODO: Allow setting creator fields on publish
|
@@ -1909,7 +1985,9 @@ const collectionTypes = {
|
|
1909
1985
|
}
|
1910
1986
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1911
1987
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1912
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1988
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1989
|
+
allowMultipleLocales: true
|
1990
|
+
});
|
1913
1991
|
const entityPromises = documentIds.map(
|
1914
1992
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1915
1993
|
);
|
@@ -1936,7 +2014,9 @@ const collectionTypes = {
|
|
1936
2014
|
if (permissionChecker2.cannot.unpublish()) {
|
1937
2015
|
return ctx.forbidden();
|
1938
2016
|
}
|
1939
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
2017
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2018
|
+
allowMultipleLocales: true
|
2019
|
+
});
|
1940
2020
|
const entityPromises = documentIds.map(
|
1941
2021
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1942
2022
|
);
|
@@ -1969,7 +2049,7 @@ const collectionTypes = {
|
|
1969
2049
|
}
|
1970
2050
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1971
2051
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1972
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2052
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1973
2053
|
const document = await documentManager2.findOne(id, model, {
|
1974
2054
|
populate,
|
1975
2055
|
locale,
|
@@ -2006,7 +2086,7 @@ const collectionTypes = {
|
|
2006
2086
|
}
|
2007
2087
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2008
2088
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2009
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2089
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2010
2090
|
const document = await documentManager2.findOne(id, model, {
|
2011
2091
|
populate,
|
2012
2092
|
locale,
|
@@ -2037,7 +2117,7 @@ const collectionTypes = {
|
|
2037
2117
|
}
|
2038
2118
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2039
2119
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2040
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2120
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2041
2121
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2042
2122
|
populate,
|
2043
2123
|
locale
|
@@ -2064,7 +2144,7 @@ const collectionTypes = {
|
|
2064
2144
|
}
|
2065
2145
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2066
2146
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2067
|
-
const { locale, status
|
2147
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2068
2148
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2069
2149
|
if (!entity) {
|
2070
2150
|
return ctx.notFound();
|
@@ -2287,32 +2367,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2287
2367
|
userAbility,
|
2288
2368
|
model: model.uid
|
2289
2369
|
});
|
2290
|
-
|
2370
|
+
const isMainFieldListable = isListable(model, mainField);
|
2371
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2372
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2291
2373
|
return "id";
|
2292
2374
|
}
|
2293
|
-
if (
|
2294
|
-
|
2295
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2296
|
-
userAbility,
|
2297
|
-
model: "plugin::users-permissions.user"
|
2298
|
-
});
|
2299
|
-
if (userPermissionChecker.can.read()) {
|
2300
|
-
return "name";
|
2301
|
-
}
|
2302
|
-
}
|
2303
|
-
return "id";
|
2375
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2376
|
+
return "name";
|
2304
2377
|
}
|
2305
2378
|
return mainField;
|
2306
2379
|
};
|
2307
|
-
const addStatusToRelations = async (
|
2308
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2380
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2381
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2309
2382
|
return relations2;
|
2310
2383
|
}
|
2311
2384
|
const documentMetadata2 = getService$1("document-metadata");
|
2312
|
-
|
2385
|
+
if (!relations2.length) {
|
2386
|
+
return relations2;
|
2387
|
+
}
|
2388
|
+
const firstRelation = relations2[0];
|
2389
|
+
const filters = {
|
2390
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2391
|
+
// NOTE: find the "opposite" status
|
2392
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2393
|
+
};
|
2394
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2395
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2396
|
+
filters
|
2397
|
+
});
|
2313
2398
|
return relations2.map((relation) => {
|
2314
|
-
const availableStatuses =
|
2315
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2399
|
+
const availableStatuses = availableStatus.filter(
|
2400
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2316
2401
|
);
|
2317
2402
|
return {
|
2318
2403
|
...relation,
|
@@ -2333,11 +2418,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2333
2418
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2334
2419
|
const isSourceLocalized = isLocalized(sourceModel);
|
2335
2420
|
const isTargetLocalized = isLocalized(targetModel);
|
2336
|
-
let validatedLocale = locale;
|
2337
|
-
if (!targetModel || !isTargetLocalized)
|
2338
|
-
validatedLocale = void 0;
|
2339
2421
|
return {
|
2340
|
-
locale
|
2422
|
+
locale,
|
2341
2423
|
isSourceLocalized,
|
2342
2424
|
isTargetLocalized
|
2343
2425
|
};
|
@@ -2440,7 +2522,7 @@ const relations = {
|
|
2440
2522
|
attribute,
|
2441
2523
|
fieldsToSelect,
|
2442
2524
|
mainField,
|
2443
|
-
source: { schema: sourceSchema },
|
2525
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2444
2526
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2445
2527
|
sourceSchema,
|
2446
2528
|
targetSchema,
|
@@ -2462,7 +2544,8 @@ const relations = {
|
|
2462
2544
|
fieldsToSelect,
|
2463
2545
|
mainField,
|
2464
2546
|
source: {
|
2465
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2547
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2548
|
+
isLocalized: isSourceLocalized
|
2466
2549
|
},
|
2467
2550
|
target: {
|
2468
2551
|
schema: { uid: targetUid },
|
@@ -2500,12 +2583,16 @@ const relations = {
|
|
2500
2583
|
} else {
|
2501
2584
|
where.id = id;
|
2502
2585
|
}
|
2503
|
-
|
2504
|
-
|
2586
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2587
|
+
if (!fp.isEmpty(publishedAt)) {
|
2588
|
+
where[`${alias}.published_at`] = publishedAt;
|
2505
2589
|
}
|
2506
|
-
if (
|
2590
|
+
if (isTargetLocalized && locale) {
|
2507
2591
|
where[`${alias}.locale`] = locale;
|
2508
2592
|
}
|
2593
|
+
if (isSourceLocalized && locale) {
|
2594
|
+
where.locale = locale;
|
2595
|
+
}
|
2509
2596
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2510
2597
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2511
2598
|
}
|
@@ -2523,7 +2610,8 @@ const relations = {
|
|
2523
2610
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2524
2611
|
});
|
2525
2612
|
}
|
2526
|
-
const
|
2613
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2614
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2527
2615
|
ctx.body = {
|
2528
2616
|
...res,
|
2529
2617
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2538,29 +2626,39 @@ const relations = {
|
|
2538
2626
|
attribute,
|
2539
2627
|
targetField,
|
2540
2628
|
fieldsToSelect,
|
2541
|
-
|
2542
|
-
|
2543
|
-
}
|
2544
|
-
target: {
|
2545
|
-
schema: { uid: targetUid }
|
2546
|
-
}
|
2629
|
+
status,
|
2630
|
+
source: { schema: sourceSchema },
|
2631
|
+
target: { schema: targetSchema }
|
2547
2632
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2633
|
+
const { uid: sourceUid } = sourceSchema;
|
2634
|
+
const { uid: targetUid } = targetSchema;
|
2548
2635
|
const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2549
2636
|
const dbQuery = strapi.db.query(sourceUid);
|
2550
2637
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2638
|
+
const filters = {};
|
2639
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2640
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2641
|
+
if (status === "published") {
|
2642
|
+
filters.publishedAt = { $notNull: true };
|
2643
|
+
} else {
|
2644
|
+
filters.publishedAt = { $null: true };
|
2645
|
+
}
|
2646
|
+
}
|
2647
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2648
|
+
filters.publishedAt = { $null: true };
|
2649
|
+
}
|
2551
2650
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2552
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2651
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2553
2652
|
ordering: "desc",
|
2554
2653
|
page: ctx.request.query.page,
|
2555
|
-
pageSize: ctx.request.query.pageSize
|
2654
|
+
pageSize: ctx.request.query.pageSize,
|
2655
|
+
filters
|
2556
2656
|
});
|
2557
2657
|
const loadedIds = res.results.map((item) => item.id);
|
2558
2658
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2559
2659
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2560
2660
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2561
|
-
ordering: "desc"
|
2562
|
-
page: ctx.request.query.page,
|
2563
|
-
pageSize: ctx.request.query.pageSize
|
2661
|
+
ordering: "desc"
|
2564
2662
|
});
|
2565
2663
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2566
2664
|
ctx.body = {
|
@@ -2592,7 +2690,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2592
2690
|
throw new strapiUtils.errors.ForbiddenError();
|
2593
2691
|
}
|
2594
2692
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2595
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2693
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2596
2694
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2597
2695
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2598
2696
|
// Find the first document to check if it exists
|
@@ -2633,7 +2731,7 @@ const singleTypes = {
|
|
2633
2731
|
return ctx.forbidden();
|
2634
2732
|
}
|
2635
2733
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2636
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2734
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2637
2735
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2638
2736
|
if (!version) {
|
2639
2737
|
if (permissionChecker2.cannot.create()) {
|
@@ -2647,7 +2745,7 @@ const singleTypes = {
|
|
2647
2745
|
permissionChecker2,
|
2648
2746
|
model,
|
2649
2747
|
// @ts-expect-error - fix types
|
2650
|
-
{
|
2748
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2651
2749
|
{ availableLocales: true, availableStatus: false }
|
2652
2750
|
);
|
2653
2751
|
ctx.body = { data: {}, meta };
|
@@ -2678,7 +2776,7 @@ const singleTypes = {
|
|
2678
2776
|
}
|
2679
2777
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2680
2778
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2681
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2779
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2682
2780
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2683
2781
|
populate,
|
2684
2782
|
locale
|
@@ -2715,7 +2813,7 @@ const singleTypes = {
|
|
2715
2813
|
if (permissionChecker2.cannot.publish(document)) {
|
2716
2814
|
throw new strapiUtils.errors.ForbiddenError();
|
2717
2815
|
}
|
2718
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2816
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2719
2817
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2720
2818
|
return publishResult.at(0);
|
2721
2819
|
});
|
@@ -2738,7 +2836,7 @@ const singleTypes = {
|
|
2738
2836
|
return ctx.forbidden();
|
2739
2837
|
}
|
2740
2838
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2741
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2839
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2742
2840
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2743
2841
|
if (!document) {
|
2744
2842
|
return ctx.notFound();
|
@@ -2770,7 +2868,7 @@ const singleTypes = {
|
|
2770
2868
|
return ctx.forbidden();
|
2771
2869
|
}
|
2772
2870
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2773
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2871
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2774
2872
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2775
2873
|
if (!document) {
|
2776
2874
|
return ctx.notFound();
|
@@ -2790,7 +2888,7 @@ const singleTypes = {
|
|
2790
2888
|
const { query } = ctx.request;
|
2791
2889
|
const documentManager2 = getService$1("document-manager");
|
2792
2890
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2793
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2891
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2794
2892
|
if (permissionChecker2.cannot.read()) {
|
2795
2893
|
return ctx.forbidden();
|
2796
2894
|
}
|
@@ -2811,7 +2909,7 @@ const uid$1 = {
|
|
2811
2909
|
async generateUID(ctx) {
|
2812
2910
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2813
2911
|
const { query = {} } = ctx.request;
|
2814
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2912
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2815
2913
|
await validateUIDField(contentTypeUID, field);
|
2816
2914
|
const uidService = getService$1("uid");
|
2817
2915
|
ctx.body = {
|
@@ -2823,7 +2921,7 @@ const uid$1 = {
|
|
2823
2921
|
ctx.request.body
|
2824
2922
|
);
|
2825
2923
|
const { query = {} } = ctx.request;
|
2826
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2924
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2827
2925
|
await validateUIDField(contentTypeUID, field);
|
2828
2926
|
const uidService = getService$1("uid");
|
2829
2927
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3466,12 +3564,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3466
3564
|
ability: userAbility,
|
3467
3565
|
model
|
3468
3566
|
});
|
3469
|
-
const
|
3567
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3568
|
+
const toSubject = (entity) => {
|
3569
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3570
|
+
};
|
3470
3571
|
const can = (action, entity, field) => {
|
3471
|
-
|
3572
|
+
const subject = toSubject(entity);
|
3573
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3574
|
+
return (
|
3575
|
+
// Test the original action to see if it passes
|
3576
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3577
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3578
|
+
);
|
3472
3579
|
};
|
3473
3580
|
const cannot = (action, entity, field) => {
|
3474
|
-
|
3581
|
+
const subject = toSubject(entity);
|
3582
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3583
|
+
return (
|
3584
|
+
// Test both the original action
|
3585
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3586
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3587
|
+
);
|
3475
3588
|
};
|
3476
3589
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3477
3590
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3748,6 +3861,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3748
3861
|
const attribute = model.attributes[attributeName];
|
3749
3862
|
switch (attribute.type) {
|
3750
3863
|
case "relation": {
|
3864
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3865
|
+
if (isMorphRelation) {
|
3866
|
+
break;
|
3867
|
+
}
|
3751
3868
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3752
3869
|
populateAcc[attributeName] = {
|
3753
3870
|
count: true,
|
@@ -3999,7 +4116,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
3999
4116
|
*/
|
4000
4117
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
4001
4118
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4002
|
-
|
4119
|
+
if (version.locale) {
|
4120
|
+
delete versionsByLocale[version.locale];
|
4121
|
+
}
|
4003
4122
|
const model = strapi2.getModel(uid2);
|
4004
4123
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4005
4124
|
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
@@ -4125,7 +4244,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4125
4244
|
*/
|
4126
4245
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4127
4246
|
if (!document) {
|
4128
|
-
return
|
4247
|
+
return {
|
4248
|
+
data: document,
|
4249
|
+
meta: {
|
4250
|
+
availableLocales: [],
|
4251
|
+
availableStatus: []
|
4252
|
+
}
|
4253
|
+
};
|
4129
4254
|
}
|
4130
4255
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4131
4256
|
if (!hasDraftAndPublish) {
|
@@ -4233,10 +4358,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4233
4358
|
async clone(id, body, uid2) {
|
4234
4359
|
const populate = await buildDeepPopulate(uid2);
|
4235
4360
|
const params = {
|
4236
|
-
data:
|
4237
|
-
...omitIdField(body),
|
4238
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4239
|
-
},
|
4361
|
+
data: omitIdField(body),
|
4240
4362
|
populate
|
4241
4363
|
};
|
4242
4364
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|