@strapi/content-manager 0.0.0-experimental.d53e940834bf72ddc725f1d2fd36dac9abec30cb → 0.0.0-experimental.d74a8e5e655230b243e2d61ab5bec2fcdb426993

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 (169) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs → ComponentConfigurationPage-CIjXcRAB.mjs} +4 -4
  3. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs.map → ComponentConfigurationPage-CIjXcRAB.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js → ComponentConfigurationPage-gsCd80MU.js} +4 -4
  5. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js.map → ComponentConfigurationPage-gsCd80MU.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs → EditConfigurationPage-BglmD_BF.mjs} +4 -4
  7. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs.map → EditConfigurationPage-BglmD_BF.mjs.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js → EditConfigurationPage-DHDQKBzw.js} +4 -4
  9. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js.map → EditConfigurationPage-DHDQKBzw.js.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-zT3fBr4Y.js → EditViewPage-C4iTxUPU.js} +30 -9
  11. package/dist/_chunks/EditViewPage-C4iTxUPU.js.map +1 -0
  12. package/dist/_chunks/{EditViewPage-CPj61RMh.mjs → EditViewPage-CiwVPMaK.mjs} +30 -9
  13. package/dist/_chunks/EditViewPage-CiwVPMaK.mjs.map +1 -0
  14. package/dist/_chunks/{Field-dha5VnIQ.mjs → Field-DIjL1b5d.mjs} +249 -152
  15. package/dist/_chunks/Field-DIjL1b5d.mjs.map +1 -0
  16. package/dist/_chunks/{Field-Boxf9Ajp.js → Field-DhXEK8y1.js} +251 -154
  17. package/dist/_chunks/Field-DhXEK8y1.js.map +1 -0
  18. package/dist/_chunks/{Form-DHrru2AV.mjs → Form-CmNesrvR.mjs} +36 -17
  19. package/dist/_chunks/Form-CmNesrvR.mjs.map +1 -0
  20. package/dist/_chunks/{Form-y5g1SRsh.js → Form-CwmJ4sWe.js} +36 -17
  21. package/dist/_chunks/Form-CwmJ4sWe.js.map +1 -0
  22. package/dist/_chunks/{History-CqN6K7SX.js → History-BLCCNgCt.js} +64 -26
  23. package/dist/_chunks/History-BLCCNgCt.js.map +1 -0
  24. package/dist/_chunks/{History-Bru_KoeP.mjs → History-D-99Wh30.mjs} +65 -27
  25. package/dist/_chunks/History-D-99Wh30.mjs.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-R_p-SbHZ.js → ListConfigurationPage-DxWpeZrO.js} +21 -9
  27. package/dist/_chunks/ListConfigurationPage-DxWpeZrO.js.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-D8wGABj0.mjs → ListConfigurationPage-JPWZz7Kg.mjs} +21 -9
  29. package/dist/_chunks/ListConfigurationPage-JPWZz7Kg.mjs.map +1 -0
  30. package/dist/_chunks/{ListViewPage-pEw_zug9.js → ListViewPage-CIQekSFz.js} +73 -44
  31. package/dist/_chunks/ListViewPage-CIQekSFz.js.map +1 -0
  32. package/dist/_chunks/{ListViewPage-SID6TRb9.mjs → ListViewPage-DSK3f0ST.mjs} +71 -42
  33. package/dist/_chunks/ListViewPage-DSK3f0ST.mjs.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js → NoContentTypePage-C5cxKvC2.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js.map → NoContentTypePage-C5cxKvC2.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs → NoContentTypePage-D99LU1YP.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs.map → NoContentTypePage-D99LU1YP.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs → NoPermissionsPage-DBrBw-0y.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs.map → NoPermissionsPage-DBrBw-0y.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js → NoPermissionsPage-Oy4tmUrW.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js.map → NoPermissionsPage-Oy4tmUrW.js.map} +1 -1
  42. package/dist/_chunks/{Relations-B9Crnhnn.mjs → Relations-BBmhcWFV.mjs} +70 -37
  43. package/dist/_chunks/Relations-BBmhcWFV.mjs.map +1 -0
  44. package/dist/_chunks/{Relations-DjTQ5kGB.js → Relations-eG-9p_qS.js} +69 -36
  45. package/dist/_chunks/Relations-eG-9p_qS.js.map +1 -0
  46. package/dist/_chunks/{en-fbKQxLGn.js → en-Bm0D0IWz.js} +17 -15
  47. package/dist/_chunks/{en-fbKQxLGn.js.map → en-Bm0D0IWz.js.map} +1 -1
  48. package/dist/_chunks/{en-Ux26r5pl.mjs → en-DKV44jRb.mjs} +17 -15
  49. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-DKV44jRb.mjs.map} +1 -1
  50. package/dist/_chunks/{index-DVPWZkbS.js → index-BIWDoFLK.js} +1003 -669
  51. package/dist/_chunks/index-BIWDoFLK.js.map +1 -0
  52. package/dist/_chunks/{index-DJXJw9V5.mjs → index-BrUzbQ30.mjs} +1021 -688
  53. package/dist/_chunks/index-BrUzbQ30.mjs.map +1 -0
  54. package/dist/_chunks/{layout-Bau7ZfLV.mjs → layout-_5-cXs34.mjs} +25 -12
  55. package/dist/_chunks/layout-_5-cXs34.mjs.map +1 -0
  56. package/dist/_chunks/{layout-Dm6fbiQj.js → layout-lMc9i1-Z.js} +24 -11
  57. package/dist/_chunks/layout-lMc9i1-Z.js.map +1 -0
  58. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  59. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  60. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  61. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  62. package/dist/_chunks/{relations-CKnpRgrN.js → relations-BRHithi8.js} +3 -7
  63. package/dist/_chunks/relations-BRHithi8.js.map +1 -0
  64. package/dist/_chunks/{relations-BH_kBSJ0.mjs → relations-B_VLk-DD.mjs} +3 -7
  65. package/dist/_chunks/relations-B_VLk-DD.mjs.map +1 -0
  66. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  67. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  68. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  69. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  70. package/dist/admin/index.js +2 -1
  71. package/dist/admin/index.js.map +1 -1
  72. package/dist/admin/index.mjs +5 -4
  73. package/dist/admin/src/exports.d.ts +1 -1
  74. package/dist/admin/src/history/index.d.ts +3 -0
  75. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  76. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  77. package/dist/admin/src/index.d.ts +1 -0
  78. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
  79. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  80. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  81. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  82. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  83. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  84. package/dist/admin/src/preview/constants.d.ts +1 -0
  85. package/dist/admin/src/preview/index.d.ts +4 -0
  86. package/dist/admin/src/services/api.d.ts +1 -1
  87. package/dist/admin/src/services/components.d.ts +2 -2
  88. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  89. package/dist/admin/src/services/documents.d.ts +19 -17
  90. package/dist/admin/src/services/init.d.ts +1 -1
  91. package/dist/admin/src/services/relations.d.ts +2 -2
  92. package/dist/admin/src/services/uid.d.ts +3 -3
  93. package/dist/admin/src/utils/validation.d.ts +4 -1
  94. package/dist/server/index.js +321 -148
  95. package/dist/server/index.js.map +1 -1
  96. package/dist/server/index.mjs +322 -149
  97. package/dist/server/index.mjs.map +1 -1
  98. package/dist/server/src/bootstrap.d.ts.map +1 -1
  99. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  100. package/dist/server/src/controllers/index.d.ts.map +1 -1
  101. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  102. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  103. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  104. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  105. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  106. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  107. package/dist/server/src/history/services/history.d.ts.map +1 -1
  108. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  109. package/dist/server/src/history/services/utils.d.ts +4 -4
  110. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  111. package/dist/server/src/index.d.ts +4 -4
  112. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  113. package/dist/server/src/preview/constants.d.ts +2 -0
  114. package/dist/server/src/preview/constants.d.ts.map +1 -0
  115. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  116. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  117. package/dist/server/src/preview/controllers/preview.d.ts +9 -0
  118. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  119. package/dist/server/src/preview/index.d.ts +4 -0
  120. package/dist/server/src/preview/index.d.ts.map +1 -0
  121. package/dist/server/src/preview/routes/index.d.ts +8 -0
  122. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  123. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  124. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  125. package/dist/server/src/preview/services/index.d.ts +4 -0
  126. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  127. package/dist/server/src/preview/services/preview.d.ts +6 -0
  128. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  129. package/dist/server/src/preview/utils.d.ts +7 -0
  130. package/dist/server/src/preview/utils.d.ts.map +1 -0
  131. package/dist/server/src/routes/index.d.ts.map +1 -1
  132. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  133. package/dist/server/src/services/document-metadata.d.ts +8 -8
  134. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  135. package/dist/server/src/services/index.d.ts +4 -4
  136. package/dist/server/src/services/index.d.ts.map +1 -1
  137. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  138. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  139. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  140. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  141. package/dist/server/src/utils/index.d.ts +2 -0
  142. package/dist/server/src/utils/index.d.ts.map +1 -1
  143. package/dist/shared/contracts/collection-types.d.ts +3 -1
  144. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  145. package/package.json +12 -12
  146. package/dist/_chunks/EditViewPage-CPj61RMh.mjs.map +0 -1
  147. package/dist/_chunks/EditViewPage-zT3fBr4Y.js.map +0 -1
  148. package/dist/_chunks/Field-Boxf9Ajp.js.map +0 -1
  149. package/dist/_chunks/Field-dha5VnIQ.mjs.map +0 -1
  150. package/dist/_chunks/Form-DHrru2AV.mjs.map +0 -1
  151. package/dist/_chunks/Form-y5g1SRsh.js.map +0 -1
  152. package/dist/_chunks/History-Bru_KoeP.mjs.map +0 -1
  153. package/dist/_chunks/History-CqN6K7SX.js.map +0 -1
  154. package/dist/_chunks/ListConfigurationPage-D8wGABj0.mjs.map +0 -1
  155. package/dist/_chunks/ListConfigurationPage-R_p-SbHZ.js.map +0 -1
  156. package/dist/_chunks/ListViewPage-SID6TRb9.mjs.map +0 -1
  157. package/dist/_chunks/ListViewPage-pEw_zug9.js.map +0 -1
  158. package/dist/_chunks/Relations-B9Crnhnn.mjs.map +0 -1
  159. package/dist/_chunks/Relations-DjTQ5kGB.js.map +0 -1
  160. package/dist/_chunks/index-DJXJw9V5.mjs.map +0 -1
  161. package/dist/_chunks/index-DVPWZkbS.js.map +0 -1
  162. package/dist/_chunks/layout-Bau7ZfLV.mjs.map +0 -1
  163. package/dist/_chunks/layout-Dm6fbiQj.js.map +0 -1
  164. package/dist/_chunks/relations-BH_kBSJ0.mjs.map +0 -1
  165. package/dist/_chunks/relations-CKnpRgrN.js.map +0 -1
  166. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  167. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  168. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  169. package/strapi-server.js +0 -3
@@ -1,5 +1,5 @@
1
1
  import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
2
- import { pick, omit, difference, intersection, pipe, propOr, isEqual, isEmpty, set, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, isNil as isNil$1, getOr, propEq, merge, groupBy, castArray } from "lodash/fp";
2
+ import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
5
5
  import { scheduleJob } from "node-schedule";
@@ -95,7 +95,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
95
95
  }
96
96
  };
97
97
  };
98
- const controllers$1 = {
98
+ const controllers$2 = {
99
99
  "history-version": createHistoryVersionController
100
100
  /**
101
101
  * Casting is needed because the types aren't aware that Strapi supports
@@ -173,7 +173,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
173
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
174
  };
175
175
  const localesService = strapi2.plugin("i18n")?.service("locales");
176
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
177
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
179
  const getLocaleDictionary = async () => {
178
180
  if (!localesService)
179
181
  return {};
@@ -200,20 +202,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
202
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
203
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
204
  };
203
- const getDeepPopulate2 = (uid2) => {
205
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
206
  const model = strapi2.getModel(uid2);
205
207
  const attributes = Object.entries(model.attributes);
208
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
209
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
210
  switch (attribute.type) {
208
211
  case "relation": {
212
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
213
+ if (isMorphRelation) {
214
+ break;
215
+ }
209
216
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
210
217
  if (isVisible2) {
211
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
218
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
212
219
  }
213
220
  break;
214
221
  }
215
222
  case "media": {
216
- acc[attributeName] = { fields: ["id"] };
223
+ acc[attributeName] = { [fieldSelector]: ["id"] };
217
224
  break;
218
225
  }
219
226
  case "component": {
@@ -286,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
286
293
  getRelationRestoreValue,
287
294
  getMediaRestoreValue,
288
295
  getDefaultLocale,
296
+ isLocalizedContentType,
289
297
  getLocaleDictionary,
290
298
  getRetentionDays,
291
299
  getVersionStatus,
@@ -308,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
308
316
  });
309
317
  },
310
318
  async findVersionsPage(params) {
311
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
319
+ const model = strapi2.getModel(params.query.contentType);
320
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
321
+ const defaultLocale = await serviceUtils.getDefaultLocale();
322
+ let locale = null;
323
+ if (isLocalizedContentType) {
324
+ locale = params.query.locale || defaultLocale;
325
+ }
312
326
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
313
327
  query.findPage({
314
328
  ...params.query,
@@ -353,7 +367,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
353
367
  if (userToPopulate == null) {
354
368
  return null;
355
369
  }
356
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
370
+ return strapi2.query("admin::user").findOne({
371
+ where: {
372
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
373
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
374
+ }
375
+ });
357
376
  })
358
377
  );
359
378
  return {
@@ -464,6 +483,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
464
483
  }
465
484
  };
466
485
  };
486
+ const shouldCreateHistoryVersion = (context) => {
487
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
488
+ return false;
489
+ }
490
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
491
+ return false;
492
+ }
493
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
494
+ return false;
495
+ }
496
+ if (!context.contentType.uid.startsWith("api::")) {
497
+ return false;
498
+ }
499
+ return true;
500
+ };
501
+ const getSchemas = (uid2) => {
502
+ const attributesSchema = strapi.getModel(uid2).attributes;
503
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
504
+ (currentComponentSchemas, key) => {
505
+ const fieldSchema = attributesSchema[key];
506
+ if (fieldSchema.type === "component") {
507
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
508
+ return {
509
+ ...currentComponentSchemas,
510
+ [fieldSchema.component]: componentSchema
511
+ };
512
+ }
513
+ return currentComponentSchemas;
514
+ },
515
+ {}
516
+ );
517
+ return {
518
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
519
+ componentsSchemas
520
+ };
521
+ };
467
522
  const createLifecyclesService = ({ strapi: strapi2 }) => {
468
523
  const state = {
469
524
  deleteExpiredJob: null,
@@ -476,63 +531,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
476
531
  return;
477
532
  }
478
533
  strapi2.documents.use(async (context, next) => {
479
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
480
- return next();
481
- }
482
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
483
- return next();
484
- }
485
- if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
486
- return next();
487
- }
488
- const contentTypeUid = context.contentType.uid;
489
- if (!contentTypeUid.startsWith("api::")) {
490
- return next();
491
- }
492
534
  const result = await next();
493
- const documentContext = {
494
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
495
- locale: context.params?.locale
496
- };
535
+ if (!shouldCreateHistoryVersion(context)) {
536
+ return result;
537
+ }
538
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
497
539
  const defaultLocale = await serviceUtils.getDefaultLocale();
498
- const locale = documentContext.locale || defaultLocale;
499
- if (Array.isArray(locale)) {
500
- strapi2.log.warn(
501
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
502
- );
503
- return next();
540
+ const locales = castArray(context.params?.locale || defaultLocale);
541
+ if (!locales.length) {
542
+ return result;
504
543
  }
505
- const document = await strapi2.documents(contentTypeUid).findOne({
506
- documentId: documentContext.documentId,
507
- locale,
508
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
544
+ const uid2 = context.contentType.uid;
545
+ const schemas = getSchemas(uid2);
546
+ const model = strapi2.getModel(uid2);
547
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
548
+ const localeEntries = await strapi2.db.query(uid2).findMany({
549
+ where: {
550
+ documentId,
551
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
552
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
553
+ },
554
+ populate: serviceUtils.getDeepPopulate(
555
+ uid2,
556
+ true
557
+ /* use database syntax */
558
+ )
509
559
  });
510
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
511
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
512
- const componentsSchemas = Object.keys(
513
- attributesSchema
514
- ).reduce((currentComponentSchemas, key) => {
515
- const fieldSchema = attributesSchema[key];
516
- if (fieldSchema.type === "component") {
517
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
518
- return {
519
- ...currentComponentSchemas,
520
- [fieldSchema.component]: componentSchema
521
- };
522
- }
523
- return currentComponentSchemas;
524
- }, {});
525
560
  await strapi2.db.transaction(async ({ onCommit }) => {
526
- onCommit(() => {
527
- getService(strapi2, "history").createVersion({
528
- contentType: contentTypeUid,
529
- data: omit(FIELDS_TO_IGNORE, document),
530
- schema: omit(FIELDS_TO_IGNORE, attributesSchema),
531
- componentsSchemas,
532
- relatedDocumentId: documentContext.documentId,
533
- locale,
534
- status
535
- });
561
+ onCommit(async () => {
562
+ for (const entry of localeEntries) {
563
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
564
+ await getService(strapi2, "history").createVersion({
565
+ contentType: uid2,
566
+ data: omit(FIELDS_TO_IGNORE, entry),
567
+ relatedDocumentId: documentId,
568
+ locale: entry.locale,
569
+ status,
570
+ ...schemas
571
+ });
572
+ }
536
573
  });
537
574
  });
538
575
  return result;
@@ -557,17 +594,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
557
594
  }
558
595
  };
559
596
  };
560
- const services$1 = {
597
+ const services$2 = {
561
598
  history: createHistoryService,
562
599
  lifecycles: createLifecyclesService
563
600
  };
564
- const info = { pluginName: "content-manager", type: "admin" };
601
+ const info$1 = { pluginName: "content-manager", type: "admin" };
565
602
  const historyVersionRouter = {
566
603
  type: "admin",
567
604
  routes: [
568
605
  {
569
606
  method: "GET",
570
- info,
607
+ info: info$1,
571
608
  path: "/history-versions",
572
609
  handler: "history-version.findMany",
573
610
  config: {
@@ -576,7 +613,7 @@ const historyVersionRouter = {
576
613
  },
577
614
  {
578
615
  method: "PUT",
579
- info,
616
+ info: info$1,
580
617
  path: "/history-versions/:versionId/restore",
581
618
  handler: "history-version.restoreVersion",
582
619
  config: {
@@ -585,7 +622,7 @@ const historyVersionRouter = {
585
622
  }
586
623
  ]
587
624
  };
588
- const routes$1 = {
625
+ const routes$2 = {
589
626
  "history-version": historyVersionRouter
590
627
  };
591
628
  const historyVersion = {
@@ -632,7 +669,7 @@ const historyVersion = {
632
669
  }
633
670
  }
634
671
  };
635
- const getFeature = () => {
672
+ const getFeature$1 = () => {
636
673
  if (strapi.ee.features.isEnabled("cms-content-history")) {
637
674
  return {
638
675
  register({ strapi: strapi2 }) {
@@ -644,9 +681,9 @@ const getFeature = () => {
644
681
  destroy({ strapi: strapi2 }) {
645
682
  getService(strapi2, "lifecycles").destroy();
646
683
  },
647
- controllers: controllers$1,
648
- services: services$1,
649
- routes: routes$1
684
+ controllers: controllers$2,
685
+ services: services$2,
686
+ routes: routes$2
650
687
  };
651
688
  }
652
689
  return {
@@ -655,7 +692,7 @@ const getFeature = () => {
655
692
  }
656
693
  };
657
694
  };
658
- const history = getFeature();
695
+ const history = getFeature$1();
659
696
  const register = async ({ strapi: strapi2 }) => {
660
697
  await history.register?.({ strapi: strapi2 });
661
698
  };
@@ -663,6 +700,62 @@ const ALLOWED_WEBHOOK_EVENTS = {
663
700
  ENTRY_PUBLISH: "entry.publish",
664
701
  ENTRY_UNPUBLISH: "entry.unpublish"
665
702
  };
703
+ const FEATURE_ID = "preview";
704
+ const info = { pluginName: "content-manager", type: "admin" };
705
+ const previewRouter = {
706
+ type: "admin",
707
+ routes: [
708
+ {
709
+ method: "GET",
710
+ info,
711
+ path: "/preview/url/:contentType",
712
+ handler: "preview.getPreviewURL",
713
+ config: {
714
+ policies: ["admin::isAuthenticatedAdmin"]
715
+ }
716
+ }
717
+ ]
718
+ };
719
+ const routes$1 = {
720
+ preview: previewRouter
721
+ };
722
+ const createPreviewController = () => {
723
+ return {
724
+ async getPreviewURL(ctx) {
725
+ ctx.request;
726
+ return {
727
+ data: { url: "" }
728
+ };
729
+ }
730
+ };
731
+ };
732
+ const controllers$1 = {
733
+ preview: createPreviewController
734
+ /**
735
+ * Casting is needed because the types aren't aware that Strapi supports
736
+ * passing a controller factory as the value, instead of a controller object directly
737
+ */
738
+ };
739
+ const createPreviewService = () => {
740
+ };
741
+ const services$1 = {
742
+ preview: createPreviewService
743
+ };
744
+ const getFeature = () => {
745
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
746
+ return {};
747
+ }
748
+ return {
749
+ bootstrap() {
750
+ console.log("Bootstrapping preview server");
751
+ strapi.config.get("admin.preview");
752
+ },
753
+ routes: routes$1,
754
+ controllers: controllers$1,
755
+ services: services$1
756
+ };
757
+ };
758
+ const preview = getFeature();
666
759
  const bootstrap = async () => {
667
760
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
668
761
  strapi.get("webhookStore").addAllowedEvent(key, value);
@@ -672,6 +765,7 @@ const bootstrap = async () => {
672
765
  await getService$1("content-types").syncConfigurations();
673
766
  await getService$1("permission").registerPermissions();
674
767
  await history.bootstrap?.({ strapi });
768
+ await preview.bootstrap?.({ strapi });
675
769
  };
676
770
  const destroy = async ({ strapi: strapi2 }) => {
677
771
  await history.destroy?.({ strapi: strapi2 });
@@ -1161,7 +1255,8 @@ const admin = {
1161
1255
  };
1162
1256
  const routes = {
1163
1257
  admin,
1164
- ...history.routes ? history.routes : {}
1258
+ ...history.routes ? history.routes : {},
1259
+ ...preview.routes ? preview.routes : {}
1165
1260
  };
1166
1261
  const hasPermissionsSchema = yup$1.object({
1167
1262
  actions: yup$1.array().of(yup$1.string()),
@@ -1172,6 +1267,11 @@ const { createPolicy } = policy;
1172
1267
  const hasPermissions = createPolicy({
1173
1268
  name: "plugin::content-manager.hasPermissions",
1174
1269
  validator: validateHasPermissionsInput,
1270
+ /**
1271
+ * NOTE: Action aliases are currently not checked at this level (policy).
1272
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1273
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1274
+ */
1175
1275
  handler(ctx, config = {}) {
1176
1276
  const { actions = [], hasAtLeastOne = false } = config;
1177
1277
  const { userAbility } = ctx.state;
@@ -1565,9 +1665,11 @@ const multipleLocaleSchema = yup$1.lazy(
1565
1665
  (value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1566
1666
  );
1567
1667
  const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
1568
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1668
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1569
1669
  const { allowMultipleLocales } = opts;
1570
- const { locale, status, ...rest } = request || {};
1670
+ const { locale, status: providedStatus, ...rest } = request || {};
1671
+ const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1672
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1571
1673
  const schema = yup$1.object().shape({
1572
1674
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1573
1675
  status: statusSchema
@@ -1615,7 +1717,7 @@ const createDocument = async (ctx, opts) => {
1615
1717
  const setCreator = setCreatorFields({ user });
1616
1718
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1617
1719
  const sanitizedBody = await sanitizeFn(body);
1618
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1720
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1619
1721
  return documentManager2.create(model, {
1620
1722
  data: sanitizedBody,
1621
1723
  locale,
@@ -1634,7 +1736,7 @@ const updateDocument = async (ctx, opts) => {
1634
1736
  }
1635
1737
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1636
1738
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1637
- const { locale } = await getDocumentLocaleAndStatus(body);
1739
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1638
1740
  const [documentVersion, documentExists] = await Promise.all([
1639
1741
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1640
1742
  documentManager2.exists(model, id)
@@ -1650,7 +1752,7 @@ const updateDocument = async (ctx, opts) => {
1650
1752
  throw new errors.ForbiddenError();
1651
1753
  }
1652
1754
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1653
- const setCreator = setCreatorFields({ user, isEdition: true });
1755
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1654
1756
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1655
1757
  const sanitizedBody = await sanitizeFn(body);
1656
1758
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1672,7 +1774,7 @@ const collectionTypes = {
1672
1774
  }
1673
1775
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1674
1776
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1675
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1777
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1676
1778
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1677
1779
  { ...permissionQuery, populate, locale, status },
1678
1780
  model
@@ -1707,7 +1809,7 @@ const collectionTypes = {
1707
1809
  }
1708
1810
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1709
1811
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1710
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1812
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1711
1813
  const version = await documentManager2.findOne(id, model, {
1712
1814
  populate,
1713
1815
  locale,
@@ -1722,7 +1824,7 @@ const collectionTypes = {
1722
1824
  permissionChecker2,
1723
1825
  model,
1724
1826
  // @ts-expect-error TODO: fix
1725
- { id, locale, publishedAt: null },
1827
+ { documentId: id, locale, publishedAt: null },
1726
1828
  { availableLocales: true, availableStatus: false }
1727
1829
  );
1728
1830
  ctx.body = { data: {}, meta };
@@ -1774,7 +1876,7 @@ const collectionTypes = {
1774
1876
  }
1775
1877
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1776
1878
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1777
- const { locale } = await getDocumentLocaleAndStatus(body);
1879
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1778
1880
  const document = await documentManager2.findOne(id, model, {
1779
1881
  populate,
1780
1882
  locale,
@@ -1819,7 +1921,7 @@ const collectionTypes = {
1819
1921
  }
1820
1922
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1821
1923
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1822
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1924
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1823
1925
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1824
1926
  if (documentLocales.length === 0) {
1825
1927
  return ctx.notFound();
@@ -1848,11 +1950,34 @@ const collectionTypes = {
1848
1950
  const publishedDocument = await strapi.db.transaction(async () => {
1849
1951
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1850
1952
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1851
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1953
+ let document;
1954
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1955
+ const isCreate = isNil$1(id);
1956
+ if (isCreate) {
1957
+ if (permissionChecker2.cannot.create()) {
1958
+ throw new errors.ForbiddenError();
1959
+ }
1960
+ document = await createDocument(ctx, { populate });
1961
+ }
1962
+ const isUpdate = !isCreate;
1963
+ if (isUpdate) {
1964
+ const documentExists = documentManager2.exists(model, id);
1965
+ if (!documentExists) {
1966
+ throw new errors.NotFoundError("Document not found");
1967
+ }
1968
+ document = await documentManager2.findOne(id, model, { populate, locale });
1969
+ if (!document) {
1970
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1971
+ throw new errors.ForbiddenError();
1972
+ }
1973
+ document = await updateDocument(ctx);
1974
+ } else if (permissionChecker2.can.update(document)) {
1975
+ await updateDocument(ctx);
1976
+ }
1977
+ }
1852
1978
  if (permissionChecker2.cannot.publish(document)) {
1853
1979
  throw new errors.ForbiddenError();
1854
1980
  }
1855
- const { locale } = await getDocumentLocaleAndStatus(body);
1856
1981
  const publishResult = await documentManager2.publish(document.documentId, model, {
1857
1982
  locale
1858
1983
  // TODO: Allow setting creator fields on publish
@@ -1879,7 +2004,9 @@ const collectionTypes = {
1879
2004
  }
1880
2005
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1881
2006
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1882
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
2007
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2008
+ allowMultipleLocales: true
2009
+ });
1883
2010
  const entityPromises = documentIds.map(
1884
2011
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1885
2012
  );
@@ -1906,7 +2033,9 @@ const collectionTypes = {
1906
2033
  if (permissionChecker2.cannot.unpublish()) {
1907
2034
  return ctx.forbidden();
1908
2035
  }
1909
- const { locale } = await getDocumentLocaleAndStatus(body);
2036
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2037
+ allowMultipleLocales: true
2038
+ });
1910
2039
  const entityPromises = documentIds.map(
1911
2040
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1912
2041
  );
@@ -1939,7 +2068,7 @@ const collectionTypes = {
1939
2068
  }
1940
2069
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1941
2070
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1942
- const { locale } = await getDocumentLocaleAndStatus(body);
2071
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1943
2072
  const document = await documentManager2.findOne(id, model, {
1944
2073
  populate,
1945
2074
  locale,
@@ -1976,7 +2105,7 @@ const collectionTypes = {
1976
2105
  }
1977
2106
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1978
2107
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1979
- const { locale } = await getDocumentLocaleAndStatus(body);
2108
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1980
2109
  const document = await documentManager2.findOne(id, model, {
1981
2110
  populate,
1982
2111
  locale,
@@ -2007,7 +2136,7 @@ const collectionTypes = {
2007
2136
  }
2008
2137
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2009
2138
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2010
- const { locale } = await getDocumentLocaleAndStatus(body);
2139
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2011
2140
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2012
2141
  populate,
2013
2142
  locale
@@ -2034,7 +2163,7 @@ const collectionTypes = {
2034
2163
  }
2035
2164
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2036
2165
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2037
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2166
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2038
2167
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2039
2168
  if (!entity) {
2040
2169
  return ctx.notFound();
@@ -2057,7 +2186,7 @@ const collectionTypes = {
2057
2186
  if (permissionChecker2.cannot.read()) {
2058
2187
  return ctx.forbidden();
2059
2188
  }
2060
- const entities = await documentManager2.findMany(
2189
+ const documents = await documentManager2.findMany(
2061
2190
  {
2062
2191
  filters: {
2063
2192
  documentId: ids
@@ -2066,7 +2195,7 @@ const collectionTypes = {
2066
2195
  },
2067
2196
  model
2068
2197
  );
2069
- if (!entities) {
2198
+ if (!documents) {
2070
2199
  return ctx.notFound();
2071
2200
  }
2072
2201
  const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
@@ -2257,32 +2386,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2257
2386
  userAbility,
2258
2387
  model: model.uid
2259
2388
  });
2260
- if (!isListable(model, mainField)) {
2389
+ const isMainFieldListable = isListable(model, mainField);
2390
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2391
+ if (!isMainFieldListable || !canReadMainField) {
2261
2392
  return "id";
2262
2393
  }
2263
- if (permissionChecker2.cannot.read(null, mainField)) {
2264
- if (model.uid === "plugin::users-permissions.role") {
2265
- const userPermissionChecker = getService$1("permission-checker").create({
2266
- userAbility,
2267
- model: "plugin::users-permissions.user"
2268
- });
2269
- if (userPermissionChecker.can.read()) {
2270
- return "name";
2271
- }
2272
- }
2273
- return "id";
2394
+ if (model.uid === "plugin::users-permissions.role") {
2395
+ return "name";
2274
2396
  }
2275
2397
  return mainField;
2276
2398
  };
2277
- const addStatusToRelations = async (uid2, relations2) => {
2278
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2399
+ const addStatusToRelations = async (targetUid, relations2) => {
2400
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2279
2401
  return relations2;
2280
2402
  }
2281
2403
  const documentMetadata2 = getService$1("document-metadata");
2282
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2404
+ if (!relations2.length) {
2405
+ return relations2;
2406
+ }
2407
+ const firstRelation = relations2[0];
2408
+ const filters = {
2409
+ documentId: { $in: relations2.map((r) => r.documentId) },
2410
+ // NOTE: find the "opposite" status
2411
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2412
+ };
2413
+ const availableStatus = await strapi.query(targetUid).findMany({
2414
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2415
+ filters
2416
+ });
2283
2417
  return relations2.map((relation) => {
2284
- const availableStatuses = documentsAvailableStatus.filter(
2285
- (availableDocument) => availableDocument.documentId === relation.documentId
2418
+ const availableStatuses = availableStatus.filter(
2419
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2286
2420
  );
2287
2421
  return {
2288
2422
  ...relation,
@@ -2303,11 +2437,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2303
2437
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2304
2438
  const isSourceLocalized = isLocalized(sourceModel);
2305
2439
  const isTargetLocalized = isLocalized(targetModel);
2306
- let validatedLocale = locale;
2307
- if (!targetModel || !isTargetLocalized)
2308
- validatedLocale = void 0;
2309
2440
  return {
2310
- locale: validatedLocale,
2441
+ locale,
2311
2442
  isSourceLocalized,
2312
2443
  isTargetLocalized
2313
2444
  };
@@ -2410,7 +2541,7 @@ const relations = {
2410
2541
  attribute,
2411
2542
  fieldsToSelect,
2412
2543
  mainField,
2413
- source: { schema: sourceSchema },
2544
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2414
2545
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2415
2546
  sourceSchema,
2416
2547
  targetSchema,
@@ -2432,7 +2563,8 @@ const relations = {
2432
2563
  fieldsToSelect,
2433
2564
  mainField,
2434
2565
  source: {
2435
- schema: { uid: sourceUid, modelType: sourceModelType }
2566
+ schema: { uid: sourceUid, modelType: sourceModelType },
2567
+ isLocalized: isSourceLocalized
2436
2568
  },
2437
2569
  target: {
2438
2570
  schema: { uid: targetUid },
@@ -2470,12 +2602,16 @@ const relations = {
2470
2602
  } else {
2471
2603
  where.id = id;
2472
2604
  }
2473
- if (status) {
2474
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2605
+ const publishedAt = getPublishedAtClause(status, targetUid);
2606
+ if (!isEmpty(publishedAt)) {
2607
+ where[`${alias}.published_at`] = publishedAt;
2475
2608
  }
2476
- if (filterByLocale) {
2609
+ if (isTargetLocalized && locale) {
2477
2610
  where[`${alias}.locale`] = locale;
2478
2611
  }
2612
+ if (isSourceLocalized && locale) {
2613
+ where.locale = locale;
2614
+ }
2479
2615
  if ((idsToInclude?.length ?? 0) !== 0) {
2480
2616
  where[`${alias}.id`].$notIn = idsToInclude;
2481
2617
  }
@@ -2493,7 +2629,8 @@ const relations = {
2493
2629
  id: { $notIn: uniq(idsToOmit) }
2494
2630
  });
2495
2631
  }
2496
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2632
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2633
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2497
2634
  ctx.body = {
2498
2635
  ...res,
2499
2636
  results: await addStatusToRelations(targetUid, res.results)
@@ -2508,29 +2645,39 @@ const relations = {
2508
2645
  attribute,
2509
2646
  targetField,
2510
2647
  fieldsToSelect,
2511
- source: {
2512
- schema: { uid: sourceUid }
2513
- },
2514
- target: {
2515
- schema: { uid: targetUid }
2516
- }
2648
+ status,
2649
+ source: { schema: sourceSchema },
2650
+ target: { schema: targetSchema }
2517
2651
  } = await this.extractAndValidateRequestInfo(ctx, id);
2652
+ const { uid: sourceUid } = sourceSchema;
2653
+ const { uid: targetUid } = targetSchema;
2518
2654
  const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2519
2655
  const dbQuery = strapi.db.query(sourceUid);
2520
2656
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2657
+ const filters = {};
2658
+ if (sourceSchema?.options?.draftAndPublish) {
2659
+ if (targetSchema?.options?.draftAndPublish) {
2660
+ if (status === "published") {
2661
+ filters.publishedAt = { $notNull: true };
2662
+ } else {
2663
+ filters.publishedAt = { $null: true };
2664
+ }
2665
+ }
2666
+ } else if (targetSchema?.options?.draftAndPublish) {
2667
+ filters.publishedAt = { $null: true };
2668
+ }
2521
2669
  const res = await loadRelations({ id: entryId }, targetField, {
2522
- select: ["id", "documentId", "locale", "publishedAt"],
2670
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2523
2671
  ordering: "desc",
2524
2672
  page: ctx.request.query.page,
2525
- pageSize: ctx.request.query.pageSize
2673
+ pageSize: ctx.request.query.pageSize,
2674
+ filters
2526
2675
  });
2527
2676
  const loadedIds = res.results.map((item) => item.id);
2528
2677
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2529
2678
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2530
2679
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2531
- ordering: "desc",
2532
- page: ctx.request.query.page,
2533
- pageSize: ctx.request.query.pageSize
2680
+ ordering: "desc"
2534
2681
  });
2535
2682
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2536
2683
  ctx.body = {
@@ -2562,7 +2709,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2562
2709
  throw new errors.ForbiddenError();
2563
2710
  }
2564
2711
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2565
- const { locale } = await getDocumentLocaleAndStatus(body);
2712
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2566
2713
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2567
2714
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2568
2715
  // Find the first document to check if it exists
@@ -2603,7 +2750,7 @@ const singleTypes = {
2603
2750
  return ctx.forbidden();
2604
2751
  }
2605
2752
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2606
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2753
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2607
2754
  const version = await findDocument(permissionQuery, model, { locale, status });
2608
2755
  if (!version) {
2609
2756
  if (permissionChecker2.cannot.create()) {
@@ -2617,7 +2764,7 @@ const singleTypes = {
2617
2764
  permissionChecker2,
2618
2765
  model,
2619
2766
  // @ts-expect-error - fix types
2620
- { id: document.documentId, locale, publishedAt: null },
2767
+ { documentId: document.documentId, locale, publishedAt: null },
2621
2768
  { availableLocales: true, availableStatus: false }
2622
2769
  );
2623
2770
  ctx.body = { data: {}, meta };
@@ -2648,7 +2795,7 @@ const singleTypes = {
2648
2795
  }
2649
2796
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2650
2797
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2651
- const { locale } = await getDocumentLocaleAndStatus(query);
2798
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2652
2799
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2653
2800
  populate,
2654
2801
  locale
@@ -2685,7 +2832,7 @@ const singleTypes = {
2685
2832
  if (permissionChecker2.cannot.publish(document)) {
2686
2833
  throw new errors.ForbiddenError();
2687
2834
  }
2688
- const { locale } = await getDocumentLocaleAndStatus(document);
2835
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2689
2836
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2690
2837
  return publishResult.at(0);
2691
2838
  });
@@ -2708,7 +2855,7 @@ const singleTypes = {
2708
2855
  return ctx.forbidden();
2709
2856
  }
2710
2857
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2711
- const { locale } = await getDocumentLocaleAndStatus(body);
2858
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2712
2859
  const document = await findDocument(sanitizedQuery, model, { locale });
2713
2860
  if (!document) {
2714
2861
  return ctx.notFound();
@@ -2740,7 +2887,7 @@ const singleTypes = {
2740
2887
  return ctx.forbidden();
2741
2888
  }
2742
2889
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2743
- const { locale } = await getDocumentLocaleAndStatus(body);
2890
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2744
2891
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2745
2892
  if (!document) {
2746
2893
  return ctx.notFound();
@@ -2760,7 +2907,7 @@ const singleTypes = {
2760
2907
  const { query } = ctx.request;
2761
2908
  const documentManager2 = getService$1("document-manager");
2762
2909
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2763
- const { locale } = await getDocumentLocaleAndStatus(query);
2910
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2764
2911
  if (permissionChecker2.cannot.read()) {
2765
2912
  return ctx.forbidden();
2766
2913
  }
@@ -2781,7 +2928,7 @@ const uid$1 = {
2781
2928
  async generateUID(ctx) {
2782
2929
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2783
2930
  const { query = {} } = ctx.request;
2784
- const { locale } = await getDocumentLocaleAndStatus(query);
2931
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2785
2932
  await validateUIDField(contentTypeUID, field);
2786
2933
  const uidService = getService$1("uid");
2787
2934
  ctx.body = {
@@ -2793,7 +2940,7 @@ const uid$1 = {
2793
2940
  ctx.request.body
2794
2941
  );
2795
2942
  const { query = {} } = ctx.request;
2796
- const { locale } = await getDocumentLocaleAndStatus(query);
2943
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2797
2944
  await validateUIDField(contentTypeUID, field);
2798
2945
  const uidService = getService$1("uid");
2799
2946
  const isAvailable = await uidService.checkUIDAvailability({
@@ -2816,7 +2963,8 @@ const controllers = {
2816
2963
  relations,
2817
2964
  "single-types": singleTypes,
2818
2965
  uid: uid$1,
2819
- ...history.controllers ? history.controllers : {}
2966
+ ...history.controllers ? history.controllers : {},
2967
+ ...preview.controllers ? preview.controllers : {}
2820
2968
  };
2821
2969
  const keys = {
2822
2970
  CONFIGURATION: "configuration"
@@ -3436,12 +3584,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3436
3584
  ability: userAbility,
3437
3585
  model
3438
3586
  });
3439
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3587
+ const { actionProvider } = strapi2.service("admin::permission");
3588
+ const toSubject = (entity) => {
3589
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3590
+ };
3440
3591
  const can = (action, entity, field) => {
3441
- return userAbility.can(action, toSubject(entity), field);
3592
+ const subject = toSubject(entity);
3593
+ const aliases = actionProvider.unstable_aliases(action, model);
3594
+ return (
3595
+ // Test the original action to see if it passes
3596
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3597
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3598
+ );
3442
3599
  };
3443
3600
  const cannot = (action, entity, field) => {
3444
- return userAbility.cannot(action, toSubject(entity), field);
3601
+ const subject = toSubject(entity);
3602
+ const aliases = actionProvider.unstable_aliases(action, model);
3603
+ return (
3604
+ // Test both the original action
3605
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3606
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3607
+ );
3445
3608
  };
3446
3609
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3447
3610
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3718,6 +3881,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3718
3881
  const attribute = model.attributes[attributeName];
3719
3882
  switch (attribute.type) {
3720
3883
  case "relation": {
3884
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3885
+ if (isMorphRelation) {
3886
+ break;
3887
+ }
3721
3888
  if (isVisibleAttribute$1(model, attributeName)) {
3722
3889
  populateAcc[attributeName] = {
3723
3890
  count: true,
@@ -3969,7 +4136,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3969
4136
  */
3970
4137
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
3971
4138
  const versionsByLocale = groupBy("locale", allVersions);
3972
- delete versionsByLocale[version.locale];
4139
+ if (version.locale) {
4140
+ delete versionsByLocale[version.locale];
4141
+ }
3973
4142
  const model = strapi2.getModel(uid2);
3974
4143
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
3975
4144
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4095,7 +4264,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4095
4264
  */
4096
4265
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4097
4266
  if (!document) {
4098
- return document;
4267
+ return {
4268
+ data: document,
4269
+ meta: {
4270
+ availableLocales: [],
4271
+ availableStatus: []
4272
+ }
4273
+ };
4099
4274
  }
4100
4275
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4101
4276
  if (!hasDraftAndPublish) {
@@ -4203,10 +4378,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4203
4378
  async clone(id, body, uid2) {
4204
4379
  const populate = await buildDeepPopulate(uid2);
4205
4380
  const params = {
4206
- data: {
4207
- ...omitIdField(body),
4208
- [PUBLISHED_AT_ATTRIBUTE]: null
4209
- },
4381
+ data: omitIdField(body),
4210
4382
  populate
4211
4383
  };
4212
4384
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
@@ -4322,7 +4494,8 @@ const services = {
4322
4494
  permission,
4323
4495
  "populate-builder": populateBuilder$1,
4324
4496
  uid,
4325
- ...history.services ? history.services : {}
4497
+ ...history.services ? history.services : {},
4498
+ ...preview.services ? preview.services : {}
4326
4499
  };
4327
4500
  const index = () => {
4328
4501
  return {