@strapi/content-manager 0.0.0-experimental.bd712ad3930045f4a5d2144c119e0b7856e97fc4 → 0.0.0-experimental.c5235059f5636c4549ea2118c75c43b92e2615c8
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-BWQv6yRj.js → ComponentConfigurationPage-k6fnZytn.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BWQv6yRj.js.map → ComponentConfigurationPage-k6fnZytn.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-C7ImeKGM.mjs → ComponentConfigurationPage-o2HOTHL4.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-C7ImeKGM.mjs.map → ComponentConfigurationPage-o2HOTHL4.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CEGwxV-L.js → EditConfigurationPage-DKtok23W.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CEGwxV-L.js.map → EditConfigurationPage-DKtok23W.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-MItFGzT9.mjs → EditConfigurationPage-HNi0pVX4.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-MItFGzT9.mjs.map → EditConfigurationPage-HNi0pVX4.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CmMi2Xsn.js → EditViewPage-CrX5Iz3h.js} +3 -3
- package/dist/_chunks/{EditViewPage-CmMi2Xsn.js.map → EditViewPage-CrX5Iz3h.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-DhmAg0NK.mjs → EditViewPage-DGnFsrTV.mjs} +3 -3
- package/dist/_chunks/{EditViewPage-DhmAg0NK.mjs.map → EditViewPage-DGnFsrTV.mjs.map} +1 -1
- package/dist/_chunks/{Field-Cs62u5pl.mjs → Field-DlWgNyun.mjs} +8 -8
- package/dist/_chunks/Field-DlWgNyun.mjs.map +1 -0
- package/dist/_chunks/{Field-1DLtcLAI.js → Field-DvDdA59J.js} +8 -8
- package/dist/_chunks/Field-DvDdA59J.js.map +1 -0
- package/dist/_chunks/{Form-zYHtzGUX.mjs → Form-B7VJjkXr.mjs} +2 -2
- package/dist/_chunks/{Form-zYHtzGUX.mjs.map → Form-B7VJjkXr.mjs.map} +1 -1
- package/dist/_chunks/{Form-CqFA7F_V.js → Form-D9w2wzOa.js} +2 -2
- package/dist/_chunks/{Form-CqFA7F_V.js.map → Form-D9w2wzOa.js.map} +1 -1
- package/dist/_chunks/{History-DalgFQ3D.mjs → History-84QY4Lau.mjs} +21 -11
- package/dist/_chunks/History-84QY4Lau.mjs.map +1 -0
- package/dist/_chunks/{History-BblwXv7-.js → History-GCscEVds.js} +21 -11
- package/dist/_chunks/History-GCscEVds.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DWy-vRzs.mjs → ListConfigurationPage-C_S6OFYL.mjs} +2 -2
- package/dist/_chunks/{ListConfigurationPage-DWy-vRzs.mjs.map → ListConfigurationPage-C_S6OFYL.mjs.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-Cpy4QqNd.js → ListConfigurationPage-Ck-lKA_g.js} +2 -2
- package/dist/_chunks/{ListConfigurationPage-Cpy4QqNd.js.map → ListConfigurationPage-Ck-lKA_g.js.map} +1 -1
- package/dist/_chunks/{ListViewPage-DFjn1DNW.js → ListViewPage-D1vAbQW4.js} +9 -4
- package/dist/_chunks/ListViewPage-D1vAbQW4.js.map +1 -0
- package/dist/_chunks/{ListViewPage-BkAwIW9s.mjs → ListViewPage-DkQT6AN6.mjs} +10 -5
- package/dist/_chunks/ListViewPage-DkQT6AN6.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-B9BCNNdL.mjs → NoContentTypePage-D5QYn9pN.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-B9BCNNdL.mjs.map → NoContentTypePage-D5QYn9pN.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-C-3ykoxs.js → NoContentTypePage-DnMToxdO.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-C-3ykoxs.js.map → NoContentTypePage-DnMToxdO.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DKLmDZnZ.js → NoPermissionsPage-COirbirm.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DKLmDZnZ.js.map → NoPermissionsPage-COirbirm.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-Bt_HWGat.mjs → NoPermissionsPage-eV9XOUs6.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-Bt_HWGat.mjs.map → NoPermissionsPage-eV9XOUs6.mjs.map} +1 -1
- package/dist/_chunks/{Relations-CJmTbZ8T.mjs → Relations-CMu33f0Q.mjs} +3 -3
- package/dist/_chunks/Relations-CMu33f0Q.mjs.map +1 -0
- package/dist/_chunks/{Relations-CrxfoH2n.js → Relations-CvSHeSTB.js} +3 -3
- package/dist/_chunks/Relations-CvSHeSTB.js.map +1 -0
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-BrCTWlZv.mjs} +5 -4
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
- package/dist/_chunks/{en-fbKQxLGn.js → en-uOUIxfcQ.js} +5 -4
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-uOUIxfcQ.js.map} +1 -1
- package/dist/_chunks/{index-Buwn78Rt.js → index-BU73akFF.js} +244 -139
- package/dist/_chunks/index-BU73akFF.js.map +1 -0
- package/dist/_chunks/{index-D1344xdw.mjs → index-DYjyBm-q.mjs} +247 -142
- package/dist/_chunks/index-DYjyBm-q.mjs.map +1 -0
- package/dist/_chunks/{layout-ChVuUpa1.mjs → layout-CK49ltFD.mjs} +17 -5
- package/dist/_chunks/{layout-ChVuUpa1.mjs.map → layout-CK49ltFD.mjs.map} +1 -1
- package/dist/_chunks/{layout-DRuJUpas.js → layout-IJUR2XBA.js} +16 -4
- package/dist/_chunks/{layout-DRuJUpas.js.map → layout-IJUR2XBA.js.map} +1 -1
- package/dist/_chunks/{relations-B-deMCy4.mjs → relations-Dl8Jk9_i.mjs} +2 -2
- package/dist/_chunks/{relations-B-deMCy4.mjs.map → relations-Dl8Jk9_i.mjs.map} +1 -1
- package/dist/_chunks/{relations-DuoUwyJr.js → relations-T1zuutNL.js} +2 -2
- package/dist/_chunks/{relations-DuoUwyJr.js.map → relations-T1zuutNL.js.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
- package/dist/server/index.js +130 -85
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +131 -86
- 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/uid.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +1 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/package.json +6 -6
- package/dist/_chunks/Field-1DLtcLAI.js.map +0 -1
- package/dist/_chunks/Field-Cs62u5pl.mjs.map +0 -1
- package/dist/_chunks/History-BblwXv7-.js.map +0 -1
- package/dist/_chunks/History-DalgFQ3D.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BkAwIW9s.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-DFjn1DNW.js.map +0 -1
- package/dist/_chunks/Relations-CJmTbZ8T.mjs.map +0 -1
- package/dist/_chunks/Relations-CrxfoH2n.js.map +0 -1
- package/dist/_chunks/index-Buwn78Rt.js.map +0 -1
- package/dist/_chunks/index-D1344xdw.mjs.map +0 -1
package/dist/server/index.mjs
CHANGED
@@ -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,
|
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";
|
@@ -200,9 +200,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
200
200
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
201
201
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
202
202
|
};
|
203
|
-
const getDeepPopulate2 = (uid2) => {
|
203
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
204
204
|
const model = strapi2.getModel(uid2);
|
205
205
|
const attributes = Object.entries(model.attributes);
|
206
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
206
207
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
207
208
|
switch (attribute.type) {
|
208
209
|
case "relation": {
|
@@ -212,12 +213,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
212
213
|
}
|
213
214
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
214
215
|
if (isVisible2) {
|
215
|
-
acc[attributeName] = {
|
216
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
216
217
|
}
|
217
218
|
break;
|
218
219
|
}
|
219
220
|
case "media": {
|
220
|
-
acc[attributeName] = {
|
221
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
221
222
|
break;
|
222
223
|
}
|
223
224
|
case "component": {
|
@@ -468,6 +469,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
468
469
|
}
|
469
470
|
};
|
470
471
|
};
|
472
|
+
const shouldCreateHistoryVersion = (context) => {
|
473
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
474
|
+
return false;
|
475
|
+
}
|
476
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
477
|
+
return false;
|
478
|
+
}
|
479
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
480
|
+
return false;
|
481
|
+
}
|
482
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
return true;
|
486
|
+
};
|
487
|
+
const getSchemas = (uid2) => {
|
488
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
489
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
490
|
+
(currentComponentSchemas, key) => {
|
491
|
+
const fieldSchema = attributesSchema[key];
|
492
|
+
if (fieldSchema.type === "component") {
|
493
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
494
|
+
return {
|
495
|
+
...currentComponentSchemas,
|
496
|
+
[fieldSchema.component]: componentSchema
|
497
|
+
};
|
498
|
+
}
|
499
|
+
return currentComponentSchemas;
|
500
|
+
},
|
501
|
+
{}
|
502
|
+
);
|
503
|
+
return {
|
504
|
+
schema: omit(FIELDS_TO_IGNORE, attributesSchema),
|
505
|
+
componentsSchemas
|
506
|
+
};
|
507
|
+
};
|
471
508
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
472
509
|
const state = {
|
473
510
|
deleteExpiredJob: null,
|
@@ -480,63 +517,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
480
517
|
return;
|
481
518
|
}
|
482
519
|
strapi2.documents.use(async (context, next) => {
|
483
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
484
|
-
return next();
|
485
|
-
}
|
486
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
487
|
-
return next();
|
488
|
-
}
|
489
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
490
|
-
return next();
|
491
|
-
}
|
492
|
-
const contentTypeUid = context.contentType.uid;
|
493
|
-
if (!contentTypeUid.startsWith("api::")) {
|
494
|
-
return next();
|
495
|
-
}
|
496
520
|
const result = await next();
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
501
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
502
|
-
const
|
503
|
-
if (
|
504
|
-
|
505
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
506
|
-
);
|
507
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
508
529
|
}
|
509
|
-
const
|
510
|
-
|
511
|
-
|
512
|
-
|
530
|
+
const uid2 = context.contentType.uid;
|
531
|
+
const schemas = getSchemas(uid2);
|
532
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
533
|
+
where: {
|
534
|
+
documentId,
|
535
|
+
locale: { $in: locales },
|
536
|
+
publishedAt: null
|
537
|
+
},
|
538
|
+
populate: serviceUtils.getDeepPopulate(
|
539
|
+
uid2,
|
540
|
+
true
|
541
|
+
/* use database syntax */
|
542
|
+
)
|
513
543
|
});
|
514
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
515
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
516
|
-
const componentsSchemas = Object.keys(
|
517
|
-
attributesSchema
|
518
|
-
).reduce((currentComponentSchemas, key) => {
|
519
|
-
const fieldSchema = attributesSchema[key];
|
520
|
-
if (fieldSchema.type === "component") {
|
521
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
522
|
-
return {
|
523
|
-
...currentComponentSchemas,
|
524
|
-
[fieldSchema.component]: componentSchema
|
525
|
-
};
|
526
|
-
}
|
527
|
-
return currentComponentSchemas;
|
528
|
-
}, {});
|
529
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
530
|
-
onCommit(() => {
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
545
|
+
onCommit(async () => {
|
546
|
+
for (const entry of localeEntries) {
|
547
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
548
|
+
await getService(strapi2, "history").createVersion({
|
549
|
+
contentType: uid2,
|
550
|
+
data: omit(FIELDS_TO_IGNORE, entry),
|
551
|
+
relatedDocumentId: documentId,
|
552
|
+
locale: entry.locale,
|
553
|
+
status,
|
554
|
+
...schemas
|
555
|
+
});
|
556
|
+
}
|
540
557
|
});
|
541
558
|
});
|
542
559
|
return result;
|
@@ -1569,9 +1586,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1569
1586
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1570
1587
|
);
|
1571
1588
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1572
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1589
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1573
1590
|
const { allowMultipleLocales } = opts;
|
1574
|
-
const { locale, status, ...rest } = request || {};
|
1591
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1592
|
+
const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1593
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1575
1594
|
const schema = yup$1.object().shape({
|
1576
1595
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1577
1596
|
status: statusSchema
|
@@ -1619,7 +1638,7 @@ const createDocument = async (ctx, opts) => {
|
|
1619
1638
|
const setCreator = setCreatorFields({ user });
|
1620
1639
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1621
1640
|
const sanitizedBody = await sanitizeFn(body);
|
1622
|
-
const { locale, status
|
1641
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1623
1642
|
return documentManager2.create(model, {
|
1624
1643
|
data: sanitizedBody,
|
1625
1644
|
locale,
|
@@ -1638,7 +1657,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1638
1657
|
}
|
1639
1658
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1640
1659
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1641
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1660
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1642
1661
|
const [documentVersion, documentExists] = await Promise.all([
|
1643
1662
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1644
1663
|
documentManager2.exists(model, id)
|
@@ -1676,7 +1695,7 @@ const collectionTypes = {
|
|
1676
1695
|
}
|
1677
1696
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1678
1697
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1679
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1698
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1680
1699
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1681
1700
|
{ ...permissionQuery, populate, locale, status },
|
1682
1701
|
model
|
@@ -1711,7 +1730,7 @@ const collectionTypes = {
|
|
1711
1730
|
}
|
1712
1731
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1713
1732
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1714
|
-
const { locale, status
|
1733
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1715
1734
|
const version = await documentManager2.findOne(id, model, {
|
1716
1735
|
populate,
|
1717
1736
|
locale,
|
@@ -1778,7 +1797,7 @@ const collectionTypes = {
|
|
1778
1797
|
}
|
1779
1798
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1780
1799
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1781
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1800
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1782
1801
|
const document = await documentManager2.findOne(id, model, {
|
1783
1802
|
populate,
|
1784
1803
|
locale,
|
@@ -1823,7 +1842,7 @@ const collectionTypes = {
|
|
1823
1842
|
}
|
1824
1843
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1825
1844
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1826
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1845
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1827
1846
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1828
1847
|
if (documentLocales.length === 0) {
|
1829
1848
|
return ctx.notFound();
|
@@ -1852,11 +1871,28 @@ const collectionTypes = {
|
|
1852
1871
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1853
1872
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1854
1873
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1855
|
-
|
1874
|
+
let document;
|
1875
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1876
|
+
const isCreate = isNil$1(id);
|
1877
|
+
if (isCreate) {
|
1878
|
+
if (permissionChecker2.cannot.create()) {
|
1879
|
+
throw new errors.ForbiddenError();
|
1880
|
+
}
|
1881
|
+
document = await createDocument(ctx, { populate });
|
1882
|
+
}
|
1883
|
+
const isUpdate = !isCreate;
|
1884
|
+
if (isUpdate) {
|
1885
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1886
|
+
if (!document) {
|
1887
|
+
throw new errors.NotFoundError("Document not found");
|
1888
|
+
}
|
1889
|
+
if (permissionChecker2.can.update(document)) {
|
1890
|
+
await updateDocument(ctx);
|
1891
|
+
}
|
1892
|
+
}
|
1856
1893
|
if (permissionChecker2.cannot.publish(document)) {
|
1857
1894
|
throw new errors.ForbiddenError();
|
1858
1895
|
}
|
1859
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1860
1896
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1861
1897
|
locale
|
1862
1898
|
// TODO: Allow setting creator fields on publish
|
@@ -1883,7 +1919,9 @@ const collectionTypes = {
|
|
1883
1919
|
}
|
1884
1920
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1885
1921
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1886
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1922
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1923
|
+
allowMultipleLocales: true
|
1924
|
+
});
|
1887
1925
|
const entityPromises = documentIds.map(
|
1888
1926
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1889
1927
|
);
|
@@ -1910,7 +1948,7 @@ const collectionTypes = {
|
|
1910
1948
|
if (permissionChecker2.cannot.unpublish()) {
|
1911
1949
|
return ctx.forbidden();
|
1912
1950
|
}
|
1913
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1951
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1914
1952
|
const entityPromises = documentIds.map(
|
1915
1953
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1916
1954
|
);
|
@@ -1943,7 +1981,7 @@ const collectionTypes = {
|
|
1943
1981
|
}
|
1944
1982
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1945
1983
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1946
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1984
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1947
1985
|
const document = await documentManager2.findOne(id, model, {
|
1948
1986
|
populate,
|
1949
1987
|
locale,
|
@@ -1980,7 +2018,7 @@ const collectionTypes = {
|
|
1980
2018
|
}
|
1981
2019
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1982
2020
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1983
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2021
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1984
2022
|
const document = await documentManager2.findOne(id, model, {
|
1985
2023
|
populate,
|
1986
2024
|
locale,
|
@@ -2011,7 +2049,7 @@ const collectionTypes = {
|
|
2011
2049
|
}
|
2012
2050
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2013
2051
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2014
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2052
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2015
2053
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2016
2054
|
populate,
|
2017
2055
|
locale
|
@@ -2038,7 +2076,7 @@ const collectionTypes = {
|
|
2038
2076
|
}
|
2039
2077
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2040
2078
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2041
|
-
const { locale, status
|
2079
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2042
2080
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2043
2081
|
if (!entity) {
|
2044
2082
|
return ctx.notFound();
|
@@ -2566,7 +2604,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2566
2604
|
throw new errors.ForbiddenError();
|
2567
2605
|
}
|
2568
2606
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2569
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2607
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2570
2608
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2571
2609
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2572
2610
|
// Find the first document to check if it exists
|
@@ -2607,7 +2645,7 @@ const singleTypes = {
|
|
2607
2645
|
return ctx.forbidden();
|
2608
2646
|
}
|
2609
2647
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2610
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2648
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2611
2649
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2612
2650
|
if (!version) {
|
2613
2651
|
if (permissionChecker2.cannot.create()) {
|
@@ -2652,7 +2690,7 @@ const singleTypes = {
|
|
2652
2690
|
}
|
2653
2691
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2654
2692
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2655
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2693
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2656
2694
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2657
2695
|
populate,
|
2658
2696
|
locale
|
@@ -2689,7 +2727,7 @@ const singleTypes = {
|
|
2689
2727
|
if (permissionChecker2.cannot.publish(document)) {
|
2690
2728
|
throw new errors.ForbiddenError();
|
2691
2729
|
}
|
2692
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2730
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2693
2731
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2694
2732
|
return publishResult.at(0);
|
2695
2733
|
});
|
@@ -2712,7 +2750,7 @@ const singleTypes = {
|
|
2712
2750
|
return ctx.forbidden();
|
2713
2751
|
}
|
2714
2752
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2715
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2753
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2716
2754
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2717
2755
|
if (!document) {
|
2718
2756
|
return ctx.notFound();
|
@@ -2744,7 +2782,7 @@ const singleTypes = {
|
|
2744
2782
|
return ctx.forbidden();
|
2745
2783
|
}
|
2746
2784
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2747
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2785
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2748
2786
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2749
2787
|
if (!document) {
|
2750
2788
|
return ctx.notFound();
|
@@ -2764,7 +2802,7 @@ const singleTypes = {
|
|
2764
2802
|
const { query } = ctx.request;
|
2765
2803
|
const documentManager2 = getService$1("document-manager");
|
2766
2804
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2767
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2805
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2768
2806
|
if (permissionChecker2.cannot.read()) {
|
2769
2807
|
return ctx.forbidden();
|
2770
2808
|
}
|
@@ -2785,7 +2823,7 @@ const uid$1 = {
|
|
2785
2823
|
async generateUID(ctx) {
|
2786
2824
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2787
2825
|
const { query = {} } = ctx.request;
|
2788
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2826
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2789
2827
|
await validateUIDField(contentTypeUID, field);
|
2790
2828
|
const uidService = getService$1("uid");
|
2791
2829
|
ctx.body = {
|
@@ -2797,7 +2835,7 @@ const uid$1 = {
|
|
2797
2835
|
ctx.request.body
|
2798
2836
|
);
|
2799
2837
|
const { query = {} } = ctx.request;
|
2800
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2838
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2801
2839
|
await validateUIDField(contentTypeUID, field);
|
2802
2840
|
const uidService = getService$1("uid");
|
2803
2841
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3722,6 +3760,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3722
3760
|
const attribute = model.attributes[attributeName];
|
3723
3761
|
switch (attribute.type) {
|
3724
3762
|
case "relation": {
|
3763
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3764
|
+
if (isMorphRelation) {
|
3765
|
+
break;
|
3766
|
+
}
|
3725
3767
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3726
3768
|
populateAcc[attributeName] = {
|
3727
3769
|
count: true,
|
@@ -4099,7 +4141,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4099
4141
|
*/
|
4100
4142
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4101
4143
|
if (!document) {
|
4102
|
-
return
|
4144
|
+
return {
|
4145
|
+
data: document,
|
4146
|
+
meta: {
|
4147
|
+
availableLocales: [],
|
4148
|
+
availableStatus: []
|
4149
|
+
}
|
4150
|
+
};
|
4103
4151
|
}
|
4104
4152
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4105
4153
|
if (!hasDraftAndPublish) {
|
@@ -4207,10 +4255,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4207
4255
|
async clone(id, body, uid2) {
|
4208
4256
|
const populate = await buildDeepPopulate(uid2);
|
4209
4257
|
const params = {
|
4210
|
-
data:
|
4211
|
-
...omitIdField(body),
|
4212
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4213
|
-
},
|
4258
|
+
data: omitIdField(body),
|
4214
4259
|
populate
|
4215
4260
|
};
|
4216
4261
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|