@strapi/content-manager 0.0.0-experimental.c3e9d4b26f9fd3d9eb530b5c11f9baa1d09b13ad → 0.0.0-experimental.cb311d9fcfbd8e441f790aea232f0a39bdd90e16

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 (104) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs → ComponentConfigurationPage-D0dyDTwq.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs.map → ComponentConfigurationPage-D0dyDTwq.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js → ComponentConfigurationPage-DL1MHO8i.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js.map → ComponentConfigurationPage-DL1MHO8i.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs → EditConfigurationPage-13b7S5Cq.mjs} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs.map → EditConfigurationPage-13b7S5Cq.mjs.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js → EditConfigurationPage-CMaOf-A-.js} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js.map → EditConfigurationPage-CMaOf-A-.js.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-CTTDHKkQ.js → EditViewPage-BSVmMpRd.js} +45 -45
  11. package/dist/_chunks/EditViewPage-BSVmMpRd.js.map +1 -0
  12. package/dist/_chunks/{EditViewPage-DWb0DE7R.mjs → EditViewPage-C3tIZ8F5.mjs} +46 -46
  13. package/dist/_chunks/EditViewPage-C3tIZ8F5.mjs.map +1 -0
  14. package/dist/_chunks/{Field-DnStdvQw.mjs → Field-BvuT8cGL.mjs} +422 -142
  15. package/dist/_chunks/Field-BvuT8cGL.mjs.map +1 -0
  16. package/dist/_chunks/{Field-C5Z1Ivdv.js → Field-DUCVth4C.js} +421 -141
  17. package/dist/_chunks/Field-DUCVth4C.js.map +1 -0
  18. package/dist/_chunks/{Form-DqGgE55Q.mjs → Form-BZmDNVr9.mjs} +27 -28
  19. package/dist/_chunks/Form-BZmDNVr9.mjs.map +1 -0
  20. package/dist/_chunks/{Form-B81OtW-k.js → Form-Cpl4W1ak.js} +25 -26
  21. package/dist/_chunks/Form-Cpl4W1ak.js.map +1 -0
  22. package/dist/_chunks/{History-DS6-HCYX.mjs → History-Cq_Hrzuu.mjs} +52 -29
  23. package/dist/_chunks/History-Cq_Hrzuu.mjs.map +1 -0
  24. package/dist/_chunks/{History-4NbOq2dX.js → History-D4U2YISB.js} +51 -28
  25. package/dist/_chunks/History-D4U2YISB.js.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-CpfstlYY.js → ListConfigurationPage-Bny6CdWe.js} +48 -47
  27. package/dist/_chunks/ListConfigurationPage-Bny6CdWe.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-DQJJltko.mjs → ListConfigurationPage-W-KQHmBv.mjs} +49 -49
  29. package/dist/_chunks/ListConfigurationPage-W-KQHmBv.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-nQrOQuVo.mjs → ListViewPage-HBBnJa8K.mjs} +67 -70
  31. package/dist/_chunks/ListViewPage-HBBnJa8K.mjs.map +1 -0
  32. package/dist/_chunks/{ListViewPage-CA3I75m5.js → ListViewPage-O8F1pBJo.js} +65 -68
  33. package/dist/_chunks/ListViewPage-O8F1pBJo.js.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs → NoContentTypePage-B-gIhHWM.mjs} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs.map → NoContentTypePage-B-gIhHWM.mjs.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js → NoContentTypePage-CQWChGPw.js} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js.map → NoContentTypePage-CQWChGPw.js.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js → NoPermissionsPage-CY46zxnM.js} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js.map → NoPermissionsPage-CY46zxnM.js.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs → NoPermissionsPage-XhOPl8wx.mjs} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs.map → NoPermissionsPage-XhOPl8wx.mjs.map} +1 -1
  42. package/dist/_chunks/{Relations-DG2jnOcr.js → Relations-C4gGfZRv.js} +3 -3
  43. package/dist/_chunks/Relations-C4gGfZRv.js.map +1 -0
  44. package/dist/_chunks/{Relations-BDRl99Ux.mjs → Relations-vFZ6Wasg.mjs} +3 -3
  45. package/dist/_chunks/Relations-vFZ6Wasg.mjs.map +1 -0
  46. package/dist/_chunks/{en-Ux26r5pl.mjs → en-BrCTWlZv.mjs} +5 -4
  47. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
  48. package/dist/_chunks/{en-fbKQxLGn.js → en-uOUIxfcQ.js} +5 -4
  49. package/dist/_chunks/{en-fbKQxLGn.js.map → en-uOUIxfcQ.js.map} +1 -1
  50. package/dist/_chunks/{index-BZoNZMXL.js → index-5EMXLEM_.js} +384 -388
  51. package/dist/_chunks/index-5EMXLEM_.js.map +1 -0
  52. package/dist/_chunks/{index-Drt2DN7v.mjs → index-Dpxg3ctD.mjs} +399 -403
  53. package/dist/_chunks/index-Dpxg3ctD.mjs.map +1 -0
  54. package/dist/_chunks/{layout-BzAbmoO6.mjs → layout-C0INpKap.mjs} +22 -10
  55. package/dist/_chunks/layout-C0INpKap.mjs.map +1 -0
  56. package/dist/_chunks/{layout-DEYBqgF1.js → layout-P3eKO1Qy.js} +20 -8
  57. package/dist/_chunks/layout-P3eKO1Qy.js.map +1 -0
  58. package/dist/_chunks/{relations-D0eZ4VWw.js → relations-B1y0K6LE.js} +2 -2
  59. package/dist/_chunks/{relations-D0eZ4VWw.js.map → relations-B1y0K6LE.js.map} +1 -1
  60. package/dist/_chunks/{relations-D26zVRdi.mjs → relations-FBRRBWeO.mjs} +2 -2
  61. package/dist/_chunks/{relations-D26zVRdi.mjs.map → relations-FBRRBWeO.mjs.map} +1 -1
  62. package/dist/admin/index.js +1 -1
  63. package/dist/admin/index.mjs +4 -4
  64. package/dist/admin/src/history/index.d.ts +3 -0
  65. package/dist/admin/src/index.d.ts +1 -0
  66. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
  67. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  68. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  69. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +2 -10
  70. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  71. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  72. package/dist/server/index.js +137 -87
  73. package/dist/server/index.js.map +1 -1
  74. package/dist/server/index.mjs +138 -88
  75. package/dist/server/index.mjs.map +1 -1
  76. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  77. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  78. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  79. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  80. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  81. package/dist/server/src/history/services/utils.d.ts +1 -1
  82. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  83. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  84. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  85. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  86. package/package.json +8 -8
  87. package/dist/_chunks/EditViewPage-CTTDHKkQ.js.map +0 -1
  88. package/dist/_chunks/EditViewPage-DWb0DE7R.mjs.map +0 -1
  89. package/dist/_chunks/Field-C5Z1Ivdv.js.map +0 -1
  90. package/dist/_chunks/Field-DnStdvQw.mjs.map +0 -1
  91. package/dist/_chunks/Form-B81OtW-k.js.map +0 -1
  92. package/dist/_chunks/Form-DqGgE55Q.mjs.map +0 -1
  93. package/dist/_chunks/History-4NbOq2dX.js.map +0 -1
  94. package/dist/_chunks/History-DS6-HCYX.mjs.map +0 -1
  95. package/dist/_chunks/ListConfigurationPage-CpfstlYY.js.map +0 -1
  96. package/dist/_chunks/ListConfigurationPage-DQJJltko.mjs.map +0 -1
  97. package/dist/_chunks/ListViewPage-CA3I75m5.js.map +0 -1
  98. package/dist/_chunks/ListViewPage-nQrOQuVo.mjs.map +0 -1
  99. package/dist/_chunks/Relations-BDRl99Ux.mjs.map +0 -1
  100. package/dist/_chunks/Relations-DG2jnOcr.js.map +0 -1
  101. package/dist/_chunks/index-BZoNZMXL.js.map +0 -1
  102. package/dist/_chunks/index-Drt2DN7v.mjs.map +0 -1
  103. package/dist/_chunks/layout-BzAbmoO6.mjs.map +0 -1
  104. package/dist/_chunks/layout-DEYBqgF1.js.map +0 -1
@@ -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";
@@ -200,20 +200,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
200
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
201
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
202
  };
203
- const getDeepPopulate2 = (uid2) => {
203
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
204
  const model = strapi2.getModel(uid2);
205
205
  const attributes = Object.entries(model.attributes);
206
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
207
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
208
  switch (attribute.type) {
208
209
  case "relation": {
210
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
211
+ if (isMorphRelation) {
212
+ break;
213
+ }
209
214
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
210
215
  if (isVisible2) {
211
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
216
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
212
217
  }
213
218
  break;
214
219
  }
215
220
  case "media": {
216
- acc[attributeName] = { fields: ["id"] };
221
+ acc[attributeName] = { [fieldSelector]: ["id"] };
217
222
  break;
218
223
  }
219
224
  case "component": {
@@ -464,13 +469,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
464
469
  }
465
470
  };
466
471
  };
472
+ const shouldCreateHistoryVersion = (context) => {
473
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
474
+ return false;
475
+ }
476
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
477
+ return false;
478
+ }
479
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
480
+ return false;
481
+ }
482
+ if (!context.contentType.uid.startsWith("api::")) {
483
+ return false;
484
+ }
485
+ return true;
486
+ };
487
+ const getSchemas = (uid2) => {
488
+ const attributesSchema = strapi.getModel(uid2).attributes;
489
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
490
+ (currentComponentSchemas, key) => {
491
+ const fieldSchema = attributesSchema[key];
492
+ if (fieldSchema.type === "component") {
493
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
494
+ return {
495
+ ...currentComponentSchemas,
496
+ [fieldSchema.component]: componentSchema
497
+ };
498
+ }
499
+ return currentComponentSchemas;
500
+ },
501
+ {}
502
+ );
503
+ return {
504
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
505
+ componentsSchemas
506
+ };
507
+ };
467
508
  const createLifecyclesService = ({ strapi: strapi2 }) => {
468
509
  const state = {
469
510
  deleteExpiredJob: null,
470
511
  isInitialized: false
471
512
  };
472
- const query = strapi2.db.query(HISTORY_VERSION_UID);
473
- const historyService = getService(strapi2, "history");
474
513
  const serviceUtils = createServiceUtils({ strapi: strapi2 });
475
514
  return {
476
515
  async bootstrap() {
@@ -478,60 +517,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
478
517
  return;
479
518
  }
480
519
  strapi2.documents.use(async (context, next) => {
481
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
482
- return next();
483
- }
484
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
485
- return next();
486
- }
487
- const contentTypeUid = context.contentType.uid;
488
- if (!contentTypeUid.startsWith("api::")) {
489
- return next();
490
- }
491
520
  const result = await next();
492
- const documentContext = {
493
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
494
- locale: context.params?.locale
495
- };
521
+ if (!shouldCreateHistoryVersion(context)) {
522
+ return result;
523
+ }
524
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
496
525
  const defaultLocale = await serviceUtils.getDefaultLocale();
497
- const locale = documentContext.locale || defaultLocale;
498
- if (Array.isArray(locale)) {
499
- strapi2.log.warn(
500
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
501
- );
502
- return next();
526
+ const locales = castArray(context.params?.locale || defaultLocale);
527
+ if (!locales.length) {
528
+ return result;
503
529
  }
504
- const document = await strapi2.documents(contentTypeUid).findOne({
505
- documentId: documentContext.documentId,
506
- locale,
507
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
530
+ const uid2 = context.contentType.uid;
531
+ const schemas = getSchemas(uid2);
532
+ const localeEntries = await strapi2.db.query(uid2).findMany({
533
+ where: {
534
+ documentId,
535
+ locale: { $in: locales },
536
+ publishedAt: null
537
+ },
538
+ populate: serviceUtils.getDeepPopulate(
539
+ uid2,
540
+ true
541
+ /* use database syntax */
542
+ )
508
543
  });
509
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
510
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
511
- const componentsSchemas = Object.keys(
512
- attributesSchema
513
- ).reduce((currentComponentSchemas, key) => {
514
- const fieldSchema = attributesSchema[key];
515
- if (fieldSchema.type === "component") {
516
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
517
- return {
518
- ...currentComponentSchemas,
519
- [fieldSchema.component]: componentSchema
520
- };
521
- }
522
- return currentComponentSchemas;
523
- }, {});
524
544
  await strapi2.db.transaction(async ({ onCommit }) => {
525
- onCommit(() => {
526
- historyService.createVersion({
527
- contentType: contentTypeUid,
528
- data: omit(FIELDS_TO_IGNORE, document),
529
- schema: omit(FIELDS_TO_IGNORE, attributesSchema),
530
- componentsSchemas,
531
- relatedDocumentId: documentContext.documentId,
532
- locale,
533
- status
534
- });
545
+ onCommit(async () => {
546
+ for (const entry of localeEntries) {
547
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
548
+ await getService(strapi2, "history").createVersion({
549
+ contentType: uid2,
550
+ data: omit(FIELDS_TO_IGNORE, entry),
551
+ relatedDocumentId: documentId,
552
+ locale: entry.locale,
553
+ status,
554
+ ...schemas
555
+ });
556
+ }
535
557
  });
536
558
  });
537
559
  return result;
@@ -539,7 +561,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
539
561
  state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
540
562
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
541
563
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
542
- query.deleteMany({
564
+ strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
543
565
  where: {
544
566
  created_at: {
545
567
  $lt: expirationDate.toISOString()
@@ -1564,9 +1586,11 @@ const multipleLocaleSchema = yup$1.lazy(
1564
1586
  (value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1565
1587
  );
1566
1588
  const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
1567
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1589
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1568
1590
  const { allowMultipleLocales } = opts;
1569
- const { locale, status, ...rest } = request || {};
1591
+ const { locale, status: providedStatus, ...rest } = request || {};
1592
+ const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1593
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1570
1594
  const schema = yup$1.object().shape({
1571
1595
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1572
1596
  status: statusSchema
@@ -1614,7 +1638,7 @@ const createDocument = async (ctx, opts) => {
1614
1638
  const setCreator = setCreatorFields({ user });
1615
1639
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1616
1640
  const sanitizedBody = await sanitizeFn(body);
1617
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1641
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1618
1642
  return documentManager2.create(model, {
1619
1643
  data: sanitizedBody,
1620
1644
  locale,
@@ -1633,7 +1657,7 @@ const updateDocument = async (ctx, opts) => {
1633
1657
  }
1634
1658
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1635
1659
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1636
- const { locale } = await getDocumentLocaleAndStatus(body);
1660
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1637
1661
  const [documentVersion, documentExists] = await Promise.all([
1638
1662
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1639
1663
  documentManager2.exists(model, id)
@@ -1671,7 +1695,7 @@ const collectionTypes = {
1671
1695
  }
1672
1696
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1673
1697
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1674
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1698
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1675
1699
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1676
1700
  { ...permissionQuery, populate, locale, status },
1677
1701
  model
@@ -1706,7 +1730,7 @@ const collectionTypes = {
1706
1730
  }
1707
1731
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1708
1732
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1709
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1733
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1710
1734
  const version = await documentManager2.findOne(id, model, {
1711
1735
  populate,
1712
1736
  locale,
@@ -1773,7 +1797,7 @@ const collectionTypes = {
1773
1797
  }
1774
1798
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1775
1799
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1776
- const { locale } = await getDocumentLocaleAndStatus(body);
1800
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1777
1801
  const document = await documentManager2.findOne(id, model, {
1778
1802
  populate,
1779
1803
  locale,
@@ -1818,7 +1842,7 @@ const collectionTypes = {
1818
1842
  }
1819
1843
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1820
1844
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1821
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1845
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1822
1846
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1823
1847
  if (documentLocales.length === 0) {
1824
1848
  return ctx.notFound();
@@ -1847,11 +1871,28 @@ const collectionTypes = {
1847
1871
  const publishedDocument = await strapi.db.transaction(async () => {
1848
1872
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1849
1873
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1850
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1874
+ let document;
1875
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1876
+ const isCreate = isNil$1(id);
1877
+ if (isCreate) {
1878
+ if (permissionChecker2.cannot.create()) {
1879
+ throw new errors.ForbiddenError();
1880
+ }
1881
+ document = await createDocument(ctx, { populate });
1882
+ }
1883
+ const isUpdate = !isCreate;
1884
+ if (isUpdate) {
1885
+ document = await documentManager2.findOne(id, model, { populate, locale });
1886
+ if (!document) {
1887
+ throw new errors.NotFoundError("Document not found");
1888
+ }
1889
+ if (permissionChecker2.can.update(document)) {
1890
+ await updateDocument(ctx);
1891
+ }
1892
+ }
1851
1893
  if (permissionChecker2.cannot.publish(document)) {
1852
1894
  throw new errors.ForbiddenError();
1853
1895
  }
1854
- const { locale } = await getDocumentLocaleAndStatus(body);
1855
1896
  const publishResult = await documentManager2.publish(document.documentId, model, {
1856
1897
  locale
1857
1898
  // TODO: Allow setting creator fields on publish
@@ -1878,7 +1919,9 @@ const collectionTypes = {
1878
1919
  }
1879
1920
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1880
1921
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1881
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1922
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1923
+ allowMultipleLocales: true
1924
+ });
1882
1925
  const entityPromises = documentIds.map(
1883
1926
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1884
1927
  );
@@ -1905,7 +1948,7 @@ const collectionTypes = {
1905
1948
  if (permissionChecker2.cannot.unpublish()) {
1906
1949
  return ctx.forbidden();
1907
1950
  }
1908
- const { locale } = await getDocumentLocaleAndStatus(body);
1951
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1909
1952
  const entityPromises = documentIds.map(
1910
1953
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1911
1954
  );
@@ -1938,7 +1981,7 @@ const collectionTypes = {
1938
1981
  }
1939
1982
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1940
1983
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1941
- const { locale } = await getDocumentLocaleAndStatus(body);
1984
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1942
1985
  const document = await documentManager2.findOne(id, model, {
1943
1986
  populate,
1944
1987
  locale,
@@ -1975,7 +2018,7 @@ const collectionTypes = {
1975
2018
  }
1976
2019
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1977
2020
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1978
- const { locale } = await getDocumentLocaleAndStatus(body);
2021
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1979
2022
  const document = await documentManager2.findOne(id, model, {
1980
2023
  populate,
1981
2024
  locale,
@@ -2006,7 +2049,7 @@ const collectionTypes = {
2006
2049
  }
2007
2050
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2008
2051
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2009
- const { locale } = await getDocumentLocaleAndStatus(body);
2052
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2010
2053
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2011
2054
  populate,
2012
2055
  locale
@@ -2033,7 +2076,7 @@ const collectionTypes = {
2033
2076
  }
2034
2077
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2035
2078
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2036
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2079
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2037
2080
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2038
2081
  if (!entity) {
2039
2082
  return ctx.notFound();
@@ -2056,7 +2099,7 @@ const collectionTypes = {
2056
2099
  if (permissionChecker2.cannot.read()) {
2057
2100
  return ctx.forbidden();
2058
2101
  }
2059
- const entities = await documentManager2.findMany(
2102
+ const documents = await documentManager2.findMany(
2060
2103
  {
2061
2104
  filters: {
2062
2105
  documentId: ids
@@ -2065,7 +2108,7 @@ const collectionTypes = {
2065
2108
  },
2066
2109
  model
2067
2110
  );
2068
- if (!entities) {
2111
+ if (!documents) {
2069
2112
  return ctx.notFound();
2070
2113
  }
2071
2114
  const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
@@ -2561,7 +2604,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2561
2604
  throw new errors.ForbiddenError();
2562
2605
  }
2563
2606
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2564
- const { locale } = await getDocumentLocaleAndStatus(body);
2607
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2565
2608
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2566
2609
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2567
2610
  // Find the first document to check if it exists
@@ -2602,7 +2645,7 @@ const singleTypes = {
2602
2645
  return ctx.forbidden();
2603
2646
  }
2604
2647
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2605
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2648
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2606
2649
  const version = await findDocument(permissionQuery, model, { locale, status });
2607
2650
  if (!version) {
2608
2651
  if (permissionChecker2.cannot.create()) {
@@ -2647,7 +2690,7 @@ const singleTypes = {
2647
2690
  }
2648
2691
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2649
2692
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2650
- const { locale } = await getDocumentLocaleAndStatus(query);
2693
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2651
2694
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2652
2695
  populate,
2653
2696
  locale
@@ -2684,7 +2727,7 @@ const singleTypes = {
2684
2727
  if (permissionChecker2.cannot.publish(document)) {
2685
2728
  throw new errors.ForbiddenError();
2686
2729
  }
2687
- const { locale } = await getDocumentLocaleAndStatus(document);
2730
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2688
2731
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2689
2732
  return publishResult.at(0);
2690
2733
  });
@@ -2707,7 +2750,7 @@ const singleTypes = {
2707
2750
  return ctx.forbidden();
2708
2751
  }
2709
2752
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2710
- const { locale } = await getDocumentLocaleAndStatus(body);
2753
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2711
2754
  const document = await findDocument(sanitizedQuery, model, { locale });
2712
2755
  if (!document) {
2713
2756
  return ctx.notFound();
@@ -2739,7 +2782,7 @@ const singleTypes = {
2739
2782
  return ctx.forbidden();
2740
2783
  }
2741
2784
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2742
- const { locale } = await getDocumentLocaleAndStatus(body);
2785
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2743
2786
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2744
2787
  if (!document) {
2745
2788
  return ctx.notFound();
@@ -2759,7 +2802,7 @@ const singleTypes = {
2759
2802
  const { query } = ctx.request;
2760
2803
  const documentManager2 = getService$1("document-manager");
2761
2804
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2762
- const { locale } = await getDocumentLocaleAndStatus(query);
2805
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2763
2806
  if (permissionChecker2.cannot.read()) {
2764
2807
  return ctx.forbidden();
2765
2808
  }
@@ -2780,7 +2823,7 @@ const uid$1 = {
2780
2823
  async generateUID(ctx) {
2781
2824
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2782
2825
  const { query = {} } = ctx.request;
2783
- const { locale } = await getDocumentLocaleAndStatus(query);
2826
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2784
2827
  await validateUIDField(contentTypeUID, field);
2785
2828
  const uidService = getService$1("uid");
2786
2829
  ctx.body = {
@@ -2792,7 +2835,7 @@ const uid$1 = {
2792
2835
  ctx.request.body
2793
2836
  );
2794
2837
  const { query = {} } = ctx.request;
2795
- const { locale } = await getDocumentLocaleAndStatus(query);
2838
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2796
2839
  await validateUIDField(contentTypeUID, field);
2797
2840
  const uidService = getService$1("uid");
2798
2841
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3717,6 +3760,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3717
3760
  const attribute = model.attributes[attributeName];
3718
3761
  switch (attribute.type) {
3719
3762
  case "relation": {
3763
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3764
+ if (isMorphRelation) {
3765
+ break;
3766
+ }
3720
3767
  if (isVisibleAttribute$1(model, attributeName)) {
3721
3768
  populateAcc[attributeName] = {
3722
3769
  count: true,
@@ -4094,7 +4141,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4094
4141
  */
4095
4142
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4096
4143
  if (!document) {
4097
- return document;
4144
+ return {
4145
+ data: document,
4146
+ meta: {
4147
+ availableLocales: [],
4148
+ availableStatus: []
4149
+ }
4150
+ };
4098
4151
  }
4099
4152
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4100
4153
  if (!hasDraftAndPublish) {
@@ -4202,10 +4255,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4202
4255
  async clone(id, body, uid2) {
4203
4256
  const populate = await buildDeepPopulate(uid2);
4204
4257
  const params = {
4205
- data: {
4206
- ...omitIdField(body),
4207
- [PUBLISHED_AT_ATTRIBUTE]: null
4208
- },
4258
+ data: omitIdField(body),
4209
4259
  populate
4210
4260
  };
4211
4261
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));