@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.
Files changed (147) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs → ComponentConfigurationPage-DH3rgf1K.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs.map → ComponentConfigurationPage-DH3rgf1K.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js → ComponentConfigurationPage-DRh2GoZx.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js.map → ComponentConfigurationPage-DRh2GoZx.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js → EditConfigurationPage-BOAqRJUV.js} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js.map → EditConfigurationPage-BOAqRJUV.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs → EditConfigurationPage-C1HHivAz.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs.map → EditConfigurationPage-C1HHivAz.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-DA95Ha6J.js → EditViewPage-CgfL33yw.js} +30 -9
  10. package/dist/_chunks/EditViewPage-CgfL33yw.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-DlLEyUL6.mjs → EditViewPage-DBV7CZVf.mjs} +30 -9
  12. package/dist/_chunks/EditViewPage-DBV7CZVf.mjs.map +1 -0
  13. package/dist/_chunks/{Field-Dq7bDnuh.mjs → Field-BQFK_H87.mjs} +178 -106
  14. package/dist/_chunks/Field-BQFK_H87.mjs.map +1 -0
  15. package/dist/_chunks/{Field-CnK8dO8N.js → Field-C647fIuP.js} +180 -108
  16. package/dist/_chunks/Field-C647fIuP.js.map +1 -0
  17. package/dist/_chunks/{Form-B_JE0dbz.mjs → Form--31reETM.mjs} +36 -17
  18. package/dist/_chunks/Form--31reETM.mjs.map +1 -0
  19. package/dist/_chunks/{Form-BpiR4piS.js → Form-CsYUrVEA.js} +36 -17
  20. package/dist/_chunks/Form-CsYUrVEA.js.map +1 -0
  21. package/dist/_chunks/{History-CBNGU7a-.mjs → History-8tQaor_-.mjs} +42 -19
  22. package/dist/_chunks/History-8tQaor_-.mjs.map +1 -0
  23. package/dist/_chunks/{History-DdIstl8b.js → History-Dl6wOm0V.js} +41 -18
  24. package/dist/_chunks/History-Dl6wOm0V.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-DkKRparB.js → ListConfigurationPage-BedUJnmo.js} +15 -5
  26. package/dist/_chunks/ListConfigurationPage-BedUJnmo.js.map +1 -0
  27. package/dist/_chunks/{ListConfigurationPage-5dr4qpue.mjs → ListConfigurationPage-_WWIGpVT.mjs} +15 -5
  28. package/dist/_chunks/ListConfigurationPage-_WWIGpVT.mjs.map +1 -0
  29. package/dist/_chunks/{ListViewPage-wE0lXqoD.js → ListViewPage-5QzoAtAo.js} +61 -41
  30. package/dist/_chunks/ListViewPage-5QzoAtAo.js.map +1 -0
  31. package/dist/_chunks/{ListViewPage-DecLrYV6.mjs → ListViewPage-CZfw9OW9.mjs} +59 -39
  32. package/dist/_chunks/ListViewPage-CZfw9OW9.mjs.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs → NoContentTypePage-D-RqshUI.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs.map → NoContentTypePage-D-RqshUI.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js → NoContentTypePage-DBIyA7hd.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js.map → NoContentTypePage-DBIyA7hd.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js → NoPermissionsPage-CCAreseM.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js.map → NoPermissionsPage-CCAreseM.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs → NoPermissionsPage-m7GAd26r.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs.map → NoPermissionsPage-m7GAd26r.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-Dqz0C1fz.mjs → Relations-Dq52hb_u.mjs} +70 -37
  42. package/dist/_chunks/Relations-Dq52hb_u.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-L0xYRoSQ.js → Relations-SRwPhmo7.js} +69 -36
  44. package/dist/_chunks/Relations-SRwPhmo7.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-BSn97i8U.mjs → index-1Bdj-6ls.mjs} +914 -710
  50. package/dist/_chunks/index-1Bdj-6ls.mjs.map +1 -0
  51. package/dist/_chunks/{index-DyvUPg1a.js → index-CsrCnNa3.js} +895 -690
  52. package/dist/_chunks/index-CsrCnNa3.js.map +1 -0
  53. package/dist/_chunks/{layout-TPqF2oJ5.js → layout-B33V9Tdu.js} +21 -8
  54. package/dist/_chunks/layout-B33V9Tdu.js.map +1 -0
  55. package/dist/_chunks/{layout-DPaHUusj.mjs → layout-ByD1cQSW.mjs} +22 -9
  56. package/dist/_chunks/layout-ByD1cQSW.mjs.map +1 -0
  57. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  58. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  59. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  60. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  61. package/dist/_chunks/{relations-BWYS9gkn.js → relations-BBHlo3qQ.js} +3 -7
  62. package/dist/_chunks/relations-BBHlo3qQ.js.map +1 -0
  63. package/dist/_chunks/{relations-Ck7-ecDT.mjs → relations-DFwbNLZ0.mjs} +3 -7
  64. package/dist/_chunks/relations-DFwbNLZ0.mjs.map +1 -0
  65. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  66. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  67. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  68. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  69. package/dist/admin/index.js +2 -1
  70. package/dist/admin/index.js.map +1 -1
  71. package/dist/admin/index.mjs +5 -4
  72. package/dist/admin/src/exports.d.ts +1 -1
  73. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  74. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  75. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  76. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  77. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  78. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  79. package/dist/admin/src/preview/constants.d.ts +1 -0
  80. package/dist/admin/src/preview/index.d.ts +4 -0
  81. package/dist/admin/src/services/api.d.ts +1 -1
  82. package/dist/admin/src/services/components.d.ts +2 -2
  83. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  84. package/dist/admin/src/services/documents.d.ts +19 -17
  85. package/dist/admin/src/services/init.d.ts +1 -1
  86. package/dist/admin/src/services/relations.d.ts +2 -2
  87. package/dist/admin/src/services/uid.d.ts +3 -3
  88. package/dist/admin/src/utils/validation.d.ts +4 -1
  89. package/dist/server/index.js +256 -134
  90. package/dist/server/index.js.map +1 -1
  91. package/dist/server/index.mjs +257 -135
  92. package/dist/server/index.mjs.map +1 -1
  93. package/dist/server/src/bootstrap.d.ts.map +1 -1
  94. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  95. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  96. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  97. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  98. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  99. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  100. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  101. package/dist/server/src/history/services/history.d.ts.map +1 -1
  102. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  103. package/dist/server/src/history/services/utils.d.ts +2 -1
  104. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  105. package/dist/server/src/index.d.ts +4 -4
  106. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  107. package/dist/server/src/preview/constants.d.ts +2 -0
  108. package/dist/server/src/preview/constants.d.ts.map +1 -0
  109. package/dist/server/src/preview/index.d.ts +4 -0
  110. package/dist/server/src/preview/index.d.ts.map +1 -0
  111. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  112. package/dist/server/src/services/document-metadata.d.ts +8 -8
  113. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  114. package/dist/server/src/services/index.d.ts +4 -4
  115. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  116. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  117. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  118. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  119. package/dist/server/src/utils/index.d.ts +2 -0
  120. package/dist/server/src/utils/index.d.ts.map +1 -1
  121. package/dist/shared/contracts/collection-types.d.ts +3 -1
  122. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  123. package/package.json +13 -13
  124. package/dist/_chunks/EditViewPage-DA95Ha6J.js.map +0 -1
  125. package/dist/_chunks/EditViewPage-DlLEyUL6.mjs.map +0 -1
  126. package/dist/_chunks/Field-CnK8dO8N.js.map +0 -1
  127. package/dist/_chunks/Field-Dq7bDnuh.mjs.map +0 -1
  128. package/dist/_chunks/Form-B_JE0dbz.mjs.map +0 -1
  129. package/dist/_chunks/Form-BpiR4piS.js.map +0 -1
  130. package/dist/_chunks/History-CBNGU7a-.mjs.map +0 -1
  131. package/dist/_chunks/History-DdIstl8b.js.map +0 -1
  132. package/dist/_chunks/ListConfigurationPage-5dr4qpue.mjs.map +0 -1
  133. package/dist/_chunks/ListConfigurationPage-DkKRparB.js.map +0 -1
  134. package/dist/_chunks/ListViewPage-DecLrYV6.mjs.map +0 -1
  135. package/dist/_chunks/ListViewPage-wE0lXqoD.js.map +0 -1
  136. package/dist/_chunks/Relations-Dqz0C1fz.mjs.map +0 -1
  137. package/dist/_chunks/Relations-L0xYRoSQ.js.map +0 -1
  138. package/dist/_chunks/index-BSn97i8U.mjs.map +0 -1
  139. package/dist/_chunks/index-DyvUPg1a.js.map +0 -1
  140. package/dist/_chunks/layout-DPaHUusj.mjs.map +0 -1
  141. package/dist/_chunks/layout-TPqF2oJ5.js.map +0 -1
  142. package/dist/_chunks/relations-BWYS9gkn.js.map +0 -1
  143. package/dist/_chunks/relations-Ck7-ecDT.mjs.map +0 -1
  144. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  145. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  146. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  147. package/strapi-server.js +0 -3
@@ -1,5 +1,5 @@
1
1
  import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
2
- import { pick, omit, difference, intersection, pipe, propOr, isEqual, isEmpty, set, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, isNil as isNil$1, getOr, propEq, merge, groupBy, castArray } from "lodash/fp";
2
+ import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
5
5
  import { scheduleJob } from "node-schedule";
@@ -173,7 +173,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
173
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
174
  };
175
175
  const localesService = strapi2.plugin("i18n")?.service("locales");
176
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
177
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
179
  const getLocaleDictionary = async () => {
178
180
  if (!localesService)
179
181
  return {};
@@ -200,9 +202,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
202
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
203
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
204
  };
203
- const getDeepPopulate2 = (uid2) => {
205
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
206
  const model = strapi2.getModel(uid2);
205
207
  const attributes = Object.entries(model.attributes);
208
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
209
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
210
  switch (attribute.type) {
208
211
  case "relation": {
@@ -212,12 +215,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
212
215
  }
213
216
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
214
217
  if (isVisible2) {
215
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
218
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
216
219
  }
217
220
  break;
218
221
  }
219
222
  case "media": {
220
- acc[attributeName] = { fields: ["id"] };
223
+ acc[attributeName] = { [fieldSelector]: ["id"] };
221
224
  break;
222
225
  }
223
226
  case "component": {
@@ -290,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
290
293
  getRelationRestoreValue,
291
294
  getMediaRestoreValue,
292
295
  getDefaultLocale,
296
+ isLocalizedContentType,
293
297
  getLocaleDictionary,
294
298
  getRetentionDays,
295
299
  getVersionStatus,
@@ -312,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
312
316
  });
313
317
  },
314
318
  async findVersionsPage(params) {
315
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
319
+ const model = strapi2.getModel(params.query.contentType);
320
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
321
+ const defaultLocale = await serviceUtils.getDefaultLocale();
322
+ let locale = null;
323
+ if (isLocalizedContentType) {
324
+ locale = params.query.locale || defaultLocale;
325
+ }
316
326
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
317
327
  query.findPage({
318
328
  ...params.query,
@@ -357,7 +367,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
357
367
  if (userToPopulate == null) {
358
368
  return null;
359
369
  }
360
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
370
+ return strapi2.query("admin::user").findOne({
371
+ where: {
372
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
373
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
374
+ }
375
+ });
361
376
  })
362
377
  );
363
378
  return {
@@ -468,6 +483,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
468
483
  }
469
484
  };
470
485
  };
486
+ const shouldCreateHistoryVersion = (context) => {
487
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
488
+ return false;
489
+ }
490
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
491
+ return false;
492
+ }
493
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
494
+ return false;
495
+ }
496
+ if (!context.contentType.uid.startsWith("api::")) {
497
+ return false;
498
+ }
499
+ return true;
500
+ };
501
+ const getSchemas = (uid2) => {
502
+ const attributesSchema = strapi.getModel(uid2).attributes;
503
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
504
+ (currentComponentSchemas, key) => {
505
+ const fieldSchema = attributesSchema[key];
506
+ if (fieldSchema.type === "component") {
507
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
508
+ return {
509
+ ...currentComponentSchemas,
510
+ [fieldSchema.component]: componentSchema
511
+ };
512
+ }
513
+ return currentComponentSchemas;
514
+ },
515
+ {}
516
+ );
517
+ return {
518
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
519
+ componentsSchemas
520
+ };
521
+ };
471
522
  const createLifecyclesService = ({ strapi: strapi2 }) => {
472
523
  const state = {
473
524
  deleteExpiredJob: null,
@@ -480,63 +531,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
480
531
  return;
481
532
  }
482
533
  strapi2.documents.use(async (context, next) => {
483
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
484
- return next();
485
- }
486
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
487
- return next();
488
- }
489
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
490
- return next();
491
- }
492
- const contentTypeUid = context.contentType.uid;
493
- if (!contentTypeUid.startsWith("api::")) {
494
- return next();
495
- }
496
534
  const result = await next();
497
- const documentContext = {
498
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
499
- locale: context.params?.locale
500
- };
535
+ if (!shouldCreateHistoryVersion(context)) {
536
+ return result;
537
+ }
538
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
501
539
  const defaultLocale = await serviceUtils.getDefaultLocale();
502
- const locale = documentContext.locale || defaultLocale;
503
- if (Array.isArray(locale)) {
504
- strapi2.log.warn(
505
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
506
- );
507
- return next();
540
+ const locales = castArray(context.params?.locale || defaultLocale);
541
+ if (!locales.length) {
542
+ return result;
508
543
  }
509
- const document = await strapi2.documents(contentTypeUid).findOne({
510
- documentId: documentContext.documentId,
511
- locale,
512
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
544
+ const uid2 = context.contentType.uid;
545
+ const schemas = getSchemas(uid2);
546
+ const model = strapi2.getModel(uid2);
547
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
548
+ const localeEntries = await strapi2.db.query(uid2).findMany({
549
+ where: {
550
+ documentId,
551
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
552
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
553
+ },
554
+ populate: serviceUtils.getDeepPopulate(
555
+ uid2,
556
+ true
557
+ /* use database syntax */
558
+ )
513
559
  });
514
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
515
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
516
- const componentsSchemas = Object.keys(
517
- attributesSchema
518
- ).reduce((currentComponentSchemas, key) => {
519
- const fieldSchema = attributesSchema[key];
520
- if (fieldSchema.type === "component") {
521
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
522
- return {
523
- ...currentComponentSchemas,
524
- [fieldSchema.component]: componentSchema
525
- };
526
- }
527
- return currentComponentSchemas;
528
- }, {});
529
560
  await strapi2.db.transaction(async ({ onCommit }) => {
530
- onCommit(() => {
531
- getService(strapi2, "history").createVersion({
532
- contentType: contentTypeUid,
533
- data: omit(FIELDS_TO_IGNORE, document),
534
- schema: omit(FIELDS_TO_IGNORE, attributesSchema),
535
- componentsSchemas,
536
- relatedDocumentId: documentContext.documentId,
537
- locale,
538
- status
539
- });
561
+ onCommit(async () => {
562
+ for (const entry of localeEntries) {
563
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
564
+ await getService(strapi2, "history").createVersion({
565
+ contentType: uid2,
566
+ data: omit(FIELDS_TO_IGNORE, entry),
567
+ relatedDocumentId: documentId,
568
+ locale: entry.locale,
569
+ status,
570
+ ...schemas
571
+ });
572
+ }
540
573
  });
541
574
  });
542
575
  return result;
@@ -636,7 +669,7 @@ const historyVersion = {
636
669
  }
637
670
  }
638
671
  };
639
- const getFeature = () => {
672
+ const getFeature$1 = () => {
640
673
  if (strapi.ee.features.isEnabled("cms-content-history")) {
641
674
  return {
642
675
  register({ strapi: strapi2 }) {
@@ -659,7 +692,7 @@ const getFeature = () => {
659
692
  }
660
693
  };
661
694
  };
662
- const history = getFeature();
695
+ const history = getFeature$1();
663
696
  const register = async ({ strapi: strapi2 }) => {
664
697
  await history.register?.({ strapi: strapi2 });
665
698
  };
@@ -667,6 +700,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
667
700
  ENTRY_PUBLISH: "entry.publish",
668
701
  ENTRY_UNPUBLISH: "entry.unpublish"
669
702
  };
703
+ const FEATURE_ID = "preview";
704
+ const getFeature = () => {
705
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
706
+ return {};
707
+ }
708
+ return {
709
+ bootstrap() {
710
+ console.log("Bootstrapping preview server");
711
+ }
712
+ };
713
+ };
714
+ const preview = getFeature();
670
715
  const bootstrap = async () => {
671
716
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
672
717
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -676,6 +721,7 @@ const bootstrap = async () => {
676
721
  await getService$1("content-types").syncConfigurations();
677
722
  await getService$1("permission").registerPermissions();
678
723
  await history.bootstrap?.({ strapi });
724
+ await preview.bootstrap?.({ strapi });
679
725
  };
680
726
  const destroy = async ({ strapi: strapi2 }) => {
681
727
  await history.destroy?.({ strapi: strapi2 });
@@ -1176,6 +1222,11 @@ const { createPolicy } = policy;
1176
1222
  const hasPermissions = createPolicy({
1177
1223
  name: "plugin::content-manager.hasPermissions",
1178
1224
  validator: validateHasPermissionsInput,
1225
+ /**
1226
+ * NOTE: Action aliases are currently not checked at this level (policy).
1227
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1228
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1229
+ */
1179
1230
  handler(ctx, config = {}) {
1180
1231
  const { actions = [], hasAtLeastOne = false } = config;
1181
1232
  const { userAbility } = ctx.state;
@@ -1569,9 +1620,11 @@ const multipleLocaleSchema = yup$1.lazy(
1569
1620
  (value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1570
1621
  );
1571
1622
  const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
1572
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1623
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1573
1624
  const { allowMultipleLocales } = opts;
1574
- const { locale, status, ...rest } = request || {};
1625
+ const { locale, status: providedStatus, ...rest } = request || {};
1626
+ const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1627
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1575
1628
  const schema = yup$1.object().shape({
1576
1629
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1577
1630
  status: statusSchema
@@ -1619,7 +1672,7 @@ const createDocument = async (ctx, opts) => {
1619
1672
  const setCreator = setCreatorFields({ user });
1620
1673
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1621
1674
  const sanitizedBody = await sanitizeFn(body);
1622
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1675
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1623
1676
  return documentManager2.create(model, {
1624
1677
  data: sanitizedBody,
1625
1678
  locale,
@@ -1638,7 +1691,7 @@ const updateDocument = async (ctx, opts) => {
1638
1691
  }
1639
1692
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1640
1693
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1641
- const { locale } = await getDocumentLocaleAndStatus(body);
1694
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1642
1695
  const [documentVersion, documentExists] = await Promise.all([
1643
1696
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1644
1697
  documentManager2.exists(model, id)
@@ -1654,7 +1707,7 @@ const updateDocument = async (ctx, opts) => {
1654
1707
  throw new errors.ForbiddenError();
1655
1708
  }
1656
1709
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1657
- const setCreator = setCreatorFields({ user, isEdition: true });
1710
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1658
1711
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1659
1712
  const sanitizedBody = await sanitizeFn(body);
1660
1713
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1676,7 +1729,7 @@ const collectionTypes = {
1676
1729
  }
1677
1730
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1678
1731
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1679
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1732
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1680
1733
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1681
1734
  { ...permissionQuery, populate, locale, status },
1682
1735
  model
@@ -1711,7 +1764,7 @@ const collectionTypes = {
1711
1764
  }
1712
1765
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1713
1766
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1714
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1767
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1715
1768
  const version = await documentManager2.findOne(id, model, {
1716
1769
  populate,
1717
1770
  locale,
@@ -1726,7 +1779,7 @@ const collectionTypes = {
1726
1779
  permissionChecker2,
1727
1780
  model,
1728
1781
  // @ts-expect-error TODO: fix
1729
- { id, locale, publishedAt: null },
1782
+ { documentId: id, locale, publishedAt: null },
1730
1783
  { availableLocales: true, availableStatus: false }
1731
1784
  );
1732
1785
  ctx.body = { data: {}, meta };
@@ -1778,7 +1831,7 @@ const collectionTypes = {
1778
1831
  }
1779
1832
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1780
1833
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1781
- const { locale } = await getDocumentLocaleAndStatus(body);
1834
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1782
1835
  const document = await documentManager2.findOne(id, model, {
1783
1836
  populate,
1784
1837
  locale,
@@ -1823,7 +1876,7 @@ const collectionTypes = {
1823
1876
  }
1824
1877
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1825
1878
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1826
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1879
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1827
1880
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1828
1881
  if (documentLocales.length === 0) {
1829
1882
  return ctx.notFound();
@@ -1852,11 +1905,34 @@ const collectionTypes = {
1852
1905
  const publishedDocument = await strapi.db.transaction(async () => {
1853
1906
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1854
1907
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1855
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1908
+ let document;
1909
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1910
+ const isCreate = isNil$1(id);
1911
+ if (isCreate) {
1912
+ if (permissionChecker2.cannot.create()) {
1913
+ throw new errors.ForbiddenError();
1914
+ }
1915
+ document = await createDocument(ctx, { populate });
1916
+ }
1917
+ const isUpdate = !isCreate;
1918
+ if (isUpdate) {
1919
+ const documentExists = documentManager2.exists(model, id);
1920
+ if (!documentExists) {
1921
+ throw new errors.NotFoundError("Document not found");
1922
+ }
1923
+ document = await documentManager2.findOne(id, model, { populate, locale });
1924
+ if (!document) {
1925
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1926
+ throw new errors.ForbiddenError();
1927
+ }
1928
+ document = await updateDocument(ctx);
1929
+ } else if (permissionChecker2.can.update(document)) {
1930
+ await updateDocument(ctx);
1931
+ }
1932
+ }
1856
1933
  if (permissionChecker2.cannot.publish(document)) {
1857
1934
  throw new errors.ForbiddenError();
1858
1935
  }
1859
- const { locale } = await getDocumentLocaleAndStatus(body);
1860
1936
  const publishResult = await documentManager2.publish(document.documentId, model, {
1861
1937
  locale
1862
1938
  // TODO: Allow setting creator fields on publish
@@ -1883,7 +1959,9 @@ const collectionTypes = {
1883
1959
  }
1884
1960
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1885
1961
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1886
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1962
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1963
+ allowMultipleLocales: true
1964
+ });
1887
1965
  const entityPromises = documentIds.map(
1888
1966
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1889
1967
  );
@@ -1910,7 +1988,9 @@ const collectionTypes = {
1910
1988
  if (permissionChecker2.cannot.unpublish()) {
1911
1989
  return ctx.forbidden();
1912
1990
  }
1913
- const { locale } = await getDocumentLocaleAndStatus(body);
1991
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1992
+ allowMultipleLocales: true
1993
+ });
1914
1994
  const entityPromises = documentIds.map(
1915
1995
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1916
1996
  );
@@ -1943,7 +2023,7 @@ const collectionTypes = {
1943
2023
  }
1944
2024
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1945
2025
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1946
- const { locale } = await getDocumentLocaleAndStatus(body);
2026
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1947
2027
  const document = await documentManager2.findOne(id, model, {
1948
2028
  populate,
1949
2029
  locale,
@@ -1980,7 +2060,7 @@ const collectionTypes = {
1980
2060
  }
1981
2061
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1982
2062
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1983
- const { locale } = await getDocumentLocaleAndStatus(body);
2063
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1984
2064
  const document = await documentManager2.findOne(id, model, {
1985
2065
  populate,
1986
2066
  locale,
@@ -2011,7 +2091,7 @@ const collectionTypes = {
2011
2091
  }
2012
2092
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2013
2093
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2014
- const { locale } = await getDocumentLocaleAndStatus(body);
2094
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2015
2095
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2016
2096
  populate,
2017
2097
  locale
@@ -2038,7 +2118,7 @@ const collectionTypes = {
2038
2118
  }
2039
2119
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2040
2120
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2041
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2121
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2042
2122
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2043
2123
  if (!entity) {
2044
2124
  return ctx.notFound();
@@ -2261,32 +2341,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2261
2341
  userAbility,
2262
2342
  model: model.uid
2263
2343
  });
2264
- if (!isListable(model, mainField)) {
2344
+ const isMainFieldListable = isListable(model, mainField);
2345
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2346
+ if (!isMainFieldListable || !canReadMainField) {
2265
2347
  return "id";
2266
2348
  }
2267
- if (permissionChecker2.cannot.read(null, mainField)) {
2268
- if (model.uid === "plugin::users-permissions.role") {
2269
- const userPermissionChecker = getService$1("permission-checker").create({
2270
- userAbility,
2271
- model: "plugin::users-permissions.user"
2272
- });
2273
- if (userPermissionChecker.can.read()) {
2274
- return "name";
2275
- }
2276
- }
2277
- return "id";
2349
+ if (model.uid === "plugin::users-permissions.role") {
2350
+ return "name";
2278
2351
  }
2279
2352
  return mainField;
2280
2353
  };
2281
- const addStatusToRelations = async (uid2, relations2) => {
2282
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2354
+ const addStatusToRelations = async (targetUid, relations2) => {
2355
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2283
2356
  return relations2;
2284
2357
  }
2285
2358
  const documentMetadata2 = getService$1("document-metadata");
2286
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2359
+ if (!relations2.length) {
2360
+ return relations2;
2361
+ }
2362
+ const firstRelation = relations2[0];
2363
+ const filters = {
2364
+ documentId: { $in: relations2.map((r) => r.documentId) },
2365
+ // NOTE: find the "opposite" status
2366
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2367
+ };
2368
+ const availableStatus = await strapi.query(targetUid).findMany({
2369
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2370
+ filters
2371
+ });
2287
2372
  return relations2.map((relation) => {
2288
- const availableStatuses = documentsAvailableStatus.filter(
2289
- (availableDocument) => availableDocument.documentId === relation.documentId
2373
+ const availableStatuses = availableStatus.filter(
2374
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2290
2375
  );
2291
2376
  return {
2292
2377
  ...relation,
@@ -2307,11 +2392,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2307
2392
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2308
2393
  const isSourceLocalized = isLocalized(sourceModel);
2309
2394
  const isTargetLocalized = isLocalized(targetModel);
2310
- let validatedLocale = locale;
2311
- if (!targetModel || !isTargetLocalized)
2312
- validatedLocale = void 0;
2313
2395
  return {
2314
- locale: validatedLocale,
2396
+ locale,
2315
2397
  isSourceLocalized,
2316
2398
  isTargetLocalized
2317
2399
  };
@@ -2414,7 +2496,7 @@ const relations = {
2414
2496
  attribute,
2415
2497
  fieldsToSelect,
2416
2498
  mainField,
2417
- source: { schema: sourceSchema },
2499
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2418
2500
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2419
2501
  sourceSchema,
2420
2502
  targetSchema,
@@ -2436,7 +2518,8 @@ const relations = {
2436
2518
  fieldsToSelect,
2437
2519
  mainField,
2438
2520
  source: {
2439
- schema: { uid: sourceUid, modelType: sourceModelType }
2521
+ schema: { uid: sourceUid, modelType: sourceModelType },
2522
+ isLocalized: isSourceLocalized
2440
2523
  },
2441
2524
  target: {
2442
2525
  schema: { uid: targetUid },
@@ -2474,12 +2557,16 @@ const relations = {
2474
2557
  } else {
2475
2558
  where.id = id;
2476
2559
  }
2477
- if (status) {
2478
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2560
+ const publishedAt = getPublishedAtClause(status, targetUid);
2561
+ if (!isEmpty(publishedAt)) {
2562
+ where[`${alias}.published_at`] = publishedAt;
2479
2563
  }
2480
- if (filterByLocale) {
2564
+ if (isTargetLocalized && locale) {
2481
2565
  where[`${alias}.locale`] = locale;
2482
2566
  }
2567
+ if (isSourceLocalized && locale) {
2568
+ where.locale = locale;
2569
+ }
2483
2570
  if ((idsToInclude?.length ?? 0) !== 0) {
2484
2571
  where[`${alias}.id`].$notIn = idsToInclude;
2485
2572
  }
@@ -2497,7 +2584,8 @@ const relations = {
2497
2584
  id: { $notIn: uniq(idsToOmit) }
2498
2585
  });
2499
2586
  }
2500
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2587
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2588
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2501
2589
  ctx.body = {
2502
2590
  ...res,
2503
2591
  results: await addStatusToRelations(targetUid, res.results)
@@ -2512,29 +2600,39 @@ const relations = {
2512
2600
  attribute,
2513
2601
  targetField,
2514
2602
  fieldsToSelect,
2515
- source: {
2516
- schema: { uid: sourceUid }
2517
- },
2518
- target: {
2519
- schema: { uid: targetUid }
2520
- }
2603
+ status,
2604
+ source: { schema: sourceSchema },
2605
+ target: { schema: targetSchema }
2521
2606
  } = await this.extractAndValidateRequestInfo(ctx, id);
2607
+ const { uid: sourceUid } = sourceSchema;
2608
+ const { uid: targetUid } = targetSchema;
2522
2609
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2523
2610
  const dbQuery = strapi.db.query(sourceUid);
2524
2611
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2612
+ const filters = {};
2613
+ if (sourceSchema?.options?.draftAndPublish) {
2614
+ if (targetSchema?.options?.draftAndPublish) {
2615
+ if (status === "published") {
2616
+ filters.publishedAt = { $notNull: true };
2617
+ } else {
2618
+ filters.publishedAt = { $null: true };
2619
+ }
2620
+ }
2621
+ } else if (targetSchema?.options?.draftAndPublish) {
2622
+ filters.publishedAt = { $null: true };
2623
+ }
2525
2624
  const res = await loadRelations({ id: entryId }, targetField, {
2526
- select: ["id", "documentId", "locale", "publishedAt"],
2625
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2527
2626
  ordering: "desc",
2528
2627
  page: ctx.request.query.page,
2529
- pageSize: ctx.request.query.pageSize
2628
+ pageSize: ctx.request.query.pageSize,
2629
+ filters
2530
2630
  });
2531
2631
  const loadedIds = res.results.map((item) => item.id);
2532
2632
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2533
2633
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2534
2634
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2535
- ordering: "desc",
2536
- page: ctx.request.query.page,
2537
- pageSize: ctx.request.query.pageSize
2635
+ ordering: "desc"
2538
2636
  });
2539
2637
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2540
2638
  ctx.body = {
@@ -2566,7 +2664,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2566
2664
  throw new errors.ForbiddenError();
2567
2665
  }
2568
2666
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2569
- const { locale } = await getDocumentLocaleAndStatus(body);
2667
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2570
2668
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2571
2669
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2572
2670
  // Find the first document to check if it exists
@@ -2607,7 +2705,7 @@ const singleTypes = {
2607
2705
  return ctx.forbidden();
2608
2706
  }
2609
2707
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2610
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2708
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2611
2709
  const version = await findDocument(permissionQuery, model, { locale, status });
2612
2710
  if (!version) {
2613
2711
  if (permissionChecker2.cannot.create()) {
@@ -2621,7 +2719,7 @@ const singleTypes = {
2621
2719
  permissionChecker2,
2622
2720
  model,
2623
2721
  // @ts-expect-error - fix types
2624
- { id: document.documentId, locale, publishedAt: null },
2722
+ { documentId: document.documentId, locale, publishedAt: null },
2625
2723
  { availableLocales: true, availableStatus: false }
2626
2724
  );
2627
2725
  ctx.body = { data: {}, meta };
@@ -2652,7 +2750,7 @@ const singleTypes = {
2652
2750
  }
2653
2751
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2654
2752
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2655
- const { locale } = await getDocumentLocaleAndStatus(query);
2753
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2656
2754
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2657
2755
  populate,
2658
2756
  locale
@@ -2689,7 +2787,7 @@ const singleTypes = {
2689
2787
  if (permissionChecker2.cannot.publish(document)) {
2690
2788
  throw new errors.ForbiddenError();
2691
2789
  }
2692
- const { locale } = await getDocumentLocaleAndStatus(document);
2790
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2693
2791
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2694
2792
  return publishResult.at(0);
2695
2793
  });
@@ -2712,7 +2810,7 @@ const singleTypes = {
2712
2810
  return ctx.forbidden();
2713
2811
  }
2714
2812
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2715
- const { locale } = await getDocumentLocaleAndStatus(body);
2813
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2716
2814
  const document = await findDocument(sanitizedQuery, model, { locale });
2717
2815
  if (!document) {
2718
2816
  return ctx.notFound();
@@ -2744,7 +2842,7 @@ const singleTypes = {
2744
2842
  return ctx.forbidden();
2745
2843
  }
2746
2844
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2747
- const { locale } = await getDocumentLocaleAndStatus(body);
2845
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2748
2846
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2749
2847
  if (!document) {
2750
2848
  return ctx.notFound();
@@ -2764,7 +2862,7 @@ const singleTypes = {
2764
2862
  const { query } = ctx.request;
2765
2863
  const documentManager2 = getService$1("document-manager");
2766
2864
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2767
- const { locale } = await getDocumentLocaleAndStatus(query);
2865
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2768
2866
  if (permissionChecker2.cannot.read()) {
2769
2867
  return ctx.forbidden();
2770
2868
  }
@@ -2785,7 +2883,7 @@ const uid$1 = {
2785
2883
  async generateUID(ctx) {
2786
2884
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2787
2885
  const { query = {} } = ctx.request;
2788
- const { locale } = await getDocumentLocaleAndStatus(query);
2886
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2789
2887
  await validateUIDField(contentTypeUID, field);
2790
2888
  const uidService = getService$1("uid");
2791
2889
  ctx.body = {
@@ -2797,7 +2895,7 @@ const uid$1 = {
2797
2895
  ctx.request.body
2798
2896
  );
2799
2897
  const { query = {} } = ctx.request;
2800
- const { locale } = await getDocumentLocaleAndStatus(query);
2898
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2801
2899
  await validateUIDField(contentTypeUID, field);
2802
2900
  const uidService = getService$1("uid");
2803
2901
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3440,12 +3538,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3440
3538
  ability: userAbility,
3441
3539
  model
3442
3540
  });
3443
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3541
+ const { actionProvider } = strapi2.service("admin::permission");
3542
+ const toSubject = (entity) => {
3543
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3544
+ };
3444
3545
  const can = (action, entity, field) => {
3445
- return userAbility.can(action, toSubject(entity), field);
3546
+ const subject = toSubject(entity);
3547
+ const aliases = actionProvider.unstable_aliases(action, model);
3548
+ return (
3549
+ // Test the original action to see if it passes
3550
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3551
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3552
+ );
3446
3553
  };
3447
3554
  const cannot = (action, entity, field) => {
3448
- return userAbility.cannot(action, toSubject(entity), field);
3555
+ const subject = toSubject(entity);
3556
+ const aliases = actionProvider.unstable_aliases(action, model);
3557
+ return (
3558
+ // Test both the original action
3559
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3560
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3561
+ );
3449
3562
  };
3450
3563
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3451
3564
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3722,6 +3835,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3722
3835
  const attribute = model.attributes[attributeName];
3723
3836
  switch (attribute.type) {
3724
3837
  case "relation": {
3838
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3839
+ if (isMorphRelation) {
3840
+ break;
3841
+ }
3725
3842
  if (isVisibleAttribute$1(model, attributeName)) {
3726
3843
  populateAcc[attributeName] = {
3727
3844
  count: true,
@@ -3973,7 +4090,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3973
4090
  */
3974
4091
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
3975
4092
  const versionsByLocale = groupBy("locale", allVersions);
3976
- delete versionsByLocale[version.locale];
4093
+ if (version.locale) {
4094
+ delete versionsByLocale[version.locale];
4095
+ }
3977
4096
  const model = strapi2.getModel(uid2);
3978
4097
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
3979
4098
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4099,7 +4218,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4099
4218
  */
4100
4219
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4101
4220
  if (!document) {
4102
- return document;
4221
+ return {
4222
+ data: document,
4223
+ meta: {
4224
+ availableLocales: [],
4225
+ availableStatus: []
4226
+ }
4227
+ };
4103
4228
  }
4104
4229
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4105
4230
  if (!hasDraftAndPublish) {
@@ -4207,10 +4332,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4207
4332
  async clone(id, body, uid2) {
4208
4333
  const populate = await buildDeepPopulate(uid2);
4209
4334
  const params = {
4210
- data: {
4211
- ...omitIdField(body),
4212
- [PUBLISHED_AT_ATTRIBUTE]: null
4213
- },
4335
+ data: omitIdField(body),
4214
4336
  populate
4215
4337
  };
4216
4338
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));