@strapi/content-manager 0.0.0-experimental.dd3311938ac827f1fa8560c8840a9a394f5896c0 → 0.0.0-experimental.e02b4637b3906c6d31048d00600d09a23a0edc3d

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.
Files changed (133) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs → ComponentConfigurationPage-DfFSZQxe.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs.map → ComponentConfigurationPage-DfFSZQxe.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js → ComponentConfigurationPage-FqfsxQ1j.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js.map → ComponentConfigurationPage-FqfsxQ1j.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js → EditConfigurationPage-Cn0e8t3I.js} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js.map → EditConfigurationPage-Cn0e8t3I.js.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs → EditConfigurationPage-DdPNAbl3.mjs} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs.map → EditConfigurationPage-DdPNAbl3.mjs.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-DWb0DE7R.mjs → EditViewPage-B82x_x1b.mjs} +69 -48
  11. package/dist/_chunks/EditViewPage-B82x_x1b.mjs.map +1 -0
  12. package/dist/_chunks/{EditViewPage-CTTDHKkQ.js → EditViewPage-DlxEHhUt.js} +68 -47
  13. package/dist/_chunks/EditViewPage-DlxEHhUt.js.map +1 -0
  14. package/dist/_chunks/{Field-C5Z1Ivdv.js → Field-COL25JiC.js} +581 -229
  15. package/dist/_chunks/Field-COL25JiC.js.map +1 -0
  16. package/dist/_chunks/{Field-DnStdvQw.mjs → Field-DufHXW17.mjs} +579 -227
  17. package/dist/_chunks/Field-DufHXW17.mjs.map +1 -0
  18. package/dist/_chunks/{Form-B81OtW-k.js → Form-BssUwrTO.js} +52 -34
  19. package/dist/_chunks/Form-BssUwrTO.js.map +1 -0
  20. package/dist/_chunks/{Form-DqGgE55Q.mjs → Form-u_kAOhwB.mjs} +54 -36
  21. package/dist/_chunks/Form-u_kAOhwB.mjs.map +1 -0
  22. package/dist/_chunks/{History-4NbOq2dX.js → History-C9t9UqpO.js} +68 -32
  23. package/dist/_chunks/History-C9t9UqpO.js.map +1 -0
  24. package/dist/_chunks/{History-DS6-HCYX.mjs → History-DRwA3oMM.mjs} +69 -33
  25. package/dist/_chunks/History-DRwA3oMM.mjs.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-CpfstlYY.js → ListConfigurationPage-BXYPohh-.js} +57 -46
  27. package/dist/_chunks/ListConfigurationPage-BXYPohh-.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-DQJJltko.mjs → ListConfigurationPage-BxfQJzPk.mjs} +58 -48
  29. package/dist/_chunks/ListConfigurationPage-BxfQJzPk.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-nQrOQuVo.mjs → ListViewPage-CELx2ysp.mjs} +103 -102
  31. package/dist/_chunks/ListViewPage-CELx2ysp.mjs.map +1 -0
  32. package/dist/_chunks/{ListViewPage-CA3I75m5.js → ListViewPage-D2VD8Szg.js} +105 -104
  33. package/dist/_chunks/ListViewPage-D2VD8Szg.js.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js → NoContentTypePage-BV9IjJSM.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js.map → NoContentTypePage-BV9IjJSM.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs → NoContentTypePage-DtJ9jcfk.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs.map → NoContentTypePage-DtJ9jcfk.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs → NoPermissionsPage-DWleVYK7.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs.map → NoPermissionsPage-DWleVYK7.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js → NoPermissionsPage-Dp8NpF9I.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js.map → NoPermissionsPage-Dp8NpF9I.js.map} +1 -1
  42. package/dist/_chunks/{Relations-BDRl99Ux.mjs → Relations-BTcf5xaw.mjs} +33 -24
  43. package/dist/_chunks/Relations-BTcf5xaw.mjs.map +1 -0
  44. package/dist/_chunks/{Relations-DG2jnOcr.js → Relations-DR7EUgyC.js} +33 -24
  45. package/dist/_chunks/Relations-DR7EUgyC.js.map +1 -0
  46. package/dist/_chunks/{en-fbKQxLGn.js → en-Bm0D0IWz.js} +17 -15
  47. package/dist/_chunks/{en-fbKQxLGn.js.map → en-Bm0D0IWz.js.map} +1 -1
  48. package/dist/_chunks/{en-Ux26r5pl.mjs → en-DKV44jRb.mjs} +17 -15
  49. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  50. package/dist/_chunks/{index-BZoNZMXL.js → index-BdMf2lfT.js} +1015 -862
  51. package/dist/_chunks/index-BdMf2lfT.js.map +1 -0
  52. package/dist/_chunks/{index-Drt2DN7v.mjs → index-wnqzm4Q8.mjs} +1025 -872
  53. package/dist/_chunks/index-wnqzm4Q8.mjs.map +1 -0
  54. package/dist/_chunks/{layout-BzAbmoO6.mjs → layout-2CfjL0T9.mjs} +27 -14
  55. package/dist/_chunks/layout-2CfjL0T9.mjs.map +1 -0
  56. package/dist/_chunks/{layout-DEYBqgF1.js → layout-B2MyZU-_.js} +25 -12
  57. package/dist/_chunks/layout-B2MyZU-_.js.map +1 -0
  58. package/dist/_chunks/{relations-D0eZ4VWw.js → relations-BH7JJGGe.js} +2 -2
  59. package/dist/_chunks/{relations-D0eZ4VWw.js.map → relations-BH7JJGGe.js.map} +1 -1
  60. package/dist/_chunks/{relations-D26zVRdi.mjs → relations-C0w0GcXi.mjs} +2 -2
  61. package/dist/_chunks/{relations-D26zVRdi.mjs.map → relations-C0w0GcXi.mjs.map} +1 -1
  62. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  63. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  65. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  66. package/dist/admin/index.js +2 -1
  67. package/dist/admin/index.js.map +1 -1
  68. package/dist/admin/index.mjs +3 -2
  69. package/dist/admin/src/exports.d.ts +1 -1
  70. package/dist/admin/src/history/index.d.ts +3 -0
  71. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  72. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  73. package/dist/admin/src/index.d.ts +1 -0
  74. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
  75. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  76. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  77. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  78. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  79. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
  80. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  81. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  82. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  83. package/dist/admin/src/services/api.d.ts +1 -1
  84. package/dist/admin/src/services/components.d.ts +2 -2
  85. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  86. package/dist/admin/src/services/documents.d.ts +19 -17
  87. package/dist/admin/src/services/init.d.ts +1 -1
  88. package/dist/admin/src/services/relations.d.ts +2 -2
  89. package/dist/admin/src/services/uid.d.ts +3 -3
  90. package/dist/admin/src/utils/validation.d.ts +4 -1
  91. package/dist/server/index.js +208 -123
  92. package/dist/server/index.js.map +1 -1
  93. package/dist/server/index.mjs +209 -124
  94. package/dist/server/index.mjs.map +1 -1
  95. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  96. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  97. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  98. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  99. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  100. package/dist/server/src/history/services/history.d.ts.map +1 -1
  101. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  102. package/dist/server/src/history/services/utils.d.ts +2 -1
  103. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  104. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  105. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  106. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  107. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  108. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  109. package/dist/shared/contracts/collection-types.d.ts +3 -1
  110. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  111. package/package.json +12 -12
  112. package/dist/_chunks/EditViewPage-CTTDHKkQ.js.map +0 -1
  113. package/dist/_chunks/EditViewPage-DWb0DE7R.mjs.map +0 -1
  114. package/dist/_chunks/Field-C5Z1Ivdv.js.map +0 -1
  115. package/dist/_chunks/Field-DnStdvQw.mjs.map +0 -1
  116. package/dist/_chunks/Form-B81OtW-k.js.map +0 -1
  117. package/dist/_chunks/Form-DqGgE55Q.mjs.map +0 -1
  118. package/dist/_chunks/History-4NbOq2dX.js.map +0 -1
  119. package/dist/_chunks/History-DS6-HCYX.mjs.map +0 -1
  120. package/dist/_chunks/ListConfigurationPage-CpfstlYY.js.map +0 -1
  121. package/dist/_chunks/ListConfigurationPage-DQJJltko.mjs.map +0 -1
  122. package/dist/_chunks/ListViewPage-CA3I75m5.js.map +0 -1
  123. package/dist/_chunks/ListViewPage-nQrOQuVo.mjs.map +0 -1
  124. package/dist/_chunks/Relations-BDRl99Ux.mjs.map +0 -1
  125. package/dist/_chunks/Relations-DG2jnOcr.js.map +0 -1
  126. package/dist/_chunks/index-BZoNZMXL.js.map +0 -1
  127. package/dist/_chunks/index-Drt2DN7v.mjs.map +0 -1
  128. package/dist/_chunks/layout-BzAbmoO6.mjs.map +0 -1
  129. package/dist/_chunks/layout-DEYBqgF1.js.map +0 -1
  130. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  131. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  132. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  133. package/strapi-server.js +0 -3
@@ -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,20 +228,25 @@ 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
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
239
+ if (isMorphRelation) {
240
+ break;
241
+ }
235
242
  const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
236
243
  if (isVisible2) {
237
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
244
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
238
245
  }
239
246
  break;
240
247
  }
241
248
  case "media": {
242
- acc[attributeName] = { fields: ["id"] };
249
+ acc[attributeName] = { [fieldSelector]: ["id"] };
243
250
  break;
244
251
  }
245
252
  case "component": {
@@ -312,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
312
319
  getRelationRestoreValue,
313
320
  getMediaRestoreValue,
314
321
  getDefaultLocale,
322
+ isLocalizedContentType,
315
323
  getLocaleDictionary,
316
324
  getRetentionDays,
317
325
  getVersionStatus,
@@ -334,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
334
342
  });
335
343
  },
336
344
  async findVersionsPage(params) {
337
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
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
+ }
338
352
  const [{ results, pagination }, localeDictionary] = await Promise.all([
339
353
  query.findPage({
340
354
  ...params.query,
@@ -379,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
379
393
  if (userToPopulate == null) {
380
394
  return null;
381
395
  }
382
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
396
+ return strapi2.query("admin::user").findOne({
397
+ where: {
398
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
399
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
400
+ }
401
+ });
383
402
  })
384
403
  );
385
404
  return {
@@ -490,13 +509,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
490
509
  }
491
510
  };
492
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
+ };
493
548
  const createLifecyclesService = ({ strapi: strapi2 }) => {
494
549
  const state = {
495
550
  deleteExpiredJob: null,
496
551
  isInitialized: false
497
552
  };
498
- const query = strapi2.db.query(HISTORY_VERSION_UID);
499
- const historyService = getService(strapi2, "history");
500
553
  const serviceUtils = createServiceUtils({ strapi: strapi2 });
501
554
  return {
502
555
  async bootstrap() {
@@ -504,63 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
504
557
  return;
505
558
  }
506
559
  strapi2.documents.use(async (context, next) => {
507
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
508
- return next();
509
- }
510
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
511
- return next();
512
- }
513
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
514
- return next();
515
- }
516
- const contentTypeUid = context.contentType.uid;
517
- if (!contentTypeUid.startsWith("api::")) {
518
- return next();
519
- }
520
560
  const result = await next();
521
- const documentContext = {
522
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
523
- locale: context.params?.locale
524
- };
561
+ if (!shouldCreateHistoryVersion(context)) {
562
+ return result;
563
+ }
564
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
525
565
  const defaultLocale = await serviceUtils.getDefaultLocale();
526
- const locale = documentContext.locale || defaultLocale;
527
- if (Array.isArray(locale)) {
528
- strapi2.log.warn(
529
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
530
- );
531
- return next();
566
+ const locales = fp.castArray(context.params?.locale || defaultLocale);
567
+ if (!locales.length) {
568
+ return result;
532
569
  }
533
- const document = await strapi2.documents(contentTypeUid).findOne({
534
- documentId: documentContext.documentId,
535
- locale,
536
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
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
+ )
537
585
  });
538
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
539
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
540
- const componentsSchemas = Object.keys(
541
- attributesSchema
542
- ).reduce((currentComponentSchemas, key) => {
543
- const fieldSchema = attributesSchema[key];
544
- if (fieldSchema.type === "component") {
545
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
546
- return {
547
- ...currentComponentSchemas,
548
- [fieldSchema.component]: componentSchema
549
- };
550
- }
551
- return currentComponentSchemas;
552
- }, {});
553
586
  await strapi2.db.transaction(async ({ onCommit }) => {
554
- onCommit(() => {
555
- historyService.createVersion({
556
- contentType: contentTypeUid,
557
- data: fp.omit(FIELDS_TO_IGNORE, document),
558
- schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
559
- componentsSchemas,
560
- relatedDocumentId: documentContext.documentId,
561
- locale,
562
- status
563
- });
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
+ }
564
599
  });
565
600
  });
566
601
  return result;
@@ -568,7 +603,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
568
603
  state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
569
604
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
570
605
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
571
- query.deleteMany({
606
+ strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
572
607
  where: {
573
608
  created_at: {
574
609
  $lt: expirationDate.toISOString()
@@ -1200,6 +1235,11 @@ const { createPolicy } = strapiUtils.policy;
1200
1235
  const hasPermissions = createPolicy({
1201
1236
  name: "plugin::content-manager.hasPermissions",
1202
1237
  validator: validateHasPermissionsInput,
1238
+ /**
1239
+ * NOTE: Action aliases are currently not checked at this level (policy).
1240
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1241
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1242
+ */
1203
1243
  handler(ctx, config = {}) {
1204
1244
  const { actions = [], hasAtLeastOne = false } = config;
1205
1245
  const { userAbility } = ctx.state;
@@ -1593,9 +1633,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
1593
1633
  (value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1594
1634
  );
1595
1635
  const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
1596
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1636
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1597
1637
  const { allowMultipleLocales } = opts;
1598
- const { locale, status, ...rest } = request || {};
1638
+ const { locale, status: providedStatus, ...rest } = request || {};
1639
+ const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1640
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1599
1641
  const schema = strapiUtils.yup.object().shape({
1600
1642
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1601
1643
  status: statusSchema
@@ -1643,7 +1685,7 @@ const createDocument = async (ctx, opts) => {
1643
1685
  const setCreator = strapiUtils.setCreatorFields({ user });
1644
1686
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1645
1687
  const sanitizedBody = await sanitizeFn(body);
1646
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1688
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1647
1689
  return documentManager2.create(model, {
1648
1690
  data: sanitizedBody,
1649
1691
  locale,
@@ -1662,7 +1704,7 @@ const updateDocument = async (ctx, opts) => {
1662
1704
  }
1663
1705
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1664
1706
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1665
- const { locale } = await getDocumentLocaleAndStatus(body);
1707
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1666
1708
  const [documentVersion, documentExists] = await Promise.all([
1667
1709
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1668
1710
  documentManager2.exists(model, id)
@@ -1678,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
1678
1720
  throw new strapiUtils.errors.ForbiddenError();
1679
1721
  }
1680
1722
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1681
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1723
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1682
1724
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1683
1725
  const sanitizedBody = await sanitizeFn(body);
1684
1726
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1700,7 +1742,7 @@ const collectionTypes = {
1700
1742
  }
1701
1743
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1702
1744
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1703
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1745
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1704
1746
  const { results: documents, pagination } = await documentManager2.findPage(
1705
1747
  { ...permissionQuery, populate, locale, status },
1706
1748
  model
@@ -1735,7 +1777,7 @@ const collectionTypes = {
1735
1777
  }
1736
1778
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1737
1779
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1738
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1780
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1739
1781
  const version = await documentManager2.findOne(id, model, {
1740
1782
  populate,
1741
1783
  locale,
@@ -1750,7 +1792,7 @@ const collectionTypes = {
1750
1792
  permissionChecker2,
1751
1793
  model,
1752
1794
  // @ts-expect-error TODO: fix
1753
- { id, locale, publishedAt: null },
1795
+ { documentId: id, locale, publishedAt: null },
1754
1796
  { availableLocales: true, availableStatus: false }
1755
1797
  );
1756
1798
  ctx.body = { data: {}, meta };
@@ -1802,7 +1844,7 @@ const collectionTypes = {
1802
1844
  }
1803
1845
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1804
1846
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1805
- const { locale } = await getDocumentLocaleAndStatus(body);
1847
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1806
1848
  const document = await documentManager2.findOne(id, model, {
1807
1849
  populate,
1808
1850
  locale,
@@ -1847,7 +1889,7 @@ const collectionTypes = {
1847
1889
  }
1848
1890
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1849
1891
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1850
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1892
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1851
1893
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1852
1894
  if (documentLocales.length === 0) {
1853
1895
  return ctx.notFound();
@@ -1876,11 +1918,34 @@ const collectionTypes = {
1876
1918
  const publishedDocument = await strapi.db.transaction(async () => {
1877
1919
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1878
1920
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1879
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1921
+ let document;
1922
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1923
+ const isCreate = fp.isNil(id);
1924
+ if (isCreate) {
1925
+ if (permissionChecker2.cannot.create()) {
1926
+ throw new strapiUtils.errors.ForbiddenError();
1927
+ }
1928
+ document = await createDocument(ctx, { populate });
1929
+ }
1930
+ const isUpdate = !isCreate;
1931
+ if (isUpdate) {
1932
+ const documentExists = documentManager2.exists(model, id);
1933
+ if (!documentExists) {
1934
+ throw new strapiUtils.errors.NotFoundError("Document not found");
1935
+ }
1936
+ document = await documentManager2.findOne(id, model, { populate, locale });
1937
+ if (!document) {
1938
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1939
+ throw new strapiUtils.errors.ForbiddenError();
1940
+ }
1941
+ document = await updateDocument(ctx);
1942
+ } else if (permissionChecker2.can.update(document)) {
1943
+ await updateDocument(ctx);
1944
+ }
1945
+ }
1880
1946
  if (permissionChecker2.cannot.publish(document)) {
1881
1947
  throw new strapiUtils.errors.ForbiddenError();
1882
1948
  }
1883
- const { locale } = await getDocumentLocaleAndStatus(body);
1884
1949
  const publishResult = await documentManager2.publish(document.documentId, model, {
1885
1950
  locale
1886
1951
  // TODO: Allow setting creator fields on publish
@@ -1907,7 +1972,9 @@ const collectionTypes = {
1907
1972
  }
1908
1973
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1909
1974
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1910
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1975
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1976
+ allowMultipleLocales: true
1977
+ });
1911
1978
  const entityPromises = documentIds.map(
1912
1979
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1913
1980
  );
@@ -1934,7 +2001,9 @@ const collectionTypes = {
1934
2001
  if (permissionChecker2.cannot.unpublish()) {
1935
2002
  return ctx.forbidden();
1936
2003
  }
1937
- const { locale } = await getDocumentLocaleAndStatus(body);
2004
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2005
+ allowMultipleLocales: true
2006
+ });
1938
2007
  const entityPromises = documentIds.map(
1939
2008
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1940
2009
  );
@@ -1967,7 +2036,7 @@ const collectionTypes = {
1967
2036
  }
1968
2037
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1969
2038
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1970
- const { locale } = await getDocumentLocaleAndStatus(body);
2039
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1971
2040
  const document = await documentManager2.findOne(id, model, {
1972
2041
  populate,
1973
2042
  locale,
@@ -2004,7 +2073,7 @@ const collectionTypes = {
2004
2073
  }
2005
2074
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2006
2075
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2007
- const { locale } = await getDocumentLocaleAndStatus(body);
2076
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2008
2077
  const document = await documentManager2.findOne(id, model, {
2009
2078
  populate,
2010
2079
  locale,
@@ -2035,7 +2104,7 @@ const collectionTypes = {
2035
2104
  }
2036
2105
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2037
2106
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2038
- const { locale } = await getDocumentLocaleAndStatus(body);
2107
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2039
2108
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2040
2109
  populate,
2041
2110
  locale
@@ -2062,7 +2131,7 @@ const collectionTypes = {
2062
2131
  }
2063
2132
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2064
2133
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2065
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2134
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2066
2135
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2067
2136
  if (!entity) {
2068
2137
  return ctx.notFound();
@@ -2085,7 +2154,7 @@ const collectionTypes = {
2085
2154
  if (permissionChecker2.cannot.read()) {
2086
2155
  return ctx.forbidden();
2087
2156
  }
2088
- const entities = await documentManager2.findMany(
2157
+ const documents = await documentManager2.findMany(
2089
2158
  {
2090
2159
  filters: {
2091
2160
  documentId: ids
@@ -2094,7 +2163,7 @@ const collectionTypes = {
2094
2163
  },
2095
2164
  model
2096
2165
  );
2097
- if (!entities) {
2166
+ if (!documents) {
2098
2167
  return ctx.notFound();
2099
2168
  }
2100
2169
  const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
@@ -2285,20 +2354,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2285
2354
  userAbility,
2286
2355
  model: model.uid
2287
2356
  });
2288
- if (!isListable(model, mainField)) {
2357
+ const isMainFieldListable = isListable(model, mainField);
2358
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2359
+ if (!isMainFieldListable || !canReadMainField) {
2289
2360
  return "id";
2290
2361
  }
2291
- if (permissionChecker2.cannot.read(null, mainField)) {
2292
- if (model.uid === "plugin::users-permissions.role") {
2293
- const userPermissionChecker = getService$1("permission-checker").create({
2294
- userAbility,
2295
- model: "plugin::users-permissions.user"
2296
- });
2297
- if (userPermissionChecker.can.read()) {
2298
- return "name";
2299
- }
2300
- }
2301
- return "id";
2362
+ if (model.uid === "plugin::users-permissions.role") {
2363
+ return "name";
2302
2364
  }
2303
2365
  return mainField;
2304
2366
  };
@@ -2331,11 +2393,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2331
2393
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2332
2394
  const isSourceLocalized = isLocalized(sourceModel);
2333
2395
  const isTargetLocalized = isLocalized(targetModel);
2334
- let validatedLocale = locale;
2335
- if (!targetModel || !isTargetLocalized)
2336
- validatedLocale = void 0;
2337
2396
  return {
2338
- locale: validatedLocale,
2397
+ locale,
2339
2398
  isSourceLocalized,
2340
2399
  isTargetLocalized
2341
2400
  };
@@ -2438,7 +2497,7 @@ const relations = {
2438
2497
  attribute,
2439
2498
  fieldsToSelect,
2440
2499
  mainField,
2441
- source: { schema: sourceSchema },
2500
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2442
2501
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2443
2502
  sourceSchema,
2444
2503
  targetSchema,
@@ -2460,7 +2519,8 @@ const relations = {
2460
2519
  fieldsToSelect,
2461
2520
  mainField,
2462
2521
  source: {
2463
- schema: { uid: sourceUid, modelType: sourceModelType }
2522
+ schema: { uid: sourceUid, modelType: sourceModelType },
2523
+ isLocalized: isSourceLocalized
2464
2524
  },
2465
2525
  target: {
2466
2526
  schema: { uid: targetUid },
@@ -2498,12 +2558,16 @@ const relations = {
2498
2558
  } else {
2499
2559
  where.id = id;
2500
2560
  }
2501
- if (status) {
2502
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2561
+ const publishedAt = getPublishedAtClause(status, targetUid);
2562
+ if (!fp.isEmpty(publishedAt)) {
2563
+ where[`${alias}.published_at`] = publishedAt;
2503
2564
  }
2504
- if (filterByLocale) {
2565
+ if (isTargetLocalized && locale) {
2505
2566
  where[`${alias}.locale`] = locale;
2506
2567
  }
2568
+ if (isSourceLocalized && locale) {
2569
+ where.locale = locale;
2570
+ }
2507
2571
  if ((idsToInclude?.length ?? 0) !== 0) {
2508
2572
  where[`${alias}.id`].$notIn = idsToInclude;
2509
2573
  }
@@ -2521,7 +2585,8 @@ const relations = {
2521
2585
  id: { $notIn: fp.uniq(idsToOmit) }
2522
2586
  });
2523
2587
  }
2524
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2588
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2589
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2525
2590
  ctx.body = {
2526
2591
  ...res,
2527
2592
  results: await addStatusToRelations(targetUid, res.results)
@@ -2556,9 +2621,7 @@ const relations = {
2556
2621
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2557
2622
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2558
2623
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2559
- ordering: "desc",
2560
- page: ctx.request.query.page,
2561
- pageSize: ctx.request.query.pageSize
2624
+ ordering: "desc"
2562
2625
  });
2563
2626
  const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
2564
2627
  ctx.body = {
@@ -2590,7 +2653,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2590
2653
  throw new strapiUtils.errors.ForbiddenError();
2591
2654
  }
2592
2655
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2593
- const { locale } = await getDocumentLocaleAndStatus(body);
2656
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2594
2657
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2595
2658
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2596
2659
  // Find the first document to check if it exists
@@ -2631,7 +2694,7 @@ const singleTypes = {
2631
2694
  return ctx.forbidden();
2632
2695
  }
2633
2696
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2634
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2697
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2635
2698
  const version = await findDocument(permissionQuery, model, { locale, status });
2636
2699
  if (!version) {
2637
2700
  if (permissionChecker2.cannot.create()) {
@@ -2645,7 +2708,7 @@ const singleTypes = {
2645
2708
  permissionChecker2,
2646
2709
  model,
2647
2710
  // @ts-expect-error - fix types
2648
- { id: document.documentId, locale, publishedAt: null },
2711
+ { documentId: document.documentId, locale, publishedAt: null },
2649
2712
  { availableLocales: true, availableStatus: false }
2650
2713
  );
2651
2714
  ctx.body = { data: {}, meta };
@@ -2676,7 +2739,7 @@ const singleTypes = {
2676
2739
  }
2677
2740
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2678
2741
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2679
- const { locale } = await getDocumentLocaleAndStatus(query);
2742
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2680
2743
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2681
2744
  populate,
2682
2745
  locale
@@ -2713,7 +2776,7 @@ const singleTypes = {
2713
2776
  if (permissionChecker2.cannot.publish(document)) {
2714
2777
  throw new strapiUtils.errors.ForbiddenError();
2715
2778
  }
2716
- const { locale } = await getDocumentLocaleAndStatus(document);
2779
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2717
2780
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2718
2781
  return publishResult.at(0);
2719
2782
  });
@@ -2736,7 +2799,7 @@ const singleTypes = {
2736
2799
  return ctx.forbidden();
2737
2800
  }
2738
2801
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2739
- const { locale } = await getDocumentLocaleAndStatus(body);
2802
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2740
2803
  const document = await findDocument(sanitizedQuery, model, { locale });
2741
2804
  if (!document) {
2742
2805
  return ctx.notFound();
@@ -2768,7 +2831,7 @@ const singleTypes = {
2768
2831
  return ctx.forbidden();
2769
2832
  }
2770
2833
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2771
- const { locale } = await getDocumentLocaleAndStatus(body);
2834
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2772
2835
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2773
2836
  if (!document) {
2774
2837
  return ctx.notFound();
@@ -2788,7 +2851,7 @@ const singleTypes = {
2788
2851
  const { query } = ctx.request;
2789
2852
  const documentManager2 = getService$1("document-manager");
2790
2853
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2791
- const { locale } = await getDocumentLocaleAndStatus(query);
2854
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2792
2855
  if (permissionChecker2.cannot.read()) {
2793
2856
  return ctx.forbidden();
2794
2857
  }
@@ -2809,7 +2872,7 @@ const uid$1 = {
2809
2872
  async generateUID(ctx) {
2810
2873
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2811
2874
  const { query = {} } = ctx.request;
2812
- const { locale } = await getDocumentLocaleAndStatus(query);
2875
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2813
2876
  await validateUIDField(contentTypeUID, field);
2814
2877
  const uidService = getService$1("uid");
2815
2878
  ctx.body = {
@@ -2821,7 +2884,7 @@ const uid$1 = {
2821
2884
  ctx.request.body
2822
2885
  );
2823
2886
  const { query = {} } = ctx.request;
2824
- const { locale } = await getDocumentLocaleAndStatus(query);
2887
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2825
2888
  await validateUIDField(contentTypeUID, field);
2826
2889
  const uidService = getService$1("uid");
2827
2890
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3464,12 +3527,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3464
3527
  ability: userAbility,
3465
3528
  model
3466
3529
  });
3467
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3530
+ const { actionProvider } = strapi2.service("admin::permission");
3531
+ const toSubject = (entity) => {
3532
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3533
+ };
3468
3534
  const can = (action, entity, field) => {
3469
- return userAbility.can(action, toSubject(entity), field);
3535
+ const subject = toSubject(entity);
3536
+ const aliases = actionProvider.unstable_aliases(action, model);
3537
+ return (
3538
+ // Test the original action to see if it passes
3539
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3540
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3541
+ );
3470
3542
  };
3471
3543
  const cannot = (action, entity, field) => {
3472
- return userAbility.cannot(action, toSubject(entity), field);
3544
+ const subject = toSubject(entity);
3545
+ const aliases = actionProvider.unstable_aliases(action, model);
3546
+ return (
3547
+ // Test both the original action
3548
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3549
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3550
+ );
3473
3551
  };
3474
3552
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3475
3553
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3746,6 +3824,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3746
3824
  const attribute = model.attributes[attributeName];
3747
3825
  switch (attribute.type) {
3748
3826
  case "relation": {
3827
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3828
+ if (isMorphRelation) {
3829
+ break;
3830
+ }
3749
3831
  if (isVisibleAttribute$1(model, attributeName)) {
3750
3832
  populateAcc[attributeName] = {
3751
3833
  count: true,
@@ -4123,7 +4205,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4123
4205
  */
4124
4206
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4125
4207
  if (!document) {
4126
- return document;
4208
+ return {
4209
+ data: document,
4210
+ meta: {
4211
+ availableLocales: [],
4212
+ availableStatus: []
4213
+ }
4214
+ };
4127
4215
  }
4128
4216
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4129
4217
  if (!hasDraftAndPublish) {
@@ -4231,10 +4319,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4231
4319
  async clone(id, body, uid2) {
4232
4320
  const populate = await buildDeepPopulate(uid2);
4233
4321
  const params = {
4234
- data: {
4235
- ...omitIdField(body),
4236
- [PUBLISHED_AT_ATTRIBUTE]: null
4237
- },
4322
+ data: omitIdField(body),
4238
4323
  populate
4239
4324
  };
4240
4325
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));