@strapi/content-manager 0.0.0-experimental.9c5778c9200404fcee94d5a0fc88da5e4376b82c → 0.0.0-experimental.9c7de54d8ce77e13047fc15ada33f937a068f1f2

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 (112) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs → ComponentConfigurationPage-CIjXcRAB.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-CpBFh6_r.mjs.map → ComponentConfigurationPage-CIjXcRAB.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js → ComponentConfigurationPage-gsCd80MU.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-_zF8p6CY.js.map → ComponentConfigurationPage-gsCd80MU.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs → EditConfigurationPage-BglmD_BF.mjs} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-CE_yavTi.mjs.map → EditConfigurationPage-BglmD_BF.mjs.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js → EditConfigurationPage-DHDQKBzw.js} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-_aG2DJSU.js.map → EditConfigurationPage-DHDQKBzw.js.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-G9uNzwYL.js → EditViewPage-C4iTxUPU.js} +15 -5
  10. package/dist/_chunks/EditViewPage-C4iTxUPU.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-DeTn7rAF.mjs → EditViewPage-CiwVPMaK.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-CiwVPMaK.mjs.map +1 -0
  13. package/dist/_chunks/{Field-CnCKhI1R.mjs → Field-DIjL1b5d.mjs} +70 -26
  14. package/dist/_chunks/Field-DIjL1b5d.mjs.map +1 -0
  15. package/dist/_chunks/{Field-DDHUWEfV.js → Field-DhXEK8y1.js} +70 -26
  16. package/dist/_chunks/Field-DhXEK8y1.js.map +1 -0
  17. package/dist/_chunks/{Form-IvVVwqRL.mjs → Form-CmNesrvR.mjs} +3 -3
  18. package/dist/_chunks/Form-CmNesrvR.mjs.map +1 -0
  19. package/dist/_chunks/{Form-DYETaKUX.js → Form-CwmJ4sWe.js} +3 -3
  20. package/dist/_chunks/Form-CwmJ4sWe.js.map +1 -0
  21. package/dist/_chunks/{History-CnZDctSO.js → History-BLCCNgCt.js} +24 -11
  22. package/dist/_chunks/History-BLCCNgCt.js.map +1 -0
  23. package/dist/_chunks/{History-BMunT-do.mjs → History-D-99Wh30.mjs} +25 -12
  24. package/dist/_chunks/History-D-99Wh30.mjs.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-BynalOp8.js → ListConfigurationPage-DxWpeZrO.js} +3 -3
  26. package/dist/_chunks/{ListConfigurationPage-BynalOp8.js.map → ListConfigurationPage-DxWpeZrO.js.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs → ListConfigurationPage-JPWZz7Kg.mjs} +3 -3
  28. package/dist/_chunks/{ListConfigurationPage-CDqkCxgV.mjs.map → ListConfigurationPage-JPWZz7Kg.mjs.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-I88Ouzoq.js → ListViewPage-CIQekSFz.js} +22 -7
  30. package/dist/_chunks/ListViewPage-CIQekSFz.js.map +1 -0
  31. package/dist/_chunks/{ListViewPage-_5gS-DOF.mjs → ListViewPage-DSK3f0ST.mjs} +22 -7
  32. package/dist/_chunks/ListViewPage-DSK3f0ST.mjs.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js → NoContentTypePage-C5cxKvC2.js} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-BaWQ7HsA.js.map → NoContentTypePage-C5cxKvC2.js.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs → NoContentTypePage-D99LU1YP.mjs} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-Dht-55hr.mjs.map → NoContentTypePage-D99LU1YP.mjs.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs → NoPermissionsPage-DBrBw-0y.mjs} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-Bs8D5W_v.mjs.map → NoPermissionsPage-DBrBw-0y.mjs.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js → NoPermissionsPage-Oy4tmUrW.js} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-DCVUh5at.js.map → NoPermissionsPage-Oy4tmUrW.js.map} +1 -1
  41. package/dist/_chunks/{Relations-Chdt5qWc.mjs → Relations-BBmhcWFV.mjs} +69 -36
  42. package/dist/_chunks/Relations-BBmhcWFV.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-BPgFQeGj.js → Relations-eG-9p_qS.js} +68 -35
  44. package/dist/_chunks/Relations-eG-9p_qS.js.map +1 -0
  45. package/dist/_chunks/{en-BVzUkPxZ.js → en-Bm0D0IWz.js} +8 -8
  46. package/dist/_chunks/{en-BVzUkPxZ.js.map → en-Bm0D0IWz.js.map} +1 -1
  47. package/dist/_chunks/{en-CPTj6CjC.mjs → en-DKV44jRb.mjs} +8 -8
  48. package/dist/_chunks/{en-CPTj6CjC.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  49. package/dist/_chunks/{index-BhbLFX4l.js → index-BIWDoFLK.js} +957 -868
  50. package/dist/_chunks/index-BIWDoFLK.js.map +1 -0
  51. package/dist/_chunks/{index-D4UGPFZC.mjs → index-BrUzbQ30.mjs} +958 -870
  52. package/dist/_chunks/index-BrUzbQ30.mjs.map +1 -0
  53. package/dist/_chunks/{layout-D4HI4_PS.mjs → layout-_5-cXs34.mjs} +3 -3
  54. package/dist/_chunks/{layout-D4HI4_PS.mjs.map → layout-_5-cXs34.mjs.map} +1 -1
  55. package/dist/_chunks/{layout-CYA7s0qO.js → layout-lMc9i1-Z.js} +3 -3
  56. package/dist/_chunks/{layout-CYA7s0qO.js.map → layout-lMc9i1-Z.js.map} +1 -1
  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-DDZ9OxNo.js → relations-BRHithi8.js} +3 -7
  62. package/dist/_chunks/relations-BRHithi8.js.map +1 -0
  63. package/dist/_chunks/{relations-1pXaYpBK.mjs → relations-B_VLk-DD.mjs} +3 -7
  64. package/dist/_chunks/relations-B_VLk-DD.mjs.map +1 -0
  65. package/dist/admin/index.js +2 -1
  66. package/dist/admin/index.js.map +1 -1
  67. package/dist/admin/index.mjs +3 -2
  68. package/dist/admin/src/exports.d.ts +1 -1
  69. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  70. package/dist/admin/src/pages/EditView/components/Header.d.ts +1 -0
  71. package/dist/admin/src/preview/constants.d.ts +1 -0
  72. package/dist/admin/src/preview/index.d.ts +4 -0
  73. package/dist/server/index.js +85 -32
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server/index.mjs +85 -32
  76. package/dist/server/index.mjs.map +1 -1
  77. package/dist/server/src/bootstrap.d.ts.map +1 -1
  78. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  79. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  80. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  81. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  82. package/dist/server/src/history/services/history.d.ts.map +1 -1
  83. package/dist/server/src/index.d.ts +4 -4
  84. package/dist/server/src/preview/constants.d.ts +2 -0
  85. package/dist/server/src/preview/constants.d.ts.map +1 -0
  86. package/dist/server/src/preview/index.d.ts +4 -0
  87. package/dist/server/src/preview/index.d.ts.map +1 -0
  88. package/dist/server/src/services/document-metadata.d.ts +8 -8
  89. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  90. package/dist/server/src/services/index.d.ts +4 -4
  91. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  92. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  93. package/dist/server/src/utils/index.d.ts +2 -0
  94. package/dist/server/src/utils/index.d.ts.map +1 -1
  95. package/package.json +12 -12
  96. package/dist/_chunks/EditViewPage-DeTn7rAF.mjs.map +0 -1
  97. package/dist/_chunks/EditViewPage-G9uNzwYL.js.map +0 -1
  98. package/dist/_chunks/Field-CnCKhI1R.mjs.map +0 -1
  99. package/dist/_chunks/Field-DDHUWEfV.js.map +0 -1
  100. package/dist/_chunks/Form-DYETaKUX.js.map +0 -1
  101. package/dist/_chunks/Form-IvVVwqRL.mjs.map +0 -1
  102. package/dist/_chunks/History-BMunT-do.mjs.map +0 -1
  103. package/dist/_chunks/History-CnZDctSO.js.map +0 -1
  104. package/dist/_chunks/ListViewPage-I88Ouzoq.js.map +0 -1
  105. package/dist/_chunks/ListViewPage-_5gS-DOF.mjs.map +0 -1
  106. package/dist/_chunks/Relations-BPgFQeGj.js.map +0 -1
  107. package/dist/_chunks/Relations-Chdt5qWc.mjs.map +0 -1
  108. package/dist/_chunks/index-BhbLFX4l.js.map +0 -1
  109. package/dist/_chunks/index-D4UGPFZC.mjs.map +0 -1
  110. package/dist/_chunks/relations-1pXaYpBK.mjs.map +0 -1
  111. package/dist/_chunks/relations-DDZ9OxNo.js.map +0 -1
  112. package/strapi-server.js +0 -3
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;"}
@@ -1,11 +1,12 @@
1
- import { l, d, K, J, L, h, f } from "../_chunks/index-D4UGPFZC.mjs";
1
+ import { l, d, K, L, J, M, h, f } from "../_chunks/index-BrUzbQ30.mjs";
2
2
  import "@strapi/icons";
3
3
  export {
4
4
  l as DocumentRBAC,
5
5
  d as buildValidParams,
6
6
  K as default,
7
+ L as unstable_useContentManagerContext,
7
8
  J as unstable_useDocument,
8
- L as unstable_useDocumentActions,
9
+ M as unstable_useDocumentActions,
9
10
  h as unstable_useDocumentLayout,
10
11
  f as useDocumentRBAC
11
12
  };
@@ -4,7 +4,7 @@
4
4
  * but should still export the same things.
5
5
  */
6
6
  export { buildValidParams } from './utils/api';
7
- export { useDocument as unstable_useDocument } from './hooks/useDocument';
7
+ export { useDocument as unstable_useDocument, useContentManagerContext as unstable_useContentManagerContext, } from './hooks/useDocument';
8
8
  export { useDocumentActions as unstable_useDocumentActions } from './hooks/useDocumentActions';
9
9
  export { useDocumentLayout as unstable_useDocumentLayout } from './hooks/useDocumentLayout';
10
10
  export type { EditFieldLayout, EditLayout, ListFieldLayout, ListLayout, } from './hooks/useDocumentLayout';
@@ -31,7 +31,9 @@ type UseDocument = (args: UseDocumentArgs, opts?: UseDocumentOpts) => {
31
31
  * This is the schema of the content type, it is not the same as the layout.
32
32
  */
33
33
  schema?: Schema;
34
+ schemas?: Schema[];
34
35
  validate: (document: Document) => null | FormErrors;
36
+ hasError?: boolean;
35
37
  };
36
38
  /**
37
39
  * @alpha
@@ -78,10 +80,39 @@ declare const useDoc: () => {
78
80
  * This is the schema of the content type, it is not the same as the layout.
79
81
  */
80
82
  schema?: ContentType | undefined;
83
+ schemas?: ContentType[] | undefined;
81
84
  validate: (document: Document) => null | FormErrors;
85
+ hasError?: boolean | undefined;
82
86
  collectionType: string;
83
87
  model: string;
84
88
  id: string | undefined;
85
89
  };
86
- export { useDocument, useDoc };
90
+ /**
91
+ * @public
92
+ * @experimental
93
+ * Content manager context hooks for plugin development.
94
+ * Make sure to use this hook inside the content manager.
95
+ */
96
+ declare const useContentManagerContext: () => {
97
+ error: import("@reduxjs/toolkit").SerializedError | import("../utils/api").BaseQueryError | undefined;
98
+ isLoading: boolean;
99
+ model: string;
100
+ collectionType: string;
101
+ id: string | undefined;
102
+ slug: string;
103
+ isCreatingEntry: boolean;
104
+ isSingleType: boolean;
105
+ hasDraftAndPublish: boolean;
106
+ components: ComponentsDictionary;
107
+ contentType: ContentType | undefined;
108
+ contentTypes: ContentType[] | undefined;
109
+ form: import("@strapi/admin/strapi-admin").FormContextValue<import("@strapi/admin/strapi-admin").FormValues>;
110
+ layout: {
111
+ error?: import("@reduxjs/toolkit").SerializedError | import("../utils/api").BaseQueryError | undefined;
112
+ isLoading: boolean;
113
+ edit: import("./useDocumentLayout").EditLayout;
114
+ list: import("./useDocumentLayout").ListLayout;
115
+ };
116
+ };
117
+ export { useDocument, useDoc, useContentManagerContext };
87
118
  export type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };
@@ -28,6 +28,7 @@ interface HeaderActionDescription {
28
28
  }>;
29
29
  onSelect?: (value: string) => void;
30
30
  value?: string;
31
+ customizeContent?: (value: string) => React.ReactNode;
31
32
  }
32
33
  declare const DEFAULT_HEADER_ACTIONS: DocumentActionComponent[];
33
34
  export { Header, DEFAULT_HEADER_ACTIONS };
@@ -0,0 +1 @@
1
+ export declare const FEATURE_ID = "preview";
@@ -0,0 +1,4 @@
1
+ declare const previewAdmin: {
2
+ bootstrap(app: Pick<import("@strapi/admin/strapi-admin").StrapiApp, "getPlugin" | "addSettingsLink" | "addSettingsLinks" | "registerHook">): {} | undefined;
3
+ };
4
+ export { previewAdmin };
@@ -393,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
393
393
  if (userToPopulate == null) {
394
394
  return null;
395
395
  }
396
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
396
+ return strapi2.query("admin::user").findOne({
397
+ where: {
398
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
399
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
400
+ }
401
+ });
397
402
  })
398
403
  );
399
404
  return {
@@ -690,7 +695,7 @@ const historyVersion = {
690
695
  }
691
696
  }
692
697
  };
693
- const getFeature = () => {
698
+ const getFeature$1 = () => {
694
699
  if (strapi.ee.features.isEnabled("cms-content-history")) {
695
700
  return {
696
701
  register({ strapi: strapi2 }) {
@@ -713,7 +718,7 @@ const getFeature = () => {
713
718
  }
714
719
  };
715
720
  };
716
- const history = getFeature();
721
+ const history = getFeature$1();
717
722
  const register = async ({ strapi: strapi2 }) => {
718
723
  await history.register?.({ strapi: strapi2 });
719
724
  };
@@ -721,6 +726,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
721
726
  ENTRY_PUBLISH: "entry.publish",
722
727
  ENTRY_UNPUBLISH: "entry.unpublish"
723
728
  };
729
+ const FEATURE_ID = "preview";
730
+ const getFeature = () => {
731
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
732
+ return {};
733
+ }
734
+ return {
735
+ bootstrap() {
736
+ console.log("Bootstrapping preview server");
737
+ }
738
+ };
739
+ };
740
+ const preview = getFeature();
724
741
  const bootstrap = async () => {
725
742
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
726
743
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -730,6 +747,7 @@ const bootstrap = async () => {
730
747
  await getService$1("content-types").syncConfigurations();
731
748
  await getService$1("permission").registerPermissions();
732
749
  await history.bootstrap?.({ strapi });
750
+ await preview.bootstrap?.({ strapi });
733
751
  };
734
752
  const destroy = async ({ strapi: strapi2 }) => {
735
753
  await history.destroy?.({ strapi: strapi2 });
@@ -1715,7 +1733,7 @@ const updateDocument = async (ctx, opts) => {
1715
1733
  throw new strapiUtils.errors.ForbiddenError();
1716
1734
  }
1717
1735
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1718
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1736
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1719
1737
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1720
1738
  const sanitizedBody = await sanitizeFn(body);
1721
1739
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1924,11 +1942,17 @@ const collectionTypes = {
1924
1942
  }
1925
1943
  const isUpdate = !isCreate;
1926
1944
  if (isUpdate) {
1927
- document = await documentManager2.findOne(id, model, { populate, locale });
1928
- if (!document) {
1945
+ const documentExists = documentManager2.exists(model, id);
1946
+ if (!documentExists) {
1929
1947
  throw new strapiUtils.errors.NotFoundError("Document not found");
1930
1948
  }
1931
- if (permissionChecker2.can.update(document)) {
1949
+ document = await documentManager2.findOne(id, model, { populate, locale });
1950
+ if (!document) {
1951
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1952
+ throw new strapiUtils.errors.ForbiddenError();
1953
+ }
1954
+ document = await updateDocument(ctx);
1955
+ } else if (permissionChecker2.can.update(document)) {
1932
1956
  await updateDocument(ctx);
1933
1957
  }
1934
1958
  }
@@ -2353,15 +2377,27 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2353
2377
  }
2354
2378
  return mainField;
2355
2379
  };
2356
- const addStatusToRelations = async (uid2, relations2) => {
2357
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2380
+ const addStatusToRelations = async (targetUid, relations2) => {
2381
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2358
2382
  return relations2;
2359
2383
  }
2360
2384
  const documentMetadata2 = getService$1("document-metadata");
2361
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2385
+ if (!relations2.length) {
2386
+ return relations2;
2387
+ }
2388
+ const firstRelation = relations2[0];
2389
+ const filters = {
2390
+ documentId: { $in: relations2.map((r) => r.documentId) },
2391
+ // NOTE: find the "opposite" status
2392
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2393
+ };
2394
+ const availableStatus = await strapi.query(targetUid).findMany({
2395
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2396
+ filters
2397
+ });
2362
2398
  return relations2.map((relation) => {
2363
- const availableStatuses = documentsAvailableStatus.filter(
2364
- (availableDocument) => availableDocument.documentId === relation.documentId
2399
+ const availableStatuses = availableStatus.filter(
2400
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2365
2401
  );
2366
2402
  return {
2367
2403
  ...relation,
@@ -2382,11 +2418,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2382
2418
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2383
2419
  const isSourceLocalized = isLocalized(sourceModel);
2384
2420
  const isTargetLocalized = isLocalized(targetModel);
2385
- let validatedLocale = locale;
2386
- if (!targetModel || !isTargetLocalized)
2387
- validatedLocale = void 0;
2388
2421
  return {
2389
- locale: validatedLocale,
2422
+ locale,
2390
2423
  isSourceLocalized,
2391
2424
  isTargetLocalized
2392
2425
  };
@@ -2489,7 +2522,7 @@ const relations = {
2489
2522
  attribute,
2490
2523
  fieldsToSelect,
2491
2524
  mainField,
2492
- source: { schema: sourceSchema },
2525
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2493
2526
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2494
2527
  sourceSchema,
2495
2528
  targetSchema,
@@ -2511,7 +2544,8 @@ const relations = {
2511
2544
  fieldsToSelect,
2512
2545
  mainField,
2513
2546
  source: {
2514
- schema: { uid: sourceUid, modelType: sourceModelType }
2547
+ schema: { uid: sourceUid, modelType: sourceModelType },
2548
+ isLocalized: isSourceLocalized
2515
2549
  },
2516
2550
  target: {
2517
2551
  schema: { uid: targetUid },
@@ -2549,12 +2583,16 @@ const relations = {
2549
2583
  } else {
2550
2584
  where.id = id;
2551
2585
  }
2552
- if (status) {
2553
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2586
+ const publishedAt = getPublishedAtClause(status, targetUid);
2587
+ if (!fp.isEmpty(publishedAt)) {
2588
+ where[`${alias}.published_at`] = publishedAt;
2554
2589
  }
2555
- if (filterByLocale) {
2590
+ if (isTargetLocalized && locale) {
2556
2591
  where[`${alias}.locale`] = locale;
2557
2592
  }
2593
+ if (isSourceLocalized && locale) {
2594
+ where.locale = locale;
2595
+ }
2558
2596
  if ((idsToInclude?.length ?? 0) !== 0) {
2559
2597
  where[`${alias}.id`].$notIn = idsToInclude;
2560
2598
  }
@@ -2572,7 +2610,8 @@ const relations = {
2572
2610
  id: { $notIn: fp.uniq(idsToOmit) }
2573
2611
  });
2574
2612
  }
2575
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2613
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2614
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2576
2615
  ctx.body = {
2577
2616
  ...res,
2578
2617
  results: await addStatusToRelations(targetUid, res.results)
@@ -2587,21 +2626,33 @@ const relations = {
2587
2626
  attribute,
2588
2627
  targetField,
2589
2628
  fieldsToSelect,
2590
- source: {
2591
- schema: { uid: sourceUid }
2592
- },
2593
- target: {
2594
- schema: { uid: targetUid }
2595
- }
2629
+ status,
2630
+ source: { schema: sourceSchema },
2631
+ target: { schema: targetSchema }
2596
2632
  } = await this.extractAndValidateRequestInfo(ctx, id);
2633
+ const { uid: sourceUid } = sourceSchema;
2634
+ const { uid: targetUid } = targetSchema;
2597
2635
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2598
2636
  const dbQuery = strapi.db.query(sourceUid);
2599
2637
  const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2638
+ const filters = {};
2639
+ if (sourceSchema?.options?.draftAndPublish) {
2640
+ if (targetSchema?.options?.draftAndPublish) {
2641
+ if (status === "published") {
2642
+ filters.publishedAt = { $notNull: true };
2643
+ } else {
2644
+ filters.publishedAt = { $null: true };
2645
+ }
2646
+ }
2647
+ } else if (targetSchema?.options?.draftAndPublish) {
2648
+ filters.publishedAt = { $null: true };
2649
+ }
2600
2650
  const res = await loadRelations({ id: entryId }, targetField, {
2601
- select: ["id", "documentId", "locale", "publishedAt"],
2651
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2602
2652
  ordering: "desc",
2603
2653
  page: ctx.request.query.page,
2604
- pageSize: ctx.request.query.pageSize
2654
+ pageSize: ctx.request.query.pageSize,
2655
+ filters
2605
2656
  });
2606
2657
  const loadedIds = res.results.map((item) => item.id);
2607
2658
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
@@ -2694,7 +2745,7 @@ const singleTypes = {
2694
2745
  permissionChecker2,
2695
2746
  model,
2696
2747
  // @ts-expect-error - fix types
2697
- { id: document.documentId, locale, publishedAt: null },
2748
+ { documentId: document.documentId, locale, publishedAt: null },
2698
2749
  { availableLocales: true, availableStatus: false }
2699
2750
  );
2700
2751
  ctx.body = { data: {}, meta };
@@ -4065,7 +4116,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4065
4116
  */
4066
4117
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4067
4118
  const versionsByLocale = fp.groupBy("locale", allVersions);
4068
- delete versionsByLocale[version.locale];
4119
+ if (version.locale) {
4120
+ delete versionsByLocale[version.locale];
4121
+ }
4069
4122
  const model = strapi2.getModel(uid2);
4070
4123
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4071
4124
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(