@strapi/content-manager 0.0.0-experimental.cb311d9fcfbd8e441f790aea232f0a39bdd90e16 → 0.0.0-experimental.cb74730ce5154c26404d4dccca14976a22319002

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 (210) hide show
  1. package/dist/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
  2. package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
  3. package/dist/_chunks/{ComponentConfigurationPage-D0dyDTwq.mjs → ComponentConfigurationPage-BgCLcjXO.mjs} +4 -4
  4. package/dist/_chunks/{ComponentConfigurationPage-D0dyDTwq.mjs.map → ComponentConfigurationPage-BgCLcjXO.mjs.map} +1 -1
  5. package/dist/_chunks/{ComponentConfigurationPage-DL1MHO8i.js → ComponentConfigurationPage-DywpTZeV.js} +5 -6
  6. package/dist/_chunks/{ComponentConfigurationPage-DL1MHO8i.js.map → ComponentConfigurationPage-DywpTZeV.js.map} +1 -1
  7. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
  8. package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
  9. package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
  10. package/dist/_chunks/{EditConfigurationPage-13b7S5Cq.mjs → EditConfigurationPage-BNjOAHNS.mjs} +4 -4
  11. package/dist/_chunks/{EditConfigurationPage-13b7S5Cq.mjs.map → EditConfigurationPage-BNjOAHNS.mjs.map} +1 -1
  12. package/dist/_chunks/{EditConfigurationPage-CMaOf-A-.js → EditConfigurationPage-CxRlP5if.js} +5 -6
  13. package/dist/_chunks/{EditConfigurationPage-CMaOf-A-.js.map → EditConfigurationPage-CxRlP5if.js.map} +1 -1
  14. package/dist/_chunks/{EditViewPage-BSVmMpRd.js → EditViewPage-BRewdTqE.js} +63 -13
  15. package/dist/_chunks/EditViewPage-BRewdTqE.js.map +1 -0
  16. package/dist/_chunks/{EditViewPage-C3tIZ8F5.mjs → EditViewPage-CD_hqc1J.mjs} +63 -12
  17. package/dist/_chunks/EditViewPage-CD_hqc1J.mjs.map +1 -0
  18. package/dist/_chunks/{Field-BvuT8cGL.mjs → Field-BPkQ-3Ku.mjs} +230 -158
  19. package/dist/_chunks/Field-BPkQ-3Ku.mjs.map +1 -0
  20. package/dist/_chunks/{Field-DUCVth4C.js → Field-DwvmENVf.js} +233 -162
  21. package/dist/_chunks/Field-DwvmENVf.js.map +1 -0
  22. package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
  23. package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
  24. package/dist/_chunks/{Form-Cpl4W1ak.js → Form-C_Gwv8P_.js} +39 -21
  25. package/dist/_chunks/Form-C_Gwv8P_.js.map +1 -0
  26. package/dist/_chunks/{Form-BZmDNVr9.mjs → Form-Czi0cf_2.mjs} +37 -18
  27. package/dist/_chunks/Form-Czi0cf_2.mjs.map +1 -0
  28. package/dist/_chunks/{History-D4U2YISB.js → History-C1TKAig-.js} +42 -100
  29. package/dist/_chunks/History-C1TKAig-.js.map +1 -0
  30. package/dist/_chunks/{History-Cq_Hrzuu.mjs → History-CIQHyi4T.mjs} +43 -100
  31. package/dist/_chunks/History-CIQHyi4T.mjs.map +1 -0
  32. package/dist/_chunks/{ListConfigurationPage-Bny6CdWe.js → ListConfigurationPage-D-NGRLYu.js} +19 -9
  33. package/dist/_chunks/ListConfigurationPage-D-NGRLYu.js.map +1 -0
  34. package/dist/_chunks/{ListConfigurationPage-W-KQHmBv.mjs → ListConfigurationPage-DcZsfyEL.mjs} +19 -8
  35. package/dist/_chunks/ListConfigurationPage-DcZsfyEL.mjs.map +1 -0
  36. package/dist/_chunks/{ListViewPage-HBBnJa8K.mjs → ListViewPage-C10McTK1.mjs} +99 -72
  37. package/dist/_chunks/ListViewPage-C10McTK1.mjs.map +1 -0
  38. package/dist/_chunks/{ListViewPage-O8F1pBJo.js → ListViewPage-xv5IQoZp.js} +103 -77
  39. package/dist/_chunks/ListViewPage-xv5IQoZp.js.map +1 -0
  40. package/dist/_chunks/{NoContentTypePage-B-gIhHWM.mjs → NoContentTypePage-CPc0Cd3S.mjs} +2 -2
  41. package/dist/_chunks/{NoContentTypePage-B-gIhHWM.mjs.map → NoContentTypePage-CPc0Cd3S.mjs.map} +1 -1
  42. package/dist/_chunks/{NoContentTypePage-CQWChGPw.js → NoContentTypePage-Dzw5Yj5u.js} +2 -2
  43. package/dist/_chunks/{NoContentTypePage-CQWChGPw.js.map → NoContentTypePage-Dzw5Yj5u.js.map} +1 -1
  44. package/dist/_chunks/{NoPermissionsPage-CY46zxnM.js → NoPermissionsPage-DAe5CDCC.js} +2 -2
  45. package/dist/_chunks/{NoPermissionsPage-CY46zxnM.js.map → NoPermissionsPage-DAe5CDCC.js.map} +1 -1
  46. package/dist/_chunks/{NoPermissionsPage-XhOPl8wx.mjs → NoPermissionsPage-wfPBh2_0.mjs} +2 -2
  47. package/dist/_chunks/{NoPermissionsPage-XhOPl8wx.mjs.map → NoPermissionsPage-wfPBh2_0.mjs.map} +1 -1
  48. package/dist/_chunks/Preview-B7LyGT_b.js +290 -0
  49. package/dist/_chunks/Preview-B7LyGT_b.js.map +1 -0
  50. package/dist/_chunks/Preview-BVFFm7uB.mjs +272 -0
  51. package/dist/_chunks/Preview-BVFFm7uB.mjs.map +1 -0
  52. package/dist/_chunks/{Relations-C4gGfZRv.js → Relations-BmYR1AjY.js} +76 -43
  53. package/dist/_chunks/Relations-BmYR1AjY.js.map +1 -0
  54. package/dist/_chunks/{Relations-vFZ6Wasg.mjs → Relations-JPhWxk-s.mjs} +76 -42
  55. package/dist/_chunks/Relations-JPhWxk-s.mjs.map +1 -0
  56. package/dist/_chunks/{en-uOUIxfcQ.js → en-BK8Xyl5I.js} +28 -15
  57. package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BK8Xyl5I.js.map} +1 -1
  58. package/dist/_chunks/{en-BrCTWlZv.mjs → en-Dtk_ot79.mjs} +28 -15
  59. package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-Dtk_ot79.mjs.map} +1 -1
  60. package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
  61. package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
  62. package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
  63. package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
  64. package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
  65. package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
  66. package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
  67. package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
  68. package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
  69. package/dist/_chunks/{index-5EMXLEM_.js → index-C2Q_PLWj.js} +1199 -927
  70. package/dist/_chunks/index-C2Q_PLWj.js.map +1 -0
  71. package/dist/_chunks/{index-Dpxg3ctD.mjs → index-DLIkNVnQ.mjs} +1217 -945
  72. package/dist/_chunks/index-DLIkNVnQ.mjs.map +1 -0
  73. package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
  74. package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
  75. package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
  76. package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
  77. package/dist/_chunks/{layout-P3eKO1Qy.js → layout-7AsWJzZJ.js} +10 -10
  78. package/dist/_chunks/layout-7AsWJzZJ.js.map +1 -0
  79. package/dist/_chunks/{layout-C0INpKap.mjs → layout-qE8qkNH_.mjs} +9 -8
  80. package/dist/_chunks/layout-qE8qkNH_.mjs.map +1 -0
  81. package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
  82. package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
  83. package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
  84. package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
  85. package/dist/_chunks/{relations-FBRRBWeO.mjs → relations-BjHH_1Am.mjs} +6 -7
  86. package/dist/_chunks/relations-BjHH_1Am.mjs.map +1 -0
  87. package/dist/_chunks/{relations-B1y0K6LE.js → relations-EifVzf_2.js} +6 -7
  88. package/dist/_chunks/relations-EifVzf_2.js.map +1 -0
  89. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  90. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  91. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  92. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  93. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
  94. package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
  95. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
  96. package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
  97. package/dist/admin/index.js +2 -1
  98. package/dist/admin/index.js.map +1 -1
  99. package/dist/admin/index.mjs +5 -4
  100. package/dist/admin/src/exports.d.ts +1 -1
  101. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  102. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  103. package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
  104. package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
  105. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  106. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  107. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
  108. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  109. package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
  110. package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
  111. package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
  112. package/dist/admin/src/preview/constants.d.ts +1 -0
  113. package/dist/admin/src/preview/index.d.ts +4 -0
  114. package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
  115. package/dist/admin/src/preview/routes.d.ts +3 -0
  116. package/dist/admin/src/preview/services/preview.d.ts +3 -0
  117. package/dist/admin/src/router.d.ts +1 -1
  118. package/dist/admin/src/services/api.d.ts +1 -1
  119. package/dist/admin/src/services/components.d.ts +2 -2
  120. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  121. package/dist/admin/src/services/documents.d.ts +19 -20
  122. package/dist/admin/src/services/init.d.ts +1 -1
  123. package/dist/admin/src/services/relations.d.ts +2 -2
  124. package/dist/admin/src/services/uid.d.ts +3 -3
  125. package/dist/admin/src/utils/validation.d.ts +4 -1
  126. package/dist/server/index.js +486 -219
  127. package/dist/server/index.js.map +1 -1
  128. package/dist/server/index.mjs +486 -218
  129. package/dist/server/index.mjs.map +1 -1
  130. package/dist/server/src/bootstrap.d.ts.map +1 -1
  131. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  132. package/dist/server/src/controllers/index.d.ts.map +1 -1
  133. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  134. package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
  135. package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
  136. package/dist/server/src/history/services/history.d.ts.map +1 -1
  137. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  138. package/dist/server/src/history/services/utils.d.ts +3 -3
  139. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  140. package/dist/server/src/index.d.ts +4 -4
  141. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  142. package/dist/server/src/preview/constants.d.ts +2 -0
  143. package/dist/server/src/preview/constants.d.ts.map +1 -0
  144. package/dist/server/src/preview/controllers/index.d.ts +2 -0
  145. package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
  146. package/dist/server/src/preview/controllers/preview.d.ts +13 -0
  147. package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
  148. package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
  149. package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
  150. package/dist/server/src/preview/index.d.ts +4 -0
  151. package/dist/server/src/preview/index.d.ts.map +1 -0
  152. package/dist/server/src/preview/routes/index.d.ts +8 -0
  153. package/dist/server/src/preview/routes/index.d.ts.map +1 -0
  154. package/dist/server/src/preview/routes/preview.d.ts +4 -0
  155. package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
  156. package/dist/server/src/preview/services/index.d.ts +16 -0
  157. package/dist/server/src/preview/services/index.d.ts.map +1 -0
  158. package/dist/server/src/preview/services/preview-config.d.ts +32 -0
  159. package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
  160. package/dist/server/src/preview/services/preview.d.ts +12 -0
  161. package/dist/server/src/preview/services/preview.d.ts.map +1 -0
  162. package/dist/server/src/preview/utils.d.ts +19 -0
  163. package/dist/server/src/preview/utils.d.ts.map +1 -0
  164. package/dist/server/src/register.d.ts.map +1 -1
  165. package/dist/server/src/routes/index.d.ts.map +1 -1
  166. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  167. package/dist/server/src/services/document-metadata.d.ts +8 -8
  168. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  169. package/dist/server/src/services/index.d.ts +4 -4
  170. package/dist/server/src/services/index.d.ts.map +1 -1
  171. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  172. package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
  173. package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
  174. package/dist/server/src/utils/index.d.ts +2 -0
  175. package/dist/server/src/utils/index.d.ts.map +1 -1
  176. package/dist/shared/contracts/collection-types.d.ts +3 -1
  177. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  178. package/dist/shared/contracts/index.d.ts +1 -0
  179. package/dist/shared/contracts/index.d.ts.map +1 -1
  180. package/dist/shared/contracts/preview.d.ts +27 -0
  181. package/dist/shared/contracts/preview.d.ts.map +1 -0
  182. package/dist/shared/index.js +4 -0
  183. package/dist/shared/index.js.map +1 -1
  184. package/dist/shared/index.mjs +4 -0
  185. package/dist/shared/index.mjs.map +1 -1
  186. package/package.json +15 -15
  187. package/dist/_chunks/EditViewPage-BSVmMpRd.js.map +0 -1
  188. package/dist/_chunks/EditViewPage-C3tIZ8F5.mjs.map +0 -1
  189. package/dist/_chunks/Field-BvuT8cGL.mjs.map +0 -1
  190. package/dist/_chunks/Field-DUCVth4C.js.map +0 -1
  191. package/dist/_chunks/Form-BZmDNVr9.mjs.map +0 -1
  192. package/dist/_chunks/Form-Cpl4W1ak.js.map +0 -1
  193. package/dist/_chunks/History-Cq_Hrzuu.mjs.map +0 -1
  194. package/dist/_chunks/History-D4U2YISB.js.map +0 -1
  195. package/dist/_chunks/ListConfigurationPage-Bny6CdWe.js.map +0 -1
  196. package/dist/_chunks/ListConfigurationPage-W-KQHmBv.mjs.map +0 -1
  197. package/dist/_chunks/ListViewPage-HBBnJa8K.mjs.map +0 -1
  198. package/dist/_chunks/ListViewPage-O8F1pBJo.js.map +0 -1
  199. package/dist/_chunks/Relations-C4gGfZRv.js.map +0 -1
  200. package/dist/_chunks/Relations-vFZ6Wasg.mjs.map +0 -1
  201. package/dist/_chunks/index-5EMXLEM_.js.map +0 -1
  202. package/dist/_chunks/index-Dpxg3ctD.mjs.map +0 -1
  203. package/dist/_chunks/layout-C0INpKap.mjs.map +0 -1
  204. package/dist/_chunks/layout-P3eKO1Qy.js.map +0 -1
  205. package/dist/_chunks/relations-B1y0K6LE.js.map +0 -1
  206. package/dist/_chunks/relations-FBRRBWeO.mjs.map +0 -1
  207. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  208. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  209. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  210. 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, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
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,6 +200,17 @@ 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 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
+ };
203
214
  const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
215
  const model = strapi2.getModel(uid2);
205
216
  const attributes = Object.entries(model.attributes);
@@ -223,13 +234,19 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
223
234
  }
224
235
  case "component": {
225
236
  const populate = getDeepPopulate2(attribute.component);
226
- acc[attributeName] = { populate };
237
+ acc[attributeName] = {
238
+ populate,
239
+ [fieldSelector]: getComponentFields(attribute.component)
240
+ };
227
241
  break;
228
242
  }
229
243
  case "dynamiczone": {
230
244
  const populatedComponents = (attribute.components || []).reduce(
231
245
  (acc2, componentUID) => {
232
- acc2[componentUID] = { populate: getDeepPopulate2(componentUID) };
246
+ acc2[componentUID] = {
247
+ populate: getDeepPopulate2(componentUID),
248
+ [fieldSelector]: getComponentFields(componentUID)
249
+ };
233
250
  return acc2;
234
251
  },
235
252
  {}
@@ -291,6 +308,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
291
308
  getRelationRestoreValue,
292
309
  getMediaRestoreValue,
293
310
  getDefaultLocale,
311
+ isLocalizedContentType,
294
312
  getLocaleDictionary,
295
313
  getRetentionDays,
296
314
  getVersionStatus,
@@ -313,7 +331,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
313
331
  });
314
332
  },
315
333
  async findVersionsPage(params) {
316
- 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
+ }
317
341
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
318
342
  query.findPage({
319
343
  ...params.query,
@@ -335,7 +359,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
335
359
  const attributeValue = entry.data[attributeKey];
336
360
  const attributeValues = Array.isArray(attributeValue) ? attributeValue : [attributeValue];
337
361
  if (attributeSchema.type === "media") {
338
- const permissionChecker2 = getService$1("permission-checker").create({
362
+ const permissionChecker2 = getService$2("permission-checker").create({
339
363
  userAbility: params.state.userAbility,
340
364
  model: "plugin::upload.file"
341
365
  });
@@ -358,7 +382,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
358
382
  if (userToPopulate == null) {
359
383
  return null;
360
384
  }
361
- 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
+ });
362
391
  })
363
392
  );
364
393
  return {
@@ -371,7 +400,7 @@ const createHistoryService = ({ strapi: strapi2 }) => {
371
400
  [attributeKey]: adminUsers
372
401
  };
373
402
  }
374
- const permissionChecker2 = getService$1("permission-checker").create({
403
+ const permissionChecker2 = getService$2("permission-checker").create({
375
404
  userAbility: params.state.userAbility,
376
405
  model: attributeSchema.target
377
406
  });
@@ -529,11 +558,13 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
529
558
  }
530
559
  const uid2 = context.contentType.uid;
531
560
  const schemas = getSchemas(uid2);
561
+ const model = strapi2.getModel(uid2);
562
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
532
563
  const localeEntries = await strapi2.db.query(uid2).findMany({
533
564
  where: {
534
565
  documentId,
535
- locale: { $in: locales },
536
- publishedAt: null
566
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
567
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
537
568
  },
538
569
  populate: serviceUtils.getDeepPopulate(
539
570
  uid2,
@@ -545,7 +576,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
545
576
  onCommit(async () => {
546
577
  for (const entry of localeEntries) {
547
578
  const status = await serviceUtils.getVersionStatus(uid2, entry);
548
- await getService(strapi2, "history").createVersion({
579
+ await getService$1(strapi2, "history").createVersion({
549
580
  contentType: uid2,
550
581
  data: omit(FIELDS_TO_IGNORE, entry),
551
582
  relatedDocumentId: documentId,
@@ -558,15 +589,19 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
558
589
  });
559
590
  return result;
560
591
  });
561
- state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
592
+ state.deleteExpiredJob = scheduleJob("historyDaily", "0 0 * * *", () => {
562
593
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
563
594
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
564
595
  strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
565
596
  where: {
566
597
  created_at: {
567
- $lt: expirationDate.toISOString()
598
+ $lt: expirationDate
568
599
  }
569
600
  }
601
+ }).catch((error) => {
602
+ if (error instanceof Error) {
603
+ strapi2.log.error("Error deleting expired history versions", error.message);
604
+ }
570
605
  });
571
606
  });
572
607
  state.isInitialized = true;
@@ -578,17 +613,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
578
613
  }
579
614
  };
580
615
  };
581
- const services$1 = {
616
+ const services$2 = {
582
617
  history: createHistoryService,
583
618
  lifecycles: createLifecyclesService
584
619
  };
585
- const info = { pluginName: "content-manager", type: "admin" };
620
+ const info$1 = { pluginName: "content-manager", type: "admin" };
586
621
  const historyVersionRouter = {
587
622
  type: "admin",
588
623
  routes: [
589
624
  {
590
625
  method: "GET",
591
- info,
626
+ info: info$1,
592
627
  path: "/history-versions",
593
628
  handler: "history-version.findMany",
594
629
  config: {
@@ -597,7 +632,7 @@ const historyVersionRouter = {
597
632
  },
598
633
  {
599
634
  method: "PUT",
600
- info,
635
+ info: info$1,
601
636
  path: "/history-versions/:versionId/restore",
602
637
  handler: "history-version.restoreVersion",
603
638
  config: {
@@ -606,7 +641,7 @@ const historyVersionRouter = {
606
641
  }
607
642
  ]
608
643
  };
609
- const routes$1 = {
644
+ const routes$2 = {
610
645
  "history-version": historyVersionRouter
611
646
  };
612
647
  const historyVersion = {
@@ -653,21 +688,21 @@ const historyVersion = {
653
688
  }
654
689
  }
655
690
  };
656
- const getFeature = () => {
691
+ const getFeature$1 = () => {
657
692
  if (strapi.ee.features.isEnabled("cms-content-history")) {
658
693
  return {
659
694
  register({ strapi: strapi2 }) {
660
695
  strapi2.get("models").add(historyVersion);
661
696
  },
662
697
  bootstrap({ strapi: strapi2 }) {
663
- getService(strapi2, "lifecycles").bootstrap();
698
+ getService$1(strapi2, "lifecycles").bootstrap();
664
699
  },
665
700
  destroy({ strapi: strapi2 }) {
666
- getService(strapi2, "lifecycles").destroy();
701
+ getService$1(strapi2, "lifecycles").destroy();
667
702
  },
668
- controllers: controllers$1,
669
- services: services$1,
670
- routes: routes$1
703
+ controllers: controllers$2,
704
+ services: services$2,
705
+ routes: routes$2
671
706
  };
672
707
  }
673
708
  return {
@@ -676,9 +711,205 @@ const getFeature = () => {
676
711
  }
677
712
  };
678
713
  };
679
- 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();
680
910
  const register = async ({ strapi: strapi2 }) => {
681
911
  await history.register?.({ strapi: strapi2 });
912
+ await preview.register?.({ strapi: strapi2 });
682
913
  };
683
914
  const ALLOWED_WEBHOOK_EVENTS = {
684
915
  ENTRY_PUBLISH: "entry.publish",
@@ -688,11 +919,12 @@ const bootstrap = async () => {
688
919
  Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
689
920
  strapi.get("webhookStore").addAllowedEvent(key, value);
690
921
  });
691
- getService$1("field-sizes").setCustomFieldInputSizes();
692
- await getService$1("components").syncConfigurations();
693
- await getService$1("content-types").syncConfigurations();
694
- 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();
695
926
  await history.bootstrap?.({ strapi });
927
+ await preview.bootstrap?.({ strapi });
696
928
  };
697
929
  const destroy = async ({ strapi: strapi2 }) => {
698
930
  await history.destroy?.({ strapi: strapi2 });
@@ -1182,7 +1414,8 @@ const admin = {
1182
1414
  };
1183
1415
  const routes = {
1184
1416
  admin,
1185
- ...history.routes ? history.routes : {}
1417
+ ...history.routes ? history.routes : {},
1418
+ ...preview.routes ? preview.routes : {}
1186
1419
  };
1187
1420
  const hasPermissionsSchema = yup$1.object({
1188
1421
  actions: yup$1.array().of(yup$1.string()),
@@ -1193,6 +1426,11 @@ const { createPolicy } = policy;
1193
1426
  const hasPermissions = createPolicy({
1194
1427
  name: "plugin::content-manager.hasPermissions",
1195
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
+ */
1196
1434
  handler(ctx, config = {}) {
1197
1435
  const { actions = [], hasAtLeastOne = false } = config;
1198
1436
  const { userAbility } = ctx.state;
@@ -1240,8 +1478,7 @@ const isSortable = (schema, name) => {
1240
1478
  if (!_.has(schema.attributes, name)) {
1241
1479
  return false;
1242
1480
  }
1243
- if (schema.modelType === "component" && name === "id")
1244
- return false;
1481
+ if (schema.modelType === "component" && name === "id") return false;
1245
1482
  const attribute = schema.attributes[name];
1246
1483
  if (NON_SORTABLES.includes(attribute.type)) {
1247
1484
  return false;
@@ -1386,8 +1623,7 @@ const createDefaultSettings = async (schema) => {
1386
1623
  };
1387
1624
  };
1388
1625
  const syncSettings = async (configuration, schema) => {
1389
- if (isEmpty(configuration.settings))
1390
- return createDefaultSettings(schema);
1626
+ if (isEmpty(configuration.settings)) return createDefaultSettings(schema);
1391
1627
  const defaultField = getDefaultMainField(schema);
1392
1628
  const { mainField = defaultField, defaultSortBy = defaultField } = configuration.settings || {};
1393
1629
  return {
@@ -1434,7 +1670,7 @@ const createMetadasSchema = (schema) => {
1434
1670
  if (!value) {
1435
1671
  return yup$1.string();
1436
1672
  }
1437
- const targetSchema = getService$1("content-types").findContentType(
1673
+ const targetSchema = getService$2("content-types").findContentType(
1438
1674
  schema.attributes[key].targetModel
1439
1675
  );
1440
1676
  if (!targetSchema) {
@@ -1563,8 +1799,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1563
1799
  }
1564
1800
  switch (attribute.type) {
1565
1801
  case "relation": {
1566
- if (canCreate(attributePath))
1567
- return body2;
1802
+ if (canCreate(attributePath)) return body2;
1568
1803
  return set(attributePath, { set: [] }, body2);
1569
1804
  }
1570
1805
  case "component": {
@@ -1574,8 +1809,7 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
1574
1809
  ]);
1575
1810
  }
1576
1811
  default: {
1577
- if (canCreate(attributePath))
1578
- return body2;
1812
+ if (canCreate(attributePath)) return body2;
1579
1813
  return set(attributePath, null, body2);
1580
1814
  }
1581
1815
  }
@@ -1603,7 +1837,7 @@ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultiple
1603
1837
  }
1604
1838
  };
1605
1839
  const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
1606
- const documentMetadata2 = getService$1("document-metadata");
1840
+ const documentMetadata2 = getService$2("document-metadata");
1607
1841
  const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
1608
1842
  let {
1609
1843
  meta: { availableLocales, availableStatus }
@@ -1629,8 +1863,8 @@ const createDocument = async (ctx, opts) => {
1629
1863
  const { userAbility, user } = ctx.state;
1630
1864
  const { model } = ctx.params;
1631
1865
  const { body } = ctx.request;
1632
- const documentManager2 = getService$1("document-manager");
1633
- 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 });
1634
1868
  if (permissionChecker2.cannot.create()) {
1635
1869
  throw new errors.ForbiddenError();
1636
1870
  }
@@ -1650,13 +1884,13 @@ const updateDocument = async (ctx, opts) => {
1650
1884
  const { userAbility, user } = ctx.state;
1651
1885
  const { id, model } = ctx.params;
1652
1886
  const { body } = ctx.request;
1653
- const documentManager2 = getService$1("document-manager");
1654
- 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 });
1655
1889
  if (permissionChecker2.cannot.update()) {
1656
1890
  throw new errors.ForbiddenError();
1657
1891
  }
1658
1892
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1659
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1893
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1660
1894
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1661
1895
  const [documentVersion, documentExists] = await Promise.all([
1662
1896
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
@@ -1673,7 +1907,7 @@ const updateDocument = async (ctx, opts) => {
1673
1907
  throw new errors.ForbiddenError();
1674
1908
  }
1675
1909
  const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
1676
- const setCreator = setCreatorFields({ user, isEdition: true });
1910
+ const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
1677
1911
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1678
1912
  const sanitizedBody = await sanitizeFn(body);
1679
1913
  return documentManager2.update(documentVersion?.documentId || id, model, {
@@ -1687,14 +1921,14 @@ const collectionTypes = {
1687
1921
  const { userAbility } = ctx.state;
1688
1922
  const { model } = ctx.params;
1689
1923
  const { query } = ctx.request;
1690
- const documentMetadata2 = getService$1("document-metadata");
1691
- const documentManager2 = getService$1("document-manager");
1692
- 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 });
1693
1927
  if (permissionChecker2.cannot.read()) {
1694
1928
  return ctx.forbidden();
1695
1929
  }
1696
1930
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1697
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1931
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1698
1932
  const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1699
1933
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1700
1934
  { ...permissionQuery, populate, locale, status },
@@ -1723,13 +1957,13 @@ const collectionTypes = {
1723
1957
  async findOne(ctx) {
1724
1958
  const { userAbility } = ctx.state;
1725
1959
  const { model, id } = ctx.params;
1726
- const documentManager2 = getService$1("document-manager");
1727
- 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 });
1728
1962
  if (permissionChecker2.cannot.read()) {
1729
1963
  return ctx.forbidden();
1730
1964
  }
1731
1965
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1732
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1966
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1733
1967
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1734
1968
  const version = await documentManager2.findOne(id, model, {
1735
1969
  populate,
@@ -1745,7 +1979,7 @@ const collectionTypes = {
1745
1979
  permissionChecker2,
1746
1980
  model,
1747
1981
  // @ts-expect-error TODO: fix
1748
- { id, locale, publishedAt: null },
1982
+ { documentId: id, locale, publishedAt: null },
1749
1983
  { availableLocales: true, availableStatus: false }
1750
1984
  );
1751
1985
  ctx.body = { data: {}, meta };
@@ -1760,7 +1994,7 @@ const collectionTypes = {
1760
1994
  async create(ctx) {
1761
1995
  const { userAbility } = ctx.state;
1762
1996
  const { model } = ctx.params;
1763
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
1997
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1764
1998
  const [totalEntries, document] = await Promise.all([
1765
1999
  strapi.db.query(model).count(),
1766
2000
  createDocument(ctx)
@@ -1781,7 +2015,7 @@ const collectionTypes = {
1781
2015
  async update(ctx) {
1782
2016
  const { userAbility } = ctx.state;
1783
2017
  const { model } = ctx.params;
1784
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2018
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
1785
2019
  const updatedVersion = await updateDocument(ctx);
1786
2020
  const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
1787
2021
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
@@ -1790,13 +2024,13 @@ const collectionTypes = {
1790
2024
  const { userAbility, user } = ctx.state;
1791
2025
  const { model, sourceId: id } = ctx.params;
1792
2026
  const { body } = ctx.request;
1793
- const documentManager2 = getService$1("document-manager");
1794
- 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 });
1795
2029
  if (permissionChecker2.cannot.create()) {
1796
2030
  return ctx.forbidden();
1797
2031
  }
1798
2032
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1799
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2033
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1800
2034
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1801
2035
  const document = await documentManager2.findOne(id, model, {
1802
2036
  populate,
@@ -1835,13 +2069,13 @@ const collectionTypes = {
1835
2069
  async delete(ctx) {
1836
2070
  const { userAbility } = ctx.state;
1837
2071
  const { id, model } = ctx.params;
1838
- const documentManager2 = getService$1("document-manager");
1839
- 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 });
1840
2074
  if (permissionChecker2.cannot.delete()) {
1841
2075
  return ctx.forbidden();
1842
2076
  }
1843
2077
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1844
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2078
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1845
2079
  const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1846
2080
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1847
2081
  if (documentLocales.length === 0) {
@@ -1863,14 +2097,14 @@ const collectionTypes = {
1863
2097
  const { userAbility } = ctx.state;
1864
2098
  const { id, model } = ctx.params;
1865
2099
  const { body } = ctx.request;
1866
- const documentManager2 = getService$1("document-manager");
1867
- 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 });
1868
2102
  if (permissionChecker2.cannot.publish()) {
1869
2103
  return ctx.forbidden();
1870
2104
  }
1871
2105
  const publishedDocument = await strapi.db.transaction(async () => {
1872
2106
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1873
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2107
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1874
2108
  let document;
1875
2109
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1876
2110
  const isCreate = isNil$1(id);
@@ -1882,11 +2116,17 @@ const collectionTypes = {
1882
2116
  }
1883
2117
  const isUpdate = !isCreate;
1884
2118
  if (isUpdate) {
1885
- document = await documentManager2.findOne(id, model, { populate, locale });
1886
- if (!document) {
2119
+ const documentExists = documentManager2.exists(model, id);
2120
+ if (!documentExists) {
1887
2121
  throw new errors.NotFoundError("Document not found");
1888
2122
  }
1889
- if (permissionChecker2.can.update(document)) {
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)) {
1890
2130
  await updateDocument(ctx);
1891
2131
  }
1892
2132
  }
@@ -1912,13 +2152,13 @@ const collectionTypes = {
1912
2152
  const { body } = ctx.request;
1913
2153
  const { documentIds } = body;
1914
2154
  await validateBulkActionInput(body);
1915
- const documentManager2 = getService$1("document-manager");
1916
- 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 });
1917
2157
  if (permissionChecker2.cannot.publish()) {
1918
2158
  return ctx.forbidden();
1919
2159
  }
1920
2160
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1921
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
2161
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1922
2162
  const { locale } = await getDocumentLocaleAndStatus(body, model, {
1923
2163
  allowMultipleLocales: true
1924
2164
  });
@@ -1943,12 +2183,14 @@ const collectionTypes = {
1943
2183
  const { body } = ctx.request;
1944
2184
  const { documentIds } = body;
1945
2185
  await validateBulkActionInput(body);
1946
- const documentManager2 = getService$1("document-manager");
1947
- 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 });
1948
2188
  if (permissionChecker2.cannot.unpublish()) {
1949
2189
  return ctx.forbidden();
1950
2190
  }
1951
- const { locale } = await getDocumentLocaleAndStatus(body, model);
2191
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
2192
+ allowMultipleLocales: true
2193
+ });
1952
2194
  const entityPromises = documentIds.map(
1953
2195
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1954
2196
  );
@@ -1971,8 +2213,8 @@ const collectionTypes = {
1971
2213
  const {
1972
2214
  body: { discardDraft, ...body }
1973
2215
  } = ctx.request;
1974
- const documentManager2 = getService$1("document-manager");
1975
- 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 });
1976
2218
  if (permissionChecker2.cannot.unpublish()) {
1977
2219
  return ctx.forbidden();
1978
2220
  }
@@ -1980,7 +2222,7 @@ const collectionTypes = {
1980
2222
  return ctx.forbidden();
1981
2223
  }
1982
2224
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1983
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2225
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
1984
2226
  const { locale } = await getDocumentLocaleAndStatus(body, model);
1985
2227
  const document = await documentManager2.findOne(id, model, {
1986
2228
  populate,
@@ -2011,13 +2253,13 @@ const collectionTypes = {
2011
2253
  const { userAbility } = ctx.state;
2012
2254
  const { id, model } = ctx.params;
2013
2255
  const { body } = ctx.request;
2014
- const documentManager2 = getService$1("document-manager");
2015
- 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 });
2016
2258
  if (permissionChecker2.cannot.discard()) {
2017
2259
  return ctx.forbidden();
2018
2260
  }
2019
2261
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
2020
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2262
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2021
2263
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2022
2264
  const document = await documentManager2.findOne(id, model, {
2023
2265
  populate,
@@ -2042,13 +2284,13 @@ const collectionTypes = {
2042
2284
  const { query, body } = ctx.request;
2043
2285
  const { documentIds } = body;
2044
2286
  await validateBulkActionInput(body);
2045
- const documentManager2 = getService$1("document-manager");
2046
- 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 });
2047
2289
  if (permissionChecker2.cannot.delete()) {
2048
2290
  return ctx.forbidden();
2049
2291
  }
2050
2292
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2051
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2293
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2052
2294
  const { locale } = await getDocumentLocaleAndStatus(body, model);
2053
2295
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2054
2296
  populate,
@@ -2069,13 +2311,13 @@ const collectionTypes = {
2069
2311
  async countDraftRelations(ctx) {
2070
2312
  const { userAbility } = ctx.state;
2071
2313
  const { model, id } = ctx.params;
2072
- const documentManager2 = getService$1("document-manager");
2073
- 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 });
2074
2316
  if (permissionChecker2.cannot.read()) {
2075
2317
  return ctx.forbidden();
2076
2318
  }
2077
2319
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2078
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2320
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2079
2321
  const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2080
2322
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2081
2323
  if (!entity) {
@@ -2094,8 +2336,8 @@ const collectionTypes = {
2094
2336
  const ids = ctx.request.query.documentIds;
2095
2337
  const locale = ctx.request.query.locale;
2096
2338
  const { model } = ctx.params;
2097
- const documentManager2 = getService$1("document-manager");
2098
- 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 });
2099
2341
  if (permissionChecker2.cannot.read()) {
2100
2342
  return ctx.forbidden();
2101
2343
  }
@@ -2119,13 +2361,13 @@ const collectionTypes = {
2119
2361
  };
2120
2362
  const components$1 = {
2121
2363
  findComponents(ctx) {
2122
- const components2 = getService$1("components").findAllComponents();
2123
- const { toDto } = getService$1("data-mapper");
2364
+ const components2 = getService$2("components").findAllComponents();
2365
+ const { toDto } = getService$2("data-mapper");
2124
2366
  ctx.body = { data: components2.map(toDto) };
2125
2367
  },
2126
2368
  async findComponentConfiguration(ctx) {
2127
2369
  const { uid: uid2 } = ctx.params;
2128
- const componentService = getService$1("components");
2370
+ const componentService = getService$2("components");
2129
2371
  const component = componentService.findComponent(uid2);
2130
2372
  if (!component) {
2131
2373
  return ctx.notFound("component.notFound");
@@ -2142,7 +2384,7 @@ const components$1 = {
2142
2384
  async updateComponentConfiguration(ctx) {
2143
2385
  const { uid: uid2 } = ctx.params;
2144
2386
  const { body } = ctx.request;
2145
- const componentService = getService$1("components");
2387
+ const componentService = getService$2("components");
2146
2388
  const component = componentService.findComponent(uid2);
2147
2389
  if (!component) {
2148
2390
  return ctx.notFound("component.notFound");
@@ -2176,12 +2418,12 @@ const contentTypes = {
2176
2418
  } catch (error) {
2177
2419
  return ctx.send({ error }, 400);
2178
2420
  }
2179
- const contentTypes2 = getService$1("content-types").findContentTypesByKind(kind);
2180
- const { toDto } = getService$1("data-mapper");
2421
+ const contentTypes2 = getService$2("content-types").findContentTypesByKind(kind);
2422
+ const { toDto } = getService$2("data-mapper");
2181
2423
  ctx.body = { data: contentTypes2.map(toDto) };
2182
2424
  },
2183
2425
  async findContentTypesSettings(ctx) {
2184
- const { findAllContentTypes, findConfiguration } = getService$1("content-types");
2426
+ const { findAllContentTypes, findConfiguration } = getService$2("content-types");
2185
2427
  const contentTypes2 = await findAllContentTypes();
2186
2428
  const configurations = await Promise.all(
2187
2429
  contentTypes2.map(async (contentType) => {
@@ -2195,7 +2437,7 @@ const contentTypes = {
2195
2437
  },
2196
2438
  async findContentTypeConfiguration(ctx) {
2197
2439
  const { uid: uid2 } = ctx.params;
2198
- const contentTypeService = getService$1("content-types");
2440
+ const contentTypeService = getService$2("content-types");
2199
2441
  const contentType = await contentTypeService.findContentType(uid2);
2200
2442
  if (!contentType) {
2201
2443
  return ctx.notFound("contentType.notFound");
@@ -2217,13 +2459,13 @@ const contentTypes = {
2217
2459
  const { userAbility } = ctx.state;
2218
2460
  const { uid: uid2 } = ctx.params;
2219
2461
  const { body } = ctx.request;
2220
- const contentTypeService = getService$1("content-types");
2221
- const metricsService = getService$1("metrics");
2462
+ const contentTypeService = getService$2("content-types");
2463
+ const metricsService = getService$2("metrics");
2222
2464
  const contentType = await contentTypeService.findContentType(uid2);
2223
2465
  if (!contentType) {
2224
2466
  return ctx.notFound("contentType.notFound");
2225
2467
  }
2226
- if (!getService$1("permission").canConfigureContentType({ userAbility, contentType })) {
2468
+ if (!getService$2("permission").canConfigureContentType({ userAbility, contentType })) {
2227
2469
  return ctx.forbidden();
2228
2470
  }
2229
2471
  let input;
@@ -2256,10 +2498,10 @@ const contentTypes = {
2256
2498
  };
2257
2499
  const init = {
2258
2500
  getInitData(ctx) {
2259
- const { toDto } = getService$1("data-mapper");
2260
- const { findAllComponents } = getService$1("components");
2261
- const { getAllFieldSizes } = getService$1("field-sizes");
2262
- 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");
2263
2505
  ctx.body = {
2264
2506
  data: {
2265
2507
  fieldSizes: getAllFieldSizes(),
@@ -2295,36 +2537,41 @@ const addFiltersClause = (params, filtersClause) => {
2295
2537
  params.filters.$and.push(filtersClause);
2296
2538
  };
2297
2539
  const sanitizeMainField = (model, mainField, userAbility) => {
2298
- const permissionChecker2 = getService$1("permission-checker").create({
2540
+ const permissionChecker2 = getService$2("permission-checker").create({
2299
2541
  userAbility,
2300
2542
  model: model.uid
2301
2543
  });
2302
- if (!isListable(model, mainField)) {
2544
+ const isMainFieldListable = isListable(model, mainField);
2545
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2546
+ if (!isMainFieldListable || !canReadMainField) {
2303
2547
  return "id";
2304
2548
  }
2305
- if (permissionChecker2.cannot.read(null, mainField)) {
2306
- if (model.uid === "plugin::users-permissions.role") {
2307
- const userPermissionChecker = getService$1("permission-checker").create({
2308
- userAbility,
2309
- model: "plugin::users-permissions.user"
2310
- });
2311
- if (userPermissionChecker.can.read()) {
2312
- return "name";
2313
- }
2314
- }
2315
- return "id";
2549
+ if (model.uid === "plugin::users-permissions.role") {
2550
+ return "name";
2316
2551
  }
2317
2552
  return mainField;
2318
2553
  };
2319
- const addStatusToRelations = async (uid2, relations2) => {
2320
- if (!contentTypes$1.hasDraftAndPublish(strapi.contentTypes[uid2])) {
2554
+ const addStatusToRelations = async (targetUid, relations2) => {
2555
+ if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
2321
2556
  return relations2;
2322
2557
  }
2323
- const documentMetadata2 = getService$1("document-metadata");
2324
- 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
+ });
2325
2572
  return relations2.map((relation) => {
2326
- const availableStatuses = documentsAvailableStatus.filter(
2327
- (availableDocument) => availableDocument.documentId === relation.documentId
2573
+ const availableStatuses = availableStatus.filter(
2574
+ (availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
2328
2575
  );
2329
2576
  return {
2330
2577
  ...relation,
@@ -2345,11 +2592,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
2345
2592
  const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
2346
2593
  const isSourceLocalized = isLocalized(sourceModel);
2347
2594
  const isTargetLocalized = isLocalized(targetModel);
2348
- let validatedLocale = locale;
2349
- if (!targetModel || !isTargetLocalized)
2350
- validatedLocale = void 0;
2351
2595
  return {
2352
- locale: validatedLocale,
2596
+ locale,
2353
2597
  isSourceLocalized,
2354
2598
  isTargetLocalized
2355
2599
  };
@@ -2358,8 +2602,7 @@ const validateStatus = (sourceUid, status) => {
2358
2602
  const sourceModel = strapi.getModel(sourceUid);
2359
2603
  const isDP = contentTypes$1.hasDraftAndPublish;
2360
2604
  const isSourceDP = isDP(sourceModel);
2361
- if (!isSourceDP)
2362
- return { status: void 0 };
2605
+ if (!isSourceDP) return { status: void 0 };
2363
2606
  switch (status) {
2364
2607
  case "published":
2365
2608
  return { status: "published" };
@@ -2389,7 +2632,7 @@ const relations = {
2389
2632
  ctx.request?.query?.locale
2390
2633
  );
2391
2634
  const { status } = validateStatus(sourceUid, ctx.request?.query?.status);
2392
- const permissionChecker2 = getService$1("permission-checker").create({
2635
+ const permissionChecker2 = getService$2("permission-checker").create({
2393
2636
  userAbility,
2394
2637
  model
2395
2638
  });
@@ -2414,7 +2657,7 @@ const relations = {
2414
2657
  where.id = id;
2415
2658
  }
2416
2659
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2417
- const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2660
+ const populate = await getService$2("populate-builder")(model).populateFromQuery(permissionQuery).build();
2418
2661
  const currentEntity = await strapi.db.query(model).findOne({
2419
2662
  where,
2420
2663
  populate
@@ -2429,7 +2672,7 @@ const relations = {
2429
2672
  }
2430
2673
  entryId = currentEntity.id;
2431
2674
  }
2432
- 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);
2433
2676
  const targetSchema = strapi.getModel(targetUid);
2434
2677
  const mainField = flow(
2435
2678
  prop(`metadatas.${targetField}.edit.mainField`),
@@ -2452,7 +2695,7 @@ const relations = {
2452
2695
  attribute,
2453
2696
  fieldsToSelect,
2454
2697
  mainField,
2455
- source: { schema: sourceSchema },
2698
+ source: { schema: sourceSchema, isLocalized: isSourceLocalized },
2456
2699
  target: { schema: targetSchema, isLocalized: isTargetLocalized },
2457
2700
  sourceSchema,
2458
2701
  targetSchema,
@@ -2474,7 +2717,8 @@ const relations = {
2474
2717
  fieldsToSelect,
2475
2718
  mainField,
2476
2719
  source: {
2477
- schema: { uid: sourceUid, modelType: sourceModelType }
2720
+ schema: { uid: sourceUid, modelType: sourceModelType },
2721
+ isLocalized: isSourceLocalized
2478
2722
  },
2479
2723
  target: {
2480
2724
  schema: { uid: targetUid },
@@ -2482,7 +2726,7 @@ const relations = {
2482
2726
  }
2483
2727
  } = await this.extractAndValidateRequestInfo(ctx, id);
2484
2728
  const { idsToOmit, idsToInclude, _q, ...query } = ctx.request.query;
2485
- const permissionChecker2 = getService$1("permission-checker").create({
2729
+ const permissionChecker2 = getService$2("permission-checker").create({
2486
2730
  userAbility: ctx.state.userAbility,
2487
2731
  model: targetUid
2488
2732
  });
@@ -2512,12 +2756,16 @@ const relations = {
2512
2756
  } else {
2513
2757
  where.id = id;
2514
2758
  }
2515
- if (status) {
2516
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2759
+ const publishedAt = getPublishedAtClause(status, targetUid);
2760
+ if (!isEmpty(publishedAt)) {
2761
+ where[`${alias}.published_at`] = publishedAt;
2517
2762
  }
2518
- if (filterByLocale) {
2763
+ if (isTargetLocalized && locale) {
2519
2764
  where[`${alias}.locale`] = locale;
2520
2765
  }
2766
+ if (isSourceLocalized && locale) {
2767
+ where.locale = locale;
2768
+ }
2521
2769
  if ((idsToInclude?.length ?? 0) !== 0) {
2522
2770
  where[`${alias}.id`].$notIn = idsToInclude;
2523
2771
  }
@@ -2535,7 +2783,8 @@ const relations = {
2535
2783
  id: { $notIn: uniq(idsToOmit) }
2536
2784
  });
2537
2785
  }
2538
- 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);
2539
2788
  ctx.body = {
2540
2789
  ...res,
2541
2790
  results: await addStatusToRelations(targetUid, res.results)
@@ -2550,29 +2799,39 @@ const relations = {
2550
2799
  attribute,
2551
2800
  targetField,
2552
2801
  fieldsToSelect,
2553
- source: {
2554
- schema: { uid: sourceUid }
2555
- },
2556
- target: {
2557
- schema: { uid: targetUid }
2558
- }
2802
+ status,
2803
+ source: { schema: sourceSchema },
2804
+ target: { schema: targetSchema }
2559
2805
  } = await this.extractAndValidateRequestInfo(ctx, id);
2560
- 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 });
2561
2809
  const dbQuery = strapi.db.query(sourceUid);
2562
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
+ }
2563
2823
  const res = await loadRelations({ id: entryId }, targetField, {
2564
- select: ["id", "documentId", "locale", "publishedAt"],
2824
+ select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
2565
2825
  ordering: "desc",
2566
2826
  page: ctx.request.query.page,
2567
- pageSize: ctx.request.query.pageSize
2827
+ pageSize: ctx.request.query.pageSize,
2828
+ filters
2568
2829
  });
2569
2830
  const loadedIds = res.results.map((item) => item.id);
2570
2831
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2571
2832
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2572
2833
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2573
- ordering: "desc",
2574
- page: ctx.request.query.page,
2575
- pageSize: ctx.request.query.pageSize
2834
+ ordering: "desc"
2576
2835
  });
2577
2836
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2578
2837
  ctx.body = {
@@ -2587,10 +2846,10 @@ const relations = {
2587
2846
  }
2588
2847
  };
2589
2848
  const buildPopulateFromQuery = async (query, model) => {
2590
- 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();
2591
2850
  };
2592
2851
  const findDocument = async (query, uid2, opts = {}) => {
2593
- const documentManager2 = getService$1("document-manager");
2852
+ const documentManager2 = getService$2("document-manager");
2594
2853
  const populate = await buildPopulateFromQuery(query, uid2);
2595
2854
  return documentManager2.findMany({ ...opts, populate }, uid2).then((documents) => documents[0]);
2596
2855
  };
@@ -2598,8 +2857,8 @@ const createOrUpdateDocument = async (ctx, opts) => {
2598
2857
  const { user, userAbility } = ctx.state;
2599
2858
  const { model } = ctx.params;
2600
2859
  const { body, query } = ctx.request;
2601
- const documentManager2 = getService$1("document-manager");
2602
- 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 });
2603
2862
  if (permissionChecker2.cannot.create() && permissionChecker2.cannot.update()) {
2604
2863
  throw new errors.ForbiddenError();
2605
2864
  }
@@ -2640,7 +2899,7 @@ const singleTypes = {
2640
2899
  const { userAbility } = ctx.state;
2641
2900
  const { model } = ctx.params;
2642
2901
  const { query = {} } = ctx.request;
2643
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2902
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2644
2903
  if (permissionChecker2.cannot.read()) {
2645
2904
  return ctx.forbidden();
2646
2905
  }
@@ -2659,7 +2918,7 @@ const singleTypes = {
2659
2918
  permissionChecker2,
2660
2919
  model,
2661
2920
  // @ts-expect-error - fix types
2662
- { id: document.documentId, locale, publishedAt: null },
2921
+ { documentId: document.documentId, locale, publishedAt: null },
2663
2922
  { availableLocales: true, availableStatus: false }
2664
2923
  );
2665
2924
  ctx.body = { data: {}, meta };
@@ -2674,7 +2933,7 @@ const singleTypes = {
2674
2933
  async createOrUpdate(ctx) {
2675
2934
  const { userAbility } = ctx.state;
2676
2935
  const { model } = ctx.params;
2677
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2936
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2678
2937
  const document = await createOrUpdateDocument(ctx);
2679
2938
  const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
2680
2939
  ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
@@ -2683,8 +2942,8 @@ const singleTypes = {
2683
2942
  const { userAbility } = ctx.state;
2684
2943
  const { model } = ctx.params;
2685
2944
  const { query = {} } = ctx.request;
2686
- const documentManager2 = getService$1("document-manager");
2687
- 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 });
2688
2947
  if (permissionChecker2.cannot.delete()) {
2689
2948
  return ctx.forbidden();
2690
2949
  }
@@ -2712,8 +2971,8 @@ const singleTypes = {
2712
2971
  const { userAbility } = ctx.state;
2713
2972
  const { model } = ctx.params;
2714
2973
  const { query = {} } = ctx.request;
2715
- const documentManager2 = getService$1("document-manager");
2716
- 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 });
2717
2976
  if (permissionChecker2.cannot.publish()) {
2718
2977
  return ctx.forbidden();
2719
2978
  }
@@ -2741,8 +3000,8 @@ const singleTypes = {
2741
3000
  body: { discardDraft, ...body },
2742
3001
  query = {}
2743
3002
  } = ctx.request;
2744
- const documentManager2 = getService$1("document-manager");
2745
- 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 });
2746
3005
  if (permissionChecker2.cannot.unpublish()) {
2747
3006
  return ctx.forbidden();
2748
3007
  }
@@ -2776,8 +3035,8 @@ const singleTypes = {
2776
3035
  const { userAbility } = ctx.state;
2777
3036
  const { model } = ctx.params;
2778
3037
  const { body, query = {} } = ctx.request;
2779
- const documentManager2 = getService$1("document-manager");
2780
- 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 });
2781
3040
  if (permissionChecker2.cannot.discard()) {
2782
3041
  return ctx.forbidden();
2783
3042
  }
@@ -2800,8 +3059,8 @@ const singleTypes = {
2800
3059
  const { userAbility } = ctx.state;
2801
3060
  const { model } = ctx.params;
2802
3061
  const { query } = ctx.request;
2803
- const documentManager2 = getService$1("document-manager");
2804
- const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
3062
+ const documentManager2 = getService$2("document-manager");
3063
+ const permissionChecker2 = getService$2("permission-checker").create({ userAbility, model });
2805
3064
  const { locale } = await getDocumentLocaleAndStatus(query, model);
2806
3065
  if (permissionChecker2.cannot.read()) {
2807
3066
  return ctx.forbidden();
@@ -2825,7 +3084,7 @@ const uid$1 = {
2825
3084
  const { query = {} } = ctx.request;
2826
3085
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2827
3086
  await validateUIDField(contentTypeUID, field);
2828
- const uidService = getService$1("uid");
3087
+ const uidService = getService$2("uid");
2829
3088
  ctx.body = {
2830
3089
  data: await uidService.generateUIDField({ contentTypeUID, field, data, locale })
2831
3090
  };
@@ -2837,7 +3096,7 @@ const uid$1 = {
2837
3096
  const { query = {} } = ctx.request;
2838
3097
  const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2839
3098
  await validateUIDField(contentTypeUID, field);
2840
- const uidService = getService$1("uid");
3099
+ const uidService = getService$2("uid");
2841
3100
  const isAvailable = await uidService.checkUIDAvailability({
2842
3101
  contentTypeUID,
2843
3102
  field,
@@ -2858,7 +3117,8 @@ const controllers = {
2858
3117
  relations,
2859
3118
  "single-types": singleTypes,
2860
3119
  uid: uid$1,
2861
- ...history.controllers ? history.controllers : {}
3120
+ ...history.controllers ? history.controllers : {},
3121
+ ...preview.controllers ? preview.controllers : {}
2862
3122
  };
2863
3123
  const keys = {
2864
3124
  CONFIGURATION: "configuration"
@@ -2987,18 +3247,15 @@ async function syncMetadatas(configuration, schema) {
2987
3247
  _.set(updatedMeta, ["list", "searchable"], false);
2988
3248
  _.set(acc, [key], updatedMeta);
2989
3249
  }
2990
- if (!_.has(edit, "mainField"))
2991
- return acc;
3250
+ if (!_.has(edit, "mainField")) return acc;
2992
3251
  if (!isRelation$1(attr)) {
2993
3252
  _.set(updatedMeta, "edit", _.omit(edit, ["mainField"]));
2994
3253
  _.set(acc, [key], updatedMeta);
2995
3254
  return acc;
2996
3255
  }
2997
- if (edit.mainField === "id")
2998
- return acc;
3256
+ if (edit.mainField === "id") return acc;
2999
3257
  const targetSchema = getTargetSchema(attr.targetModel);
3000
- if (!targetSchema)
3001
- return acc;
3258
+ if (!targetSchema) return acc;
3002
3259
  if (!isSortable(targetSchema, edit.mainField) && !isListable(targetSchema, edit.mainField)) {
3003
3260
  _.set(updatedMeta, ["edit", "mainField"], getDefaultMainField(targetSchema));
3004
3261
  _.set(acc, [key], updatedMeta);
@@ -3009,12 +3266,12 @@ async function syncMetadatas(configuration, schema) {
3009
3266
  return _.assign(metasWithDefaults, updatedMetas);
3010
3267
  }
3011
3268
  const getTargetSchema = (targetModel) => {
3012
- return getService$1("content-types").findContentType(targetModel);
3269
+ return getService$2("content-types").findContentType(targetModel);
3013
3270
  };
3014
3271
  const DEFAULT_LIST_LENGTH = 4;
3015
3272
  const MAX_ROW_SIZE = 12;
3016
3273
  const isAllowedFieldSize = (type, size) => {
3017
- const { getFieldSize } = getService$1("field-sizes");
3274
+ const { getFieldSize } = getService$2("field-sizes");
3018
3275
  const fieldSize = getFieldSize(type);
3019
3276
  if (!fieldSize.isResizable && size !== fieldSize.default) {
3020
3277
  return false;
@@ -3022,7 +3279,7 @@ const isAllowedFieldSize = (type, size) => {
3022
3279
  return size <= MAX_ROW_SIZE;
3023
3280
  };
3024
3281
  const getDefaultFieldSize = (attribute) => {
3025
- const { hasFieldSize, getFieldSize } = getService$1("field-sizes");
3282
+ const { hasFieldSize, getFieldSize } = getService$2("field-sizes");
3026
3283
  return getFieldSize(hasFieldSize(attribute.customField) ? attribute.customField : attribute.type).default;
3027
3284
  };
3028
3285
  async function createDefaultLayouts(schema) {
@@ -3043,8 +3300,7 @@ function createDefaultEditLayout(schema) {
3043
3300
  return appendToEditLayout([], keys2, schema);
3044
3301
  }
3045
3302
  function syncLayouts(configuration, schema) {
3046
- if (_.isEmpty(configuration.layouts))
3047
- return createDefaultLayouts(schema);
3303
+ if (_.isEmpty(configuration.layouts)) return createDefaultLayouts(schema);
3048
3304
  const { list = [], editRelations = [], edit = [] } = configuration.layouts || {};
3049
3305
  let cleanList = list.filter((attr) => isListable(schema, attr));
3050
3306
  const cleanEditRelations = editRelations.filter(
@@ -3055,9 +3311,8 @@ function syncLayouts(configuration, schema) {
3055
3311
  for (const row of edit) {
3056
3312
  const newRow = [];
3057
3313
  for (const el of row) {
3058
- if (!hasEditableAttribute(schema, el.name))
3059
- continue;
3060
- const { hasFieldSize } = getService$1("field-sizes");
3314
+ if (!hasEditableAttribute(schema, el.name)) continue;
3315
+ const { hasFieldSize } = getService$2("field-sizes");
3061
3316
  const fieldType = hasFieldSize(schema.attributes[el.name].customField) ? schema.attributes[el.name].customField : schema.attributes[el.name].type;
3062
3317
  if (!isAllowedFieldSize(fieldType, el.size)) {
3063
3318
  elementsToReAppend.push(el.name);
@@ -3087,8 +3342,7 @@ function syncLayouts(configuration, schema) {
3087
3342
  };
3088
3343
  }
3089
3344
  const appendToEditLayout = (layout = [], keysToAppend, schema) => {
3090
- if (keysToAppend.length === 0)
3091
- return layout;
3345
+ if (keysToAppend.length === 0) return layout;
3092
3346
  let currentRowIndex = Math.max(layout.length - 1, 0);
3093
3347
  if (!layout[currentRowIndex]) {
3094
3348
  layout[currentRowIndex] = [];
@@ -3197,17 +3451,17 @@ const configurationService$1 = createConfigurationService({
3197
3451
  isComponent: true,
3198
3452
  prefix: STORE_KEY_PREFIX,
3199
3453
  getModels() {
3200
- const { toContentManagerModel } = getService$1("data-mapper");
3454
+ const { toContentManagerModel } = getService$2("data-mapper");
3201
3455
  return mapValues(toContentManagerModel, strapi.components);
3202
3456
  }
3203
3457
  });
3204
3458
  const components = ({ strapi: strapi2 }) => ({
3205
3459
  findAllComponents() {
3206
- const { toContentManagerModel } = getService$1("data-mapper");
3460
+ const { toContentManagerModel } = getService$2("data-mapper");
3207
3461
  return Object.values(strapi2.components).map(toContentManagerModel);
3208
3462
  },
3209
3463
  findComponent(uid2) {
3210
- const { toContentManagerModel } = getService$1("data-mapper");
3464
+ const { toContentManagerModel } = getService$2("data-mapper");
3211
3465
  const component = strapi2.components[uid2];
3212
3466
  return isNil$1(component) ? component : toContentManagerModel(component);
3213
3467
  },
@@ -3258,17 +3512,17 @@ const configurationService = createConfigurationService({
3258
3512
  storeUtils,
3259
3513
  prefix: "content_types",
3260
3514
  getModels() {
3261
- const { toContentManagerModel } = getService$1("data-mapper");
3515
+ const { toContentManagerModel } = getService$2("data-mapper");
3262
3516
  return mapValues(toContentManagerModel, strapi.contentTypes);
3263
3517
  }
3264
3518
  });
3265
3519
  const service = ({ strapi: strapi2 }) => ({
3266
3520
  findAllContentTypes() {
3267
- const { toContentManagerModel } = getService$1("data-mapper");
3521
+ const { toContentManagerModel } = getService$2("data-mapper");
3268
3522
  return Object.values(strapi2.contentTypes).map(toContentManagerModel);
3269
3523
  },
3270
3524
  findContentType(uid2) {
3271
- const { toContentManagerModel } = getService$1("data-mapper");
3525
+ const { toContentManagerModel } = getService$2("data-mapper");
3272
3526
  const contentType = strapi2.contentTypes[uid2];
3273
3527
  return isNil$1(contentType) ? contentType : toContentManagerModel(contentType);
3274
3528
  },
@@ -3297,7 +3551,7 @@ const service = ({ strapi: strapi2 }) => ({
3297
3551
  return this.findConfiguration(contentType);
3298
3552
  },
3299
3553
  findComponentsConfigurations(contentType) {
3300
- return getService$1("components").findComponentsConfigurations(contentType);
3554
+ return getService$2("components").findComponentsConfigurations(contentType);
3301
3555
  },
3302
3556
  syncConfigurations() {
3303
3557
  return configurationService.syncConfigurations();
@@ -3478,12 +3732,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3478
3732
  ability: userAbility,
3479
3733
  model
3480
3734
  });
3481
- 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
+ };
3482
3739
  const can = (action, entity, field) => {
3483
- 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
+ );
3484
3747
  };
3485
3748
  const cannot = (action, entity, field) => {
3486
- 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
+ );
3487
3756
  };
3488
3757
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3489
3758
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3554,7 +3823,7 @@ const permission = ({ strapi: strapi2 }) => ({
3554
3823
  return userAbility.can(action);
3555
3824
  },
3556
3825
  async registerPermissions() {
3557
- const displayedContentTypes = getService$1("content-types").findDisplayedContentTypes();
3826
+ const displayedContentTypes = getService$2("content-types").findDisplayedContentTypes();
3558
3827
  const contentTypesUids = displayedContentTypes.map(prop("uid"));
3559
3828
  const actions = [
3560
3829
  {
@@ -3830,7 +4099,7 @@ const getQueryPopulate = async (uid2, query) => {
3830
4099
  return populateQuery;
3831
4100
  };
3832
4101
  const buildDeepPopulate = (uid2) => {
3833
- return getService$1("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
4102
+ return getService$2("populate-builder")(uid2).populateDeep(Infinity).countRelations().build();
3834
4103
  };
3835
4104
  const populateBuilder = (uid2) => {
3836
4105
  let getInitialPopulate = async () => {
@@ -4015,7 +4284,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4015
4284
  */
4016
4285
  async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
4017
4286
  const versionsByLocale = groupBy("locale", allVersions);
4018
- delete versionsByLocale[version.locale];
4287
+ if (version.locale) {
4288
+ delete versionsByLocale[version.locale];
4289
+ }
4019
4290
  const model = strapi2.getModel(uid2);
4020
4291
  const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
4021
4292
  const traversalFunction = async (localeVersion) => traverseEntity(
@@ -4062,8 +4333,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4062
4333
  const matchStatus = status === "published" ? v.publishedAt !== null : v.publishedAt === null;
4063
4334
  return matchLocale && matchStatus;
4064
4335
  });
4065
- if (!availableStatus)
4066
- return availableStatus;
4336
+ if (!availableStatus) return availableStatus;
4067
4337
  return pick(AVAILABLE_STATUS_FIELDS, availableStatus);
4068
4338
  },
4069
4339
  /**
@@ -4073,8 +4343,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4073
4343
  * @returns
4074
4344
  */
4075
4345
  async getManyAvailableStatus(uid2, documents) {
4076
- if (!documents.length)
4077
- return [];
4346
+ if (!documents.length) return [];
4078
4347
  const status = documents[0].publishedAt !== null ? "published" : "draft";
4079
4348
  const locale = documents[0]?.locale;
4080
4349
  const otherStatus = status === "published" ? "draft" : "published";
@@ -4101,10 +4370,8 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4101
4370
  } else if (otherVersion) {
4102
4371
  draftVersion = otherVersion;
4103
4372
  }
4104
- if (!draftVersion)
4105
- return CONTENT_MANAGER_STATUS.PUBLISHED;
4106
- if (!publishedVersion)
4107
- return CONTENT_MANAGER_STATUS.DRAFT;
4373
+ if (!draftVersion) return CONTENT_MANAGER_STATUS.PUBLISHED;
4374
+ if (!publishedVersion) return CONTENT_MANAGER_STATUS.DRAFT;
4108
4375
  const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
4109
4376
  return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
4110
4377
  },
@@ -4371,7 +4638,8 @@ const services = {
4371
4638
  permission,
4372
4639
  "populate-builder": populateBuilder$1,
4373
4640
  uid,
4374
- ...history.services ? history.services : {}
4641
+ ...history.services ? history.services : {},
4642
+ ...preview.services ? preview.services : {}
4375
4643
  };
4376
4644
  const index = () => {
4377
4645
  return {