@strapi/content-manager 0.0.0-experimental.545ccead2ee1717bbc7ab950455dbb0ddb9924a3 → 0.0.0-experimental.56109c4ad2fb374b04c392a229599354fa6586e1

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 (134) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js → ComponentConfigurationPage-CQDCxI8x.js} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js.map → ComponentConfigurationPage-CQDCxI8x.js.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs → ComponentConfigurationPage-jmWwucg_.mjs} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs.map → ComponentConfigurationPage-jmWwucg_.mjs.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js → EditConfigurationPage-Ce4bIm4n.js} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js.map → EditConfigurationPage-Ce4bIm4n.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs → EditConfigurationPage-W07CEdm2.mjs} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs.map → EditConfigurationPage-W07CEdm2.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-DA95Ha6J.js → EditViewPage-CqHMM0P0.js} +30 -9
  10. package/dist/_chunks/EditViewPage-CqHMM0P0.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-DlLEyUL6.mjs → EditViewPage-al5OO1NR.mjs} +30 -9
  12. package/dist/_chunks/EditViewPage-al5OO1NR.mjs.map +1 -0
  13. package/dist/_chunks/{Field-CnK8dO8N.js → Field-DSOUlTCm.js} +179 -107
  14. package/dist/_chunks/Field-DSOUlTCm.js.map +1 -0
  15. package/dist/_chunks/{Field-Dq7bDnuh.mjs → Field-EeG6NQ7x.mjs} +177 -105
  16. package/dist/_chunks/Field-EeG6NQ7x.mjs.map +1 -0
  17. package/dist/_chunks/{Form-B_JE0dbz.mjs → Form-BAo9ANb_.mjs} +36 -17
  18. package/dist/_chunks/Form-BAo9ANb_.mjs.map +1 -0
  19. package/dist/_chunks/{Form-BpiR4piS.js → Form-DAEfHKzm.js} +36 -17
  20. package/dist/_chunks/Form-DAEfHKzm.js.map +1 -0
  21. package/dist/_chunks/{History-CBNGU7a-.mjs → History-BpLIu67W.mjs} +41 -18
  22. package/dist/_chunks/History-BpLIu67W.mjs.map +1 -0
  23. package/dist/_chunks/{History-DdIstl8b.js → History-CTFvy6XH.js} +40 -17
  24. package/dist/_chunks/History-CTFvy6XH.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-DkKRparB.js → ListConfigurationPage-CDzlMBz_.js} +14 -4
  26. package/dist/_chunks/ListConfigurationPage-CDzlMBz_.js.map +1 -0
  27. package/dist/_chunks/{ListConfigurationPage-5dr4qpue.mjs → ListConfigurationPage-DOqj5f8Y.mjs} +14 -4
  28. package/dist/_chunks/ListConfigurationPage-DOqj5f8Y.mjs.map +1 -0
  29. package/dist/_chunks/{ListViewPage-DecLrYV6.mjs → ListViewPage-BbXYNI0v.mjs} +47 -38
  30. package/dist/_chunks/ListViewPage-BbXYNI0v.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-wE0lXqoD.js → ListViewPage-D0fpPYKp.js} +49 -40
  32. package/dist/_chunks/ListViewPage-D0fpPYKp.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js → NoContentTypePage-DTzkSAV5.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js.map → NoContentTypePage-DTzkSAV5.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs → NoContentTypePage-w2Q0VVOT.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs.map → NoContentTypePage-w2Q0VVOT.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js → NoPermissionsPage-BoI2rU68.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js.map → NoPermissionsPage-BoI2rU68.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs → NoPermissionsPage-Km0Vk5Wp.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs.map → NoPermissionsPage-Km0Vk5Wp.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-Dqz0C1fz.mjs → Relations-C_bpmSuQ.mjs} +51 -29
  42. package/dist/_chunks/Relations-C_bpmSuQ.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-L0xYRoSQ.js → Relations-D6Nz5ksc.js} +51 -29
  44. package/dist/_chunks/Relations-D6Nz5ksc.js.map +1 -0
  45. package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
  46. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
  47. package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
  48. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  49. package/dist/_chunks/{index-DyvUPg1a.js → index-BsMu2oVP.js} +726 -530
  50. package/dist/_chunks/index-BsMu2oVP.js.map +1 -0
  51. package/dist/_chunks/{index-BSn97i8U.mjs → index-DcQ6xogO.mjs} +745 -550
  52. package/dist/_chunks/index-DcQ6xogO.mjs.map +1 -0
  53. package/dist/_chunks/{layout-TPqF2oJ5.js → layout-B4aCAdTt.js} +21 -8
  54. package/dist/_chunks/layout-B4aCAdTt.js.map +1 -0
  55. package/dist/_chunks/{layout-DPaHUusj.mjs → layout-BavJ6v4B.mjs} +22 -9
  56. package/dist/_chunks/layout-BavJ6v4B.mjs.map +1 -0
  57. package/dist/_chunks/{relations-Ck7-ecDT.mjs → relations-DMG453Od.mjs} +2 -2
  58. package/dist/_chunks/{relations-Ck7-ecDT.mjs.map → relations-DMG453Od.mjs.map} +1 -1
  59. package/dist/_chunks/{relations-BWYS9gkn.js → relations-Lrm9nz_m.js} +2 -2
  60. package/dist/_chunks/{relations-BWYS9gkn.js.map → relations-Lrm9nz_m.js.map} +1 -1
  61. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  62. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  63. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  65. package/dist/admin/index.js +2 -1
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +5 -4
  68. package/dist/admin/src/exports.d.ts +1 -1
  69. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  70. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  71. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  72. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  73. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  74. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  75. package/dist/admin/src/services/api.d.ts +1 -1
  76. package/dist/admin/src/services/components.d.ts +2 -2
  77. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  78. package/dist/admin/src/services/documents.d.ts +19 -17
  79. package/dist/admin/src/services/init.d.ts +1 -1
  80. package/dist/admin/src/services/relations.d.ts +2 -2
  81. package/dist/admin/src/services/uid.d.ts +3 -3
  82. package/dist/admin/src/utils/validation.d.ts +4 -1
  83. package/dist/server/index.js +241 -132
  84. package/dist/server/index.js.map +1 -1
  85. package/dist/server/index.mjs +242 -133
  86. package/dist/server/index.mjs.map +1 -1
  87. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  88. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  89. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  90. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  91. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  92. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  93. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  94. package/dist/server/src/history/services/history.d.ts.map +1 -1
  95. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  96. package/dist/server/src/history/services/utils.d.ts +2 -1
  97. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  98. package/dist/server/src/index.d.ts +4 -4
  99. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  100. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  101. package/dist/server/src/services/document-metadata.d.ts +8 -8
  102. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  103. package/dist/server/src/services/index.d.ts +4 -4
  104. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  105. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  106. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  107. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  108. package/dist/server/src/utils/index.d.ts +2 -0
  109. package/dist/server/src/utils/index.d.ts.map +1 -1
  110. package/dist/shared/contracts/collection-types.d.ts +3 -1
  111. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  112. package/package.json +12 -12
  113. package/dist/_chunks/EditViewPage-DA95Ha6J.js.map +0 -1
  114. package/dist/_chunks/EditViewPage-DlLEyUL6.mjs.map +0 -1
  115. package/dist/_chunks/Field-CnK8dO8N.js.map +0 -1
  116. package/dist/_chunks/Field-Dq7bDnuh.mjs.map +0 -1
  117. package/dist/_chunks/Form-B_JE0dbz.mjs.map +0 -1
  118. package/dist/_chunks/Form-BpiR4piS.js.map +0 -1
  119. package/dist/_chunks/History-CBNGU7a-.mjs.map +0 -1
  120. package/dist/_chunks/History-DdIstl8b.js.map +0 -1
  121. package/dist/_chunks/ListConfigurationPage-5dr4qpue.mjs.map +0 -1
  122. package/dist/_chunks/ListConfigurationPage-DkKRparB.js.map +0 -1
  123. package/dist/_chunks/ListViewPage-DecLrYV6.mjs.map +0 -1
  124. package/dist/_chunks/ListViewPage-wE0lXqoD.js.map +0 -1
  125. package/dist/_chunks/Relations-Dqz0C1fz.mjs.map +0 -1
  126. package/dist/_chunks/Relations-L0xYRoSQ.js.map +0 -1
  127. package/dist/_chunks/index-BSn97i8U.mjs.map +0 -1
  128. package/dist/_chunks/index-DyvUPg1a.js.map +0 -1
  129. package/dist/_chunks/layout-DPaHUusj.mjs.map +0 -1
  130. package/dist/_chunks/layout-TPqF2oJ5.js.map +0 -1
  131. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  132. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  133. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  134. 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,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] = { fields: ["documentId", "locale", "publishedAt"] };
244
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
242
245
  }
243
246
  break;
244
247
  }
245
248
  case "media": {
246
- acc[attributeName] = { fields: ["id"] };
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 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
+ }
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({ 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
+ });
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
- const documentContext = {
524
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
525
- locale: context.params?.locale
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 locale = documentContext.locale || defaultLocale;
529
- if (Array.isArray(locale)) {
530
- strapi2.log.warn(
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 document = await strapi2.documents(contentTypeUid).findOne({
536
- documentId: documentContext.documentId,
537
- locale,
538
- 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
+ )
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
- getService(strapi2, "history").createVersion({
558
- contentType: contentTypeUid,
559
- data: fp.omit(FIELDS_TO_IGNORE, document),
560
- schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
561
- componentsSchemas,
562
- relatedDocumentId: documentContext.documentId,
563
- locale,
564
- status
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;
@@ -1202,6 +1235,11 @@ const { createPolicy } = strapiUtils.policy;
1202
1235
  const hasPermissions = createPolicy({
1203
1236
  name: "plugin::content-manager.hasPermissions",
1204
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
+ */
1205
1243
  handler(ctx, config = {}) {
1206
1244
  const { actions = [], hasAtLeastOne = false } = config;
1207
1245
  const { userAbility } = ctx.state;
@@ -1595,9 +1633,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
1595
1633
  (value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1596
1634
  );
1597
1635
  const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
1598
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1636
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1599
1637
  const { allowMultipleLocales } = opts;
1600
- 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;
1601
1641
  const schema = strapiUtils.yup.object().shape({
1602
1642
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1603
1643
  status: statusSchema
@@ -1645,7 +1685,7 @@ const createDocument = async (ctx, opts) => {
1645
1685
  const setCreator = strapiUtils.setCreatorFields({ user });
1646
1686
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1647
1687
  const sanitizedBody = await sanitizeFn(body);
1648
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1688
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1649
1689
  return documentManager2.create(model, {
1650
1690
  data: sanitizedBody,
1651
1691
  locale,
@@ -1664,7 +1704,7 @@ const updateDocument = async (ctx, opts) => {
1664
1704
  }
1665
1705
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1666
1706
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1667
- const { locale } = await getDocumentLocaleAndStatus(body);
1707
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1668
1708
  const [documentVersion, documentExists] = await Promise.all([
1669
1709
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1670
1710
  documentManager2.exists(model, id)
@@ -1680,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
1680
1720
  throw new strapiUtils.errors.ForbiddenError();
1681
1721
  }
1682
1722
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1683
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1723
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1684
1724
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1685
1725
  const sanitizedBody = await sanitizeFn(body);
1686
1726
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1702,7 +1742,7 @@ const collectionTypes = {
1702
1742
  }
1703
1743
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1704
1744
  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);
1745
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1706
1746
  const { results: documents, pagination } = await documentManager2.findPage(
1707
1747
  { ...permissionQuery, populate, locale, status },
1708
1748
  model
@@ -1737,7 +1777,7 @@ const collectionTypes = {
1737
1777
  }
1738
1778
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1739
1779
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1740
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1780
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1741
1781
  const version = await documentManager2.findOne(id, model, {
1742
1782
  populate,
1743
1783
  locale,
@@ -1752,7 +1792,7 @@ const collectionTypes = {
1752
1792
  permissionChecker2,
1753
1793
  model,
1754
1794
  // @ts-expect-error TODO: fix
1755
- { id, locale, publishedAt: null },
1795
+ { documentId: id, locale, publishedAt: null },
1756
1796
  { availableLocales: true, availableStatus: false }
1757
1797
  );
1758
1798
  ctx.body = { data: {}, meta };
@@ -1804,7 +1844,7 @@ const collectionTypes = {
1804
1844
  }
1805
1845
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1806
1846
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1807
- const { locale } = await getDocumentLocaleAndStatus(body);
1847
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1808
1848
  const document = await documentManager2.findOne(id, model, {
1809
1849
  populate,
1810
1850
  locale,
@@ -1849,7 +1889,7 @@ const collectionTypes = {
1849
1889
  }
1850
1890
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1851
1891
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1852
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1892
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1853
1893
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1854
1894
  if (documentLocales.length === 0) {
1855
1895
  return ctx.notFound();
@@ -1878,11 +1918,34 @@ const collectionTypes = {
1878
1918
  const publishedDocument = await strapi.db.transaction(async () => {
1879
1919
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1880
1920
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1881
- 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
+ }
1882
1946
  if (permissionChecker2.cannot.publish(document)) {
1883
1947
  throw new strapiUtils.errors.ForbiddenError();
1884
1948
  }
1885
- const { locale } = await getDocumentLocaleAndStatus(body);
1886
1949
  const publishResult = await documentManager2.publish(document.documentId, model, {
1887
1950
  locale
1888
1951
  // TODO: Allow setting creator fields on publish
@@ -1909,7 +1972,9 @@ const collectionTypes = {
1909
1972
  }
1910
1973
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1911
1974
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1912
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1975
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1976
+ allowMultipleLocales: true
1977
+ });
1913
1978
  const entityPromises = documentIds.map(
1914
1979
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1915
1980
  );
@@ -1936,7 +2001,9 @@ const collectionTypes = {
1936
2001
  if (permissionChecker2.cannot.unpublish()) {
1937
2002
  return ctx.forbidden();
1938
2003
  }
1939
- const { locale } = await getDocumentLocaleAndStatus(body);
2004
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2005
+ allowMultipleLocales: true
2006
+ });
1940
2007
  const entityPromises = documentIds.map(
1941
2008
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1942
2009
  );
@@ -1969,7 +2036,7 @@ const collectionTypes = {
1969
2036
  }
1970
2037
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1971
2038
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1972
- const { locale } = await getDocumentLocaleAndStatus(body);
2039
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1973
2040
  const document = await documentManager2.findOne(id, model, {
1974
2041
  populate,
1975
2042
  locale,
@@ -2006,7 +2073,7 @@ const collectionTypes = {
2006
2073
  }
2007
2074
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2008
2075
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2009
- const { locale } = await getDocumentLocaleAndStatus(body);
2076
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2010
2077
  const document = await documentManager2.findOne(id, model, {
2011
2078
  populate,
2012
2079
  locale,
@@ -2037,7 +2104,7 @@ const collectionTypes = {
2037
2104
  }
2038
2105
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2039
2106
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2040
- const { locale } = await getDocumentLocaleAndStatus(body);
2107
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2041
2108
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2042
2109
  populate,
2043
2110
  locale
@@ -2064,7 +2131,7 @@ const collectionTypes = {
2064
2131
  }
2065
2132
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2066
2133
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2067
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2134
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2068
2135
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2069
2136
  if (!entity) {
2070
2137
  return ctx.notFound();
@@ -2287,32 +2354,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2287
2354
  userAbility,
2288
2355
  model: model.uid
2289
2356
  });
2290
- if (!isListable(model, mainField)) {
2357
+ const isMainFieldListable = isListable(model, mainField);
2358
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2359
+ if (!isMainFieldListable || !canReadMainField) {
2291
2360
  return "id";
2292
2361
  }
2293
- if (permissionChecker2.cannot.read(null, mainField)) {
2294
- if (model.uid === "plugin::users-permissions.role") {
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";
2362
+ if (model.uid === "plugin::users-permissions.role") {
2363
+ return "name";
2304
2364
  }
2305
2365
  return mainField;
2306
2366
  };
2307
- const addStatusToRelations = async (uid2, relations2) => {
2308
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2367
+ const addStatusToRelations = async (targetUid, relations2) => {
2368
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2309
2369
  return relations2;
2310
2370
  }
2311
2371
  const documentMetadata2 = getService$1("document-metadata");
2312
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2372
+ if (!relations2.length) {
2373
+ return relations2;
2374
+ }
2375
+ const firstRelation = relations2[0];
2376
+ const filters = {
2377
+ documentId: { $in: relations2.map((r) => r.documentId) },
2378
+ // NOTE: find the "opposite" status
2379
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2380
+ };
2381
+ const availableStatus = await strapi.query(targetUid).findMany({
2382
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2383
+ filters
2384
+ });
2313
2385
  return relations2.map((relation) => {
2314
- const availableStatuses = documentsAvailableStatus.filter(
2315
- (availableDocument) => availableDocument.documentId === relation.documentId
2386
+ const availableStatuses = availableStatus.filter(
2387
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2316
2388
  );
2317
2389
  return {
2318
2390
  ...relation,
@@ -2333,11 +2405,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2333
2405
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2334
2406
  const isSourceLocalized = isLocalized(sourceModel);
2335
2407
  const isTargetLocalized = isLocalized(targetModel);
2336
- let validatedLocale = locale;
2337
- if (!targetModel || !isTargetLocalized)
2338
- validatedLocale = void 0;
2339
2408
  return {
2340
- locale: validatedLocale,
2409
+ locale,
2341
2410
  isSourceLocalized,
2342
2411
  isTargetLocalized
2343
2412
  };
@@ -2440,7 +2509,7 @@ const relations = {
2440
2509
  attribute,
2441
2510
  fieldsToSelect,
2442
2511
  mainField,
2443
- source: { schema: sourceSchema },
2512
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2444
2513
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2445
2514
  sourceSchema,
2446
2515
  targetSchema,
@@ -2462,7 +2531,8 @@ const relations = {
2462
2531
  fieldsToSelect,
2463
2532
  mainField,
2464
2533
  source: {
2465
- schema: { uid: sourceUid, modelType: sourceModelType }
2534
+ schema: { uid: sourceUid, modelType: sourceModelType },
2535
+ isLocalized: isSourceLocalized
2466
2536
  },
2467
2537
  target: {
2468
2538
  schema: { uid: targetUid },
@@ -2500,12 +2570,16 @@ const relations = {
2500
2570
  } else {
2501
2571
  where.id = id;
2502
2572
  }
2503
- if (status) {
2504
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2573
+ const publishedAt = getPublishedAtClause(status, targetUid);
2574
+ if (!fp.isEmpty(publishedAt)) {
2575
+ where[`${alias}.published_at`] = publishedAt;
2505
2576
  }
2506
- if (filterByLocale) {
2577
+ if (isTargetLocalized && locale) {
2507
2578
  where[`${alias}.locale`] = locale;
2508
2579
  }
2580
+ if (isSourceLocalized && locale) {
2581
+ where.locale = locale;
2582
+ }
2509
2583
  if ((idsToInclude?.length ?? 0) !== 0) {
2510
2584
  where[`${alias}.id`].$notIn = idsToInclude;
2511
2585
  }
@@ -2523,7 +2597,8 @@ const relations = {
2523
2597
  id: { $notIn: fp.uniq(idsToOmit) }
2524
2598
  });
2525
2599
  }
2526
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2600
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2601
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2527
2602
  ctx.body = {
2528
2603
  ...res,
2529
2604
  results: await addStatusToRelations(targetUid, res.results)
@@ -2538,29 +2613,39 @@ const relations = {
2538
2613
  attribute,
2539
2614
  targetField,
2540
2615
  fieldsToSelect,
2541
- source: {
2542
- schema: { uid: sourceUid }
2543
- },
2544
- target: {
2545
- schema: { uid: targetUid }
2546
- }
2616
+ status,
2617
+ source: { schema: sourceSchema },
2618
+ target: { schema: targetSchema }
2547
2619
  } = await this.extractAndValidateRequestInfo(ctx, id);
2620
+ const { uid: sourceUid } = sourceSchema;
2621
+ const { uid: targetUid } = targetSchema;
2548
2622
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2549
2623
  const dbQuery = strapi.db.query(sourceUid);
2550
2624
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2625
+ const filters = {};
2626
+ if (sourceSchema?.options?.draftAndPublish) {
2627
+ if (targetSchema?.options?.draftAndPublish) {
2628
+ if (status === "published") {
2629
+ filters.publishedAt = { $notNull: true };
2630
+ } else {
2631
+ filters.publishedAt = { $null: true };
2632
+ }
2633
+ }
2634
+ } else if (targetSchema?.options?.draftAndPublish) {
2635
+ filters.publishedAt = { $null: true };
2636
+ }
2551
2637
  const res = await loadRelations({ id: entryId }, targetField, {
2552
- select: ["id", "documentId", "locale", "publishedAt"],
2638
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2553
2639
  ordering: "desc",
2554
2640
  page: ctx.request.query.page,
2555
- pageSize: ctx.request.query.pageSize
2641
+ pageSize: ctx.request.query.pageSize,
2642
+ filters
2556
2643
  });
2557
2644
  const loadedIds = res.results.map((item) => item.id);
2558
2645
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2559
2646
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2560
2647
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2561
- ordering: "desc",
2562
- page: ctx.request.query.page,
2563
- pageSize: ctx.request.query.pageSize
2648
+ ordering: "desc"
2564
2649
  });
2565
2650
  const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
2566
2651
  ctx.body = {
@@ -2592,7 +2677,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2592
2677
  throw new strapiUtils.errors.ForbiddenError();
2593
2678
  }
2594
2679
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2595
- const { locale } = await getDocumentLocaleAndStatus(body);
2680
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2596
2681
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2597
2682
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2598
2683
  // Find the first document to check if it exists
@@ -2633,7 +2718,7 @@ const singleTypes = {
2633
2718
  return ctx.forbidden();
2634
2719
  }
2635
2720
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2636
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2721
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2637
2722
  const version = await findDocument(permissionQuery, model, { locale, status });
2638
2723
  if (!version) {
2639
2724
  if (permissionChecker2.cannot.create()) {
@@ -2647,7 +2732,7 @@ const singleTypes = {
2647
2732
  permissionChecker2,
2648
2733
  model,
2649
2734
  // @ts-expect-error - fix types
2650
- { id: document.documentId, locale, publishedAt: null },
2735
+ { documentId: document.documentId, locale, publishedAt: null },
2651
2736
  { availableLocales: true, availableStatus: false }
2652
2737
  );
2653
2738
  ctx.body = { data: {}, meta };
@@ -2678,7 +2763,7 @@ const singleTypes = {
2678
2763
  }
2679
2764
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2680
2765
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2681
- const { locale } = await getDocumentLocaleAndStatus(query);
2766
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2682
2767
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2683
2768
  populate,
2684
2769
  locale
@@ -2715,7 +2800,7 @@ const singleTypes = {
2715
2800
  if (permissionChecker2.cannot.publish(document)) {
2716
2801
  throw new strapiUtils.errors.ForbiddenError();
2717
2802
  }
2718
- const { locale } = await getDocumentLocaleAndStatus(document);
2803
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2719
2804
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2720
2805
  return publishResult.at(0);
2721
2806
  });
@@ -2738,7 +2823,7 @@ const singleTypes = {
2738
2823
  return ctx.forbidden();
2739
2824
  }
2740
2825
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2741
- const { locale } = await getDocumentLocaleAndStatus(body);
2826
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2742
2827
  const document = await findDocument(sanitizedQuery, model, { locale });
2743
2828
  if (!document) {
2744
2829
  return ctx.notFound();
@@ -2770,7 +2855,7 @@ const singleTypes = {
2770
2855
  return ctx.forbidden();
2771
2856
  }
2772
2857
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2773
- const { locale } = await getDocumentLocaleAndStatus(body);
2858
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2774
2859
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2775
2860
  if (!document) {
2776
2861
  return ctx.notFound();
@@ -2790,7 +2875,7 @@ const singleTypes = {
2790
2875
  const { query } = ctx.request;
2791
2876
  const documentManager2 = getService$1("document-manager");
2792
2877
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2793
- const { locale } = await getDocumentLocaleAndStatus(query);
2878
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2794
2879
  if (permissionChecker2.cannot.read()) {
2795
2880
  return ctx.forbidden();
2796
2881
  }
@@ -2811,7 +2896,7 @@ const uid$1 = {
2811
2896
  async generateUID(ctx) {
2812
2897
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2813
2898
  const { query = {} } = ctx.request;
2814
- const { locale } = await getDocumentLocaleAndStatus(query);
2899
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2815
2900
  await validateUIDField(contentTypeUID, field);
2816
2901
  const uidService = getService$1("uid");
2817
2902
  ctx.body = {
@@ -2823,7 +2908,7 @@ const uid$1 = {
2823
2908
  ctx.request.body
2824
2909
  );
2825
2910
  const { query = {} } = ctx.request;
2826
- const { locale } = await getDocumentLocaleAndStatus(query);
2911
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2827
2912
  await validateUIDField(contentTypeUID, field);
2828
2913
  const uidService = getService$1("uid");
2829
2914
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3466,12 +3551,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3466
3551
  ability: userAbility,
3467
3552
  model
3468
3553
  });
3469
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3554
+ const { actionProvider } = strapi2.service("admin::permission");
3555
+ const toSubject = (entity) => {
3556
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3557
+ };
3470
3558
  const can = (action, entity, field) => {
3471
- return userAbility.can(action, toSubject(entity), field);
3559
+ const subject = toSubject(entity);
3560
+ const aliases = actionProvider.unstable_aliases(action, model);
3561
+ return (
3562
+ // Test the original action to see if it passes
3563
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3564
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3565
+ );
3472
3566
  };
3473
3567
  const cannot = (action, entity, field) => {
3474
- return userAbility.cannot(action, toSubject(entity), field);
3568
+ const subject = toSubject(entity);
3569
+ const aliases = actionProvider.unstable_aliases(action, model);
3570
+ return (
3571
+ // Test both the original action
3572
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3573
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3574
+ );
3475
3575
  };
3476
3576
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3477
3577
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3748,6 +3848,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3748
3848
  const attribute = model.attributes[attributeName];
3749
3849
  switch (attribute.type) {
3750
3850
  case "relation": {
3851
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3852
+ if (isMorphRelation) {
3853
+ break;
3854
+ }
3751
3855
  if (isVisibleAttribute$1(model, attributeName)) {
3752
3856
  populateAcc[attributeName] = {
3753
3857
  count: true,
@@ -3999,7 +4103,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3999
4103
  */
4000
4104
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4001
4105
  const versionsByLocale = fp.groupBy("locale", allVersions);
4002
- delete versionsByLocale[version.locale];
4106
+ if (version.locale) {
4107
+ delete versionsByLocale[version.locale];
4108
+ }
4003
4109
  const model = strapi2.getModel(uid2);
4004
4110
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4005
4111
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
@@ -4125,7 +4231,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4125
4231
  */
4126
4232
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4127
4233
  if (!document) {
4128
- return document;
4234
+ return {
4235
+ data: document,
4236
+ meta: {
4237
+ availableLocales: [],
4238
+ availableStatus: []
4239
+ }
4240
+ };
4129
4241
  }
4130
4242
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4131
4243
  if (!hasDraftAndPublish) {
@@ -4233,10 +4345,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4233
4345
  async clone(id, body, uid2) {
4234
4346
  const populate = await buildDeepPopulate(uid2);
4235
4347
  const params = {
4236
- data: {
4237
- ...omitIdField(body),
4238
- [PUBLISHED_AT_ATTRIBUTE]: null
4239
- },
4348
+ data: omitIdField(body),
4240
4349
  populate
4241
4350
  };
4242
4351
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));