@strapi/content-manager 0.0.0-experimental.abc → 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 (136) hide show
  1. package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs → ComponentConfigurationPage-DH3rgf1K.mjs} +4 -4
  2. package/dist/_chunks/{ComponentConfigurationPage-B3yDbeU1.mjs.map → ComponentConfigurationPage-DH3rgf1K.mjs.map} +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js → ComponentConfigurationPage-DRh2GoZx.js} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-KXSuLnQD.js.map → ComponentConfigurationPage-DRh2GoZx.js.map} +1 -1
  5. package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js → EditConfigurationPage-BOAqRJUV.js} +4 -4
  6. package/dist/_chunks/{EditConfigurationPage-BQ17--5R.js.map → EditConfigurationPage-BOAqRJUV.js.map} +1 -1
  7. package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs → EditConfigurationPage-C1HHivAz.mjs} +4 -4
  8. package/dist/_chunks/{EditConfigurationPage-D7PrLO8j.mjs.map → EditConfigurationPage-C1HHivAz.mjs.map} +1 -1
  9. package/dist/_chunks/{EditViewPage-BgjdnGz2.js → EditViewPage-CgfL33yw.js} +15 -5
  10. package/dist/_chunks/EditViewPage-CgfL33yw.js.map +1 -0
  11. package/dist/_chunks/{EditViewPage-B7VgwJaG.mjs → EditViewPage-DBV7CZVf.mjs} +15 -5
  12. package/dist/_chunks/EditViewPage-DBV7CZVf.mjs.map +1 -0
  13. package/dist/_chunks/{Field-tHCw4lGA.mjs → Field-BQFK_H87.mjs} +98 -85
  14. package/dist/_chunks/Field-BQFK_H87.mjs.map +1 -0
  15. package/dist/_chunks/{Field-CdK7ZLmv.js → Field-C647fIuP.js} +101 -88
  16. package/dist/_chunks/Field-C647fIuP.js.map +1 -0
  17. package/dist/_chunks/{Form-BJxdTv3Q.mjs → Form--31reETM.mjs} +16 -8
  18. package/dist/_chunks/Form--31reETM.mjs.map +1 -0
  19. package/dist/_chunks/{Form-C_0KTVvV.js → Form-CsYUrVEA.js} +16 -8
  20. package/dist/_chunks/Form-CsYUrVEA.js.map +1 -0
  21. package/dist/_chunks/{History-DR2txJLE.mjs → History-8tQaor_-.mjs} +25 -12
  22. package/dist/_chunks/History-8tQaor_-.mjs.map +1 -0
  23. package/dist/_chunks/{History-nuEzM5qm.js → History-Dl6wOm0V.js} +24 -11
  24. package/dist/_chunks/History-Dl6wOm0V.js.map +1 -0
  25. package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js → ListConfigurationPage-BedUJnmo.js} +3 -3
  26. package/dist/_chunks/{ListConfigurationPage-CnB86Psm.js.map → ListConfigurationPage-BedUJnmo.js.map} +1 -1
  27. package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs → ListConfigurationPage-_WWIGpVT.mjs} +3 -3
  28. package/dist/_chunks/{ListConfigurationPage-voFVtXu6.mjs.map → ListConfigurationPage-_WWIGpVT.mjs.map} +1 -1
  29. package/dist/_chunks/{ListViewPage-SXIXm-RM.js → ListViewPage-5QzoAtAo.js} +55 -40
  30. package/dist/_chunks/ListViewPage-5QzoAtAo.js.map +1 -0
  31. package/dist/_chunks/{ListViewPage-B_GaWgRH.mjs → ListViewPage-CZfw9OW9.mjs} +52 -37
  32. package/dist/_chunks/ListViewPage-CZfw9OW9.mjs.map +1 -0
  33. package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs → NoContentTypePage-D-RqshUI.mjs} +2 -2
  34. package/dist/_chunks/{NoContentTypePage-CYiGpsbj.mjs.map → NoContentTypePage-D-RqshUI.mjs.map} +1 -1
  35. package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js → NoContentTypePage-DBIyA7hd.js} +2 -2
  36. package/dist/_chunks/{NoContentTypePage-BzsQ3hLZ.js.map → NoContentTypePage-DBIyA7hd.js.map} +1 -1
  37. package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js → NoPermissionsPage-CCAreseM.js} +2 -2
  38. package/dist/_chunks/{NoPermissionsPage-IGkId4C5.js.map → NoPermissionsPage-CCAreseM.js.map} +1 -1
  39. package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs → NoPermissionsPage-m7GAd26r.mjs} +2 -2
  40. package/dist/_chunks/{NoPermissionsPage-B5baIHal.mjs.map → NoPermissionsPage-m7GAd26r.mjs.map} +1 -1
  41. package/dist/_chunks/{Relations-CIYDdKU-.mjs → Relations-Dq52hb_u.mjs} +69 -36
  42. package/dist/_chunks/Relations-Dq52hb_u.mjs.map +1 -0
  43. package/dist/_chunks/{Relations-Dhuurpx2.js → Relations-SRwPhmo7.js} +68 -35
  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-C9TJPyni.mjs → index-1Bdj-6ls.mjs} +2067 -1914
  50. package/dist/_chunks/index-1Bdj-6ls.mjs.map +1 -0
  51. package/dist/_chunks/{index-CdT0kHZ8.js → index-CsrCnNa3.js} +2048 -1894
  52. package/dist/_chunks/index-CsrCnNa3.js.map +1 -0
  53. package/dist/_chunks/{layout-C6dxWYT7.js → layout-B33V9Tdu.js} +5 -4
  54. package/dist/_chunks/{layout-C6dxWYT7.js.map → layout-B33V9Tdu.js.map} +1 -1
  55. package/dist/_chunks/{layout-BNqvLR_b.mjs → layout-ByD1cQSW.mjs} +5 -4
  56. package/dist/_chunks/{layout-BNqvLR_b.mjs.map → layout-ByD1cQSW.mjs.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-DtFaDnP1.js → relations-BBHlo3qQ.js} +3 -7
  62. package/dist/_chunks/relations-BBHlo3qQ.js.map +1 -0
  63. package/dist/_chunks/{relations-CkKqKw65.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/WysiwygStyles.d.ts +0 -32
  76. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  77. package/dist/admin/src/preview/constants.d.ts +1 -0
  78. package/dist/admin/src/preview/index.d.ts +4 -0
  79. package/dist/admin/src/services/api.d.ts +1 -1
  80. package/dist/admin/src/services/components.d.ts +2 -2
  81. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  82. package/dist/admin/src/services/documents.d.ts +19 -17
  83. package/dist/admin/src/services/init.d.ts +1 -1
  84. package/dist/admin/src/services/relations.d.ts +2 -2
  85. package/dist/admin/src/services/uid.d.ts +3 -3
  86. package/dist/admin/src/utils/validation.d.ts +4 -1
  87. package/dist/server/index.js +132 -55
  88. package/dist/server/index.js.map +1 -1
  89. package/dist/server/index.mjs +132 -55
  90. package/dist/server/index.mjs.map +1 -1
  91. package/dist/server/src/bootstrap.d.ts.map +1 -1
  92. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  93. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  94. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  95. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  96. package/dist/server/src/history/services/history.d.ts.map +1 -1
  97. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  98. package/dist/server/src/history/services/utils.d.ts +1 -0
  99. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  100. package/dist/server/src/index.d.ts +4 -4
  101. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  102. package/dist/server/src/preview/constants.d.ts +2 -0
  103. package/dist/server/src/preview/constants.d.ts.map +1 -0
  104. package/dist/server/src/preview/index.d.ts +4 -0
  105. package/dist/server/src/preview/index.d.ts.map +1 -0
  106. package/dist/server/src/services/document-metadata.d.ts +8 -8
  107. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  108. package/dist/server/src/services/index.d.ts +4 -4
  109. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  110. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  111. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  112. package/dist/server/src/utils/index.d.ts +2 -0
  113. package/dist/server/src/utils/index.d.ts.map +1 -1
  114. package/dist/shared/contracts/collection-types.d.ts +3 -1
  115. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  116. package/package.json +13 -13
  117. package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +0 -1
  118. package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +0 -1
  119. package/dist/_chunks/Field-CdK7ZLmv.js.map +0 -1
  120. package/dist/_chunks/Field-tHCw4lGA.mjs.map +0 -1
  121. package/dist/_chunks/Form-BJxdTv3Q.mjs.map +0 -1
  122. package/dist/_chunks/Form-C_0KTVvV.js.map +0 -1
  123. package/dist/_chunks/History-DR2txJLE.mjs.map +0 -1
  124. package/dist/_chunks/History-nuEzM5qm.js.map +0 -1
  125. package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +0 -1
  126. package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +0 -1
  127. package/dist/_chunks/Relations-CIYDdKU-.mjs.map +0 -1
  128. package/dist/_chunks/Relations-Dhuurpx2.js.map +0 -1
  129. package/dist/_chunks/index-C9TJPyni.mjs.map +0 -1
  130. package/dist/_chunks/index-CdT0kHZ8.js.map +0 -1
  131. package/dist/_chunks/relations-CkKqKw65.mjs.map +0 -1
  132. package/dist/_chunks/relations-DtFaDnP1.js.map +0 -1
  133. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  134. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  135. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  136. package/strapi-server.js +0 -3
@@ -199,7 +199,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
199
199
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
200
200
  };
201
201
  const localesService = strapi2.plugin("i18n")?.service("locales");
202
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
202
203
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
204
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
203
205
  const getLocaleDictionary = async () => {
204
206
  if (!localesService)
205
207
  return {};
@@ -317,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
317
319
  getRelationRestoreValue,
318
320
  getMediaRestoreValue,
319
321
  getDefaultLocale,
322
+ isLocalizedContentType,
320
323
  getLocaleDictionary,
321
324
  getRetentionDays,
322
325
  getVersionStatus,
@@ -339,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
339
342
  });
340
343
  },
341
344
  async findVersionsPage(params) {
342
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
345
+ const model = strapi2.getModel(params.query.contentType);
346
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
347
+ const defaultLocale = await serviceUtils.getDefaultLocale();
348
+ let locale = null;
349
+ if (isLocalizedContentType) {
350
+ locale = params.query.locale || defaultLocale;
351
+ }
343
352
  const [{ results, pagination }, localeDictionary] = await Promise.all([
344
353
  query.findPage({
345
354
  ...params.query,
@@ -384,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
384
393
  if (userToPopulate == null) {
385
394
  return null;
386
395
  }
387
- 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
+ });
388
402
  })
389
403
  );
390
404
  return {
@@ -555,11 +569,13 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
555
569
  }
556
570
  const uid2 = context.contentType.uid;
557
571
  const schemas = getSchemas(uid2);
572
+ const model = strapi2.getModel(uid2);
573
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
558
574
  const localeEntries = await strapi2.db.query(uid2).findMany({
559
575
  where: {
560
576
  documentId,
561
- locale: { $in: locales },
562
- publishedAt: null
577
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
578
+ ...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
563
579
  },
564
580
  populate: serviceUtils.getDeepPopulate(
565
581
  uid2,
@@ -679,7 +695,7 @@ const historyVersion = {
679
695
  }
680
696
  }
681
697
  };
682
- const getFeature = () => {
698
+ const getFeature$1 = () => {
683
699
  if (strapi.ee.features.isEnabled("cms-content-history")) {
684
700
  return {
685
701
  register({ strapi: strapi2 }) {
@@ -702,7 +718,7 @@ const getFeature = () => {
702
718
  }
703
719
  };
704
720
  };
705
- const history = getFeature();
721
+ const history = getFeature$1();
706
722
  const register = async ({ strapi: strapi2 }) => {
707
723
  await history.register?.({ strapi: strapi2 });
708
724
  };
@@ -710,6 +726,18 @@ const ALLOWED_WEBHOOK_EVENTS = {
710
726
  ENTRY_PUBLISH: "entry.publish",
711
727
  ENTRY_UNPUBLISH: "entry.unpublish"
712
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();
713
741
  const bootstrap = async () => {
714
742
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
715
743
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -719,6 +747,7 @@ const bootstrap = async () => {
719
747
  await getService$1("content-types").syncConfigurations();
720
748
  await getService$1("permission").registerPermissions();
721
749
  await history.bootstrap?.({ strapi });
750
+ await preview.bootstrap?.({ strapi });
722
751
  };
723
752
  const destroy = async ({ strapi: strapi2 }) => {
724
753
  await history.destroy?.({ strapi: strapi2 });
@@ -1219,6 +1248,11 @@ const { createPolicy } = strapiUtils.policy;
1219
1248
  const hasPermissions = createPolicy({
1220
1249
  name: "plugin::content-manager.hasPermissions",
1221
1250
  validator: validateHasPermissionsInput,
1251
+ /**
1252
+ * NOTE: Action aliases are currently not checked at this level (policy).
1253
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1254
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1255
+ */
1222
1256
  handler(ctx, config = {}) {
1223
1257
  const { actions = [], hasAtLeastOne = false } = config;
1224
1258
  const { userAbility } = ctx.state;
@@ -1699,7 +1733,7 @@ const updateDocument = async (ctx, opts) => {
1699
1733
  throw new strapiUtils.errors.ForbiddenError();
1700
1734
  }
1701
1735
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1702
- const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
1736
+ const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
1703
1737
  const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
1704
1738
  const sanitizedBody = await sanitizeFn(body);
1705
1739
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1771,7 +1805,7 @@ const collectionTypes = {
1771
1805
  permissionChecker2,
1772
1806
  model,
1773
1807
  // @ts-expect-error TODO: fix
1774
- { id, locale, publishedAt: null },
1808
+ { documentId: id, locale, publishedAt: null },
1775
1809
  { availableLocales: true, availableStatus: false }
1776
1810
  );
1777
1811
  ctx.body = { data: {}, meta };
@@ -1908,11 +1942,17 @@ const collectionTypes = {
1908
1942
  }
1909
1943
  const isUpdate = !isCreate;
1910
1944
  if (isUpdate) {
1911
- document = await documentManager2.findOne(id, model, { populate, locale });
1912
- if (!document) {
1945
+ const documentExists = documentManager2.exists(model, id);
1946
+ if (!documentExists) {
1913
1947
  throw new strapiUtils.errors.NotFoundError("Document not found");
1914
1948
  }
1915
- 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)) {
1916
1956
  await updateDocument(ctx);
1917
1957
  }
1918
1958
  }
@@ -1974,7 +2014,9 @@ const collectionTypes = {
1974
2014
  if (permissionChecker2.cannot.unpublish()) {
1975
2015
  return ctx.forbidden();
1976
2016
  }
1977
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2017
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2018
+ allowMultipleLocales: true
2019
+ });
1978
2020
  const entityPromises = documentIds.map(
1979
2021
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1980
2022
  );
@@ -2325,32 +2367,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2325
2367
  userAbility,
2326
2368
  model: model.uid
2327
2369
  });
2328
- if (!isListable(model, mainField)) {
2370
+ const isMainFieldListable = isListable(model, mainField);
2371
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2372
+ if (!isMainFieldListable || !canReadMainField) {
2329
2373
  return "id";
2330
2374
  }
2331
- if (permissionChecker2.cannot.read(null, mainField)) {
2332
- if (model.uid === "plugin::users-permissions.role") {
2333
- const userPermissionChecker = getService$1("permission-checker").create({
2334
- userAbility,
2335
- model: "plugin::users-permissions.user"
2336
- });
2337
- if (userPermissionChecker.can.read()) {
2338
- return "name";
2339
- }
2340
- }
2341
- return "id";
2375
+ if (model.uid === "plugin::users-permissions.role") {
2376
+ return "name";
2342
2377
  }
2343
2378
  return mainField;
2344
2379
  };
2345
- const addStatusToRelations = async (uid2, relations2) => {
2346
- if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2380
+ const addStatusToRelations = async (targetUid, relations2) => {
2381
+ if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
2347
2382
  return relations2;
2348
2383
  }
2349
2384
  const documentMetadata2 = getService$1("document-metadata");
2350
- 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
+ });
2351
2398
  return relations2.map((relation) => {
2352
- const availableStatuses = documentsAvailableStatus.filter(
2353
- (availableDocument) => availableDocument.documentId === relation.documentId
2399
+ const availableStatuses = availableStatus.filter(
2400
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2354
2401
  );
2355
2402
  return {
2356
2403
  ...relation,
@@ -2371,11 +2418,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2371
2418
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2372
2419
  const isSourceLocalized = isLocalized(sourceModel);
2373
2420
  const isTargetLocalized = isLocalized(targetModel);
2374
- let validatedLocale = locale;
2375
- if (!targetModel || !isTargetLocalized)
2376
- validatedLocale = void 0;
2377
2421
  return {
2378
- locale: validatedLocale,
2422
+ locale,
2379
2423
  isSourceLocalized,
2380
2424
  isTargetLocalized
2381
2425
  };
@@ -2478,7 +2522,7 @@ const relations = {
2478
2522
  attribute,
2479
2523
  fieldsToSelect,
2480
2524
  mainField,
2481
- source: { schema: sourceSchema },
2525
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2482
2526
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2483
2527
  sourceSchema,
2484
2528
  targetSchema,
@@ -2500,7 +2544,8 @@ const relations = {
2500
2544
  fieldsToSelect,
2501
2545
  mainField,
2502
2546
  source: {
2503
- schema: { uid: sourceUid, modelType: sourceModelType }
2547
+ schema: { uid: sourceUid, modelType: sourceModelType },
2548
+ isLocalized: isSourceLocalized
2504
2549
  },
2505
2550
  target: {
2506
2551
  schema: { uid: targetUid },
@@ -2538,12 +2583,16 @@ const relations = {
2538
2583
  } else {
2539
2584
  where.id = id;
2540
2585
  }
2541
- if (status) {
2542
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2586
+ const publishedAt = getPublishedAtClause(status, targetUid);
2587
+ if (!fp.isEmpty(publishedAt)) {
2588
+ where[`${alias}.published_at`] = publishedAt;
2543
2589
  }
2544
- if (filterByLocale) {
2590
+ if (isTargetLocalized && locale) {
2545
2591
  where[`${alias}.locale`] = locale;
2546
2592
  }
2593
+ if (isSourceLocalized && locale) {
2594
+ where.locale = locale;
2595
+ }
2547
2596
  if ((idsToInclude?.length ?? 0) !== 0) {
2548
2597
  where[`${alias}.id`].$notIn = idsToInclude;
2549
2598
  }
@@ -2561,7 +2610,8 @@ const relations = {
2561
2610
  id: { $notIn: fp.uniq(idsToOmit) }
2562
2611
  });
2563
2612
  }
2564
- 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);
2565
2615
  ctx.body = {
2566
2616
  ...res,
2567
2617
  results: await addStatusToRelations(targetUid, res.results)
@@ -2576,29 +2626,39 @@ const relations = {
2576
2626
  attribute,
2577
2627
  targetField,
2578
2628
  fieldsToSelect,
2579
- source: {
2580
- schema: { uid: sourceUid }
2581
- },
2582
- target: {
2583
- schema: { uid: targetUid }
2584
- }
2629
+ status,
2630
+ source: { schema: sourceSchema },
2631
+ target: { schema: targetSchema }
2585
2632
  } = await this.extractAndValidateRequestInfo(ctx, id);
2633
+ const { uid: sourceUid } = sourceSchema;
2634
+ const { uid: targetUid } = targetSchema;
2586
2635
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2587
2636
  const dbQuery = strapi.db.query(sourceUid);
2588
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
+ }
2589
2650
  const res = await loadRelations({ id: entryId }, targetField, {
2590
- select: ["id", "documentId", "locale", "publishedAt"],
2651
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2591
2652
  ordering: "desc",
2592
2653
  page: ctx.request.query.page,
2593
- pageSize: ctx.request.query.pageSize
2654
+ pageSize: ctx.request.query.pageSize,
2655
+ filters
2594
2656
  });
2595
2657
  const loadedIds = res.results.map((item) => item.id);
2596
2658
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2597
2659
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2598
2660
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2599
- ordering: "desc",
2600
- page: ctx.request.query.page,
2601
- pageSize: ctx.request.query.pageSize
2661
+ ordering: "desc"
2602
2662
  });
2603
2663
  const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
2604
2664
  ctx.body = {
@@ -2685,7 +2745,7 @@ const singleTypes = {
2685
2745
  permissionChecker2,
2686
2746
  model,
2687
2747
  // @ts-expect-error - fix types
2688
- { id: document.documentId, locale, publishedAt: null },
2748
+ { documentId: document.documentId, locale, publishedAt: null },
2689
2749
  { availableLocales: true, availableStatus: false }
2690
2750
  );
2691
2751
  ctx.body = { data: {}, meta };
@@ -3504,12 +3564,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3504
3564
  ability: userAbility,
3505
3565
  model
3506
3566
  });
3507
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3567
+ const { actionProvider } = strapi2.service("admin::permission");
3568
+ const toSubject = (entity) => {
3569
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3570
+ };
3508
3571
  const can = (action, entity, field) => {
3509
- return userAbility.can(action, toSubject(entity), field);
3572
+ const subject = toSubject(entity);
3573
+ const aliases = actionProvider.unstable_aliases(action, model);
3574
+ return (
3575
+ // Test the original action to see if it passes
3576
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3577
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3578
+ );
3510
3579
  };
3511
3580
  const cannot = (action, entity, field) => {
3512
- return userAbility.cannot(action, toSubject(entity), field);
3581
+ const subject = toSubject(entity);
3582
+ const aliases = actionProvider.unstable_aliases(action, model);
3583
+ return (
3584
+ // Test both the original action
3585
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3586
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3587
+ );
3513
3588
  };
3514
3589
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3515
3590
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -4041,7 +4116,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4041
4116
  */
4042
4117
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4043
4118
  const versionsByLocale = fp.groupBy("locale", allVersions);
4044
- delete versionsByLocale[version.locale];
4119
+ if (version.locale) {
4120
+ delete versionsByLocale[version.locale];
4121
+ }
4045
4122
  const model = strapi2.getModel(uid2);
4046
4123
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4047
4124
  const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(