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

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 (220) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
  3. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs → ComponentConfigurationPage-D4J64ny7.mjs} +4 -4
  5. package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs.map → ComponentConfigurationPage-D4J64ny7.mjs.map} +1 -1
  6. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js → ComponentConfigurationPage-DHV8IFbd.js} +5 -6
  7. package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js.map → ComponentConfigurationPage-DHV8IFbd.js.map} +1 -1
  8. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
  9. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
  10. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
  11. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs → EditConfigurationPage-DMnf8orh.mjs} +4 -4
  12. package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs.map → EditConfigurationPage-DMnf8orh.mjs.map} +1 -1
  13. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js → EditConfigurationPage-q76oeVU1.js} +5 -6
  14. package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js.map → EditConfigurationPage-q76oeVU1.js.map} +1 -1
  15. package/dist/_chunks/{EditViewPage-zT3fBr4Y.js → EditViewPage-BXoY-ITh.js} +63 -13
  16. package/dist/_chunks/EditViewPage-BXoY-ITh.js.map +1 -0
  17. package/dist/_chunks/{EditViewPage-CPj61RMh.mjs → EditViewPage-COVXj9bh.mjs} +63 -12
  18. package/dist/_chunks/EditViewPage-COVXj9bh.mjs.map +1 -0
  19. package/dist/_chunks/{Field-dha5VnIQ.mjs → Field-CcppsFQR.mjs} +300 -203
  20. package/dist/_chunks/Field-CcppsFQR.mjs.map +1 -0
  21. package/dist/_chunks/{Field-Boxf9Ajp.js → Field-Dj1nOvt8.js} +303 -207
  22. package/dist/_chunks/Field-Dj1nOvt8.js.map +1 -0
  23. package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
  24. package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
  25. package/dist/_chunks/{Form-DHrru2AV.mjs → Form-DbWwH0-A.mjs} +37 -18
  26. package/dist/_chunks/Form-DbWwH0-A.mjs.map +1 -0
  27. package/dist/_chunks/{Form-y5g1SRsh.js → Form-aTchNxab.js} +39 -21
  28. package/dist/_chunks/Form-aTchNxab.js.map +1 -0
  29. package/dist/_chunks/{History-CqN6K7SX.js → History-Cs6XM6EU.js} +81 -114
  30. package/dist/_chunks/History-Cs6XM6EU.js.map +1 -0
  31. package/dist/_chunks/{History-Bru_KoeP.mjs → History-tU567_hc.mjs} +82 -114
  32. package/dist/_chunks/History-tU567_hc.mjs.map +1 -0
  33. package/dist/_chunks/{ListConfigurationPage-R_p-SbHZ.js → ListConfigurationPage-7LeytuFD.js} +25 -13
  34. package/dist/_chunks/ListConfigurationPage-7LeytuFD.js.map +1 -0
  35. package/dist/_chunks/{ListConfigurationPage-D8wGABj0.mjs → ListConfigurationPage-DQryo_4i.mjs} +25 -12
  36. package/dist/_chunks/ListConfigurationPage-DQryo_4i.mjs.map +1 -0
  37. package/dist/_chunks/{ListViewPage-SID6TRb9.mjs → ListViewPage-B50esy_x.mjs} +118 -77
  38. package/dist/_chunks/ListViewPage-B50esy_x.mjs.map +1 -0
  39. package/dist/_chunks/{ListViewPage-pEw_zug9.js → ListViewPage-CaGBu5H5.js} +121 -81
  40. package/dist/_chunks/ListViewPage-CaGBu5H5.js.map +1 -0
  41. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js → NoContentTypePage-BaBE00IO.js} +2 -2
  42. package/dist/_chunks/{NoContentTypePage-C5dcQojD.js.map → NoContentTypePage-BaBE00IO.js.map} +1 -1
  43. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs → NoContentTypePage-CiPP8cLx.mjs} +2 -2
  44. package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs.map → NoContentTypePage-CiPP8cLx.mjs.map} +1 -1
  45. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs → NoPermissionsPage-0-CW106p.mjs} +2 -2
  46. package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs.map → NoPermissionsPage-0-CW106p.mjs.map} +1 -1
  47. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js → NoPermissionsPage-DQn5cqZz.js} +2 -2
  48. package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js.map → NoPermissionsPage-DQn5cqZz.js.map} +1 -1
  49. package/dist/_chunks/Preview-C1dBkhXf.mjs +272 -0
  50. package/dist/_chunks/Preview-C1dBkhXf.mjs.map +1 -0
  51. package/dist/_chunks/Preview-DH1h7kJ6.js +290 -0
  52. package/dist/_chunks/Preview-DH1h7kJ6.js.map +1 -0
  53. package/dist/_chunks/{Relations-B9Crnhnn.mjs → Relations-Bvne4TvU.mjs} +76 -42
  54. package/dist/_chunks/Relations-Bvne4TvU.mjs.map +1 -0
  55. package/dist/_chunks/{Relations-DjTQ5kGB.js → Relations-CkECnBOd.js} +76 -43
  56. package/dist/_chunks/Relations-CkECnBOd.js.map +1 -0
  57. package/dist/_chunks/{en-fbKQxLGn.js → en-BK8Xyl5I.js} +32 -18
  58. package/dist/_chunks/{en-fbKQxLGn.js.map → en-BK8Xyl5I.js.map} +1 -1
  59. package/dist/_chunks/{en-Ux26r5pl.mjs → en-Dtk_ot79.mjs} +32 -18
  60. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-Dtk_ot79.mjs.map} +1 -1
  61. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  62. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  63. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  64. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  65. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  66. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  67. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  68. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  69. package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
  70. package/dist/_chunks/{index-DVPWZkbS.js → index-BN1pPa5v.js} +1135 -693
  71. package/dist/_chunks/index-BN1pPa5v.js.map +1 -0
  72. package/dist/_chunks/{index-DJXJw9V5.mjs → index-ByPZ754U.mjs} +1156 -714
  73. package/dist/_chunks/index-ByPZ754U.mjs.map +1 -0
  74. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  75. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  76. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  77. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  78. package/dist/_chunks/{layout-Bau7ZfLV.mjs → layout-CUTOYU8I.mjs} +26 -13
  79. package/dist/_chunks/layout-CUTOYU8I.mjs.map +1 -0
  80. package/dist/_chunks/{layout-Dm6fbiQj.js → layout-nBPDlXjr.js} +26 -14
  81. package/dist/_chunks/layout-nBPDlXjr.js.map +1 -0
  82. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  83. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  84. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  85. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  86. package/dist/_chunks/{relations-CKnpRgrN.js → relations-B6B-b7lI.js} +6 -7
  87. package/dist/_chunks/relations-B6B-b7lI.js.map +1 -0
  88. package/dist/_chunks/{relations-BH_kBSJ0.mjs → relations-CBc5HYHC.mjs} +6 -7
  89. package/dist/_chunks/relations-CBc5HYHC.mjs.map +1 -0
  90. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  91. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  92. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  93. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  94. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
  95. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
  96. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
  97. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
  98. package/dist/admin/index.js +2 -1
  99. package/dist/admin/index.js.map +1 -1
  100. package/dist/admin/index.mjs +5 -4
  101. package/dist/admin/src/content-manager.d.ts +3 -2
  102. package/dist/admin/src/exports.d.ts +1 -1
  103. package/dist/admin/src/history/index.d.ts +3 -0
  104. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  105. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  106. package/dist/admin/src/index.d.ts +1 -0
  107. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  108. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +2 -1
  109. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  110. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  111. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  112. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  113. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  114. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  115. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  116. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  117. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  118. package/dist/admin/src/preview/constants.d.ts +1 -0
  119. package/dist/admin/src/preview/index.d.ts +4 -0
  120. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  121. package/dist/admin/src/preview/routes.d.ts +3 -0
  122. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  123. package/dist/admin/src/router.d.ts +1 -1
  124. package/dist/admin/src/services/api.d.ts +1 -1
  125. package/dist/admin/src/services/components.d.ts +2 -2
  126. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  127. package/dist/admin/src/services/documents.d.ts +19 -20
  128. package/dist/admin/src/services/init.d.ts +1 -1
  129. package/dist/admin/src/services/relations.d.ts +2 -2
  130. package/dist/admin/src/services/uid.d.ts +3 -3
  131. package/dist/admin/src/utils/validation.d.ts +4 -1
  132. package/dist/server/index.js +615 -299
  133. package/dist/server/index.js.map +1 -1
  134. package/dist/server/index.mjs +615 -298
  135. package/dist/server/index.mjs.map +1 -1
  136. package/dist/server/src/bootstrap.d.ts.map +1 -1
  137. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  138. package/dist/server/src/controllers/index.d.ts.map +1 -1
  139. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  140. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  141. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  142. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  143. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  144. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  145. package/dist/server/src/history/services/history.d.ts.map +1 -1
  146. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  147. package/dist/server/src/history/services/utils.d.ts +4 -4
  148. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  149. package/dist/server/src/index.d.ts +4 -4
  150. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  151. package/dist/server/src/preview/constants.d.ts +2 -0
  152. package/dist/server/src/preview/constants.d.ts.map +1 -0
  153. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  154. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  155. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  156. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  157. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  158. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  159. package/dist/server/src/preview/index.d.ts +4 -0
  160. package/dist/server/src/preview/index.d.ts.map +1 -0
  161. package/dist/server/src/preview/routes/index.d.ts +8 -0
  162. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  163. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  164. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  165. package/dist/server/src/preview/services/index.d.ts +16 -0
  166. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  167. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  168. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  169. package/dist/server/src/preview/services/preview.d.ts +12 -0
  170. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  171. package/dist/server/src/preview/utils.d.ts +19 -0
  172. package/dist/server/src/preview/utils.d.ts.map +1 -0
  173. package/dist/server/src/register.d.ts.map +1 -1
  174. package/dist/server/src/routes/index.d.ts.map +1 -1
  175. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  176. package/dist/server/src/services/document-metadata.d.ts +8 -8
  177. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  178. package/dist/server/src/services/index.d.ts +4 -4
  179. package/dist/server/src/services/index.d.ts.map +1 -1
  180. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  181. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  182. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  183. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  184. package/dist/server/src/utils/index.d.ts +2 -0
  185. package/dist/server/src/utils/index.d.ts.map +1 -1
  186. package/dist/shared/contracts/collection-types.d.ts +3 -1
  187. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  188. package/dist/shared/contracts/index.d.ts +1 -0
  189. package/dist/shared/contracts/index.d.ts.map +1 -1
  190. package/dist/shared/contracts/preview.d.ts +27 -0
  191. package/dist/shared/contracts/preview.d.ts.map +1 -0
  192. package/dist/shared/index.js +4 -0
  193. package/dist/shared/index.js.map +1 -1
  194. package/dist/shared/index.mjs +4 -0
  195. package/dist/shared/index.mjs.map +1 -1
  196. package/package.json +15 -15
  197. package/dist/_chunks/EditViewPage-CPj61RMh.mjs.map +0 -1
  198. package/dist/_chunks/EditViewPage-zT3fBr4Y.js.map +0 -1
  199. package/dist/_chunks/Field-Boxf9Ajp.js.map +0 -1
  200. package/dist/_chunks/Field-dha5VnIQ.mjs.map +0 -1
  201. package/dist/_chunks/Form-DHrru2AV.mjs.map +0 -1
  202. package/dist/_chunks/Form-y5g1SRsh.js.map +0 -1
  203. package/dist/_chunks/History-Bru_KoeP.mjs.map +0 -1
  204. package/dist/_chunks/History-CqN6K7SX.js.map +0 -1
  205. package/dist/_chunks/ListConfigurationPage-D8wGABj0.mjs.map +0 -1
  206. package/dist/_chunks/ListConfigurationPage-R_p-SbHZ.js.map +0 -1
  207. package/dist/_chunks/ListViewPage-SID6TRb9.mjs.map +0 -1
  208. package/dist/_chunks/ListViewPage-pEw_zug9.js.map +0 -1
  209. package/dist/_chunks/Relations-B9Crnhnn.mjs.map +0 -1
  210. package/dist/_chunks/Relations-DjTQ5kGB.js.map +0 -1
  211. package/dist/_chunks/index-DJXJw9V5.mjs.map +0 -1
  212. package/dist/_chunks/index-DVPWZkbS.js.map +0 -1
  213. package/dist/_chunks/layout-Bau7ZfLV.mjs.map +0 -1
  214. package/dist/_chunks/layout-Dm6fbiQj.js.map +0 -1
  215. package/dist/_chunks/relations-BH_kBSJ0.mjs.map +0 -1
  216. package/dist/_chunks/relations-CKnpRgrN.js.map +0 -1
  217. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  218. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  219. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  220. 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, mergeWith, 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";
@@ -7,10 +7,10 @@ import isNil from "lodash/isNil";
7
7
  import _, { intersection as intersection$1, difference as difference$1 } from "lodash";
8
8
  import qs from "qs";
9
9
  import slugify from "@sindresorhus/slugify";
10
- const getService$1 = (name) => {
10
+ const getService$2 = (name) => {
11
11
  return strapi.plugin("content-manager").service(name);
12
12
  };
13
- function getService(strapi2, name) {
13
+ function getService$1(strapi2, name) {
14
14
  return strapi2.service(`plugin::content-manager.${name}`);
15
15
  }
16
16
  const historyRestoreVersionSchema = yup.object().shape({
@@ -46,7 +46,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
46
46
  if (!isSingleType && (!contentTypeUid || !ctx.query.documentId)) {
47
47
  throw new errors.ForbiddenError("contentType and documentId are required");
48
48
  }
49
- const permissionChecker2 = getService$1("permission-checker").create({
49
+ const permissionChecker2 = getService$2("permission-checker").create({
50
50
  userAbility: ctx.state.userAbility,
51
51
  model: ctx.query.contentType
52
52
  });
@@ -54,7 +54,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
54
54
  return ctx.forbidden();
55
55
  }
56
56
  const query = await permissionChecker2.sanitizeQuery(ctx.query);
57
- const { results, pagination: pagination2 } = await getService(strapi2, "history").findVersionsPage({
57
+ const { results, pagination: pagination2 } = await getService$1(strapi2, "history").findVersionsPage({
58
58
  query: {
59
59
  ...query,
60
60
  ...getValidPagination({ page: query.page, pageSize: query.pageSize })
@@ -79,14 +79,14 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
79
79
  async restoreVersion(ctx) {
80
80
  const request = ctx.request;
81
81
  await validateRestoreVersion(request.body, "contentType is required");
82
- const permissionChecker2 = getService$1("permission-checker").create({
82
+ const permissionChecker2 = getService$2("permission-checker").create({
83
83
  userAbility: ctx.state.userAbility,
84
84
  model: request.body.contentType
85
85
  });
86
86
  if (permissionChecker2.cannot.update()) {
87
87
  throw new errors.ForbiddenError();
88
88
  }
89
- const restoredDocument = await getService(strapi2, "history").restoreVersion(
89
+ const restoredDocument = await getService$1(strapi2, "history").restoreVersion(
90
90
  request.params.versionId
91
91
  );
92
92
  return {
@@ -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
@@ -141,8 +141,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
141
141
  };
142
142
  const getRelationRestoreValue = async (versionRelationData, attribute) => {
143
143
  if (Array.isArray(versionRelationData)) {
144
- if (versionRelationData.length === 0)
145
- return versionRelationData;
144
+ if (versionRelationData.length === 0) return versionRelationData;
146
145
  const existingAndMissingRelations = await Promise.all(
147
146
  versionRelationData.map((relation) => {
148
147
  return strapi2.documents(attribute.target).findOne({
@@ -173,10 +172,11 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
172
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
173
  };
175
174
  const localesService = strapi2.plugin("i18n")?.service("locales");
175
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
176
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
177
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
178
  const getLocaleDictionary = async () => {
178
- if (!localesService)
179
- return {};
179
+ if (!localesService) return {};
180
180
  const locales = await localesService.find() || [];
181
181
  return locales.reduce(
182
182
  (acc, locale) => {
@@ -200,31 +200,53 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
200
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
201
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
202
  };
203
- const getDeepPopulate2 = (uid2) => {
203
+ const getComponentFields = (componentUID) => {
204
+ return Object.entries(strapi2.getModel(componentUID).attributes).reduce(
205
+ (fieldsAcc, [key, attribute]) => {
206
+ if (!["relation", "media", "component", "dynamiczone"].includes(attribute.type)) {
207
+ fieldsAcc.push(key);
208
+ }
209
+ return fieldsAcc;
210
+ },
211
+ []
212
+ );
213
+ };
214
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
215
  const model = strapi2.getModel(uid2);
205
216
  const attributes = Object.entries(model.attributes);
217
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
218
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
219
  switch (attribute.type) {
208
220
  case "relation": {
221
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
222
+ if (isMorphRelation) {
223
+ break;
224
+ }
209
225
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
210
226
  if (isVisible2) {
211
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
227
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
212
228
  }
213
229
  break;
214
230
  }
215
231
  case "media": {
216
- acc[attributeName] = { fields: ["id"] };
232
+ acc[attributeName] = { [fieldSelector]: ["id"] };
217
233
  break;
218
234
  }
219
235
  case "component": {
220
236
  const populate = getDeepPopulate2(attribute.component);
221
- acc[attributeName] = { populate };
237
+ acc[attributeName] = {
238
+ populate,
239
+ [fieldSelector]: getComponentFields(attribute.component)
240
+ };
222
241
  break;
223
242
  }
224
243
  case "dynamiczone": {
225
244
  const populatedComponents = (attribute.components || []).reduce(
226
245
  (acc2, componentUID) => {
227
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
246
+ acc2[componentUID] = {
247
+ populate: getDeepPopulate2(componentUID),
248
+ [fieldSelector]: getComponentFields(componentUID)
249
+ };
228
250
  return acc2;
229
251
  },
230
252
  {}
@@ -286,6 +308,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
286
308
  getRelationRestoreValue,
287
309
  getMediaRestoreValue,
288
310
  getDefaultLocale,
311
+ isLocalizedContentType,
289
312
  getLocaleDictionary,
290
313
  getRetentionDays,
291
314
  getVersionStatus,
@@ -308,7 +331,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
308
331
  });
309
332
  },
310
333
  async findVersionsPage(params) {
311
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
334
+ const model = strapi2.getModel(params.query.contentType);
335
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
336
+ const defaultLocale = await serviceUtils.getDefaultLocale();
337
+ let locale = null;
338
+ if (isLocalizedContentType) {
339
+ locale = params.query.locale || defaultLocale;
340
+ }
312
341
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
313
342
  query.findPage({
314
343
  ...params.query,
@@ -330,7 +359,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
330
359
  const attributeValue = entry.data[attributeKey];
331
360
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
332
361
  if (attributeSchema.type === "media") {
333
- const permissionChecker2 = getService$1("permission-checker").create({
362
+ const permissionChecker2 = getService$2("permission-checker").create({
334
363
  userAbility: params.state.userAbility,
335
364
  model: "plugin::upload.file"
336
365
  });
@@ -353,7 +382,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
353
382
  if (userToPopulate == null) {
354
383
  return null;
355
384
  }
356
- return strapi2.query("admin::user").findOne({ where: { id: userToPopulate.id } });
385
+ return strapi2.query("admin::user").findOne({
386
+ where: {
387
+ ...userToPopulate.id ? { id: userToPopulate.id } : {},
388
+ ...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
389
+ }
390
+ });
357
391
  })
358
392
  );
359
393
  return {
@@ -366,7 +400,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
366
400
  [attributeKey]: adminUsers
367
401
  };
368
402
  }
369
- const permissionChecker2 = getService$1("permission-checker").create({
403
+ const permissionChecker2 = getService$2("permission-checker").create({
370
404
  userAbility: params.state.userAbility,
371
405
  model: attributeSchema.target
372
406
  });
@@ -464,6 +498,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
464
498
  }
465
499
  };
466
500
  };
501
+ const shouldCreateHistoryVersion = (context) => {
502
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
503
+ return false;
504
+ }
505
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
506
+ return false;
507
+ }
508
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
509
+ return false;
510
+ }
511
+ if (!context.contentType.uid.startsWith("api::")) {
512
+ return false;
513
+ }
514
+ return true;
515
+ };
516
+ const getSchemas = (uid2) => {
517
+ const attributesSchema = strapi.getModel(uid2).attributes;
518
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
519
+ (currentComponentSchemas, key) => {
520
+ const fieldSchema = attributesSchema[key];
521
+ if (fieldSchema.type === "component") {
522
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
523
+ return {
524
+ ...currentComponentSchemas,
525
+ [fieldSchema.component]: componentSchema
526
+ };
527
+ }
528
+ return currentComponentSchemas;
529
+ },
530
+ {}
531
+ );
532
+ return {
533
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
534
+ componentsSchemas
535
+ };
536
+ };
467
537
  const createLifecyclesService = ({ strapi: strapi2 }) => {
468
538
  const state = {
469
539
  deleteExpiredJob: null,
@@ -476,76 +546,62 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
476
546
  return;
477
547
  }
478
548
  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
549
  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
- };
550
+ if (!shouldCreateHistoryVersion(context)) {
551
+ return result;
552
+ }
553
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
497
554
  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();
555
+ const locales = castArray(context.params?.locale || defaultLocale);
556
+ if (!locales.length) {
557
+ return result;
504
558
  }
505
- const document = await strapi2.documents(contentTypeUid).findOne({
506
- documentId: documentContext.documentId,
507
- locale,
508
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
559
+ const uid2 = context.contentType.uid;
560
+ const schemas = getSchemas(uid2);
561
+ const model = strapi2.getModel(uid2);
562
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
563
+ const localeEntries = await strapi2.db.query(uid2).findMany({
564
+ where: {
565
+ documentId,
566
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
567
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
568
+ },
569
+ populate: serviceUtils.getDeepPopulate(
570
+ uid2,
571
+ true
572
+ /* use database syntax */
573
+ )
509
574
  });
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
575
  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
- });
576
+ onCommit(async () => {
577
+ for (const entry of localeEntries) {
578
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
579
+ await getService$1(strapi2, "history").createVersion({
580
+ contentType: uid2,
581
+ data: omit(FIELDS_TO_IGNORE, entry),
582
+ relatedDocumentId: documentId,
583
+ locale: entry.locale,
584
+ status,
585
+ ...schemas
586
+ });
587
+ }
536
588
  });
537
589
  });
538
590
  return result;
539
591
  });
540
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
592
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
541
593
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
542
594
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
543
595
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
544
596
  where: {
545
597
  created_at: {
546
- $lt: expirationDate.toISOString()
598
+ $lt: expirationDate
547
599
  }
548
600
  }
601
+ }).catch((error) => {
602
+ if (error instanceof Error) {
603
+ strapi2.log.error("Error deleting expired history versions", error.message);
604
+ }
549
605
  });
550
606
  });
551
607
  state.isInitialized = true;
@@ -557,17 +613,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
557
613
  }
558
614
  };
559
615
  };
560
- const services$1 = {
616
+ const services$2 = {
561
617
  history: createHistoryService,
562
618
  lifecycles: createLifecyclesService
563
619
  };
564
- const info = { pluginName: "content-manager", type: "admin" };
620
+ const info$1 = { pluginName: "content-manager", type: "admin" };
565
621
  const historyVersionRouter = {
566
622
  type: "admin",
567
623
  routes: [
568
624
  {
569
625
  method: "GET",
570
- info,
626
+ info: info$1,
571
627
  path: "/history-versions",
572
628
  handler: "history-version.findMany",
573
629
  config: {
@@ -576,7 +632,7 @@ const historyVersionRouter = {
576
632
  },
577
633
  {
578
634
  method: "PUT",
579
- info,
635
+ info: info$1,
580
636
  path: "/history-versions/:versionId/restore",
581
637
  handler: "history-version.restoreVersion",
582
638
  config: {
@@ -585,7 +641,7 @@ const historyVersionRouter = {
585
641
  }
586
642
  ]
587
643
  };
588
- const routes$1 = {
644
+ const routes$2 = {
589
645
  "history-version": historyVersionRouter
590
646
  };
591
647
  const historyVersion = {
@@ -632,21 +688,21 @@ const historyVersion = {
632
688
  }
633
689
  }
634
690
  };
635
- const getFeature = () => {
691
+ const getFeature$1 = () => {
636
692
  if (strapi.ee.features.isEnabled("cms-content-history")) {
637
693
  return {
638
694
  register({ strapi: strapi2 }) {
639
695
  strapi2.get("models").add(historyVersion);
640
696
  },
641
697
  bootstrap({ strapi: strapi2 }) {
642
- getService(strapi2, "lifecycles").bootstrap();
698
+ getService$1(strapi2, "lifecycles").bootstrap();
643
699
  },
644
700
  destroy({ strapi: strapi2 }) {
645
- getService(strapi2, "lifecycles").destroy();
701
+ getService$1(strapi2, "lifecycles").destroy();
646
702
  },
647
- controllers: controllers$1,
648
- services: services$1,
649
- routes: routes$1
703
+ controllers: controllers$2,
704
+ services: services$2,
705
+ routes: routes$2
650
706
  };
651
707
  }
652
708
  return {
@@ -655,9 +711,205 @@ const getFeature = () => {
655
711
  }
656
712
  };
657
713
  };
658
- const history = getFeature();
714
+ const history = getFeature$1();
715
+ const FEATURE_ID = "preview";
716
+ const info = { pluginName: "content-manager", type: "admin" };
717
+ const previewRouter = {
718
+ type: "admin",
719
+ routes: [
720
+ {
721
+ method: "GET",
722
+ info,
723
+ path: "/preview/url/:contentType",
724
+ handler: "preview.getPreviewUrl",
725
+ config: {
726
+ policies: ["admin::isAuthenticatedAdmin"]
727
+ }
728
+ }
729
+ ]
730
+ };
731
+ const routes$1 = {
732
+ preview: previewRouter
733
+ };
734
+ function getService(strapi2, name) {
735
+ return strapi2.service(`plugin::content-manager.${name}`);
736
+ }
737
+ const getPreviewUrlSchema = yup.object().shape({
738
+ // Will be undefined for single types
739
+ documentId: yup.string(),
740
+ locale: yup.string().nullable(),
741
+ status: yup.string()
742
+ }).required();
743
+ const validatePreviewUrl = async (strapi2, uid2, params) => {
744
+ await validateYupSchema(getPreviewUrlSchema)(params);
745
+ const newParams = pick(["documentId", "locale", "status"], params);
746
+ const model = strapi2.getModel(uid2);
747
+ if (!model || model.modelType !== "contentType") {
748
+ throw new errors.ValidationError("Invalid content type");
749
+ }
750
+ const isSingleType = model?.kind === "singleType";
751
+ if (!isSingleType && !params.documentId) {
752
+ throw new errors.ValidationError("documentId is required for Collection Types");
753
+ }
754
+ if (isSingleType) {
755
+ const doc = await strapi2.documents(uid2).findFirst();
756
+ if (!doc) {
757
+ throw new errors.NotFoundError("Document not found");
758
+ }
759
+ newParams.documentId = doc?.documentId;
760
+ }
761
+ if (!newParams.status) {
762
+ const isDPEnabled = model?.options?.draftAndPublish;
763
+ newParams.status = isDPEnabled ? "draft" : "published";
764
+ }
765
+ return newParams;
766
+ };
767
+ const createPreviewController = () => {
768
+ return {
769
+ /**
770
+ * Transforms an entry into a preview URL, so that it can be previewed
771
+ * in the Content Manager.
772
+ */
773
+ async getPreviewUrl(ctx) {
774
+ const uid2 = ctx.params.contentType;
775
+ const query = ctx.request.query;
776
+ const params = await validatePreviewUrl(strapi, uid2, query);
777
+ const previewService = getService(strapi, "preview");
778
+ const url = await previewService.getPreviewUrl(uid2, params);
779
+ if (!url) {
780
+ ctx.status = 204;
781
+ }
782
+ return {
783
+ data: { url }
784
+ };
785
+ }
786
+ };
787
+ };
788
+ const controllers$1 = {
789
+ preview: createPreviewController
790
+ /**
791
+ * Casting is needed because the types aren't aware that Strapi supports
792
+ * passing a controller factory as the value, instead of a controller object directly
793
+ */
794
+ };
795
+ const createPreviewService = ({ strapi: strapi2 }) => {
796
+ const config = getService(strapi2, "preview-config");
797
+ return {
798
+ async getPreviewUrl(uid2, params) {
799
+ const handler = config.getPreviewHandler();
800
+ try {
801
+ return handler(uid2, params);
802
+ } catch (error) {
803
+ strapi2.log.error(`Failed to get preview URL: ${error}`);
804
+ throw new errors.ApplicationError("Failed to get preview URL");
805
+ }
806
+ return;
807
+ }
808
+ };
809
+ };
810
+ const extendMiddlewareConfiguration = (middleware = { name: "", config: {} }) => {
811
+ const middlewares = strapi.config.get("middlewares");
812
+ const configuredMiddlewares = middlewares.map((currentMiddleware) => {
813
+ if (currentMiddleware === middleware.name) {
814
+ return middleware;
815
+ }
816
+ if (currentMiddleware.name === middleware.name) {
817
+ return mergeWith(
818
+ (objValue, srcValue) => {
819
+ if (Array.isArray(objValue)) {
820
+ return objValue.concat(srcValue);
821
+ }
822
+ return void 0;
823
+ },
824
+ currentMiddleware,
825
+ middleware
826
+ );
827
+ }
828
+ return currentMiddleware;
829
+ });
830
+ strapi.config.set("middlewares", configuredMiddlewares);
831
+ };
832
+ const createPreviewConfigService = ({ strapi: strapi2 }) => {
833
+ return {
834
+ register() {
835
+ if (!this.isEnabled()) {
836
+ return;
837
+ }
838
+ const config = strapi2.config.get("admin.preview");
839
+ if (config.config?.allowedOrigins) {
840
+ extendMiddlewareConfiguration({
841
+ name: "strapi::security",
842
+ config: {
843
+ contentSecurityPolicy: {
844
+ directives: {
845
+ "frame-src": config.config.allowedOrigins
846
+ }
847
+ }
848
+ }
849
+ });
850
+ }
851
+ },
852
+ isEnabled() {
853
+ const config = strapi2.config.get("admin.preview");
854
+ if (!config) {
855
+ return false;
856
+ }
857
+ return config?.enabled ?? true;
858
+ },
859
+ /**
860
+ * Validate if the configuration is valid
861
+ */
862
+ validate() {
863
+ if (!this.isEnabled()) {
864
+ return;
865
+ }
866
+ const handler = this.getPreviewHandler();
867
+ if (typeof handler !== "function") {
868
+ throw new errors.ValidationError(
869
+ "Preview configuration is invalid. Handler must be a function"
870
+ );
871
+ }
872
+ },
873
+ /**
874
+ * Utility to get the preview handler from the configuration
875
+ */
876
+ getPreviewHandler() {
877
+ const config = strapi2.config.get("admin.preview");
878
+ const emptyHandler = () => {
879
+ return void 0;
880
+ };
881
+ if (!this.isEnabled()) {
882
+ return emptyHandler;
883
+ }
884
+ return config?.config?.handler || emptyHandler;
885
+ }
886
+ };
887
+ };
888
+ const services$1 = {
889
+ preview: createPreviewService,
890
+ "preview-config": createPreviewConfigService
891
+ };
892
+ const getFeature = () => {
893
+ if (!strapi.features.future.isEnabled(FEATURE_ID)) {
894
+ return {};
895
+ }
896
+ return {
897
+ register() {
898
+ const config = getService(strapi, "preview-config");
899
+ config.validate();
900
+ config.register();
901
+ },
902
+ bootstrap() {
903
+ },
904
+ routes: routes$1,
905
+ controllers: controllers$1,
906
+ services: services$1
907
+ };
908
+ };
909
+ const preview = getFeature();
659
910
  const register = async ({ strapi: strapi2 }) => {
660
911
  await history.register?.({ strapi: strapi2 });
912
+ await preview.register?.({ strapi: strapi2 });
661
913
  };
662
914
  const ALLOWED_WEBHOOK_EVENTS = {
663
915
  ENTRY_PUBLISH: "entry.publish",
@@ -667,11 +919,12 @@ const bootstrap = async () => {
667
919
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
668
920
  strapi.get("webhookStore").addAllowedEvent(key, value);
669
921
  });
670
- getService$1("field-sizes").setCustomFieldInputSizes();
671
- await getService$1("components").syncConfigurations();
672
- await getService$1("content-types").syncConfigurations();
673
- await getService$1("permission").registerPermissions();
922
+ getService$2("field-sizes").setCustomFieldInputSizes();
923
+ await getService$2("components").syncConfigurations();
924
+ await getService$2("content-types").syncConfigurations();
925
+ await getService$2("permission").registerPermissions();
674
926
  await history.bootstrap?.({ strapi });
927
+ await preview.bootstrap?.({ strapi });
675
928
  };
676
929
  const destroy = async ({ strapi: strapi2 }) => {
677
930
  await history.destroy?.({ strapi: strapi2 });
@@ -1161,7 +1414,8 @@ const admin = {
1161
1414
  };
1162
1415
  const routes = {
1163
1416
  admin,
1164
- ...history.routes ? history.routes : {}
1417
+ ...history.routes ? history.routes : {},
1418
+ ...preview.routes ? preview.routes : {}
1165
1419
  };
1166
1420
  const hasPermissionsSchema = yup$1.object({
1167
1421
  actions: yup$1.array().of(yup$1.string()),
@@ -1172,6 +1426,11 @@ const { createPolicy } = policy;
1172
1426
  const hasPermissions = createPolicy({
1173
1427
  name: "plugin::content-manager.hasPermissions",
1174
1428
  validator: validateHasPermissionsInput,
1429
+ /**
1430
+ * NOTE: Action aliases are currently not checked at this level (policy).
1431
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1432
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1433
+ */
1175
1434
  handler(ctx, config = {}) {
1176
1435
  const { actions = [], hasAtLeastOne = false } = config;
1177
1436
  const { userAbility } = ctx.state;
@@ -1219,8 +1478,7 @@ const isSortable = (schema, name) => {
1219
1478
  if (!_.has(schema.attributes, name)) {
1220
1479
  return false;
1221
1480
  }
1222
- if (schema.modelType === "component" && name === "id")
1223
- return false;
1481
+ if (schema.modelType === "component" && name === "id") return false;
1224
1482
  const attribute = schema.attributes[name];
1225
1483
  if (NON_SORTABLES.includes(attribute.type)) {
1226
1484
  return false;
@@ -1365,8 +1623,7 @@ const createDefaultSettings = async (schema) => {
1365
1623
  };
1366
1624
  };
1367
1625
  const syncSettings = async (configuration, schema) => {
1368
- if (isEmpty(configuration.settings))
1369
- return createDefaultSettings(schema);
1626
+ if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
1370
1627
  const defaultField = getDefaultMainField(schema);
1371
1628
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1372
1629
  return {
@@ -1413,7 +1670,7 @@ const createMetadasSchema = (schema) => {
1413
1670
  if (!value) {
1414
1671
  return yup$1.string();
1415
1672
  }
1416
- const targetSchema = getService$1("content-types").findContentType(
1673
+ const targetSchema = getService$2("content-types").findContentType(
1417
1674
  schema.attributes[key].targetModel
1418
1675
  );
1419
1676
  if (!targetSchema) {
@@ -1542,8 +1799,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1542
1799
  }
1543
1800
  switch (attribute.type) {
1544
1801
  case "relation": {
1545
- if (canCreate(attributePath))
1546
- return body2;
1802
+ if (canCreate(attributePath)) return body2;
1547
1803
  return set(attributePath, { set: [] }, body2);
1548
1804
  }
1549
1805
  case "component": {
@@ -1553,8 +1809,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1553
1809
  ]);
1554
1810
  }
1555
1811
  default: {
1556
- if (canCreate(attributePath))
1557
- return body2;
1812
+ if (canCreate(attributePath)) return body2;
1558
1813
  return set(attributePath, null, body2);
1559
1814
  }
1560
1815
  }
@@ -1565,9 +1820,11 @@ const multipleLocaleSchema = yup$1.lazy(
1565
1820
  (value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1566
1821
  );
1567
1822
  const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
1568
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1823
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1569
1824
  const { allowMultipleLocales } = opts;
1570
- const { locale, status, ...rest } = request || {};
1825
+ const { locale, status: providedStatus, ...rest } = request || {};
1826
+ const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1827
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1571
1828
  const schema = yup$1.object().shape({
1572
1829
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1573
1830
  status: statusSchema
@@ -1580,7 +1837,7 @@ const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales
1580
1837
  }
1581
1838
  };
1582
1839
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1583
- const documentMetadata2 = getService$1("document-metadata");
1840
+ const documentMetadata2 = getService$2("document-metadata");
1584
1841
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1585
1842
  let {
1586
1843
  meta: { availableLocales, availableStatus }
@@ -1606,8 +1863,8 @@ const createDocument = async (ctx, opts) => {
1606
1863
  const { userAbility, user } = ctx.state;
1607
1864
  const { model } = ctx.params;
1608
1865
  const { body } = ctx.request;
1609
- const documentManager2 = getService$1("document-manager");
1610
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1866
+ const documentManager2 = getService$2("document-manager");
1867
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1611
1868
  if (permissionChecker2.cannot.create()) {
1612
1869
  throw new errors.ForbiddenError();
1613
1870
  }
@@ -1615,7 +1872,7 @@ const createDocument = async (ctx, opts) => {
1615
1872
  const setCreator = setCreatorFields({ user });
1616
1873
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1617
1874
  const sanitizedBody = await sanitizeFn(body);
1618
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1875
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1619
1876
  return documentManager2.create(model, {
1620
1877
  data: sanitizedBody,
1621
1878
  locale,
@@ -1627,14 +1884,14 @@ const updateDocument = async (ctx, opts) => {
1627
1884
  const { userAbility, user } = ctx.state;
1628
1885
  const { id, model } = ctx.params;
1629
1886
  const { body } = ctx.request;
1630
- const documentManager2 = getService$1("document-manager");
1631
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1887
+ const documentManager2 = getService$2("document-manager");
1888
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1632
1889
  if (permissionChecker2.cannot.update()) {
1633
1890
  throw new errors.ForbiddenError();
1634
1891
  }
1635
1892
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1636
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1637
- const { locale } = await getDocumentLocaleAndStatus(body);
1893
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1894
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1638
1895
  const [documentVersion, documentExists] = await Promise.all([
1639
1896
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1640
1897
  documentManager2.exists(model, id)
@@ -1650,7 +1907,7 @@ const updateDocument = async (ctx, opts) => {
1650
1907
  throw new errors.ForbiddenError();
1651
1908
  }
1652
1909
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1653
- const setCreator = setCreatorFields({ user, isEdition: true });
1910
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1654
1911
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1655
1912
  const sanitizedBody = await sanitizeFn(body);
1656
1913
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1664,15 +1921,15 @@ const collectionTypes = {
1664
1921
  const { userAbility } = ctx.state;
1665
1922
  const { model } = ctx.params;
1666
1923
  const { query } = ctx.request;
1667
- const documentMetadata2 = getService$1("document-metadata");
1668
- const documentManager2 = getService$1("document-manager");
1669
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1924
+ const documentMetadata2 = getService$2("document-metadata");
1925
+ const documentManager2 = getService$2("document-manager");
1926
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1670
1927
  if (permissionChecker2.cannot.read()) {
1671
1928
  return ctx.forbidden();
1672
1929
  }
1673
1930
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1674
- 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);
1931
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1932
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1676
1933
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1677
1934
  { ...permissionQuery, populate, locale, status },
1678
1935
  model
@@ -1700,14 +1957,14 @@ const collectionTypes = {
1700
1957
  async findOne(ctx) {
1701
1958
  const { userAbility } = ctx.state;
1702
1959
  const { model, id } = ctx.params;
1703
- const documentManager2 = getService$1("document-manager");
1704
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1960
+ const documentManager2 = getService$2("document-manager");
1961
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1705
1962
  if (permissionChecker2.cannot.read()) {
1706
1963
  return ctx.forbidden();
1707
1964
  }
1708
1965
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1709
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1710
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1966
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1967
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1711
1968
  const version = await documentManager2.findOne(id, model, {
1712
1969
  populate,
1713
1970
  locale,
@@ -1722,7 +1979,7 @@ const collectionTypes = {
1722
1979
  permissionChecker2,
1723
1980
  model,
1724
1981
  // @ts-expect-error TODO: fix
1725
- { id, locale, publishedAt: null },
1982
+ { documentId: id, locale, publishedAt: null },
1726
1983
  { availableLocales: true, availableStatus: false }
1727
1984
  );
1728
1985
  ctx.body = { data: {}, meta };
@@ -1737,7 +1994,7 @@ const collectionTypes = {
1737
1994
  async create(ctx) {
1738
1995
  const { userAbility } = ctx.state;
1739
1996
  const { model } = ctx.params;
1740
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1997
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1741
1998
  const [totalEntries, document] = await Promise.all([
1742
1999
  strapi.db.query(model).count(),
1743
2000
  createDocument(ctx)
@@ -1758,7 +2015,7 @@ const collectionTypes = {
1758
2015
  async update(ctx) {
1759
2016
  const { userAbility } = ctx.state;
1760
2017
  const { model } = ctx.params;
1761
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2018
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1762
2019
  const updatedVersion = await updateDocument(ctx);
1763
2020
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1764
2021
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1767,14 +2024,14 @@ const collectionTypes = {
1767
2024
  const { userAbility, user } = ctx.state;
1768
2025
  const { model, sourceId: id } = ctx.params;
1769
2026
  const { body } = ctx.request;
1770
- const documentManager2 = getService$1("document-manager");
1771
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2027
+ const documentManager2 = getService$2("document-manager");
2028
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1772
2029
  if (permissionChecker2.cannot.create()) {
1773
2030
  return ctx.forbidden();
1774
2031
  }
1775
2032
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1776
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1777
- const { locale } = await getDocumentLocaleAndStatus(body);
2033
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2034
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1778
2035
  const document = await documentManager2.findOne(id, model, {
1779
2036
  populate,
1780
2037
  locale,
@@ -1812,14 +2069,14 @@ const collectionTypes = {
1812
2069
  async delete(ctx) {
1813
2070
  const { userAbility } = ctx.state;
1814
2071
  const { id, model } = ctx.params;
1815
- const documentManager2 = getService$1("document-manager");
1816
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2072
+ const documentManager2 = getService$2("document-manager");
2073
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1817
2074
  if (permissionChecker2.cannot.delete()) {
1818
2075
  return ctx.forbidden();
1819
2076
  }
1820
2077
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1821
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1822
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
2078
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2079
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1823
2080
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1824
2081
  if (documentLocales.length === 0) {
1825
2082
  return ctx.notFound();
@@ -1840,19 +2097,42 @@ const collectionTypes = {
1840
2097
  const { userAbility } = ctx.state;
1841
2098
  const { id, model } = ctx.params;
1842
2099
  const { body } = ctx.request;
1843
- const documentManager2 = getService$1("document-manager");
1844
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2100
+ const documentManager2 = getService$2("document-manager");
2101
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1845
2102
  if (permissionChecker2.cannot.publish()) {
1846
2103
  return ctx.forbidden();
1847
2104
  }
1848
2105
  const publishedDocument = await strapi.db.transaction(async () => {
1849
2106
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1850
- 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 });
2107
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2108
+ let document;
2109
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2110
+ const isCreate = isNil$1(id);
2111
+ if (isCreate) {
2112
+ if (permissionChecker2.cannot.create()) {
2113
+ throw new errors.ForbiddenError();
2114
+ }
2115
+ document = await createDocument(ctx, { populate });
2116
+ }
2117
+ const isUpdate = !isCreate;
2118
+ if (isUpdate) {
2119
+ const documentExists = documentManager2.exists(model, id);
2120
+ if (!documentExists) {
2121
+ throw new errors.NotFoundError("Document not found");
2122
+ }
2123
+ document = await documentManager2.findOne(id, model, { populate, locale });
2124
+ if (!document) {
2125
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
2126
+ throw new errors.ForbiddenError();
2127
+ }
2128
+ document = await updateDocument(ctx);
2129
+ } else if (permissionChecker2.can.update(document)) {
2130
+ await updateDocument(ctx);
2131
+ }
2132
+ }
1852
2133
  if (permissionChecker2.cannot.publish(document)) {
1853
2134
  throw new errors.ForbiddenError();
1854
2135
  }
1855
- const { locale } = await getDocumentLocaleAndStatus(body);
1856
2136
  const publishResult = await documentManager2.publish(document.documentId, model, {
1857
2137
  locale
1858
2138
  // TODO: Allow setting creator fields on publish
@@ -1872,14 +2152,16 @@ const collectionTypes = {
1872
2152
  const { body } = ctx.request;
1873
2153
  const { documentIds } = body;
1874
2154
  await validateBulkActionInput(body);
1875
- const documentManager2 = getService$1("document-manager");
1876
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2155
+ const documentManager2 = getService$2("document-manager");
2156
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1877
2157
  if (permissionChecker2.cannot.publish()) {
1878
2158
  return ctx.forbidden();
1879
2159
  }
1880
2160
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1881
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1882
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
2161
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2162
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2163
+ allowMultipleLocales: true
2164
+ });
1883
2165
  const entityPromises = documentIds.map(
1884
2166
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1885
2167
  );
@@ -1901,12 +2183,14 @@ const collectionTypes = {
1901
2183
  const { body } = ctx.request;
1902
2184
  const { documentIds } = body;
1903
2185
  await validateBulkActionInput(body);
1904
- const documentManager2 = getService$1("document-manager");
1905
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2186
+ const documentManager2 = getService$2("document-manager");
2187
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1906
2188
  if (permissionChecker2.cannot.unpublish()) {
1907
2189
  return ctx.forbidden();
1908
2190
  }
1909
- const { locale } = await getDocumentLocaleAndStatus(body);
2191
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2192
+ allowMultipleLocales: true
2193
+ });
1910
2194
  const entityPromises = documentIds.map(
1911
2195
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1912
2196
  );
@@ -1929,8 +2213,8 @@ const collectionTypes = {
1929
2213
  const {
1930
2214
  body: { discardDraft, ...body }
1931
2215
  } = ctx.request;
1932
- const documentManager2 = getService$1("document-manager");
1933
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2216
+ const documentManager2 = getService$2("document-manager");
2217
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1934
2218
  if (permissionChecker2.cannot.unpublish()) {
1935
2219
  return ctx.forbidden();
1936
2220
  }
@@ -1938,8 +2222,8 @@ const collectionTypes = {
1938
2222
  return ctx.forbidden();
1939
2223
  }
1940
2224
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1941
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1942
- const { locale } = await getDocumentLocaleAndStatus(body);
2225
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2226
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1943
2227
  const document = await documentManager2.findOne(id, model, {
1944
2228
  populate,
1945
2229
  locale,
@@ -1969,14 +2253,14 @@ const collectionTypes = {
1969
2253
  const { userAbility } = ctx.state;
1970
2254
  const { id, model } = ctx.params;
1971
2255
  const { body } = ctx.request;
1972
- const documentManager2 = getService$1("document-manager");
1973
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2256
+ const documentManager2 = getService$2("document-manager");
2257
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1974
2258
  if (permissionChecker2.cannot.discard()) {
1975
2259
  return ctx.forbidden();
1976
2260
  }
1977
2261
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1978
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1979
- const { locale } = await getDocumentLocaleAndStatus(body);
2262
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2263
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1980
2264
  const document = await documentManager2.findOne(id, model, {
1981
2265
  populate,
1982
2266
  locale,
@@ -2000,14 +2284,14 @@ const collectionTypes = {
2000
2284
  const { query, body } = ctx.request;
2001
2285
  const { documentIds } = body;
2002
2286
  await validateBulkActionInput(body);
2003
- const documentManager2 = getService$1("document-manager");
2004
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2287
+ const documentManager2 = getService$2("document-manager");
2288
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2005
2289
  if (permissionChecker2.cannot.delete()) {
2006
2290
  return ctx.forbidden();
2007
2291
  }
2008
2292
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2009
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2010
- const { locale } = await getDocumentLocaleAndStatus(body);
2293
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2294
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2011
2295
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2012
2296
  populate,
2013
2297
  locale
@@ -2027,14 +2311,14 @@ const collectionTypes = {
2027
2311
  async countDraftRelations(ctx) {
2028
2312
  const { userAbility } = ctx.state;
2029
2313
  const { model, id } = ctx.params;
2030
- const documentManager2 = getService$1("document-manager");
2031
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2314
+ const documentManager2 = getService$2("document-manager");
2315
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2032
2316
  if (permissionChecker2.cannot.read()) {
2033
2317
  return ctx.forbidden();
2034
2318
  }
2035
2319
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2036
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2037
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2320
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2321
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2038
2322
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2039
2323
  if (!entity) {
2040
2324
  return ctx.notFound();
@@ -2052,12 +2336,12 @@ const collectionTypes = {
2052
2336
  const ids = ctx.request.query.documentIds;
2053
2337
  const locale = ctx.request.query.locale;
2054
2338
  const { model } = ctx.params;
2055
- const documentManager2 = getService$1("document-manager");
2056
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2339
+ const documentManager2 = getService$2("document-manager");
2340
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2057
2341
  if (permissionChecker2.cannot.read()) {
2058
2342
  return ctx.forbidden();
2059
2343
  }
2060
- const entities = await documentManager2.findMany(
2344
+ const documents = await documentManager2.findMany(
2061
2345
  {
2062
2346
  filters: {
2063
2347
  documentId: ids
@@ -2066,7 +2350,7 @@ const collectionTypes = {
2066
2350
  },
2067
2351
  model
2068
2352
  );
2069
- if (!entities) {
2353
+ if (!documents) {
2070
2354
  return ctx.notFound();
2071
2355
  }
2072
2356
  const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
@@ -2077,13 +2361,13 @@ const collectionTypes = {
2077
2361
  };
2078
2362
  const components$1 = {
2079
2363
  findComponents(ctx) {
2080
- const components2 = getService$1("components").findAllComponents();
2081
- const { toDto } = getService$1("data-mapper");
2364
+ const components2 = getService$2("components").findAllComponents();
2365
+ const { toDto } = getService$2("data-mapper");
2082
2366
  ctx.body = { data: components2.map(toDto) };
2083
2367
  },
2084
2368
  async findComponentConfiguration(ctx) {
2085
2369
  const { uid: uid2 } = ctx.params;
2086
- const componentService = getService$1("components");
2370
+ const componentService = getService$2("components");
2087
2371
  const component = componentService.findComponent(uid2);
2088
2372
  if (!component) {
2089
2373
  return ctx.notFound("component.notFound");
@@ -2100,7 +2384,7 @@ const components$1 = {
2100
2384
  async updateComponentConfiguration(ctx) {
2101
2385
  const { uid: uid2 } = ctx.params;
2102
2386
  const { body } = ctx.request;
2103
- const componentService = getService$1("components");
2387
+ const componentService = getService$2("components");
2104
2388
  const component = componentService.findComponent(uid2);
2105
2389
  if (!component) {
2106
2390
  return ctx.notFound("component.notFound");
@@ -2134,12 +2418,12 @@ const contentTypes = {
2134
2418
  } catch (error) {
2135
2419
  return ctx.send({ error }, 400);
2136
2420
  }
2137
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2138
- const { toDto } = getService$1("data-mapper");
2421
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2422
+ const { toDto } = getService$2("data-mapper");
2139
2423
  ctx.body = { data: contentTypes2.map(toDto) };
2140
2424
  },
2141
2425
  async findContentTypesSettings(ctx) {
2142
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2426
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2143
2427
  const contentTypes2 = await findAllContentTypes();
2144
2428
  const configurations = await Promise.all(
2145
2429
  contentTypes2.map(async (contentType) => {
@@ -2153,7 +2437,7 @@ const contentTypes = {
2153
2437
  },
2154
2438
  async findContentTypeConfiguration(ctx) {
2155
2439
  const { uid: uid2 } = ctx.params;
2156
- const contentTypeService = getService$1("content-types");
2440
+ const contentTypeService = getService$2("content-types");
2157
2441
  const contentType = await contentTypeService.findContentType(uid2);
2158
2442
  if (!contentType) {
2159
2443
  return ctx.notFound("contentType.notFound");
@@ -2175,13 +2459,13 @@ const contentTypes = {
2175
2459
  const { userAbility } = ctx.state;
2176
2460
  const { uid: uid2 } = ctx.params;
2177
2461
  const { body } = ctx.request;
2178
- const contentTypeService = getService$1("content-types");
2179
- const metricsService = getService$1("metrics");
2462
+ const contentTypeService = getService$2("content-types");
2463
+ const metricsService = getService$2("metrics");
2180
2464
  const contentType = await contentTypeService.findContentType(uid2);
2181
2465
  if (!contentType) {
2182
2466
  return ctx.notFound("contentType.notFound");
2183
2467
  }
2184
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2468
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2185
2469
  return ctx.forbidden();
2186
2470
  }
2187
2471
  let input;
@@ -2214,10 +2498,10 @@ const contentTypes = {
2214
2498
  };
2215
2499
  const init = {
2216
2500
  getInitData(ctx) {
2217
- const { toDto } = getService$1("data-mapper");
2218
- const { findAllComponents } = getService$1("components");
2219
- const { getAllFieldSizes } = getService$1("field-sizes");
2220
- const { findAllContentTypes } = getService$1("content-types");
2501
+ const { toDto } = getService$2("data-mapper");
2502
+ const { findAllComponents } = getService$2("components");
2503
+ const { getAllFieldSizes } = getService$2("field-sizes");
2504
+ const { findAllContentTypes } = getService$2("content-types");
2221
2505
  ctx.body = {
2222
2506
  data: {
2223
2507
  fieldSizes: getAllFieldSizes(),
@@ -2253,36 +2537,41 @@ const addFiltersClause = (params, filtersClause) => {
2253
2537
  params.filters.$and.push(filtersClause);
2254
2538
  };
2255
2539
  const sanitizeMainField = (model, mainField, userAbility) => {
2256
- const permissionChecker2 = getService$1("permission-checker").create({
2540
+ const permissionChecker2 = getService$2("permission-checker").create({
2257
2541
  userAbility,
2258
2542
  model: model.uid
2259
2543
  });
2260
- if (!isListable(model, mainField)) {
2544
+ const isMainFieldListable = isListable(model, mainField);
2545
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2546
+ if (!isMainFieldListable || !canReadMainField) {
2261
2547
  return "id";
2262
2548
  }
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";
2549
+ if (model.uid === "plugin::users-permissions.role") {
2550
+ return "name";
2274
2551
  }
2275
2552
  return mainField;
2276
2553
  };
2277
- const addStatusToRelations = async (uid2, relations2) => {
2278
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2554
+ const addStatusToRelations = async (targetUid, relations2) => {
2555
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2279
2556
  return relations2;
2280
2557
  }
2281
- const documentMetadata2 = getService$1("document-metadata");
2282
- const documentsAvailableStatus = await documentMetadata2.getManyAvailableStatus(uid2, relations2);
2558
+ const documentMetadata2 = getService$2("document-metadata");
2559
+ if (!relations2.length) {
2560
+ return relations2;
2561
+ }
2562
+ const firstRelation = relations2[0];
2563
+ const filters = {
2564
+ documentId: { $in: relations2.map((r) => r.documentId) },
2565
+ // NOTE: find the "opposite" status
2566
+ publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
2567
+ };
2568
+ const availableStatus = await strapi.query(targetUid).findMany({
2569
+ select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
2570
+ filters
2571
+ });
2283
2572
  return relations2.map((relation) => {
2284
- const availableStatuses = documentsAvailableStatus.filter(
2285
- (availableDocument) => availableDocument.documentId === relation.documentId
2573
+ const availableStatuses = availableStatus.filter(
2574
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2286
2575
  );
2287
2576
  return {
2288
2577
  ...relation,
@@ -2303,11 +2592,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2303
2592
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2304
2593
  const isSourceLocalized = isLocalized(sourceModel);
2305
2594
  const isTargetLocalized = isLocalized(targetModel);
2306
- let validatedLocale = locale;
2307
- if (!targetModel || !isTargetLocalized)
2308
- validatedLocale = void 0;
2309
2595
  return {
2310
- locale: validatedLocale,
2596
+ locale,
2311
2597
  isSourceLocalized,
2312
2598
  isTargetLocalized
2313
2599
  };
@@ -2316,8 +2602,7 @@ const validateStatus = (sourceUid, status) => {
2316
2602
  const sourceModel = strapi.getModel(sourceUid);
2317
2603
  const isDP = contentTypes$1.hasDraftAndPublish;
2318
2604
  const isSourceDP = isDP(sourceModel);
2319
- if (!isSourceDP)
2320
- return { status: void 0 };
2605
+ if (!isSourceDP) return { status: void 0 };
2321
2606
  switch (status) {
2322
2607
  case "published":
2323
2608
  return { status: "published" };
@@ -2347,7 +2632,7 @@ const relations = {
2347
2632
  ctx.request?.query?.locale
2348
2633
  );
2349
2634
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2350
- const permissionChecker2 = getService$1("permission-checker").create({
2635
+ const permissionChecker2 = getService$2("permission-checker").create({
2351
2636
  userAbility,
2352
2637
  model
2353
2638
  });
@@ -2372,7 +2657,7 @@ const relations = {
2372
2657
  where.id = id;
2373
2658
  }
2374
2659
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2375
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2660
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2376
2661
  const currentEntity = await strapi.db.query(model).findOne({
2377
2662
  where,
2378
2663
  populate
@@ -2387,7 +2672,7 @@ const relations = {
2387
2672
  }
2388
2673
  entryId = currentEntity.id;
2389
2674
  }
2390
- const modelConfig = isComponent2 ? await getService$1("components").findConfiguration(sourceSchema) : await getService$1("content-types").findConfiguration(sourceSchema);
2675
+ const modelConfig = isComponent2 ? await getService$2("components").findConfiguration(sourceSchema) : await getService$2("content-types").findConfiguration(sourceSchema);
2391
2676
  const targetSchema = strapi.getModel(targetUid);
2392
2677
  const mainField = flow(
2393
2678
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2410,7 +2695,7 @@ const relations = {
2410
2695
  attribute,
2411
2696
  fieldsToSelect,
2412
2697
  mainField,
2413
- source: { schema: sourceSchema },
2698
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2414
2699
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2415
2700
  sourceSchema,
2416
2701
  targetSchema,
@@ -2432,7 +2717,8 @@ const relations = {
2432
2717
  fieldsToSelect,
2433
2718
  mainField,
2434
2719
  source: {
2435
- schema: { uid: sourceUid, modelType: sourceModelType }
2720
+ schema: { uid: sourceUid, modelType: sourceModelType },
2721
+ isLocalized: isSourceLocalized
2436
2722
  },
2437
2723
  target: {
2438
2724
  schema: { uid: targetUid },
@@ -2440,7 +2726,7 @@ const relations = {
2440
2726
  }
2441
2727
  } = await this.extractAndValidateRequestInfo(ctx, id);
2442
2728
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2443
- const permissionChecker2 = getService$1("permission-checker").create({
2729
+ const permissionChecker2 = getService$2("permission-checker").create({
2444
2730
  userAbility: ctx.state.userAbility,
2445
2731
  model: targetUid
2446
2732
  });
@@ -2470,12 +2756,16 @@ const relations = {
2470
2756
  } else {
2471
2757
  where.id = id;
2472
2758
  }
2473
- if (status) {
2474
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2759
+ const publishedAt = getPublishedAtClause(status, targetUid);
2760
+ if (!isEmpty(publishedAt)) {
2761
+ where[`${alias}.published_at`] = publishedAt;
2475
2762
  }
2476
- if (filterByLocale) {
2763
+ if (isTargetLocalized && locale) {
2477
2764
  where[`${alias}.locale`] = locale;
2478
2765
  }
2766
+ if (isSourceLocalized && locale) {
2767
+ where.locale = locale;
2768
+ }
2479
2769
  if ((idsToInclude?.length ?? 0) !== 0) {
2480
2770
  where[`${alias}.id`].$notIn = idsToInclude;
2481
2771
  }
@@ -2493,7 +2783,8 @@ const relations = {
2493
2783
  id: { $notIn: uniq(idsToOmit) }
2494
2784
  });
2495
2785
  }
2496
- const res = await strapi.db.query(targetUid).findPage(strapi.get("query-params").transform(targetUid, queryParams));
2786
+ const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
2787
+ const res = await strapi.db.query(targetUid).findPage(dbQuery);
2497
2788
  ctx.body = {
2498
2789
  ...res,
2499
2790
  results: await addStatusToRelations(targetUid, res.results)
@@ -2508,29 +2799,39 @@ const relations = {
2508
2799
  attribute,
2509
2800
  targetField,
2510
2801
  fieldsToSelect,
2511
- source: {
2512
- schema: { uid: sourceUid }
2513
- },
2514
- target: {
2515
- schema: { uid: targetUid }
2516
- }
2802
+ status,
2803
+ source: { schema: sourceSchema },
2804
+ target: { schema: targetSchema }
2517
2805
  } = await this.extractAndValidateRequestInfo(ctx, id);
2518
- const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2806
+ const { uid: sourceUid } = sourceSchema;
2807
+ const { uid: targetUid } = targetSchema;
2808
+ const permissionQuery = await getService$2("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
2519
2809
  const dbQuery = strapi.db.query(sourceUid);
2520
2810
  const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
2811
+ const filters = {};
2812
+ if (sourceSchema?.options?.draftAndPublish) {
2813
+ if (targetSchema?.options?.draftAndPublish) {
2814
+ if (status === "published") {
2815
+ filters.publishedAt = { $notNull: true };
2816
+ } else {
2817
+ filters.publishedAt = { $null: true };
2818
+ }
2819
+ }
2820
+ } else if (targetSchema?.options?.draftAndPublish) {
2821
+ filters.publishedAt = { $null: true };
2822
+ }
2521
2823
  const res = await loadRelations({ id: entryId }, targetField, {
2522
- select: ["id", "documentId", "locale", "publishedAt"],
2824
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2523
2825
  ordering: "desc",
2524
2826
  page: ctx.request.query.page,
2525
- pageSize: ctx.request.query.pageSize
2827
+ pageSize: ctx.request.query.pageSize,
2828
+ filters
2526
2829
  });
2527
2830
  const loadedIds = res.results.map((item) => item.id);
2528
2831
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2529
2832
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2530
2833
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2531
- ordering: "desc",
2532
- page: ctx.request.query.page,
2533
- pageSize: ctx.request.query.pageSize
2834
+ ordering: "desc"
2534
2835
  });
2535
2836
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2536
2837
  ctx.body = {
@@ -2545,10 +2846,10 @@ const relations = {
2545
2846
  }
2546
2847
  };
2547
2848
  const buildPopulateFromQuery = async (query, model) => {
2548
- return getService$1("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2849
+ return getService$2("populate-builder")(model).populateFromQuery(query).populateDeep(Infinity).countRelations().build();
2549
2850
  };
2550
2851
  const findDocument = async (query, uid2, opts = {}) => {
2551
- const documentManager2 = getService$1("document-manager");
2852
+ const documentManager2 = getService$2("document-manager");
2552
2853
  const populate = await buildPopulateFromQuery(query, uid2);
2553
2854
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2554
2855
  };
@@ -2556,13 +2857,13 @@ const createOrUpdateDocument = async (ctx, opts) => {
2556
2857
  const { user, userAbility } = ctx.state;
2557
2858
  const { model } = ctx.params;
2558
2859
  const { body, query } = ctx.request;
2559
- const documentManager2 = getService$1("document-manager");
2560
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2860
+ const documentManager2 = getService$2("document-manager");
2861
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2561
2862
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2562
2863
  throw new errors.ForbiddenError();
2563
2864
  }
2564
2865
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2565
- const { locale } = await getDocumentLocaleAndStatus(body);
2866
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2566
2867
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2567
2868
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2568
2869
  // Find the first document to check if it exists
@@ -2598,12 +2899,12 @@ const singleTypes = {
2598
2899
  const { userAbility } = ctx.state;
2599
2900
  const { model } = ctx.params;
2600
2901
  const { query = {} } = ctx.request;
2601
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2902
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2602
2903
  if (permissionChecker2.cannot.read()) {
2603
2904
  return ctx.forbidden();
2604
2905
  }
2605
2906
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2606
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2907
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2607
2908
  const version = await findDocument(permissionQuery, model, { locale, status });
2608
2909
  if (!version) {
2609
2910
  if (permissionChecker2.cannot.create()) {
@@ -2617,7 +2918,7 @@ const singleTypes = {
2617
2918
  permissionChecker2,
2618
2919
  model,
2619
2920
  // @ts-expect-error - fix types
2620
- { id: document.documentId, locale, publishedAt: null },
2921
+ { documentId: document.documentId, locale, publishedAt: null },
2621
2922
  { availableLocales: true, availableStatus: false }
2622
2923
  );
2623
2924
  ctx.body = { data: {}, meta };
@@ -2632,7 +2933,7 @@ const singleTypes = {
2632
2933
  async createOrUpdate(ctx) {
2633
2934
  const { userAbility } = ctx.state;
2634
2935
  const { model } = ctx.params;
2635
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2936
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2636
2937
  const document = await createOrUpdateDocument(ctx);
2637
2938
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2638
2939
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2641,14 +2942,14 @@ const singleTypes = {
2641
2942
  const { userAbility } = ctx.state;
2642
2943
  const { model } = ctx.params;
2643
2944
  const { query = {} } = ctx.request;
2644
- const documentManager2 = getService$1("document-manager");
2645
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2945
+ const documentManager2 = getService$2("document-manager");
2946
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2646
2947
  if (permissionChecker2.cannot.delete()) {
2647
2948
  return ctx.forbidden();
2648
2949
  }
2649
2950
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2650
2951
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2651
- const { locale } = await getDocumentLocaleAndStatus(query);
2952
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2652
2953
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2653
2954
  populate,
2654
2955
  locale
@@ -2670,8 +2971,8 @@ const singleTypes = {
2670
2971
  const { userAbility } = ctx.state;
2671
2972
  const { model } = ctx.params;
2672
2973
  const { query = {} } = ctx.request;
2673
- const documentManager2 = getService$1("document-manager");
2674
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2974
+ const documentManager2 = getService$2("document-manager");
2975
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2675
2976
  if (permissionChecker2.cannot.publish()) {
2676
2977
  return ctx.forbidden();
2677
2978
  }
@@ -2685,7 +2986,7 @@ const singleTypes = {
2685
2986
  if (permissionChecker2.cannot.publish(document)) {
2686
2987
  throw new errors.ForbiddenError();
2687
2988
  }
2688
- const { locale } = await getDocumentLocaleAndStatus(document);
2989
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2689
2990
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2690
2991
  return publishResult.at(0);
2691
2992
  });
@@ -2699,8 +3000,8 @@ const singleTypes = {
2699
3000
  body: { discardDraft, ...body },
2700
3001
  query = {}
2701
3002
  } = ctx.request;
2702
- const documentManager2 = getService$1("document-manager");
2703
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3003
+ const documentManager2 = getService$2("document-manager");
3004
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2704
3005
  if (permissionChecker2.cannot.unpublish()) {
2705
3006
  return ctx.forbidden();
2706
3007
  }
@@ -2708,7 +3009,7 @@ const singleTypes = {
2708
3009
  return ctx.forbidden();
2709
3010
  }
2710
3011
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2711
- const { locale } = await getDocumentLocaleAndStatus(body);
3012
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2712
3013
  const document = await findDocument(sanitizedQuery, model, { locale });
2713
3014
  if (!document) {
2714
3015
  return ctx.notFound();
@@ -2734,13 +3035,13 @@ const singleTypes = {
2734
3035
  const { userAbility } = ctx.state;
2735
3036
  const { model } = ctx.params;
2736
3037
  const { body, query = {} } = ctx.request;
2737
- const documentManager2 = getService$1("document-manager");
2738
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3038
+ const documentManager2 = getService$2("document-manager");
3039
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2739
3040
  if (permissionChecker2.cannot.discard()) {
2740
3041
  return ctx.forbidden();
2741
3042
  }
2742
3043
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2743
- const { locale } = await getDocumentLocaleAndStatus(body);
3044
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2744
3045
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2745
3046
  if (!document) {
2746
3047
  return ctx.notFound();
@@ -2758,9 +3059,9 @@ const singleTypes = {
2758
3059
  const { userAbility } = ctx.state;
2759
3060
  const { model } = ctx.params;
2760
3061
  const { query } = ctx.request;
2761
- const documentManager2 = getService$1("document-manager");
2762
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2763
- const { locale } = await getDocumentLocaleAndStatus(query);
3062
+ const documentManager2 = getService$2("document-manager");
3063
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
3064
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2764
3065
  if (permissionChecker2.cannot.read()) {
2765
3066
  return ctx.forbidden();
2766
3067
  }
@@ -2781,9 +3082,9 @@ const uid$1 = {
2781
3082
  async generateUID(ctx) {
2782
3083
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2783
3084
  const { query = {} } = ctx.request;
2784
- const { locale } = await getDocumentLocaleAndStatus(query);
3085
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2785
3086
  await validateUIDField(contentTypeUID, field);
2786
- const uidService = getService$1("uid");
3087
+ const uidService = getService$2("uid");
2787
3088
  ctx.body = {
2788
3089
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2789
3090
  };
@@ -2793,9 +3094,9 @@ const uid$1 = {
2793
3094
  ctx.request.body
2794
3095
  );
2795
3096
  const { query = {} } = ctx.request;
2796
- const { locale } = await getDocumentLocaleAndStatus(query);
3097
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2797
3098
  await validateUIDField(contentTypeUID, field);
2798
- const uidService = getService$1("uid");
3099
+ const uidService = getService$2("uid");
2799
3100
  const isAvailable = await uidService.checkUIDAvailability({
2800
3101
  contentTypeUID,
2801
3102
  field,
@@ -2816,7 +3117,8 @@ const controllers = {
2816
3117
  relations,
2817
3118
  "single-types": singleTypes,
2818
3119
  uid: uid$1,
2819
- ...history.controllers ? history.controllers : {}
3120
+ ...history.controllers ? history.controllers : {},
3121
+ ...preview.controllers ? preview.controllers : {}
2820
3122
  };
2821
3123
  const keys = {
2822
3124
  CONFIGURATION: "configuration"
@@ -2945,18 +3247,15 @@ async function syncMetadatas(configuration, schema) {
2945
3247
  _.set(updatedMeta, ["list", "searchable"], false);
2946
3248
  _.set(acc, [key], updatedMeta);
2947
3249
  }
2948
- if (!_.has(edit, "mainField"))
2949
- return acc;
3250
+ if (!_.has(edit, "mainField")) return acc;
2950
3251
  if (!isRelation$1(attr)) {
2951
3252
  _.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
2952
3253
  _.set(acc, [key], updatedMeta);
2953
3254
  return acc;
2954
3255
  }
2955
- if (edit.mainField === "id")
2956
- return acc;
3256
+ if (edit.mainField === "id") return acc;
2957
3257
  const targetSchema = getTargetSchema(attr.targetModel);
2958
- if (!targetSchema)
2959
- return acc;
3258
+ if (!targetSchema) return acc;
2960
3259
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
2961
3260
  _.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
2962
3261
  _.set(acc, [key], updatedMeta);
@@ -2967,12 +3266,12 @@ async function syncMetadatas(configuration, schema) {
2967
3266
  return _.assign(metasWithDefaults, updatedMetas);
2968
3267
  }
2969
3268
  const getTargetSchema = (targetModel) => {
2970
- return getService$1("content-types").findContentType(targetModel);
3269
+ return getService$2("content-types").findContentType(targetModel);
2971
3270
  };
2972
3271
  const DEFAULT_LIST_LENGTH = 4;
2973
3272
  const MAX_ROW_SIZE = 12;
2974
3273
  const isAllowedFieldSize = (type, size) => {
2975
- const { getFieldSize } = getService$1("field-sizes");
3274
+ const { getFieldSize } = getService$2("field-sizes");
2976
3275
  const fieldSize = getFieldSize(type);
2977
3276
  if (!fieldSize.isResizable && size !== fieldSize.default) {
2978
3277
  return false;
@@ -2980,7 +3279,7 @@ const isAllowedFieldSize = (type, size) => {
2980
3279
  return size <= MAX_ROW_SIZE;
2981
3280
  };
2982
3281
  const getDefaultFieldSize = (attribute) => {
2983
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3282
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
2984
3283
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
2985
3284
  };
2986
3285
  async function createDefaultLayouts(schema) {
@@ -3001,8 +3300,7 @@ function createDefaultEditLayout(schema) {
3001
3300
  return appendToEditLayout([], keys2, schema);
3002
3301
  }
3003
3302
  function syncLayouts(configuration, schema) {
3004
- if (_.isEmpty(configuration.layouts))
3005
- return createDefaultLayouts(schema);
3303
+ if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3006
3304
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3007
3305
  let cleanList = list.filter((attr) => isListable(schema, attr));
3008
3306
  const cleanEditRelations = editRelations.filter(
@@ -3013,9 +3311,8 @@ function syncLayouts(configuration, schema) {
3013
3311
  for (const row of edit) {
3014
3312
  const newRow = [];
3015
3313
  for (const el of row) {
3016
- if (!hasEditableAttribute(schema, el.name))
3017
- continue;
3018
- const { hasFieldSize } = getService$1("field-sizes");
3314
+ if (!hasEditableAttribute(schema, el.name)) continue;
3315
+ const { hasFieldSize } = getService$2("field-sizes");
3019
3316
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3020
3317
  if (!isAllowedFieldSize(fieldType, el.size)) {
3021
3318
  elementsToReAppend.push(el.name);
@@ -3045,8 +3342,7 @@ function syncLayouts(configuration, schema) {
3045
3342
  };
3046
3343
  }
3047
3344
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3048
- if (keysToAppend.length === 0)
3049
- return layout;
3345
+ if (keysToAppend.length === 0) return layout;
3050
3346
  let currentRowIndex = Math.max(layout.length - 1, 0);
3051
3347
  if (!layout[currentRowIndex]) {
3052
3348
  layout[currentRowIndex] = [];
@@ -3155,17 +3451,17 @@ const configurationService$1 = createConfigurationService({
3155
3451
  isComponent: true,
3156
3452
  prefix: STORE_KEY_PREFIX,
3157
3453
  getModels() {
3158
- const { toContentManagerModel } = getService$1("data-mapper");
3454
+ const { toContentManagerModel } = getService$2("data-mapper");
3159
3455
  return mapValues(toContentManagerModel, strapi.components);
3160
3456
  }
3161
3457
  });
3162
3458
  const components = ({ strapi: strapi2 }) => ({
3163
3459
  findAllComponents() {
3164
- const { toContentManagerModel } = getService$1("data-mapper");
3460
+ const { toContentManagerModel } = getService$2("data-mapper");
3165
3461
  return Object.values(strapi2.components).map(toContentManagerModel);
3166
3462
  },
3167
3463
  findComponent(uid2) {
3168
- const { toContentManagerModel } = getService$1("data-mapper");
3464
+ const { toContentManagerModel } = getService$2("data-mapper");
3169
3465
  const component = strapi2.components[uid2];
3170
3466
  return isNil$1(component) ? component : toContentManagerModel(component);
3171
3467
  },
@@ -3216,17 +3512,17 @@ const configurationService = createConfigurationService({
3216
3512
  storeUtils,
3217
3513
  prefix: "content_types",
3218
3514
  getModels() {
3219
- const { toContentManagerModel } = getService$1("data-mapper");
3515
+ const { toContentManagerModel } = getService$2("data-mapper");
3220
3516
  return mapValues(toContentManagerModel, strapi.contentTypes);
3221
3517
  }
3222
3518
  });
3223
3519
  const service = ({ strapi: strapi2 }) => ({
3224
3520
  findAllContentTypes() {
3225
- const { toContentManagerModel } = getService$1("data-mapper");
3521
+ const { toContentManagerModel } = getService$2("data-mapper");
3226
3522
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3227
3523
  },
3228
3524
  findContentType(uid2) {
3229
- const { toContentManagerModel } = getService$1("data-mapper");
3525
+ const { toContentManagerModel } = getService$2("data-mapper");
3230
3526
  const contentType = strapi2.contentTypes[uid2];
3231
3527
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3232
3528
  },
@@ -3255,7 +3551,7 @@ const service = ({ strapi: strapi2 }) => ({
3255
3551
  return this.findConfiguration(contentType);
3256
3552
  },
3257
3553
  findComponentsConfigurations(contentType) {
3258
- return getService$1("components").findComponentsConfigurations(contentType);
3554
+ return getService$2("components").findComponentsConfigurations(contentType);
3259
3555
  },
3260
3556
  syncConfigurations() {
3261
3557
  return configurationService.syncConfigurations();
@@ -3436,12 +3732,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3436
3732
  ability: userAbility,
3437
3733
  model
3438
3734
  });
3439
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3735
+ const { actionProvider } = strapi2.service("admin::permission");
3736
+ const toSubject = (entity) => {
3737
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3738
+ };
3440
3739
  const can = (action, entity, field) => {
3441
- return userAbility.can(action, toSubject(entity), field);
3740
+ const subject = toSubject(entity);
3741
+ const aliases = actionProvider.unstable_aliases(action, model);
3742
+ return (
3743
+ // Test the original action to see if it passes
3744
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3745
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3746
+ );
3442
3747
  };
3443
3748
  const cannot = (action, entity, field) => {
3444
- return userAbility.cannot(action, toSubject(entity), field);
3749
+ const subject = toSubject(entity);
3750
+ const aliases = actionProvider.unstable_aliases(action, model);
3751
+ return (
3752
+ // Test both the original action
3753
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3754
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3755
+ );
3445
3756
  };
3446
3757
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3447
3758
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3512,7 +3823,7 @@ const permission = ({ strapi: strapi2 }) => ({
3512
3823
  return userAbility.can(action);
3513
3824
  },
3514
3825
  async registerPermissions() {
3515
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3826
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3516
3827
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3517
3828
  const actions = [
3518
3829
  {
@@ -3718,6 +4029,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3718
4029
  const attribute = model.attributes[attributeName];
3719
4030
  switch (attribute.type) {
3720
4031
  case "relation": {
4032
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
4033
+ if (isMorphRelation) {
4034
+ break;
4035
+ }
3721
4036
  if (isVisibleAttribute$1(model, attributeName)) {
3722
4037
  populateAcc[attributeName] = {
3723
4038
  count: true,
@@ -3784,7 +4099,7 @@ const getQueryPopulate = async (uid2, query) => {
3784
4099
  return populateQuery;
3785
4100
  };
3786
4101
  const buildDeepPopulate = (uid2) => {
3787
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4102
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3788
4103
  };
3789
4104
  const populateBuilder = (uid2) => {
3790
4105
  let getInitialPopulate = async () => {
@@ -3969,7 +4284,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
3969
4284
  */
3970
4285
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
3971
4286
  const versionsByLocale = groupBy("locale", allVersions);
3972
- delete versionsByLocale[version.locale];
4287
+ if (version.locale) {
4288
+ delete versionsByLocale[version.locale];
4289
+ }
3973
4290
  const model = strapi2.getModel(uid2);
3974
4291
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
3975
4292
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4016,8 +4333,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4016
4333
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4017
4334
  return matchLocale && matchStatus;
4018
4335
  });
4019
- if (!availableStatus)
4020
- return availableStatus;
4336
+ if (!availableStatus) return availableStatus;
4021
4337
  return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4022
4338
  },
4023
4339
  /**
@@ -4027,8 +4343,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4027
4343
  * @returns
4028
4344
  */
4029
4345
  async getManyAvailableStatus(uid2, documents) {
4030
- if (!documents.length)
4031
- return [];
4346
+ if (!documents.length) return [];
4032
4347
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4033
4348
  const locale = documents[0]?.locale;
4034
4349
  const otherStatus = status === "published" ? "draft" : "published";
@@ -4055,10 +4370,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4055
4370
  } else if (otherVersion) {
4056
4371
  draftVersion = otherVersion;
4057
4372
  }
4058
- if (!draftVersion)
4059
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4060
- if (!publishedVersion)
4061
- return CONTENT_MANAGER_STATUS.DRAFT;
4373
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4374
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4062
4375
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4063
4376
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4064
4377
  },
@@ -4095,7 +4408,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4095
4408
  */
4096
4409
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4097
4410
  if (!document) {
4098
- return document;
4411
+ return {
4412
+ data: document,
4413
+ meta: {
4414
+ availableLocales: [],
4415
+ availableStatus: []
4416
+ }
4417
+ };
4099
4418
  }
4100
4419
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4101
4420
  if (!hasDraftAndPublish) {
@@ -4203,10 +4522,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4203
4522
  async clone(id, body, uid2) {
4204
4523
  const populate = await buildDeepPopulate(uid2);
4205
4524
  const params = {
4206
- data: {
4207
- ...omitIdField(body),
4208
- [PUBLISHED_AT_ATTRIBUTE]: null
4209
- },
4525
+ data: omitIdField(body),
4210
4526
  populate
4211
4527
  };
4212
4528
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
@@ -4322,7 +4638,8 @@ const services = {
4322
4638
  permission,
4323
4639
  "populate-builder": populateBuilder$1,
4324
4640
  uid,
4325
- ...history.services ? history.services : {}
4641
+ ...history.services ? history.services : {},
4642
+ ...preview.services ? preview.services : {}
4326
4643
  };
4327
4644
  const index = () => {
4328
4645
  return {