@strapi/content-manager 0.0.0-experimental.bd712ad3930045f4a5d2144c119e0b7856e97fc4 → 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 (91) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-C7ImeKGM.mjs → ComponentConfigurationPage-D0dyDTwq.mjs} +3 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-C7ImeKGM.mjs.map → ComponentConfigurationPage-D0dyDTwq.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-BWQv6yRj.js → ComponentConfigurationPage-DL1MHO8i.js} +3 -3
  4. package/dist/_chunks/{ComponentConfigurationPage-BWQv6yRj.js.map → ComponentConfigurationPage-DL1MHO8i.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-MItFGzT9.mjs → EditConfigurationPage-13b7S5Cq.mjs} +3 -3
  6. package/dist/_chunks/{EditConfigurationPage-MItFGzT9.mjs.map → EditConfigurationPage-13b7S5Cq.mjs.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-CEGwxV-L.js → EditConfigurationPage-CMaOf-A-.js} +3 -3
  8. package/dist/_chunks/{EditConfigurationPage-CEGwxV-L.js.map → EditConfigurationPage-CMaOf-A-.js.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-CmMi2Xsn.js → EditViewPage-BSVmMpRd.js} +3 -3
  10. package/dist/_chunks/{EditViewPage-CmMi2Xsn.js.map → EditViewPage-BSVmMpRd.js.map} +1 -1
  11. package/dist/_chunks/{EditViewPage-DhmAg0NK.mjs → EditViewPage-C3tIZ8F5.mjs} +3 -3
  12. package/dist/_chunks/{EditViewPage-DhmAg0NK.mjs.map → EditViewPage-C3tIZ8F5.mjs.map} +1 -1
  13. package/dist/_chunks/{Field-Cs62u5pl.mjs → Field-BvuT8cGL.mjs} +8 -8
  14. package/dist/_chunks/Field-BvuT8cGL.mjs.map +1 -0
  15. package/dist/_chunks/{Field-1DLtcLAI.js → Field-DUCVth4C.js} +8 -8
  16. package/dist/_chunks/Field-DUCVth4C.js.map +1 -0
  17. package/dist/_chunks/{Form-zYHtzGUX.mjs → Form-BZmDNVr9.mjs} +2 -2
  18. package/dist/_chunks/{Form-zYHtzGUX.mjs.map → Form-BZmDNVr9.mjs.map} +1 -1
  19. package/dist/_chunks/{Form-CqFA7F_V.js → Form-Cpl4W1ak.js} +2 -2
  20. package/dist/_chunks/{Form-CqFA7F_V.js.map → Form-Cpl4W1ak.js.map} +1 -1
  21. package/dist/_chunks/{History-DalgFQ3D.mjs → History-Cq_Hrzuu.mjs} +21 -11
  22. package/dist/_chunks/History-Cq_Hrzuu.mjs.map +1 -0
  23. package/dist/_chunks/{History-BblwXv7-.js → History-D4U2YISB.js} +21 -11
  24. package/dist/_chunks/History-D4U2YISB.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-Cpy4QqNd.js → ListConfigurationPage-Bny6CdWe.js} +2 -2
  26. package/dist/_chunks/{ListConfigurationPage-Cpy4QqNd.js.map → ListConfigurationPage-Bny6CdWe.js.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-DWy-vRzs.mjs → ListConfigurationPage-W-KQHmBv.mjs} +2 -2
  28. package/dist/_chunks/{ListConfigurationPage-DWy-vRzs.mjs.map → ListConfigurationPage-W-KQHmBv.mjs.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-BkAwIW9s.mjs → ListViewPage-HBBnJa8K.mjs} +10 -5
  30. package/dist/_chunks/ListViewPage-HBBnJa8K.mjs.map +1 -0
  31. package/dist/_chunks/{ListViewPage-DFjn1DNW.js → ListViewPage-O8F1pBJo.js} +9 -4
  32. package/dist/_chunks/ListViewPage-O8F1pBJo.js.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-B9BCNNdL.mjs → NoContentTypePage-B-gIhHWM.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-B9BCNNdL.mjs.map → NoContentTypePage-B-gIhHWM.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-C-3ykoxs.js → NoContentTypePage-CQWChGPw.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-C-3ykoxs.js.map → NoContentTypePage-CQWChGPw.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-DKLmDZnZ.js → NoPermissionsPage-CY46zxnM.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-DKLmDZnZ.js.map → NoPermissionsPage-CY46zxnM.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-Bt_HWGat.mjs → NoPermissionsPage-XhOPl8wx.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-Bt_HWGat.mjs.map → NoPermissionsPage-XhOPl8wx.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-CrxfoH2n.js → Relations-C4gGfZRv.js} +3 -3
  42. package/dist/_chunks/Relations-C4gGfZRv.js.map +1 -0
  43. package/dist/_chunks/{Relations-CJmTbZ8T.mjs → Relations-vFZ6Wasg.mjs} +3 -3
  44. package/dist/_chunks/Relations-vFZ6Wasg.mjs.map +1 -0
  45. package/dist/_chunks/{en-Ux26r5pl.mjs → en-BrCTWlZv.mjs} +5 -4
  46. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
  47. package/dist/_chunks/{en-fbKQxLGn.js → en-uOUIxfcQ.js} +5 -4
  48. package/dist/_chunks/{en-fbKQxLGn.js.map → en-uOUIxfcQ.js.map} +1 -1
  49. package/dist/_chunks/{index-Buwn78Rt.js → index-5EMXLEM_.js} +257 -139
  50. package/dist/_chunks/index-5EMXLEM_.js.map +1 -0
  51. package/dist/_chunks/{index-D1344xdw.mjs → index-Dpxg3ctD.mjs} +260 -142
  52. package/dist/_chunks/index-Dpxg3ctD.mjs.map +1 -0
  53. package/dist/_chunks/{layout-ChVuUpa1.mjs → layout-C0INpKap.mjs} +17 -5
  54. package/dist/_chunks/{layout-ChVuUpa1.mjs.map → layout-C0INpKap.mjs.map} +1 -1
  55. package/dist/_chunks/{layout-DRuJUpas.js → layout-P3eKO1Qy.js} +16 -4
  56. package/dist/_chunks/{layout-DRuJUpas.js.map → layout-P3eKO1Qy.js.map} +1 -1
  57. package/dist/_chunks/{relations-DuoUwyJr.js → relations-B1y0K6LE.js} +2 -2
  58. package/dist/_chunks/{relations-DuoUwyJr.js.map → relations-B1y0K6LE.js.map} +1 -1
  59. package/dist/_chunks/{relations-B-deMCy4.mjs → relations-FBRRBWeO.mjs} +2 -2
  60. package/dist/_chunks/{relations-B-deMCy4.mjs.map → relations-FBRRBWeO.mjs.map} +1 -1
  61. package/dist/admin/index.js +1 -1
  62. package/dist/admin/index.mjs +1 -1
  63. package/dist/admin/src/history/index.d.ts +3 -0
  64. package/dist/admin/src/index.d.ts +1 -0
  65. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
  66. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  67. package/dist/server/index.js +130 -85
  68. package/dist/server/index.js.map +1 -1
  69. package/dist/server/index.mjs +131 -86
  70. package/dist/server/index.mjs.map +1 -1
  71. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  72. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  73. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  74. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  75. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  76. package/dist/server/src/history/services/utils.d.ts +1 -1
  77. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  78. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  79. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  80. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  81. package/package.json +6 -6
  82. package/dist/_chunks/Field-1DLtcLAI.js.map +0 -1
  83. package/dist/_chunks/Field-Cs62u5pl.mjs.map +0 -1
  84. package/dist/_chunks/History-BblwXv7-.js.map +0 -1
  85. package/dist/_chunks/History-DalgFQ3D.mjs.map +0 -1
  86. package/dist/_chunks/ListViewPage-BkAwIW9s.mjs.map +0 -1
  87. package/dist/_chunks/ListViewPage-DFjn1DNW.js.map +0 -1
  88. package/dist/_chunks/Relations-CJmTbZ8T.mjs.map +0 -1
  89. package/dist/_chunks/Relations-CrxfoH2n.js.map +0 -1
  90. package/dist/_chunks/index-Buwn78Rt.js.map +0 -1
  91. package/dist/_chunks/index-D1344xdw.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { l, d, J, G, K, h, f } from "../_chunks/index-D1344xdw.mjs";
1
+ import { l, d, J, G, K, h, f } from "../_chunks/index-Dpxg3ctD.mjs";
2
2
  import "@strapi/icons";
3
3
  export {
4
4
  l as DocumentRBAC,
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from '@strapi/types';
2
+ declare const historyAdmin: Partial<Plugin.Config.AdminInput>;
3
+ export { historyAdmin };
@@ -1,5 +1,6 @@
1
1
  declare const _default: {
2
2
  register(app: any): void;
3
+ bootstrap(app: any): void;
3
4
  registerTrads({ locales }: {
4
5
  locales: string[];
5
6
  }): Promise<({
@@ -26,6 +26,7 @@ interface DialogOptions {
26
26
  type: 'dialog';
27
27
  title: string;
28
28
  content?: React.ReactNode;
29
+ variant?: ButtonProps['variant'];
29
30
  onConfirm?: () => void | Promise<void>;
30
31
  onCancel?: () => void | Promise<void>;
31
32
  }
@@ -2,10 +2,30 @@ import * as React from 'react';
2
2
  import { type InputProps } from '@strapi/admin/strapi-admin';
3
3
  import { FlexComponent } from '@strapi/design-system';
4
4
  import { type EditFieldLayout } from '../../../../hooks/useDocumentLayout';
5
+ import { RelationResult } from '../../../../services/relations';
6
+ type RelationPosition = (Pick<RelationResult, 'status' | 'locale'> & {
7
+ before: string;
8
+ end?: never;
9
+ }) | {
10
+ end: boolean;
11
+ before?: never;
12
+ status?: never;
13
+ locale?: never;
14
+ };
15
+ interface Relation extends Pick<RelationResult, 'documentId' | 'id' | 'locale' | 'status'> {
16
+ href: string;
17
+ label: string;
18
+ position?: RelationPosition;
19
+ __temp_key__: string;
20
+ }
5
21
  interface RelationsFieldProps extends Omit<Extract<EditFieldLayout, {
6
22
  type: 'relation';
7
23
  }>, 'size' | 'hint'>, Pick<InputProps, 'hint'> {
8
24
  }
25
+ export interface RelationsFormValue {
26
+ connect?: Relation[];
27
+ disconnect?: Pick<Relation, 'id'>[];
28
+ }
9
29
  declare const FlexWrapper: import("styled-components").IStyledComponent<"web", import("styled-components/dist/types").FastOmit<Omit<Omit<import("@strapi/design-system").FlexProps<"div">, "ref"> & React.RefAttributes<unknown>, "ref"> & {
10
30
  ref?: ((instance: unknown) => void) | React.RefObject<unknown> | null | undefined;
11
31
  }, never>> & Omit<FlexComponent, keyof React.Component<any, {}, any>>;
@@ -226,9 +226,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
226
226
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
227
227
  return documentMetadataService.getStatus(document, meta.availableStatus);
228
228
  };
229
- const getDeepPopulate2 = (uid2) => {
229
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
230
230
  const model = strapi2.getModel(uid2);
231
231
  const attributes = Object.entries(model.attributes);
232
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
232
233
  return attributes.reduce((acc, [attributeName, attribute]) => {
233
234
  switch (attribute.type) {
234
235
  case "relation": {
@@ -238,12 +239,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
238
239
  }
239
240
  const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
240
241
  if (isVisible2) {
241
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
242
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
242
243
  }
243
244
  break;
244
245
  }
245
246
  case "media": {
246
- acc[attributeName] = { fields: ["id"] };
247
+ acc[attributeName] = { [fieldSelector]: ["id"] };
247
248
  break;
248
249
  }
249
250
  case "component": {
@@ -494,6 +495,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
494
495
  }
495
496
  };
496
497
  };
498
+ const shouldCreateHistoryVersion = (context) => {
499
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
500
+ return false;
501
+ }
502
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
503
+ return false;
504
+ }
505
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
506
+ return false;
507
+ }
508
+ if (!context.contentType.uid.startsWith("api::")) {
509
+ return false;
510
+ }
511
+ return true;
512
+ };
513
+ const getSchemas = (uid2) => {
514
+ const attributesSchema = strapi.getModel(uid2).attributes;
515
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
516
+ (currentComponentSchemas, key) => {
517
+ const fieldSchema = attributesSchema[key];
518
+ if (fieldSchema.type === "component") {
519
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
520
+ return {
521
+ ...currentComponentSchemas,
522
+ [fieldSchema.component]: componentSchema
523
+ };
524
+ }
525
+ return currentComponentSchemas;
526
+ },
527
+ {}
528
+ );
529
+ return {
530
+ schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
531
+ componentsSchemas
532
+ };
533
+ };
497
534
  const createLifecyclesService = ({ strapi: strapi2 }) => {
498
535
  const state = {
499
536
  deleteExpiredJob: null,
@@ -506,63 +543,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
506
543
  return;
507
544
  }
508
545
  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
546
  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
- };
547
+ if (!shouldCreateHistoryVersion(context)) {
548
+ return result;
549
+ }
550
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
527
551
  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();
552
+ const locales = fp.castArray(context.params?.locale || defaultLocale);
553
+ if (!locales.length) {
554
+ return result;
534
555
  }
535
- const document = await strapi2.documents(contentTypeUid).findOne({
536
- documentId: documentContext.documentId,
537
- locale,
538
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
556
+ const uid2 = context.contentType.uid;
557
+ const schemas = getSchemas(uid2);
558
+ const localeEntries = await strapi2.db.query(uid2).findMany({
559
+ where: {
560
+ documentId,
561
+ locale: { $in: locales },
562
+ publishedAt: null
563
+ },
564
+ populate: serviceUtils.getDeepPopulate(
565
+ uid2,
566
+ true
567
+ /* use database syntax */
568
+ )
539
569
  });
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
570
  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
- });
571
+ onCommit(async () => {
572
+ for (const entry of localeEntries) {
573
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
574
+ await getService(strapi2, "history").createVersion({
575
+ contentType: uid2,
576
+ data: fp.omit(FIELDS_TO_IGNORE, entry),
577
+ relatedDocumentId: documentId,
578
+ locale: entry.locale,
579
+ status,
580
+ ...schemas
581
+ });
582
+ }
566
583
  });
567
584
  });
568
585
  return result;
@@ -1595,9 +1612,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
1595
1612
  (value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1596
1613
  );
1597
1614
  const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
1598
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1615
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1599
1616
  const { allowMultipleLocales } = opts;
1600
- const { locale, status, ...rest } = request || {};
1617
+ const { locale, status: providedStatus, ...rest } = request || {};
1618
+ const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1619
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1601
1620
  const schema = strapiUtils.yup.object().shape({
1602
1621
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1603
1622
  status: statusSchema
@@ -1645,7 +1664,7 @@ const createDocument = async (ctx, opts) => {
1645
1664
  const setCreator = strapiUtils.setCreatorFields({ user });
1646
1665
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1647
1666
  const sanitizedBody = await sanitizeFn(body);
1648
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1667
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1649
1668
  return documentManager2.create(model, {
1650
1669
  data: sanitizedBody,
1651
1670
  locale,
@@ -1664,7 +1683,7 @@ const updateDocument = async (ctx, opts) => {
1664
1683
  }
1665
1684
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1666
1685
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1667
- const { locale } = await getDocumentLocaleAndStatus(body);
1686
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1668
1687
  const [documentVersion, documentExists] = await Promise.all([
1669
1688
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1670
1689
  documentManager2.exists(model, id)
@@ -1702,7 +1721,7 @@ const collectionTypes = {
1702
1721
  }
1703
1722
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1704
1723
  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);
1724
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1706
1725
  const { results: documents, pagination } = await documentManager2.findPage(
1707
1726
  { ...permissionQuery, populate, locale, status },
1708
1727
  model
@@ -1737,7 +1756,7 @@ const collectionTypes = {
1737
1756
  }
1738
1757
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1739
1758
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1740
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1759
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1741
1760
  const version = await documentManager2.findOne(id, model, {
1742
1761
  populate,
1743
1762
  locale,
@@ -1804,7 +1823,7 @@ const collectionTypes = {
1804
1823
  }
1805
1824
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1806
1825
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1807
- const { locale } = await getDocumentLocaleAndStatus(body);
1826
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1808
1827
  const document = await documentManager2.findOne(id, model, {
1809
1828
  populate,
1810
1829
  locale,
@@ -1849,7 +1868,7 @@ const collectionTypes = {
1849
1868
  }
1850
1869
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1851
1870
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1852
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1871
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1853
1872
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1854
1873
  if (documentLocales.length === 0) {
1855
1874
  return ctx.notFound();
@@ -1878,11 +1897,28 @@ const collectionTypes = {
1878
1897
  const publishedDocument = await strapi.db.transaction(async () => {
1879
1898
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1880
1899
  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 });
1900
+ let document;
1901
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1902
+ const isCreate = fp.isNil(id);
1903
+ if (isCreate) {
1904
+ if (permissionChecker2.cannot.create()) {
1905
+ throw new strapiUtils.errors.ForbiddenError();
1906
+ }
1907
+ document = await createDocument(ctx, { populate });
1908
+ }
1909
+ const isUpdate = !isCreate;
1910
+ if (isUpdate) {
1911
+ document = await documentManager2.findOne(id, model, { populate, locale });
1912
+ if (!document) {
1913
+ throw new strapiUtils.errors.NotFoundError("Document not found");
1914
+ }
1915
+ if (permissionChecker2.can.update(document)) {
1916
+ await updateDocument(ctx);
1917
+ }
1918
+ }
1882
1919
  if (permissionChecker2.cannot.publish(document)) {
1883
1920
  throw new strapiUtils.errors.ForbiddenError();
1884
1921
  }
1885
- const { locale } = await getDocumentLocaleAndStatus(body);
1886
1922
  const publishResult = await documentManager2.publish(document.documentId, model, {
1887
1923
  locale
1888
1924
  // TODO: Allow setting creator fields on publish
@@ -1909,7 +1945,9 @@ const collectionTypes = {
1909
1945
  }
1910
1946
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1911
1947
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1912
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1948
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1949
+ allowMultipleLocales: true
1950
+ });
1913
1951
  const entityPromises = documentIds.map(
1914
1952
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1915
1953
  );
@@ -1936,7 +1974,7 @@ const collectionTypes = {
1936
1974
  if (permissionChecker2.cannot.unpublish()) {
1937
1975
  return ctx.forbidden();
1938
1976
  }
1939
- const { locale } = await getDocumentLocaleAndStatus(body);
1977
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1940
1978
  const entityPromises = documentIds.map(
1941
1979
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1942
1980
  );
@@ -1969,7 +2007,7 @@ const collectionTypes = {
1969
2007
  }
1970
2008
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1971
2009
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1972
- const { locale } = await getDocumentLocaleAndStatus(body);
2010
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1973
2011
  const document = await documentManager2.findOne(id, model, {
1974
2012
  populate,
1975
2013
  locale,
@@ -2006,7 +2044,7 @@ const collectionTypes = {
2006
2044
  }
2007
2045
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2008
2046
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2009
- const { locale } = await getDocumentLocaleAndStatus(body);
2047
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2010
2048
  const document = await documentManager2.findOne(id, model, {
2011
2049
  populate,
2012
2050
  locale,
@@ -2037,7 +2075,7 @@ const collectionTypes = {
2037
2075
  }
2038
2076
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2039
2077
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2040
- const { locale } = await getDocumentLocaleAndStatus(body);
2078
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2041
2079
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2042
2080
  populate,
2043
2081
  locale
@@ -2064,7 +2102,7 @@ const collectionTypes = {
2064
2102
  }
2065
2103
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2066
2104
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2067
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2105
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2068
2106
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2069
2107
  if (!entity) {
2070
2108
  return ctx.notFound();
@@ -2592,7 +2630,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2592
2630
  throw new strapiUtils.errors.ForbiddenError();
2593
2631
  }
2594
2632
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2595
- const { locale } = await getDocumentLocaleAndStatus(body);
2633
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2596
2634
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2597
2635
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2598
2636
  // Find the first document to check if it exists
@@ -2633,7 +2671,7 @@ const singleTypes = {
2633
2671
  return ctx.forbidden();
2634
2672
  }
2635
2673
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2636
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2674
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2637
2675
  const version = await findDocument(permissionQuery, model, { locale, status });
2638
2676
  if (!version) {
2639
2677
  if (permissionChecker2.cannot.create()) {
@@ -2678,7 +2716,7 @@ const singleTypes = {
2678
2716
  }
2679
2717
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2680
2718
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2681
- const { locale } = await getDocumentLocaleAndStatus(query);
2719
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2682
2720
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2683
2721
  populate,
2684
2722
  locale
@@ -2715,7 +2753,7 @@ const singleTypes = {
2715
2753
  if (permissionChecker2.cannot.publish(document)) {
2716
2754
  throw new strapiUtils.errors.ForbiddenError();
2717
2755
  }
2718
- const { locale } = await getDocumentLocaleAndStatus(document);
2756
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2719
2757
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2720
2758
  return publishResult.at(0);
2721
2759
  });
@@ -2738,7 +2776,7 @@ const singleTypes = {
2738
2776
  return ctx.forbidden();
2739
2777
  }
2740
2778
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2741
- const { locale } = await getDocumentLocaleAndStatus(body);
2779
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2742
2780
  const document = await findDocument(sanitizedQuery, model, { locale });
2743
2781
  if (!document) {
2744
2782
  return ctx.notFound();
@@ -2770,7 +2808,7 @@ const singleTypes = {
2770
2808
  return ctx.forbidden();
2771
2809
  }
2772
2810
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2773
- const { locale } = await getDocumentLocaleAndStatus(body);
2811
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2774
2812
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2775
2813
  if (!document) {
2776
2814
  return ctx.notFound();
@@ -2790,7 +2828,7 @@ const singleTypes = {
2790
2828
  const { query } = ctx.request;
2791
2829
  const documentManager2 = getService$1("document-manager");
2792
2830
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2793
- const { locale } = await getDocumentLocaleAndStatus(query);
2831
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2794
2832
  if (permissionChecker2.cannot.read()) {
2795
2833
  return ctx.forbidden();
2796
2834
  }
@@ -2811,7 +2849,7 @@ const uid$1 = {
2811
2849
  async generateUID(ctx) {
2812
2850
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2813
2851
  const { query = {} } = ctx.request;
2814
- const { locale } = await getDocumentLocaleAndStatus(query);
2852
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2815
2853
  await validateUIDField(contentTypeUID, field);
2816
2854
  const uidService = getService$1("uid");
2817
2855
  ctx.body = {
@@ -2823,7 +2861,7 @@ const uid$1 = {
2823
2861
  ctx.request.body
2824
2862
  );
2825
2863
  const { query = {} } = ctx.request;
2826
- const { locale } = await getDocumentLocaleAndStatus(query);
2864
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2827
2865
  await validateUIDField(contentTypeUID, field);
2828
2866
  const uidService = getService$1("uid");
2829
2867
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3748,6 +3786,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3748
3786
  const attribute = model.attributes[attributeName];
3749
3787
  switch (attribute.type) {
3750
3788
  case "relation": {
3789
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3790
+ if (isMorphRelation) {
3791
+ break;
3792
+ }
3751
3793
  if (isVisibleAttribute$1(model, attributeName)) {
3752
3794
  populateAcc[attributeName] = {
3753
3795
  count: true,
@@ -4125,7 +4167,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4125
4167
  */
4126
4168
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4127
4169
  if (!document) {
4128
- return document;
4170
+ return {
4171
+ data: document,
4172
+ meta: {
4173
+ availableLocales: [],
4174
+ availableStatus: []
4175
+ }
4176
+ };
4129
4177
  }
4130
4178
  const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
4131
4179
  if (!hasDraftAndPublish) {
@@ -4233,10 +4281,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4233
4281
  async clone(id, body, uid2) {
4234
4282
  const populate = await buildDeepPopulate(uid2);
4235
4283
  const params = {
4236
- data: {
4237
- ...omitIdField(body),
4238
- [PUBLISHED_AT_ATTRIBUTE]: null
4239
- },
4284
+ data: omitIdField(body),
4240
4285
  populate
4241
4286
  };
4242
4287
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));