@strapi/content-manager 0.0.0-experimental.c3e9d4b26f9fd3d9eb530b5c11f9baa1d09b13ad → 0.0.0-experimental.c592deb623aed3f74ef7fdacfad9757ed59d34f7

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 (133) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs → ComponentConfigurationPage-7-qB29e7.mjs} +3 -3
  3. package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs.map → ComponentConfigurationPage-7-qB29e7.mjs.map} +1 -1
  4. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js → ComponentConfigurationPage-DP7AC0UU.js} +3 -3
  5. package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js.map → ComponentConfigurationPage-DP7AC0UU.js.map} +1 -1
  6. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs → EditConfigurationPage-CI4XoymK.mjs} +3 -3
  7. package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs.map → EditConfigurationPage-CI4XoymK.mjs.map} +1 -1
  8. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js → EditConfigurationPage-DITVliEI.js} +3 -3
  9. package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js.map → EditConfigurationPage-DITVliEI.js.map} +1 -1
  10. package/dist/_chunks/{EditViewPage-CTTDHKkQ.js → EditViewPage-CUS2EAhB.js} +62 -47
  11. package/dist/_chunks/EditViewPage-CUS2EAhB.js.map +1 -0
  12. package/dist/_chunks/{EditViewPage-DWb0DE7R.mjs → EditViewPage-Dzpno8xI.mjs} +63 -48
  13. package/dist/_chunks/EditViewPage-Dzpno8xI.mjs.map +1 -0
  14. package/dist/_chunks/{Field-DnStdvQw.mjs → Field-B_jG_EV9.mjs} +541 -221
  15. package/dist/_chunks/Field-B_jG_EV9.mjs.map +1 -0
  16. package/dist/_chunks/{Field-C5Z1Ivdv.js → Field-CtUU1Fg8.js} +543 -223
  17. package/dist/_chunks/Field-CtUU1Fg8.js.map +1 -0
  18. package/dist/_chunks/{Form-DqGgE55Q.mjs → Form-BXHao2mZ.mjs} +53 -35
  19. package/dist/_chunks/Form-BXHao2mZ.mjs.map +1 -0
  20. package/dist/_chunks/{Form-B81OtW-k.js → Form-DTqO0ymI.js} +51 -33
  21. package/dist/_chunks/Form-DTqO0ymI.js.map +1 -0
  22. package/dist/_chunks/{History-DS6-HCYX.mjs → History-2Ah2CQ4T.mjs} +52 -29
  23. package/dist/_chunks/History-2Ah2CQ4T.mjs.map +1 -0
  24. package/dist/_chunks/{History-4NbOq2dX.js → History-C_uSGzO5.js} +51 -28
  25. package/dist/_chunks/History-C_uSGzO5.js.map +1 -0
  26. package/dist/_chunks/{ListConfigurationPage-DQJJltko.mjs → ListConfigurationPage-BjSJlaoC.mjs} +58 -48
  27. package/dist/_chunks/ListConfigurationPage-BjSJlaoC.mjs.map +1 -0
  28. package/dist/_chunks/{ListConfigurationPage-CpfstlYY.js → ListConfigurationPage-nyuP7OSy.js} +57 -46
  29. package/dist/_chunks/ListConfigurationPage-nyuP7OSy.js.map +1 -0
  30. package/dist/_chunks/{ListViewPage-nQrOQuVo.mjs → ListViewPage-B75x3nz2.mjs} +103 -102
  31. package/dist/_chunks/ListViewPage-B75x3nz2.mjs.map +1 -0
  32. package/dist/_chunks/{ListViewPage-CA3I75m5.js → ListViewPage-DHgHD8Xg.js} +105 -104
  33. package/dist/_chunks/ListViewPage-DHgHD8Xg.js.map +1 -0
  34. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js → NoContentTypePage-CDUKdZ7d.js} +2 -2
  35. package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js.map → NoContentTypePage-CDUKdZ7d.js.map} +1 -1
  36. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs → NoContentTypePage-DUacQSyF.mjs} +2 -2
  37. package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs.map → NoContentTypePage-DUacQSyF.mjs.map} +1 -1
  38. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs → NoPermissionsPage-SFllMekk.mjs} +2 -2
  39. package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs.map → NoPermissionsPage-SFllMekk.mjs.map} +1 -1
  40. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js → NoPermissionsPage-zwIZydDI.js} +2 -2
  41. package/dist/_chunks/{NoPermissionsPage-CO2MK200.js.map → NoPermissionsPage-zwIZydDI.js.map} +1 -1
  42. package/dist/_chunks/{Relations-BDRl99Ux.mjs → Relations-D2NRW8fC.mjs} +14 -10
  43. package/dist/_chunks/Relations-D2NRW8fC.mjs.map +1 -0
  44. package/dist/_chunks/{Relations-DG2jnOcr.js → Relations-NFLaRNPr.js} +14 -10
  45. package/dist/_chunks/Relations-NFLaRNPr.js.map +1 -0
  46. package/dist/_chunks/{en-fbKQxLGn.js → en-BlhnxQfj.js} +11 -9
  47. package/dist/_chunks/{en-fbKQxLGn.js.map → en-BlhnxQfj.js.map} +1 -1
  48. package/dist/_chunks/{en-Ux26r5pl.mjs → en-C8YBvRrK.mjs} +11 -9
  49. package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-C8YBvRrK.mjs.map} +1 -1
  50. package/dist/_chunks/{index-Drt2DN7v.mjs → index-C9HxCo5R.mjs} +1008 -867
  51. package/dist/_chunks/index-C9HxCo5R.mjs.map +1 -0
  52. package/dist/_chunks/{index-BZoNZMXL.js → index-ovJRE1FM.js} +998 -857
  53. package/dist/_chunks/index-ovJRE1FM.js.map +1 -0
  54. package/dist/_chunks/{layout-BzAbmoO6.mjs → layout-DaUjDiWQ.mjs} +27 -14
  55. package/dist/_chunks/layout-DaUjDiWQ.mjs.map +1 -0
  56. package/dist/_chunks/{layout-DEYBqgF1.js → layout-UNWstw_s.js} +25 -12
  57. package/dist/_chunks/layout-UNWstw_s.js.map +1 -0
  58. package/dist/_chunks/{relations-D26zVRdi.mjs → relations-D8iFAeRu.mjs} +2 -2
  59. package/dist/_chunks/{relations-D26zVRdi.mjs.map → relations-D8iFAeRu.mjs.map} +1 -1
  60. package/dist/_chunks/{relations-D0eZ4VWw.js → relations-NN3coOG5.js} +2 -2
  61. package/dist/_chunks/{relations-D0eZ4VWw.js.map → relations-NN3coOG5.js.map} +1 -1
  62. package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
  63. package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
  64. package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
  65. package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
  66. package/dist/admin/index.js +2 -1
  67. package/dist/admin/index.js.map +1 -1
  68. package/dist/admin/index.mjs +3 -2
  69. package/dist/admin/src/exports.d.ts +1 -1
  70. package/dist/admin/src/history/index.d.ts +3 -0
  71. package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
  72. package/dist/admin/src/hooks/useDocument.d.ts +32 -1
  73. package/dist/admin/src/index.d.ts +1 -0
  74. package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
  75. package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
  76. package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
  77. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
  78. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
  79. package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
  80. package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
  81. package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
  82. package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
  83. package/dist/admin/src/services/api.d.ts +1 -1
  84. package/dist/admin/src/services/components.d.ts +2 -2
  85. package/dist/admin/src/services/contentTypes.d.ts +3 -3
  86. package/dist/admin/src/services/documents.d.ts +19 -17
  87. package/dist/admin/src/services/init.d.ts +1 -1
  88. package/dist/admin/src/services/relations.d.ts +2 -2
  89. package/dist/admin/src/services/uid.d.ts +3 -3
  90. package/dist/admin/src/utils/validation.d.ts +4 -1
  91. package/dist/server/index.js +191 -110
  92. package/dist/server/index.js.map +1 -1
  93. package/dist/server/index.mjs +192 -111
  94. package/dist/server/index.mjs.map +1 -1
  95. package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
  96. package/dist/server/src/controllers/relations.d.ts.map +1 -1
  97. package/dist/server/src/controllers/uid.d.ts.map +1 -1
  98. package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
  99. package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
  100. package/dist/server/src/history/services/history.d.ts.map +1 -1
  101. package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
  102. package/dist/server/src/history/services/utils.d.ts +2 -1
  103. package/dist/server/src/history/services/utils.d.ts.map +1 -1
  104. package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
  105. package/dist/server/src/services/document-manager.d.ts.map +1 -1
  106. package/dist/server/src/services/document-metadata.d.ts.map +1 -1
  107. package/dist/server/src/services/permission-checker.d.ts.map +1 -1
  108. package/dist/server/src/services/utils/populate.d.ts.map +1 -1
  109. package/dist/shared/contracts/collection-types.d.ts +3 -1
  110. package/dist/shared/contracts/collection-types.d.ts.map +1 -1
  111. package/package.json +11 -11
  112. package/dist/_chunks/EditViewPage-CTTDHKkQ.js.map +0 -1
  113. package/dist/_chunks/EditViewPage-DWb0DE7R.mjs.map +0 -1
  114. package/dist/_chunks/Field-C5Z1Ivdv.js.map +0 -1
  115. package/dist/_chunks/Field-DnStdvQw.mjs.map +0 -1
  116. package/dist/_chunks/Form-B81OtW-k.js.map +0 -1
  117. package/dist/_chunks/Form-DqGgE55Q.mjs.map +0 -1
  118. package/dist/_chunks/History-4NbOq2dX.js.map +0 -1
  119. package/dist/_chunks/History-DS6-HCYX.mjs.map +0 -1
  120. package/dist/_chunks/ListConfigurationPage-CpfstlYY.js.map +0 -1
  121. package/dist/_chunks/ListConfigurationPage-DQJJltko.mjs.map +0 -1
  122. package/dist/_chunks/ListViewPage-CA3I75m5.js.map +0 -1
  123. package/dist/_chunks/ListViewPage-nQrOQuVo.mjs.map +0 -1
  124. package/dist/_chunks/Relations-BDRl99Ux.mjs.map +0 -1
  125. package/dist/_chunks/Relations-DG2jnOcr.js.map +0 -1
  126. package/dist/_chunks/index-BZoNZMXL.js.map +0 -1
  127. package/dist/_chunks/index-Drt2DN7v.mjs.map +0 -1
  128. package/dist/_chunks/layout-BzAbmoO6.mjs.map +0 -1
  129. package/dist/_chunks/layout-DEYBqgF1.js.map +0 -1
  130. package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
  131. package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
  132. package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
  133. package/strapi-server.js +0 -3
@@ -1,5 +1,5 @@
1
1
  import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
2
- import { pick, omit, difference, intersection, pipe, propOr, isEqual, isEmpty, set, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, isNil as isNil$1, getOr, propEq, merge, groupBy, castArray } from "lodash/fp";
2
+ import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
3
3
  import "@strapi/types";
4
4
  import * as yup from "yup";
5
5
  import { scheduleJob } from "node-schedule";
@@ -173,7 +173,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
173
173
  return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
174
174
  };
175
175
  const localesService = strapi2.plugin("i18n")?.service("locales");
176
+ const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
176
177
  const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
178
+ const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
177
179
  const getLocaleDictionary = async () => {
178
180
  if (!localesService)
179
181
  return {};
@@ -200,20 +202,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
200
202
  const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
201
203
  return documentMetadataService.getStatus(document, meta.availableStatus);
202
204
  };
203
- const getDeepPopulate2 = (uid2) => {
205
+ const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
204
206
  const model = strapi2.getModel(uid2);
205
207
  const attributes = Object.entries(model.attributes);
208
+ const fieldSelector = useDatabaseSyntax ? "select" : "fields";
206
209
  return attributes.reduce((acc, [attributeName, attribute]) => {
207
210
  switch (attribute.type) {
208
211
  case "relation": {
212
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
213
+ if (isMorphRelation) {
214
+ break;
215
+ }
209
216
  const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
210
217
  if (isVisible2) {
211
- acc[attributeName] = { fields: ["documentId", "locale", "publishedAt"] };
218
+ acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
212
219
  }
213
220
  break;
214
221
  }
215
222
  case "media": {
216
- acc[attributeName] = { fields: ["id"] };
223
+ acc[attributeName] = { [fieldSelector]: ["id"] };
217
224
  break;
218
225
  }
219
226
  case "component": {
@@ -286,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
286
293
  getRelationRestoreValue,
287
294
  getMediaRestoreValue,
288
295
  getDefaultLocale,
296
+ isLocalizedContentType,
289
297
  getLocaleDictionary,
290
298
  getRetentionDays,
291
299
  getVersionStatus,
@@ -308,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
308
316
  });
309
317
  },
310
318
  async findVersionsPage(params) {
311
- const locale = params.query.locale || await serviceUtils.getDefaultLocale();
319
+ const model = strapi2.getModel(params.query.contentType);
320
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
321
+ const defaultLocale = await serviceUtils.getDefaultLocale();
322
+ let locale = null;
323
+ if (isLocalizedContentType) {
324
+ locale = params.query.locale || defaultLocale;
325
+ }
312
326
  const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
313
327
  query.findPage({
314
328
  ...params.query,
@@ -464,13 +478,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
464
478
  }
465
479
  };
466
480
  };
481
+ const shouldCreateHistoryVersion = (context) => {
482
+ if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
483
+ return false;
484
+ }
485
+ if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
486
+ return false;
487
+ }
488
+ if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
489
+ return false;
490
+ }
491
+ if (!context.contentType.uid.startsWith("api::")) {
492
+ return false;
493
+ }
494
+ return true;
495
+ };
496
+ const getSchemas = (uid2) => {
497
+ const attributesSchema = strapi.getModel(uid2).attributes;
498
+ const componentsSchemas = Object.keys(attributesSchema).reduce(
499
+ (currentComponentSchemas, key) => {
500
+ const fieldSchema = attributesSchema[key];
501
+ if (fieldSchema.type === "component") {
502
+ const componentSchema = strapi.getModel(fieldSchema.component).attributes;
503
+ return {
504
+ ...currentComponentSchemas,
505
+ [fieldSchema.component]: componentSchema
506
+ };
507
+ }
508
+ return currentComponentSchemas;
509
+ },
510
+ {}
511
+ );
512
+ return {
513
+ schema: omit(FIELDS_TO_IGNORE, attributesSchema),
514
+ componentsSchemas
515
+ };
516
+ };
467
517
  const createLifecyclesService = ({ strapi: strapi2 }) => {
468
518
  const state = {
469
519
  deleteExpiredJob: null,
470
520
  isInitialized: false
471
521
  };
472
- const query = strapi2.db.query(HISTORY_VERSION_UID);
473
- const historyService = getService(strapi2, "history");
474
522
  const serviceUtils = createServiceUtils({ strapi: strapi2 });
475
523
  return {
476
524
  async bootstrap() {
@@ -478,60 +526,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
478
526
  return;
479
527
  }
480
528
  strapi2.documents.use(async (context, next) => {
481
- if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
482
- return next();
483
- }
484
- if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
485
- return next();
486
- }
487
- const contentTypeUid = context.contentType.uid;
488
- if (!contentTypeUid.startsWith("api::")) {
489
- return next();
490
- }
491
529
  const result = await next();
492
- const documentContext = {
493
- documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
494
- locale: context.params?.locale
495
- };
530
+ if (!shouldCreateHistoryVersion(context)) {
531
+ return result;
532
+ }
533
+ const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
496
534
  const defaultLocale = await serviceUtils.getDefaultLocale();
497
- const locale = documentContext.locale || defaultLocale;
498
- if (Array.isArray(locale)) {
499
- strapi2.log.warn(
500
- "[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
501
- );
502
- return next();
535
+ const locales = castArray(context.params?.locale || defaultLocale);
536
+ if (!locales.length) {
537
+ return result;
503
538
  }
504
- const document = await strapi2.documents(contentTypeUid).findOne({
505
- documentId: documentContext.documentId,
506
- locale,
507
- populate: serviceUtils.getDeepPopulate(contentTypeUid)
539
+ const uid2 = context.contentType.uid;
540
+ const schemas = getSchemas(uid2);
541
+ const model = strapi2.getModel(uid2);
542
+ const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
543
+ const localeEntries = await strapi2.db.query(uid2).findMany({
544
+ where: {
545
+ documentId,
546
+ ...isLocalizedContentType ? { locale: { $in: locales } } : {},
547
+ ...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
548
+ },
549
+ populate: serviceUtils.getDeepPopulate(
550
+ uid2,
551
+ true
552
+ /* use database syntax */
553
+ )
508
554
  });
509
- const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
510
- const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
511
- const componentsSchemas = Object.keys(
512
- attributesSchema
513
- ).reduce((currentComponentSchemas, key) => {
514
- const fieldSchema = attributesSchema[key];
515
- if (fieldSchema.type === "component") {
516
- const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
517
- return {
518
- ...currentComponentSchemas,
519
- [fieldSchema.component]: componentSchema
520
- };
521
- }
522
- return currentComponentSchemas;
523
- }, {});
524
555
  await strapi2.db.transaction(async ({ onCommit }) => {
525
- onCommit(() => {
526
- historyService.createVersion({
527
- contentType: contentTypeUid,
528
- data: omit(FIELDS_TO_IGNORE, document),
529
- schema: omit(FIELDS_TO_IGNORE, attributesSchema),
530
- componentsSchemas,
531
- relatedDocumentId: documentContext.documentId,
532
- locale,
533
- status
534
- });
556
+ onCommit(async () => {
557
+ for (const entry of localeEntries) {
558
+ const status = await serviceUtils.getVersionStatus(uid2, entry);
559
+ await getService(strapi2, "history").createVersion({
560
+ contentType: uid2,
561
+ data: omit(FIELDS_TO_IGNORE, entry),
562
+ relatedDocumentId: documentId,
563
+ locale: entry.locale,
564
+ status,
565
+ ...schemas
566
+ });
567
+ }
535
568
  });
536
569
  });
537
570
  return result;
@@ -539,7 +572,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
539
572
  state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
540
573
  const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
541
574
  const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
542
- query.deleteMany({
575
+ strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
543
576
  where: {
544
577
  created_at: {
545
578
  $lt: expirationDate.toISOString()
@@ -1171,6 +1204,11 @@ const { createPolicy } = policy;
1171
1204
  const hasPermissions = createPolicy({
1172
1205
  name: "plugin::content-manager.hasPermissions",
1173
1206
  validator: validateHasPermissionsInput,
1207
+ /**
1208
+ * NOTE: Action aliases are currently not checked at this level (policy).
1209
+ * This is currently the intended behavior to avoid changing the behavior of API related permissions.
1210
+ * If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
1211
+ */
1174
1212
  handler(ctx, config = {}) {
1175
1213
  const { actions = [], hasAtLeastOne = false } = config;
1176
1214
  const { userAbility } = ctx.state;
@@ -1564,9 +1602,11 @@ const multipleLocaleSchema = yup$1.lazy(
1564
1602
  (value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
1565
1603
  );
1566
1604
  const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
1567
- const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
1605
+ const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
1568
1606
  const { allowMultipleLocales } = opts;
1569
- const { locale, status, ...rest } = request || {};
1607
+ const { locale, status: providedStatus, ...rest } = request || {};
1608
+ const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
1609
+ const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
1570
1610
  const schema = yup$1.object().shape({
1571
1611
  locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
1572
1612
  status: statusSchema
@@ -1614,7 +1654,7 @@ const createDocument = async (ctx, opts) => {
1614
1654
  const setCreator = setCreatorFields({ user });
1615
1655
  const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
1616
1656
  const sanitizedBody = await sanitizeFn(body);
1617
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
1657
+ const { locale, status } = await getDocumentLocaleAndStatus(body, model);
1618
1658
  return documentManager2.create(model, {
1619
1659
  data: sanitizedBody,
1620
1660
  locale,
@@ -1633,7 +1673,7 @@ const updateDocument = async (ctx, opts) => {
1633
1673
  }
1634
1674
  const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
1635
1675
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1636
- const { locale } = await getDocumentLocaleAndStatus(body);
1676
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1637
1677
  const [documentVersion, documentExists] = await Promise.all([
1638
1678
  documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
1639
1679
  documentManager2.exists(model, id)
@@ -1671,7 +1711,7 @@ const collectionTypes = {
1671
1711
  }
1672
1712
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
1673
1713
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
1674
- const { locale, status } = await getDocumentLocaleAndStatus(query);
1714
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
1675
1715
  const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
1676
1716
  { ...permissionQuery, populate, locale, status },
1677
1717
  model
@@ -1706,7 +1746,7 @@ const collectionTypes = {
1706
1746
  }
1707
1747
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
1708
1748
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1709
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
1749
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
1710
1750
  const version = await documentManager2.findOne(id, model, {
1711
1751
  populate,
1712
1752
  locale,
@@ -1721,7 +1761,7 @@ const collectionTypes = {
1721
1761
  permissionChecker2,
1722
1762
  model,
1723
1763
  // @ts-expect-error TODO: fix
1724
- { id, locale, publishedAt: null },
1764
+ { documentId: id, locale, publishedAt: null },
1725
1765
  { availableLocales: true, availableStatus: false }
1726
1766
  );
1727
1767
  ctx.body = { data: {}, meta };
@@ -1773,7 +1813,7 @@ const collectionTypes = {
1773
1813
  }
1774
1814
  const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
1775
1815
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1776
- const { locale } = await getDocumentLocaleAndStatus(body);
1816
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1777
1817
  const document = await documentManager2.findOne(id, model, {
1778
1818
  populate,
1779
1819
  locale,
@@ -1818,7 +1858,7 @@ const collectionTypes = {
1818
1858
  }
1819
1859
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
1820
1860
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1821
- const { locale } = await getDocumentLocaleAndStatus(ctx.query);
1861
+ const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
1822
1862
  const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
1823
1863
  if (documentLocales.length === 0) {
1824
1864
  return ctx.notFound();
@@ -1847,11 +1887,34 @@ const collectionTypes = {
1847
1887
  const publishedDocument = await strapi.db.transaction(async () => {
1848
1888
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1849
1889
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1850
- const document = id ? await updateDocument(ctx, { populate }) : await createDocument(ctx, { populate });
1890
+ let document;
1891
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1892
+ const isCreate = isNil$1(id);
1893
+ if (isCreate) {
1894
+ if (permissionChecker2.cannot.create()) {
1895
+ throw new errors.ForbiddenError();
1896
+ }
1897
+ document = await createDocument(ctx, { populate });
1898
+ }
1899
+ const isUpdate = !isCreate;
1900
+ if (isUpdate) {
1901
+ const documentExists = documentManager2.exists(model, id);
1902
+ if (!documentExists) {
1903
+ throw new errors.NotFoundError("Document not found");
1904
+ }
1905
+ document = await documentManager2.findOne(id, model, { populate, locale });
1906
+ if (!document) {
1907
+ if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
1908
+ throw new errors.ForbiddenError();
1909
+ }
1910
+ document = await updateDocument(ctx);
1911
+ } else if (permissionChecker2.can.update(document)) {
1912
+ await updateDocument(ctx);
1913
+ }
1914
+ }
1851
1915
  if (permissionChecker2.cannot.publish(document)) {
1852
1916
  throw new errors.ForbiddenError();
1853
1917
  }
1854
- const { locale } = await getDocumentLocaleAndStatus(body);
1855
1918
  const publishResult = await documentManager2.publish(document.documentId, model, {
1856
1919
  locale
1857
1920
  // TODO: Allow setting creator fields on publish
@@ -1878,7 +1941,9 @@ const collectionTypes = {
1878
1941
  }
1879
1942
  const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
1880
1943
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
1881
- const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
1944
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1945
+ allowMultipleLocales: true
1946
+ });
1882
1947
  const entityPromises = documentIds.map(
1883
1948
  (documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
1884
1949
  );
@@ -1905,7 +1970,9 @@ const collectionTypes = {
1905
1970
  if (permissionChecker2.cannot.unpublish()) {
1906
1971
  return ctx.forbidden();
1907
1972
  }
1908
- const { locale } = await getDocumentLocaleAndStatus(body);
1973
+ const { locale } = await getDocumentLocaleAndStatus(body, model, {
1974
+ allowMultipleLocales: true
1975
+ });
1909
1976
  const entityPromises = documentIds.map(
1910
1977
  (documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
1911
1978
  );
@@ -1938,7 +2005,7 @@ const collectionTypes = {
1938
2005
  }
1939
2006
  const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
1940
2007
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1941
- const { locale } = await getDocumentLocaleAndStatus(body);
2008
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1942
2009
  const document = await documentManager2.findOne(id, model, {
1943
2010
  populate,
1944
2011
  locale,
@@ -1975,7 +2042,7 @@ const collectionTypes = {
1975
2042
  }
1976
2043
  const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
1977
2044
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
1978
- const { locale } = await getDocumentLocaleAndStatus(body);
2045
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
1979
2046
  const document = await documentManager2.findOne(id, model, {
1980
2047
  populate,
1981
2048
  locale,
@@ -2006,7 +2073,7 @@ const collectionTypes = {
2006
2073
  }
2007
2074
  const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
2008
2075
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2009
- const { locale } = await getDocumentLocaleAndStatus(body);
2076
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2010
2077
  const documentLocales = await documentManager2.findLocales(documentIds, model, {
2011
2078
  populate,
2012
2079
  locale
@@ -2033,7 +2100,7 @@ const collectionTypes = {
2033
2100
  }
2034
2101
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
2035
2102
  const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
2036
- const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
2103
+ const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
2037
2104
  const entity = await documentManager2.findOne(id, model, { populate, locale, status });
2038
2105
  if (!entity) {
2039
2106
  return ctx.notFound();
@@ -2056,7 +2123,7 @@ const collectionTypes = {
2056
2123
  if (permissionChecker2.cannot.read()) {
2057
2124
  return ctx.forbidden();
2058
2125
  }
2059
- const entities = await documentManager2.findMany(
2126
+ const documents = await documentManager2.findMany(
2060
2127
  {
2061
2128
  filters: {
2062
2129
  documentId: ids
@@ -2065,7 +2132,7 @@ const collectionTypes = {
2065
2132
  },
2066
2133
  model
2067
2134
  );
2068
- if (!entities) {
2135
+ if (!documents) {
2069
2136
  return ctx.notFound();
2070
2137
  }
2071
2138
  const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
@@ -2256,20 +2323,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
2256
2323
  userAbility,
2257
2324
  model: model.uid
2258
2325
  });
2259
- if (!isListable(model, mainField)) {
2326
+ const isMainFieldListable = isListable(model, mainField);
2327
+ const canReadMainField = permissionChecker2.can.read(null, mainField);
2328
+ if (!isMainFieldListable || !canReadMainField) {
2260
2329
  return "id";
2261
2330
  }
2262
- if (permissionChecker2.cannot.read(null, mainField)) {
2263
- if (model.uid === "plugin::users-permissions.role") {
2264
- const userPermissionChecker = getService$1("permission-checker").create({
2265
- userAbility,
2266
- model: "plugin::users-permissions.user"
2267
- });
2268
- if (userPermissionChecker.can.read()) {
2269
- return "name";
2270
- }
2271
- }
2272
- return "id";
2331
+ if (model.uid === "plugin::users-permissions.role") {
2332
+ return "name";
2273
2333
  }
2274
2334
  return mainField;
2275
2335
  };
@@ -2469,8 +2529,9 @@ const relations = {
2469
2529
  } else {
2470
2530
  where.id = id;
2471
2531
  }
2472
- if (status) {
2473
- where[`${alias}.published_at`] = getPublishedAtClause(status, targetUid);
2532
+ const publishedAt = getPublishedAtClause(status, targetUid);
2533
+ if (!isEmpty(publishedAt)) {
2534
+ where[`${alias}.published_at`] = publishedAt;
2474
2535
  }
2475
2536
  if (filterByLocale) {
2476
2537
  where[`${alias}.locale`] = locale;
@@ -2527,9 +2588,7 @@ const relations = {
2527
2588
  addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
2528
2589
  const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
2529
2590
  ...strapi.get("query-params").transform(targetUid, permissionQuery),
2530
- ordering: "desc",
2531
- page: ctx.request.query.page,
2532
- pageSize: ctx.request.query.pageSize
2591
+ ordering: "desc"
2533
2592
  });
2534
2593
  const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
2535
2594
  ctx.body = {
@@ -2561,7 +2620,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
2561
2620
  throw new errors.ForbiddenError();
2562
2621
  }
2563
2622
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
2564
- const { locale } = await getDocumentLocaleAndStatus(body);
2623
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2565
2624
  const [documentVersion, otherDocumentVersion] = await Promise.all([
2566
2625
  findDocument(sanitizedQuery, model, { locale, status: "draft" }),
2567
2626
  // Find the first document to check if it exists
@@ -2602,7 +2661,7 @@ const singleTypes = {
2602
2661
  return ctx.forbidden();
2603
2662
  }
2604
2663
  const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
2605
- const { locale, status } = await getDocumentLocaleAndStatus(query);
2664
+ const { locale, status } = await getDocumentLocaleAndStatus(query, model);
2606
2665
  const version = await findDocument(permissionQuery, model, { locale, status });
2607
2666
  if (!version) {
2608
2667
  if (permissionChecker2.cannot.create()) {
@@ -2616,7 +2675,7 @@ const singleTypes = {
2616
2675
  permissionChecker2,
2617
2676
  model,
2618
2677
  // @ts-expect-error - fix types
2619
- { id: document.documentId, locale, publishedAt: null },
2678
+ { documentId: document.documentId, locale, publishedAt: null },
2620
2679
  { availableLocales: true, availableStatus: false }
2621
2680
  );
2622
2681
  ctx.body = { data: {}, meta };
@@ -2647,7 +2706,7 @@ const singleTypes = {
2647
2706
  }
2648
2707
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
2649
2708
  const populate = await buildPopulateFromQuery(sanitizedQuery, model);
2650
- const { locale } = await getDocumentLocaleAndStatus(query);
2709
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2651
2710
  const documentLocales = await documentManager2.findLocales(void 0, model, {
2652
2711
  populate,
2653
2712
  locale
@@ -2684,7 +2743,7 @@ const singleTypes = {
2684
2743
  if (permissionChecker2.cannot.publish(document)) {
2685
2744
  throw new errors.ForbiddenError();
2686
2745
  }
2687
- const { locale } = await getDocumentLocaleAndStatus(document);
2746
+ const { locale } = await getDocumentLocaleAndStatus(document, model);
2688
2747
  const publishResult = await documentManager2.publish(document.documentId, model, { locale });
2689
2748
  return publishResult.at(0);
2690
2749
  });
@@ -2707,7 +2766,7 @@ const singleTypes = {
2707
2766
  return ctx.forbidden();
2708
2767
  }
2709
2768
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
2710
- const { locale } = await getDocumentLocaleAndStatus(body);
2769
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2711
2770
  const document = await findDocument(sanitizedQuery, model, { locale });
2712
2771
  if (!document) {
2713
2772
  return ctx.notFound();
@@ -2739,7 +2798,7 @@ const singleTypes = {
2739
2798
  return ctx.forbidden();
2740
2799
  }
2741
2800
  const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
2742
- const { locale } = await getDocumentLocaleAndStatus(body);
2801
+ const { locale } = await getDocumentLocaleAndStatus(body, model);
2743
2802
  const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
2744
2803
  if (!document) {
2745
2804
  return ctx.notFound();
@@ -2759,7 +2818,7 @@ const singleTypes = {
2759
2818
  const { query } = ctx.request;
2760
2819
  const documentManager2 = getService$1("document-manager");
2761
2820
  const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
2762
- const { locale } = await getDocumentLocaleAndStatus(query);
2821
+ const { locale } = await getDocumentLocaleAndStatus(query, model);
2763
2822
  if (permissionChecker2.cannot.read()) {
2764
2823
  return ctx.forbidden();
2765
2824
  }
@@ -2780,7 +2839,7 @@ const uid$1 = {
2780
2839
  async generateUID(ctx) {
2781
2840
  const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
2782
2841
  const { query = {} } = ctx.request;
2783
- const { locale } = await getDocumentLocaleAndStatus(query);
2842
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2784
2843
  await validateUIDField(contentTypeUID, field);
2785
2844
  const uidService = getService$1("uid");
2786
2845
  ctx.body = {
@@ -2792,7 +2851,7 @@ const uid$1 = {
2792
2851
  ctx.request.body
2793
2852
  );
2794
2853
  const { query = {} } = ctx.request;
2795
- const { locale } = await getDocumentLocaleAndStatus(query);
2854
+ const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
2796
2855
  await validateUIDField(contentTypeUID, field);
2797
2856
  const uidService = getService$1("uid");
2798
2857
  const isAvailable = await uidService.checkUIDAvailability({
@@ -3435,12 +3494,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
3435
3494
  ability: userAbility,
3436
3495
  model
3437
3496
  });
3438
- const toSubject = (entity) => entity ? permissionsManager.toSubject(entity, model) : model;
3497
+ const { actionProvider } = strapi2.service("admin::permission");
3498
+ const toSubject = (entity) => {
3499
+ return entity ? permissionsManager.toSubject(entity, model) : model;
3500
+ };
3439
3501
  const can = (action, entity, field) => {
3440
- return userAbility.can(action, toSubject(entity), field);
3502
+ const subject = toSubject(entity);
3503
+ const aliases = actionProvider.unstable_aliases(action, model);
3504
+ return (
3505
+ // Test the original action to see if it passes
3506
+ userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
3507
+ aliases.some((alias) => userAbility.can(alias, subject, field))
3508
+ );
3441
3509
  };
3442
3510
  const cannot = (action, entity, field) => {
3443
- return userAbility.cannot(action, toSubject(entity), field);
3511
+ const subject = toSubject(entity);
3512
+ const aliases = actionProvider.unstable_aliases(action, model);
3513
+ return (
3514
+ // Test both the original action
3515
+ userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
3516
+ aliases.every((alias) => userAbility.cannot(alias, subject, field))
3517
+ );
3444
3518
  };
3445
3519
  const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
3446
3520
  return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
@@ -3717,6 +3791,10 @@ const getDeepPopulateDraftCount = (uid2) => {
3717
3791
  const attribute = model.attributes[attributeName];
3718
3792
  switch (attribute.type) {
3719
3793
  case "relation": {
3794
+ const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
3795
+ if (isMorphRelation) {
3796
+ break;
3797
+ }
3720
3798
  if (isVisibleAttribute$1(model, attributeName)) {
3721
3799
  populateAcc[attributeName] = {
3722
3800
  count: true,
@@ -4094,7 +4172,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
4094
4172
  */
4095
4173
  async formatDocumentWithMetadata(uid2, document, opts = {}) {
4096
4174
  if (!document) {
4097
- return document;
4175
+ return {
4176
+ data: document,
4177
+ meta: {
4178
+ availableLocales: [],
4179
+ availableStatus: []
4180
+ }
4181
+ };
4098
4182
  }
4099
4183
  const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
4100
4184
  if (!hasDraftAndPublish) {
@@ -4202,10 +4286,7 @@ const documentManager = ({ strapi: strapi2 }) => {
4202
4286
  async clone(id, body, uid2) {
4203
4287
  const populate = await buildDeepPopulate(uid2);
4204
4288
  const params = {
4205
- data: {
4206
- ...omitIdField(body),
4207
- [PUBLISHED_AT_ATTRIBUTE]: null
4208
- },
4289
+ data: omitIdField(body),
4209
4290
  populate
4210
4291
  };
4211
4292
  return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));