@strapi/content-manager 5.0.0-beta.7 → 5.0.0-beta.9
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.
- package/dist/_chunks/{ComponentConfigurationPage-uTMkLI60.mjs → ComponentConfigurationPage-BMajAl1u.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-uTMkLI60.mjs.map → ComponentConfigurationPage-BMajAl1u.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DMq0wvcL.js → ComponentConfigurationPage-y_7iLdmB.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DMq0wvcL.js.map → ComponentConfigurationPage-y_7iLdmB.js.map} +1 -1
- package/dist/_chunks/{ComponentIcon-BBQsYCVn.js → ComponentIcon-BXdiCGQp.js} +8 -2
- package/dist/_chunks/ComponentIcon-BXdiCGQp.js.map +1 -0
- package/dist/_chunks/{ComponentIcon-BOFnK76n.mjs → ComponentIcon-u4bIXTFY.mjs} +9 -3
- package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -0
- package/dist/_chunks/{EditConfigurationPage-BFpQwwbc.js → EditConfigurationPage-CPVB8Uqc.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BFpQwwbc.js.map → EditConfigurationPage-CPVB8Uqc.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-B2HhCh-b.mjs → EditConfigurationPage-CcOoD26O.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-B2HhCh-b.mjs.map → EditConfigurationPage-CcOoD26O.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CXXue16T.js → EditViewPage-CTTDHKkQ.js} +5 -5
- package/dist/_chunks/{EditViewPage-CXXue16T.js.map → EditViewPage-CTTDHKkQ.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-BVIrgjyG.mjs → EditViewPage-DWb0DE7R.mjs} +5 -5
- package/dist/_chunks/{EditViewPage-BVIrgjyG.mjs.map → EditViewPage-DWb0DE7R.mjs.map} +1 -1
- package/dist/_chunks/{Field-ZgzKlgxR.js → Field-C5Z1Ivdv.js} +240 -357
- package/dist/_chunks/Field-C5Z1Ivdv.js.map +1 -0
- package/dist/_chunks/{Field-0_2h1vuK.mjs → Field-DnStdvQw.mjs} +240 -357
- package/dist/_chunks/Field-DnStdvQw.mjs.map +1 -0
- package/dist/_chunks/{Form-DgTc2qkx.js → Form-B81OtW-k.js} +9 -6
- package/dist/_chunks/Form-B81OtW-k.js.map +1 -0
- package/dist/_chunks/{Form-B7TUnQDd.mjs → Form-DqGgE55Q.mjs} +9 -6
- package/dist/_chunks/Form-DqGgE55Q.mjs.map +1 -0
- package/dist/_chunks/{History-DtHjQuqM.js → History-4NbOq2dX.js} +97 -15
- package/dist/_chunks/History-4NbOq2dX.js.map +1 -0
- package/dist/_chunks/{History-Dug_4HIA.mjs → History-DS6-HCYX.mjs} +97 -15
- package/dist/_chunks/History-DS6-HCYX.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BuSdTjfa.js → ListConfigurationPage-CpfstlYY.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-BuSdTjfa.js.map → ListConfigurationPage-CpfstlYY.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-CmEeNg6T.mjs → ListConfigurationPage-DQJJltko.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-CmEeNg6T.mjs.map → ListConfigurationPage-DQJJltko.mjs.map} +1 -1
- package/dist/_chunks/{ListViewPage-CExWwa4S.js → ListViewPage-CA3I75m5.js} +23 -18
- package/dist/_chunks/ListViewPage-CA3I75m5.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Dsoa3wEA.mjs → ListViewPage-nQrOQuVo.mjs} +21 -17
- package/dist/_chunks/ListViewPage-nQrOQuVo.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Dh38hBXB.mjs → NoContentTypePage-DbnHE22g.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Dh38hBXB.mjs.map → NoContentTypePage-DbnHE22g.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DCUL8gVi.js → NoContentTypePage-Dldu-_Mx.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DCUL8gVi.js.map → NoContentTypePage-Dldu-_Mx.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BK-XCpIy.js → NoPermissionsPage-CO2MK200.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BK-XCpIy.js.map → NoPermissionsPage-CO2MK200.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Dt2O40ey.mjs → NoPermissionsPage-fOIkQM0v.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Dt2O40ey.mjs.map → NoPermissionsPage-fOIkQM0v.mjs.map} +1 -1
- package/dist/_chunks/{Relations-DZyjWZHl.mjs → Relations-BDRl99Ux.mjs} +8 -6
- package/dist/_chunks/{Relations-DZyjWZHl.mjs.map → Relations-BDRl99Ux.mjs.map} +1 -1
- package/dist/_chunks/{Relations-CNypkp-g.js → Relations-DG2jnOcr.js} +8 -6
- package/dist/_chunks/{Relations-CNypkp-g.js.map → Relations-DG2jnOcr.js.map} +1 -1
- package/dist/_chunks/{en-MBPul9Su.mjs → en-Ux26r5pl.mjs} +7 -1
- package/dist/_chunks/{en-MBPul9Su.mjs.map → en-Ux26r5pl.mjs.map} +1 -1
- package/dist/_chunks/{en-C-V1_90f.js → en-fbKQxLGn.js} +7 -1
- package/dist/_chunks/{en-C-V1_90f.js.map → en-fbKQxLGn.js.map} +1 -1
- package/dist/_chunks/{index-DFK7LwDW.js → index-BZoNZMXL.js} +1528 -779
- package/dist/_chunks/index-BZoNZMXL.js.map +1 -0
- package/dist/_chunks/{index-B3c-4it4.mjs → index-Drt2DN7v.mjs} +1552 -803
- package/dist/_chunks/index-Drt2DN7v.mjs.map +1 -0
- package/dist/_chunks/{layout-B5cm7cZj.mjs → layout-BzAbmoO6.mjs} +20 -15
- package/dist/_chunks/layout-BzAbmoO6.mjs.map +1 -0
- package/dist/_chunks/{layout-DLih5-_W.js → layout-DEYBqgF1.js} +20 -15
- package/dist/_chunks/layout-DEYBqgF1.js.map +1 -0
- package/dist/_chunks/{relations-CTvkuINQ.js → relations-D0eZ4VWw.js} +2 -2
- package/dist/_chunks/{relations-CTvkuINQ.js.map → relations-D0eZ4VWw.js.map} +1 -1
- package/dist/_chunks/{relations-BZkrMa2z.mjs → relations-D26zVRdi.mjs} +2 -2
- package/dist/_chunks/{relations-BZkrMa2z.mjs.map → relations-D26zVRdi.mjs.map} +1 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js +15 -0
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +1 -0
- package/dist/_chunks/usePrev-DH6iah0A.mjs +16 -0
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +8 -7
- package/dist/admin/src/components/ComponentIcon.d.ts +6 -3
- package/dist/admin/src/content-manager.d.ts +3 -3
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +5 -8
- package/dist/admin/src/hooks/useDocumentActions.d.ts +24 -3
- package/dist/admin/src/hooks/useDocumentLayout.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +3 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksInput.d.ts +3 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/Component/Input.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.d.ts +3 -5
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +2 -15
- package/dist/admin/src/pages/EditView/components/FormInputs/UID.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/Field.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +56 -35
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +2 -10
- package/dist/admin/src/pages/ListView/components/BulkActions/PublishAction.d.ts +9 -26
- package/dist/admin/src/services/api.d.ts +2 -3
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +5 -5
- package/dist/admin/src/services/documents.d.ts +29 -17
- package/dist/admin/src/services/init.d.ts +2 -2
- package/dist/admin/src/services/relations.d.ts +3 -3
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/api.d.ts +4 -17
- package/dist/admin/src/utils/validation.d.ts +1 -6
- package/dist/server/index.js +247 -127
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +249 -129
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/single-types.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +8 -0
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -0
- package/dist/server/src/controllers/validation/dimensions.d.ts +9 -0
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -0
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +12 -33
- package/dist/server/src/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts +6 -6
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +8 -29
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +12 -33
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts +8 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +11 -5
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/dist/shared/contracts/relations.d.ts +2 -2
- package/dist/shared/contracts/relations.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/_chunks/ComponentIcon-BBQsYCVn.js.map +0 -1
- package/dist/_chunks/ComponentIcon-BOFnK76n.mjs.map +0 -1
- package/dist/_chunks/Field-0_2h1vuK.mjs.map +0 -1
- package/dist/_chunks/Field-ZgzKlgxR.js.map +0 -1
- package/dist/_chunks/Form-B7TUnQDd.mjs.map +0 -1
- package/dist/_chunks/Form-DgTc2qkx.js.map +0 -1
- package/dist/_chunks/History-DtHjQuqM.js.map +0 -1
- package/dist/_chunks/History-Dug_4HIA.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CExWwa4S.js.map +0 -1
- package/dist/_chunks/ListViewPage-Dsoa3wEA.mjs.map +0 -1
- package/dist/_chunks/index-B3c-4it4.mjs.map +0 -1
- package/dist/_chunks/index-DFK7LwDW.js.map +0 -1
- package/dist/_chunks/layout-B5cm7cZj.mjs.map +0 -1
- package/dist/_chunks/layout-DLih5-_W.js.map +0 -1
- package/dist/_chunks/urls-CbOsUOoW.mjs +0 -7
- package/dist/_chunks/urls-CbOsUOoW.mjs.map +0 -1
- package/dist/_chunks/urls-DzZya_gm.js +0 -6
- package/dist/_chunks/urls-DzZya_gm.js.map +0 -1
- package/dist/server/src/controllers/utils/dimensions.d.ts +0 -5
- package/dist/server/src/controllers/utils/dimensions.d.ts.map +0 -1
package/dist/server/index.js
CHANGED
@@ -507,7 +507,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
507
507
|
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
508
508
|
return next();
|
509
509
|
}
|
510
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
510
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
511
511
|
return next();
|
512
512
|
}
|
513
513
|
const contentTypeUid = context.contentType.uid;
|
@@ -515,9 +515,18 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
515
515
|
return next();
|
516
516
|
}
|
517
517
|
const result = await next();
|
518
|
-
const documentContext =
|
518
|
+
const documentContext = {
|
519
|
+
documentId: context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId,
|
520
|
+
locale: context.params?.locale
|
521
|
+
};
|
519
522
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
520
523
|
const locale = documentContext.locale || defaultLocale;
|
524
|
+
if (Array.isArray(locale)) {
|
525
|
+
strapi2.log.warn(
|
526
|
+
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
527
|
+
);
|
528
|
+
return next();
|
529
|
+
}
|
521
530
|
const document = await strapi2.documents(contentTypeUid).findOne({
|
522
531
|
documentId: documentContext.documentId,
|
523
532
|
locale,
|
@@ -553,9 +562,8 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
553
562
|
});
|
554
563
|
return result;
|
555
564
|
});
|
556
|
-
const retentionDays = serviceUtils.getRetentionDays();
|
557
565
|
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
558
|
-
const retentionDaysInMilliseconds =
|
566
|
+
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
559
567
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
560
568
|
query.deleteMany({
|
561
569
|
where: {
|
@@ -1577,15 +1585,47 @@ const excludeNotCreatableFields = (uid2, permissionChecker2) => (body, path = []
|
|
1577
1585
|
}
|
1578
1586
|
}, body);
|
1579
1587
|
};
|
1580
|
-
const
|
1588
|
+
const singleLocaleSchema = strapiUtils.yup.string().nullable();
|
1589
|
+
const multipleLocaleSchema = strapiUtils.yup.lazy(
|
1590
|
+
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1591
|
+
);
|
1592
|
+
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1593
|
+
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1594
|
+
const { allowMultipleLocales } = opts;
|
1581
1595
|
const { locale, status, ...rest } = request || {};
|
1582
|
-
|
1583
|
-
|
1584
|
-
|
1585
|
-
|
1586
|
-
|
1596
|
+
const schema = strapiUtils.yup.object().shape({
|
1597
|
+
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1598
|
+
status: statusSchema
|
1599
|
+
});
|
1600
|
+
try {
|
1601
|
+
await strapiUtils.validateYupSchema(schema, { strict: true, abortEarly: false })(request);
|
1602
|
+
return { locale, status, ...rest };
|
1603
|
+
} catch (error) {
|
1604
|
+
throw new strapiUtils.errors.ValidationError(`Validation error: ${error.message}`);
|
1587
1605
|
}
|
1588
|
-
|
1606
|
+
};
|
1607
|
+
const formatDocumentWithMetadata = async (permissionChecker2, uid2, document, opts = {}) => {
|
1608
|
+
const documentMetadata2 = getService$1("document-metadata");
|
1609
|
+
const serviceOutput = await documentMetadata2.formatDocumentWithMetadata(uid2, document, opts);
|
1610
|
+
let {
|
1611
|
+
meta: { availableLocales, availableStatus }
|
1612
|
+
} = serviceOutput;
|
1613
|
+
const metadataSanitizer = permissionChecker2.sanitizeOutput;
|
1614
|
+
availableLocales = await strapiUtils.async.map(
|
1615
|
+
availableLocales,
|
1616
|
+
async (localeDocument) => metadataSanitizer(localeDocument)
|
1617
|
+
);
|
1618
|
+
availableStatus = await strapiUtils.async.map(
|
1619
|
+
availableStatus,
|
1620
|
+
async (statusDocument) => metadataSanitizer(statusDocument)
|
1621
|
+
);
|
1622
|
+
return {
|
1623
|
+
...serviceOutput,
|
1624
|
+
meta: {
|
1625
|
+
availableLocales,
|
1626
|
+
availableStatus
|
1627
|
+
}
|
1628
|
+
};
|
1589
1629
|
};
|
1590
1630
|
const createDocument = async (ctx, opts) => {
|
1591
1631
|
const { userAbility, user } = ctx.state;
|
@@ -1600,7 +1640,7 @@ const createDocument = async (ctx, opts) => {
|
|
1600
1640
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1601
1641
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1602
1642
|
const sanitizedBody = await sanitizeFn(body);
|
1603
|
-
const { locale, status = "draft" } = getDocumentLocaleAndStatus(body);
|
1643
|
+
const { locale, status = "draft" } = await getDocumentLocaleAndStatus(body);
|
1604
1644
|
return documentManager2.create(model, {
|
1605
1645
|
data: sanitizedBody,
|
1606
1646
|
locale,
|
@@ -1619,7 +1659,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1619
1659
|
}
|
1620
1660
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1621
1661
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1622
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
1662
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1623
1663
|
const [documentVersion, documentExists] = await Promise.all([
|
1624
1664
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1625
1665
|
documentManager2.exists(model, id)
|
@@ -1657,7 +1697,7 @@ const collectionTypes = {
|
|
1657
1697
|
}
|
1658
1698
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1659
1699
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1660
|
-
const { locale, status } = getDocumentLocaleAndStatus(query);
|
1700
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1661
1701
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1662
1702
|
{ ...permissionQuery, populate, locale, status },
|
1663
1703
|
model
|
@@ -1686,14 +1726,13 @@ const collectionTypes = {
|
|
1686
1726
|
const { userAbility } = ctx.state;
|
1687
1727
|
const { model, id } = ctx.params;
|
1688
1728
|
const documentManager2 = getService$1("document-manager");
|
1689
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1690
1729
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1691
1730
|
if (permissionChecker2.cannot.read()) {
|
1692
1731
|
return ctx.forbidden();
|
1693
1732
|
}
|
1694
1733
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1695
1734
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1696
|
-
const { locale, status = "draft" } = getDocumentLocaleAndStatus(ctx.query);
|
1735
|
+
const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
|
1697
1736
|
const version = await documentManager2.findOne(id, model, {
|
1698
1737
|
populate,
|
1699
1738
|
locale,
|
@@ -1704,8 +1743,10 @@ const collectionTypes = {
|
|
1704
1743
|
if (!exists) {
|
1705
1744
|
return ctx.notFound();
|
1706
1745
|
}
|
1707
|
-
const { meta } = await
|
1746
|
+
const { meta } = await formatDocumentWithMetadata(
|
1747
|
+
permissionChecker2,
|
1708
1748
|
model,
|
1749
|
+
// @ts-expect-error TODO: fix
|
1709
1750
|
{ id, locale, publishedAt: null },
|
1710
1751
|
{ availableLocales: true, availableStatus: false }
|
1711
1752
|
);
|
@@ -1716,12 +1757,11 @@ const collectionTypes = {
|
|
1716
1757
|
return ctx.forbidden();
|
1717
1758
|
}
|
1718
1759
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(version);
|
1719
|
-
ctx.body = await
|
1760
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
1720
1761
|
},
|
1721
1762
|
async create(ctx) {
|
1722
1763
|
const { userAbility } = ctx.state;
|
1723
1764
|
const { model } = ctx.params;
|
1724
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1725
1765
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1726
1766
|
const [totalEntries, document] = await Promise.all([
|
1727
1767
|
strapi.db.query(model).count(),
|
@@ -1729,7 +1769,7 @@ const collectionTypes = {
|
|
1729
1769
|
]);
|
1730
1770
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
1731
1771
|
ctx.status = 201;
|
1732
|
-
ctx.body = await
|
1772
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument, {
|
1733
1773
|
// Empty metadata as it's not relevant for a new document
|
1734
1774
|
availableLocales: false,
|
1735
1775
|
availableStatus: false
|
@@ -1743,25 +1783,23 @@ const collectionTypes = {
|
|
1743
1783
|
async update(ctx) {
|
1744
1784
|
const { userAbility } = ctx.state;
|
1745
1785
|
const { model } = ctx.params;
|
1746
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1747
1786
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1748
1787
|
const updatedVersion = await updateDocument(ctx);
|
1749
1788
|
const sanitizedVersion = await permissionChecker2.sanitizeOutput(updatedVersion);
|
1750
|
-
ctx.body = await
|
1789
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedVersion);
|
1751
1790
|
},
|
1752
1791
|
async clone(ctx) {
|
1753
1792
|
const { userAbility, user } = ctx.state;
|
1754
1793
|
const { model, sourceId: id } = ctx.params;
|
1755
1794
|
const { body } = ctx.request;
|
1756
1795
|
const documentManager2 = getService$1("document-manager");
|
1757
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1758
1796
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1759
1797
|
if (permissionChecker2.cannot.create()) {
|
1760
1798
|
return ctx.forbidden();
|
1761
1799
|
}
|
1762
1800
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1763
1801
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1764
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
1802
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1765
1803
|
const document = await documentManager2.findOne(id, model, {
|
1766
1804
|
populate,
|
1767
1805
|
locale,
|
@@ -1777,7 +1815,7 @@ const collectionTypes = {
|
|
1777
1815
|
const sanitizedBody = await sanitizeFn(body);
|
1778
1816
|
const clonedDocument = await documentManager2.clone(document.documentId, sanitizedBody, model);
|
1779
1817
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(clonedDocument);
|
1780
|
-
ctx.body = await
|
1818
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument, {
|
1781
1819
|
// Empty metadata as it's not relevant for a new document
|
1782
1820
|
availableLocales: false,
|
1783
1821
|
availableStatus: false
|
@@ -1806,7 +1844,7 @@ const collectionTypes = {
|
|
1806
1844
|
}
|
1807
1845
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1808
1846
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1809
|
-
const { locale } = getDocumentLocaleAndStatus(ctx.query);
|
1847
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1810
1848
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1811
1849
|
if (documentLocales.length === 0) {
|
1812
1850
|
return ctx.notFound();
|
@@ -1828,7 +1866,6 @@ const collectionTypes = {
|
|
1828
1866
|
const { id, model } = ctx.params;
|
1829
1867
|
const { body } = ctx.request;
|
1830
1868
|
const documentManager2 = getService$1("document-manager");
|
1831
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1832
1869
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1833
1870
|
if (permissionChecker2.cannot.publish()) {
|
1834
1871
|
return ctx.forbidden();
|
@@ -1840,15 +1877,19 @@ const collectionTypes = {
|
|
1840
1877
|
if (permissionChecker2.cannot.publish(document)) {
|
1841
1878
|
throw new strapiUtils.errors.ForbiddenError();
|
1842
1879
|
}
|
1843
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
1844
|
-
|
1880
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1881
|
+
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1845
1882
|
locale
|
1846
1883
|
// TODO: Allow setting creator fields on publish
|
1847
1884
|
// data: setCreatorFields({ user, isEdition: true })({}),
|
1848
1885
|
});
|
1886
|
+
if (!publishResult || publishResult.length === 0) {
|
1887
|
+
throw new strapiUtils.errors.NotFoundError("Document not found or already published.");
|
1888
|
+
}
|
1889
|
+
return publishResult[0];
|
1849
1890
|
});
|
1850
1891
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(publishedDocument);
|
1851
|
-
ctx.body = await
|
1892
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
1852
1893
|
},
|
1853
1894
|
async bulkPublish(ctx) {
|
1854
1895
|
const { userAbility } = ctx.state;
|
@@ -1861,9 +1902,11 @@ const collectionTypes = {
|
|
1861
1902
|
if (permissionChecker2.cannot.publish()) {
|
1862
1903
|
return ctx.forbidden();
|
1863
1904
|
}
|
1864
|
-
const
|
1905
|
+
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1906
|
+
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1907
|
+
const { locale } = await getDocumentLocaleAndStatus(body, { allowMultipleLocales: true });
|
1865
1908
|
const entityPromises = documentIds.map(
|
1866
|
-
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: false })
|
1909
|
+
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1867
1910
|
);
|
1868
1911
|
const entities = (await Promise.all(entityPromises)).flat();
|
1869
1912
|
for (const entity of entities) {
|
@@ -1874,8 +1917,7 @@ const collectionTypes = {
|
|
1874
1917
|
return ctx.forbidden();
|
1875
1918
|
}
|
1876
1919
|
}
|
1877
|
-
const
|
1878
|
-
const { count } = await documentManager2.publishMany(entitiesIds, model, { locale });
|
1920
|
+
const count = await documentManager2.publishMany(model, documentIds, locale);
|
1879
1921
|
ctx.body = { count };
|
1880
1922
|
},
|
1881
1923
|
async bulkUnpublish(ctx) {
|
@@ -1889,7 +1931,7 @@ const collectionTypes = {
|
|
1889
1931
|
if (permissionChecker2.cannot.unpublish()) {
|
1890
1932
|
return ctx.forbidden();
|
1891
1933
|
}
|
1892
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
1934
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1893
1935
|
const entityPromises = documentIds.map(
|
1894
1936
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1895
1937
|
);
|
@@ -1913,7 +1955,6 @@ const collectionTypes = {
|
|
1913
1955
|
body: { discardDraft, ...body }
|
1914
1956
|
} = ctx.request;
|
1915
1957
|
const documentManager2 = getService$1("document-manager");
|
1916
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1917
1958
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1918
1959
|
if (permissionChecker2.cannot.unpublish()) {
|
1919
1960
|
return ctx.forbidden();
|
@@ -1923,7 +1964,7 @@ const collectionTypes = {
|
|
1923
1964
|
}
|
1924
1965
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1925
1966
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1926
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
1967
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1927
1968
|
const document = await documentManager2.findOne(id, model, {
|
1928
1969
|
populate,
|
1929
1970
|
locale,
|
@@ -1945,7 +1986,7 @@ const collectionTypes = {
|
|
1945
1986
|
ctx.body = await strapiUtils.async.pipe(
|
1946
1987
|
(document2) => documentManager2.unpublish(document2.documentId, model, { locale }),
|
1947
1988
|
permissionChecker2.sanitizeOutput,
|
1948
|
-
(document2) =>
|
1989
|
+
(document2) => formatDocumentWithMetadata(permissionChecker2, model, document2)
|
1949
1990
|
)(document);
|
1950
1991
|
});
|
1951
1992
|
},
|
@@ -1954,14 +1995,13 @@ const collectionTypes = {
|
|
1954
1995
|
const { id, model } = ctx.params;
|
1955
1996
|
const { body } = ctx.request;
|
1956
1997
|
const documentManager2 = getService$1("document-manager");
|
1957
|
-
const documentMetadata2 = getService$1("document-metadata");
|
1958
1998
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
1959
1999
|
if (permissionChecker2.cannot.discard()) {
|
1960
2000
|
return ctx.forbidden();
|
1961
2001
|
}
|
1962
2002
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1963
2003
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1964
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
2004
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1965
2005
|
const document = await documentManager2.findOne(id, model, {
|
1966
2006
|
populate,
|
1967
2007
|
locale,
|
@@ -1976,7 +2016,7 @@ const collectionTypes = {
|
|
1976
2016
|
ctx.body = await strapiUtils.async.pipe(
|
1977
2017
|
(document2) => documentManager2.discardDraft(document2.documentId, model, { locale }),
|
1978
2018
|
permissionChecker2.sanitizeOutput,
|
1979
|
-
(document2) =>
|
2019
|
+
(document2) => formatDocumentWithMetadata(permissionChecker2, model, document2)
|
1980
2020
|
)(document);
|
1981
2021
|
},
|
1982
2022
|
async bulkDelete(ctx) {
|
@@ -1992,7 +2032,7 @@ const collectionTypes = {
|
|
1992
2032
|
}
|
1993
2033
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
1994
2034
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1995
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
2035
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
1996
2036
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
1997
2037
|
populate,
|
1998
2038
|
locale
|
@@ -2019,7 +2059,7 @@ const collectionTypes = {
|
|
2019
2059
|
}
|
2020
2060
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2021
2061
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2022
|
-
const { locale, status = "draft" } = getDocumentLocaleAndStatus(ctx.query);
|
2062
|
+
const { locale, status = "draft" } = await getDocumentLocaleAndStatus(ctx.query);
|
2023
2063
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2024
2064
|
if (!entity) {
|
2025
2065
|
return ctx.notFound();
|
@@ -2034,26 +2074,27 @@ const collectionTypes = {
|
|
2034
2074
|
},
|
2035
2075
|
async countManyEntriesDraftRelations(ctx) {
|
2036
2076
|
const { userAbility } = ctx.state;
|
2037
|
-
const
|
2077
|
+
const ids = ctx.request.query.documentIds;
|
2078
|
+
const locale = ctx.request.query.locale;
|
2038
2079
|
const { model } = ctx.params;
|
2039
2080
|
const documentManager2 = getService$1("document-manager");
|
2040
2081
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2041
2082
|
if (permissionChecker2.cannot.read()) {
|
2042
2083
|
return ctx.forbidden();
|
2043
2084
|
}
|
2044
|
-
const
|
2085
|
+
const entities = await documentManager2.findMany(
|
2045
2086
|
{
|
2046
2087
|
filters: {
|
2047
|
-
documentId:
|
2088
|
+
documentId: ids
|
2048
2089
|
},
|
2049
2090
|
locale
|
2050
2091
|
},
|
2051
2092
|
model
|
2052
2093
|
);
|
2053
|
-
if (!
|
2094
|
+
if (!entities) {
|
2054
2095
|
return ctx.notFound();
|
2055
2096
|
}
|
2056
|
-
const number = await documentManager2.countManyEntriesDraftRelations(
|
2097
|
+
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
2057
2098
|
return {
|
2058
2099
|
data: number
|
2059
2100
|
};
|
@@ -2546,7 +2587,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2546
2587
|
throw new strapiUtils.errors.ForbiddenError();
|
2547
2588
|
}
|
2548
2589
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2549
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
2590
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
2550
2591
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2551
2592
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2552
2593
|
// Find the first document to check if it exists
|
@@ -2583,12 +2624,11 @@ const singleTypes = {
|
|
2583
2624
|
const { model } = ctx.params;
|
2584
2625
|
const { query = {} } = ctx.request;
|
2585
2626
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2586
|
-
const documentMetadata2 = getService$1("document-metadata");
|
2587
2627
|
if (permissionChecker2.cannot.read()) {
|
2588
2628
|
return ctx.forbidden();
|
2589
2629
|
}
|
2590
2630
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2591
|
-
const { locale, status } = getDocumentLocaleAndStatus(query);
|
2631
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2592
2632
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2593
2633
|
if (!version) {
|
2594
2634
|
if (permissionChecker2.cannot.create()) {
|
@@ -2598,8 +2638,10 @@ const singleTypes = {
|
|
2598
2638
|
if (!document) {
|
2599
2639
|
return ctx.notFound();
|
2600
2640
|
}
|
2601
|
-
const { meta } = await
|
2641
|
+
const { meta } = await formatDocumentWithMetadata(
|
2642
|
+
permissionChecker2,
|
2602
2643
|
model,
|
2644
|
+
// @ts-expect-error - fix types
|
2603
2645
|
{ id: document.documentId, locale, publishedAt: null },
|
2604
2646
|
{ availableLocales: true, availableStatus: false }
|
2605
2647
|
);
|
@@ -2610,16 +2652,15 @@ const singleTypes = {
|
|
2610
2652
|
return ctx.forbidden();
|
2611
2653
|
}
|
2612
2654
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(version);
|
2613
|
-
ctx.body = await
|
2655
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
2614
2656
|
},
|
2615
2657
|
async createOrUpdate(ctx) {
|
2616
2658
|
const { userAbility } = ctx.state;
|
2617
2659
|
const { model } = ctx.params;
|
2618
|
-
const documentMetadata2 = getService$1("document-metadata");
|
2619
2660
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2620
2661
|
const document = await createOrUpdateDocument(ctx);
|
2621
2662
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(document);
|
2622
|
-
ctx.body = await
|
2663
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
2623
2664
|
},
|
2624
2665
|
async delete(ctx) {
|
2625
2666
|
const { userAbility } = ctx.state;
|
@@ -2632,7 +2673,7 @@ const singleTypes = {
|
|
2632
2673
|
}
|
2633
2674
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2634
2675
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2635
|
-
const { locale } = getDocumentLocaleAndStatus(query);
|
2676
|
+
const { locale } = await getDocumentLocaleAndStatus(query);
|
2636
2677
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2637
2678
|
populate,
|
2638
2679
|
locale
|
@@ -2655,7 +2696,6 @@ const singleTypes = {
|
|
2655
2696
|
const { model } = ctx.params;
|
2656
2697
|
const { query = {} } = ctx.request;
|
2657
2698
|
const documentManager2 = getService$1("document-manager");
|
2658
|
-
const documentMetadata2 = getService$1("document-metadata");
|
2659
2699
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2660
2700
|
if (permissionChecker2.cannot.publish()) {
|
2661
2701
|
return ctx.forbidden();
|
@@ -2670,11 +2710,12 @@ const singleTypes = {
|
|
2670
2710
|
if (permissionChecker2.cannot.publish(document)) {
|
2671
2711
|
throw new strapiUtils.errors.ForbiddenError();
|
2672
2712
|
}
|
2673
|
-
const { locale } = getDocumentLocaleAndStatus(document);
|
2674
|
-
|
2713
|
+
const { locale } = await getDocumentLocaleAndStatus(document);
|
2714
|
+
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2715
|
+
return publishResult.at(0);
|
2675
2716
|
});
|
2676
2717
|
const sanitizedDocument = await permissionChecker2.sanitizeOutput(publishedDocument);
|
2677
|
-
ctx.body = await
|
2718
|
+
ctx.body = await formatDocumentWithMetadata(permissionChecker2, model, sanitizedDocument);
|
2678
2719
|
},
|
2679
2720
|
async unpublish(ctx) {
|
2680
2721
|
const { userAbility } = ctx.state;
|
@@ -2684,7 +2725,6 @@ const singleTypes = {
|
|
2684
2725
|
query = {}
|
2685
2726
|
} = ctx.request;
|
2686
2727
|
const documentManager2 = getService$1("document-manager");
|
2687
|
-
const documentMetadata2 = getService$1("document-metadata");
|
2688
2728
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2689
2729
|
if (permissionChecker2.cannot.unpublish()) {
|
2690
2730
|
return ctx.forbidden();
|
@@ -2693,7 +2733,7 @@ const singleTypes = {
|
|
2693
2733
|
return ctx.forbidden();
|
2694
2734
|
}
|
2695
2735
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2696
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
2736
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
2697
2737
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2698
2738
|
if (!document) {
|
2699
2739
|
return ctx.notFound();
|
@@ -2711,7 +2751,7 @@ const singleTypes = {
|
|
2711
2751
|
ctx.body = await strapiUtils.async.pipe(
|
2712
2752
|
(document2) => documentManager2.unpublish(document2.documentId, model, { locale }),
|
2713
2753
|
permissionChecker2.sanitizeOutput,
|
2714
|
-
(document2) =>
|
2754
|
+
(document2) => formatDocumentWithMetadata(permissionChecker2, model, document2)
|
2715
2755
|
)(document);
|
2716
2756
|
});
|
2717
2757
|
},
|
@@ -2720,13 +2760,12 @@ const singleTypes = {
|
|
2720
2760
|
const { model } = ctx.params;
|
2721
2761
|
const { body, query = {} } = ctx.request;
|
2722
2762
|
const documentManager2 = getService$1("document-manager");
|
2723
|
-
const documentMetadata2 = getService$1("document-metadata");
|
2724
2763
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2725
2764
|
if (permissionChecker2.cannot.discard()) {
|
2726
2765
|
return ctx.forbidden();
|
2727
2766
|
}
|
2728
2767
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2729
|
-
const { locale } = getDocumentLocaleAndStatus(body);
|
2768
|
+
const { locale } = await getDocumentLocaleAndStatus(body);
|
2730
2769
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2731
2770
|
if (!document) {
|
2732
2771
|
return ctx.notFound();
|
@@ -2737,7 +2776,7 @@ const singleTypes = {
|
|
2737
2776
|
ctx.body = await strapiUtils.async.pipe(
|
2738
2777
|
(document2) => documentManager2.discardDraft(document2.documentId, model, { locale }),
|
2739
2778
|
permissionChecker2.sanitizeOutput,
|
2740
|
-
(document2) =>
|
2779
|
+
(document2) => formatDocumentWithMetadata(permissionChecker2, model, document2)
|
2741
2780
|
)(document);
|
2742
2781
|
},
|
2743
2782
|
async countDraftRelations(ctx) {
|
@@ -2746,7 +2785,7 @@ const singleTypes = {
|
|
2746
2785
|
const { query } = ctx.request;
|
2747
2786
|
const documentManager2 = getService$1("document-manager");
|
2748
2787
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2749
|
-
const { locale } = getDocumentLocaleAndStatus(query);
|
2788
|
+
const { locale } = await getDocumentLocaleAndStatus(query);
|
2750
2789
|
if (permissionChecker2.cannot.read()) {
|
2751
2790
|
return ctx.forbidden();
|
2752
2791
|
}
|
@@ -2767,7 +2806,7 @@ const uid$1 = {
|
|
2767
2806
|
async generateUID(ctx) {
|
2768
2807
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2769
2808
|
const { query = {} } = ctx.request;
|
2770
|
-
const { locale } = getDocumentLocaleAndStatus(query);
|
2809
|
+
const { locale } = await getDocumentLocaleAndStatus(query);
|
2771
2810
|
await validateUIDField(contentTypeUID, field);
|
2772
2811
|
const uidService = getService$1("uid");
|
2773
2812
|
ctx.body = {
|
@@ -2779,7 +2818,7 @@ const uid$1 = {
|
|
2779
2818
|
ctx.request.body
|
2780
2819
|
);
|
2781
2820
|
const { query = {} } = ctx.request;
|
2782
|
-
const { locale } = getDocumentLocaleAndStatus(query);
|
2821
|
+
const { locale } = await getDocumentLocaleAndStatus(query);
|
2783
2822
|
await validateUIDField(contentTypeUID, field);
|
2784
2823
|
const uidService = getService$1("uid");
|
2785
2824
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3570,7 +3609,7 @@ const permission = ({ strapi: strapi2 }) => ({
|
|
3570
3609
|
await strapi2.service("admin::permission").actionProvider.registerMany(actions);
|
3571
3610
|
}
|
3572
3611
|
});
|
3573
|
-
const { isVisibleAttribute: isVisibleAttribute$1 } = strapiUtils__default.default.contentTypes;
|
3612
|
+
const { isVisibleAttribute: isVisibleAttribute$1, isScalarAttribute, getDoesAttributeRequireValidation } = strapiUtils__default.default.contentTypes;
|
3574
3613
|
const { isAnyToMany } = strapiUtils__default.default.relations;
|
3575
3614
|
const { PUBLISHED_AT_ATTRIBUTE: PUBLISHED_AT_ATTRIBUTE$1 } = strapiUtils__default.default.contentTypes.constants;
|
3576
3615
|
const isMorphToRelation = (attribute) => isRelation(attribute) && attribute.relation.includes("morphTo");
|
@@ -3661,6 +3700,42 @@ const getDeepPopulate = (uid2, {
|
|
3661
3700
|
{}
|
3662
3701
|
);
|
3663
3702
|
};
|
3703
|
+
const getValidatableFieldsPopulate = (uid2, {
|
3704
|
+
initialPopulate = {},
|
3705
|
+
countMany = false,
|
3706
|
+
countOne = false,
|
3707
|
+
maxLevel = Infinity
|
3708
|
+
} = {}, level = 1) => {
|
3709
|
+
if (level > maxLevel) {
|
3710
|
+
return {};
|
3711
|
+
}
|
3712
|
+
const model = strapi.getModel(uid2);
|
3713
|
+
return Object.entries(model.attributes).reduce((populateAcc, [attributeName, attribute]) => {
|
3714
|
+
if (!getDoesAttributeRequireValidation(attribute)) {
|
3715
|
+
return populateAcc;
|
3716
|
+
}
|
3717
|
+
if (isScalarAttribute(attribute)) {
|
3718
|
+
return fp.merge(populateAcc, {
|
3719
|
+
[attributeName]: true
|
3720
|
+
});
|
3721
|
+
}
|
3722
|
+
return fp.merge(
|
3723
|
+
populateAcc,
|
3724
|
+
getPopulateFor(
|
3725
|
+
attributeName,
|
3726
|
+
model,
|
3727
|
+
{
|
3728
|
+
// @ts-expect-error - improve types
|
3729
|
+
initialPopulate: initialPopulate?.[attributeName],
|
3730
|
+
countMany,
|
3731
|
+
countOne,
|
3732
|
+
maxLevel
|
3733
|
+
},
|
3734
|
+
level
|
3735
|
+
)
|
3736
|
+
);
|
3737
|
+
}, {});
|
3738
|
+
};
|
3664
3739
|
const getDeepPopulateDraftCount = (uid2) => {
|
3665
3740
|
const model = strapi.getModel(uid2);
|
3666
3741
|
let hasRelations = false;
|
@@ -3682,22 +3757,24 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3682
3757
|
attribute.component
|
3683
3758
|
);
|
3684
3759
|
if (childHasRelations) {
|
3685
|
-
populateAcc[attributeName] = {
|
3760
|
+
populateAcc[attributeName] = {
|
3761
|
+
populate: populate2
|
3762
|
+
};
|
3686
3763
|
hasRelations = true;
|
3687
3764
|
}
|
3688
3765
|
break;
|
3689
3766
|
}
|
3690
3767
|
case "dynamiczone": {
|
3691
|
-
const
|
3692
|
-
const { populate:
|
3693
|
-
if (
|
3768
|
+
const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {
|
3769
|
+
const { populate: componentPopulate, hasRelations: componentHasRelations } = getDeepPopulateDraftCount(componentUID);
|
3770
|
+
if (componentHasRelations) {
|
3694
3771
|
hasRelations = true;
|
3695
|
-
return
|
3772
|
+
return { ...acc, [componentUID]: { populate: componentPopulate } };
|
3696
3773
|
}
|
3697
3774
|
return acc;
|
3698
3775
|
}, {});
|
3699
|
-
if (!fp.isEmpty(
|
3700
|
-
populateAcc[attributeName] = {
|
3776
|
+
if (!fp.isEmpty(dzPopulateFragment)) {
|
3777
|
+
populateAcc[attributeName] = { on: dzPopulateFragment };
|
3701
3778
|
}
|
3702
3779
|
break;
|
3703
3780
|
}
|
@@ -3889,41 +3966,70 @@ const AVAILABLE_STATUS_FIELDS = [
|
|
3889
3966
|
"updatedBy",
|
3890
3967
|
"status"
|
3891
3968
|
];
|
3892
|
-
const AVAILABLE_LOCALES_FIELDS = [
|
3969
|
+
const AVAILABLE_LOCALES_FIELDS = [
|
3970
|
+
"id",
|
3971
|
+
"locale",
|
3972
|
+
"updatedAt",
|
3973
|
+
"createdAt",
|
3974
|
+
"status",
|
3975
|
+
"publishedAt",
|
3976
|
+
"documentId"
|
3977
|
+
];
|
3893
3978
|
const CONTENT_MANAGER_STATUS = {
|
3894
3979
|
PUBLISHED: "published",
|
3895
3980
|
DRAFT: "draft",
|
3896
3981
|
MODIFIED: "modified"
|
3897
3982
|
};
|
3898
|
-
const
|
3899
|
-
if (!
|
3983
|
+
const getIsVersionLatestModification = (version, otherVersion) => {
|
3984
|
+
if (!version || !version.updatedAt) {
|
3900
3985
|
return false;
|
3901
3986
|
}
|
3902
|
-
const
|
3903
|
-
const
|
3904
|
-
|
3905
|
-
return difference <= threshold;
|
3987
|
+
const versionUpdatedAt = version?.updatedAt ? new Date(version.updatedAt).getTime() : 0;
|
3988
|
+
const otherUpdatedAt = otherVersion?.updatedAt ? new Date(otherVersion.updatedAt).getTime() : 0;
|
3989
|
+
return versionUpdatedAt > otherUpdatedAt;
|
3906
3990
|
};
|
3907
3991
|
const documentMetadata = ({ strapi: strapi2 }) => ({
|
3908
3992
|
/**
|
3909
3993
|
* Returns available locales of a document for the current status
|
3910
3994
|
*/
|
3911
|
-
getAvailableLocales(uid2, version, allVersions) {
|
3995
|
+
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
3912
3996
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
3913
3997
|
delete versionsByLocale[version.locale];
|
3914
|
-
|
3915
|
-
|
3916
|
-
|
3998
|
+
const model = strapi2.getModel(uid2);
|
3999
|
+
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4000
|
+
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
4001
|
+
({ key }, { remove }) => {
|
4002
|
+
if (keysToKeep.includes(key)) {
|
4003
|
+
return;
|
4004
|
+
}
|
4005
|
+
remove(key);
|
4006
|
+
},
|
4007
|
+
{ schema: model, getModel: strapi2.getModel.bind(strapi2) },
|
4008
|
+
// @ts-expect-error fix types DocumentVersion incompatible with Data
|
4009
|
+
localeVersion
|
4010
|
+
);
|
4011
|
+
const mappingResult = await strapiUtils.async.map(
|
4012
|
+
Object.values(versionsByLocale),
|
4013
|
+
async (localeVersions) => {
|
4014
|
+
const mappedLocaleVersions = await strapiUtils.async.map(
|
4015
|
+
localeVersions,
|
4016
|
+
traversalFunction
|
4017
|
+
);
|
4018
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(model)) {
|
4019
|
+
return mappedLocaleVersions[0];
|
4020
|
+
}
|
4021
|
+
const draftVersion = mappedLocaleVersions.find((v) => v.publishedAt === null);
|
4022
|
+
const otherVersions = mappedLocaleVersions.filter((v) => v.id !== draftVersion?.id);
|
4023
|
+
if (!draftVersion) {
|
4024
|
+
return;
|
4025
|
+
}
|
4026
|
+
return {
|
4027
|
+
...draftVersion,
|
4028
|
+
status: this.getStatus(draftVersion, otherVersions)
|
4029
|
+
};
|
3917
4030
|
}
|
3918
|
-
|
3919
|
-
|
3920
|
-
if (!draftVersion)
|
3921
|
-
return;
|
3922
|
-
return {
|
3923
|
-
...fp.pick(AVAILABLE_LOCALES_FIELDS, draftVersion),
|
3924
|
-
status: this.getStatus(draftVersion, otherVersions)
|
3925
|
-
};
|
3926
|
-
}).filter(Boolean);
|
4031
|
+
);
|
4032
|
+
return mappingResult.filter(Boolean);
|
3927
4033
|
},
|
3928
4034
|
/**
|
3929
4035
|
* Returns available status of a document for the current locale
|
@@ -3961,26 +4067,37 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
3961
4067
|
});
|
3962
4068
|
},
|
3963
4069
|
getStatus(version, otherDocumentStatuses) {
|
3964
|
-
|
3965
|
-
|
3966
|
-
|
4070
|
+
let draftVersion;
|
4071
|
+
let publishedVersion;
|
4072
|
+
if (version.publishedAt) {
|
4073
|
+
publishedVersion = version;
|
4074
|
+
} else {
|
4075
|
+
draftVersion = version;
|
3967
4076
|
}
|
3968
|
-
|
3969
|
-
|
3970
|
-
|
3971
|
-
|
3972
|
-
|
4077
|
+
const otherVersion = otherDocumentStatuses?.at(0);
|
4078
|
+
if (otherVersion?.publishedAt) {
|
4079
|
+
publishedVersion = otherVersion;
|
4080
|
+
} else if (otherVersion) {
|
4081
|
+
draftVersion = otherVersion;
|
3973
4082
|
}
|
3974
|
-
if (
|
4083
|
+
if (!draftVersion)
|
3975
4084
|
return CONTENT_MANAGER_STATUS.PUBLISHED;
|
3976
|
-
|
3977
|
-
|
4085
|
+
if (!publishedVersion)
|
4086
|
+
return CONTENT_MANAGER_STATUS.DRAFT;
|
4087
|
+
const isDraftModified = getIsVersionLatestModification(draftVersion, publishedVersion);
|
4088
|
+
return isDraftModified ? CONTENT_MANAGER_STATUS.MODIFIED : CONTENT_MANAGER_STATUS.PUBLISHED;
|
3978
4089
|
},
|
4090
|
+
// TODO is it necessary to return metadata on every page of the CM
|
4091
|
+
// We could refactor this so the locales are only loaded when they're
|
4092
|
+
// needed. e.g. in the bulk locale action modal.
|
3979
4093
|
async getMetadata(uid2, version, { availableLocales = true, availableStatus = true } = {}) {
|
4094
|
+
const populate = getValidatableFieldsPopulate(uid2);
|
3980
4095
|
const versions = await strapi2.db.query(uid2).findMany({
|
3981
4096
|
where: { documentId: version.documentId },
|
3982
|
-
select: ["createdAt", "updatedAt", "locale", "publishedAt", "documentId"],
|
3983
4097
|
populate: {
|
4098
|
+
// Populate only fields that require validation for bulk locale actions
|
4099
|
+
...populate,
|
4100
|
+
// NOTE: creator fields are selected in this way to avoid exposing sensitive data
|
3984
4101
|
createdBy: {
|
3985
4102
|
select: ["id", "firstname", "lastname", "email"]
|
3986
4103
|
},
|
@@ -3989,7 +4106,7 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
3989
4106
|
}
|
3990
4107
|
}
|
3991
4108
|
});
|
3992
|
-
const availableLocalesResult = availableLocales ? this.getAvailableLocales(uid2, version, versions) : [];
|
4109
|
+
const availableLocalesResult = availableLocales ? await this.getAvailableLocales(uid2, version, versions, Object.keys(populate)) : [];
|
3993
4110
|
const availableStatusResult = availableStatus ? this.getAvailableStatus(version, versions) : null;
|
3994
4111
|
return {
|
3995
4112
|
availableLocales: availableLocalesResult,
|
@@ -4002,8 +4119,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4002
4119
|
* - Available status of the document for the current locale
|
4003
4120
|
*/
|
4004
4121
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4005
|
-
if (!document)
|
4122
|
+
if (!document) {
|
4006
4123
|
return document;
|
4124
|
+
}
|
4007
4125
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4008
4126
|
if (!hasDraftAndPublish) {
|
4009
4127
|
opts.availableStatus = false;
|
@@ -4139,7 +4257,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4139
4257
|
return {};
|
4140
4258
|
},
|
4141
4259
|
// FIXME: handle relations
|
4142
|
-
async deleteMany(documentIds, uid2, opts) {
|
4260
|
+
async deleteMany(documentIds, uid2, opts = {}) {
|
4143
4261
|
const deletedEntries = await strapi2.db.transaction(async () => {
|
4144
4262
|
return Promise.all(documentIds.map(async (id) => this.delete(id, uid2, opts)));
|
4145
4263
|
});
|
@@ -4148,18 +4266,16 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4148
4266
|
async publish(id, uid2, opts = {}) {
|
4149
4267
|
const populate = await buildDeepPopulate(uid2);
|
4150
4268
|
const params = { ...opts, populate };
|
4151
|
-
return strapi2.documents(uid2).publish({ ...params, documentId: id }).then((result) => result?.entries
|
4269
|
+
return strapi2.documents(uid2).publish({ ...params, documentId: id }).then((result) => result?.entries);
|
4152
4270
|
},
|
4153
|
-
async publishMany(
|
4154
|
-
|
4155
|
-
|
4156
|
-
documentIds.map(
|
4157
|
-
(id) => strapi2.documents(uid2).publish({ ...opts, documentId: id }).then((result) => result?.entries)
|
4158
|
-
)
|
4271
|
+
async publishMany(uid2, documentIds, locale) {
|
4272
|
+
return strapi2.db.transaction(async () => {
|
4273
|
+
const results = await Promise.all(
|
4274
|
+
documentIds.map((documentId) => this.publish(documentId, uid2, { locale }))
|
4159
4275
|
);
|
4276
|
+
const publishedEntitiesCount = results.flat().filter(Boolean).length;
|
4277
|
+
return publishedEntitiesCount;
|
4160
4278
|
});
|
4161
|
-
const publishedEntitiesCount = publishedEntries.flat().filter(Boolean).length;
|
4162
|
-
return { count: publishedEntitiesCount };
|
4163
4279
|
},
|
4164
4280
|
async unpublishMany(documentIds, uid2, opts = {}) {
|
4165
4281
|
const unpublishedEntries = await strapi2.db.transaction(async () => {
|
@@ -4200,14 +4316,18 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4200
4316
|
if (!hasRelations) {
|
4201
4317
|
return 0;
|
4202
4318
|
}
|
4203
|
-
|
4319
|
+
let localeFilter = {};
|
4320
|
+
if (locale) {
|
4321
|
+
localeFilter = Array.isArray(locale) ? { locale: { $in: locale } } : { locale };
|
4322
|
+
}
|
4323
|
+
const entities = await strapi2.db.query(uid2).findMany({
|
4204
4324
|
populate,
|
4205
|
-
|
4206
|
-
documentId: documentIds
|
4207
|
-
|
4208
|
-
|
4325
|
+
where: {
|
4326
|
+
documentId: { $in: documentIds },
|
4327
|
+
...localeFilter
|
4328
|
+
}
|
4209
4329
|
});
|
4210
|
-
const totalNumberDraftRelations =
|
4330
|
+
const totalNumberDraftRelations = entities.reduce(
|
4211
4331
|
(count, entity) => sumDraftCounts(entity, uid2) + count,
|
4212
4332
|
0
|
4213
4333
|
);
|