@strapi/content-manager 0.0.0-experimental.5b211b38912691ee2eab22d47b5095ea2fcfec76 → 0.0.0-experimental.5e04dee5c96cd68273df3b3cadf4635e19dc2afc
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/LICENSE +18 -3
- package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs → ComponentConfigurationPage-B3yDbeU1.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DmwmiFQy.mjs.map → ComponentConfigurationPage-B3yDbeU1.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js → ComponentConfigurationPage-KXSuLnQD.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-C-49MccQ.js.map → ComponentConfigurationPage-KXSuLnQD.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js → EditConfigurationPage-BQ17--5R.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DjFJw56M.js.map → EditConfigurationPage-BQ17--5R.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs → EditConfigurationPage-D7PrLO8j.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-JT3E7NZy.mjs.map → EditConfigurationPage-D7PrLO8j.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CPj61RMh.mjs → EditViewPage-B7VgwJaG.mjs} +18 -7
- package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-zT3fBr4Y.js → EditViewPage-BgjdnGz2.js} +18 -7
- package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +1 -0
- package/dist/_chunks/{Field-Boxf9Ajp.js → Field-CdK7ZLmv.js} +165 -81
- package/dist/_chunks/Field-CdK7ZLmv.js.map +1 -0
- package/dist/_chunks/{Field-dha5VnIQ.mjs → Field-tHCw4lGA.mjs} +166 -82
- package/dist/_chunks/Field-tHCw4lGA.mjs.map +1 -0
- package/dist/_chunks/{Form-DHrru2AV.mjs → Form-BJxdTv3Q.mjs} +22 -11
- package/dist/_chunks/Form-BJxdTv3Q.mjs.map +1 -0
- package/dist/_chunks/{Form-y5g1SRsh.js → Form-C_0KTVvV.js} +22 -11
- package/dist/_chunks/Form-C_0KTVvV.js.map +1 -0
- package/dist/_chunks/{History-Bru_KoeP.mjs → History-DR2txJLE.mjs} +44 -19
- package/dist/_chunks/History-DR2txJLE.mjs.map +1 -0
- package/dist/_chunks/{History-CqN6K7SX.js → History-nuEzM5qm.js} +44 -19
- package/dist/_chunks/History-nuEzM5qm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-R_p-SbHZ.js → ListConfigurationPage-CnB86Psm.js} +20 -8
- package/dist/_chunks/ListConfigurationPage-CnB86Psm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-D8wGABj0.mjs → ListConfigurationPage-voFVtXu6.mjs} +20 -8
- package/dist/_chunks/ListConfigurationPage-voFVtXu6.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-SID6TRb9.mjs → ListViewPage-B_GaWgRH.mjs} +22 -8
- package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-pEw_zug9.js → ListViewPage-SXIXm-RM.js} +21 -7
- package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-C5dcQojD.js → NoContentTypePage-BzsQ3hLZ.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-C5dcQojD.js.map → NoContentTypePage-BzsQ3hLZ.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs → NoContentTypePage-CYiGpsbj.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CJ7UXwrQ.mjs.map → NoContentTypePage-CYiGpsbj.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs → NoPermissionsPage-B5baIHal.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-B7syEq5E.mjs.map → NoPermissionsPage-B5baIHal.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js → NoPermissionsPage-IGkId4C5.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BtPrImPP.js.map → NoPermissionsPage-IGkId4C5.js.map} +1 -1
- package/dist/_chunks/{Relations-B9Crnhnn.mjs → Relations-CIYDdKU-.mjs} +4 -4
- package/dist/_chunks/Relations-CIYDdKU-.mjs.map +1 -0
- package/dist/_chunks/{Relations-DjTQ5kGB.js → Relations-Dhuurpx2.js} +4 -4
- package/dist/_chunks/Relations-Dhuurpx2.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-DJXJw9V5.mjs → index-C9TJPyni.mjs} +317 -138
- package/dist/_chunks/index-C9TJPyni.mjs.map +1 -0
- package/dist/_chunks/{index-DVPWZkbS.js → index-CdT0kHZ8.js} +314 -135
- package/dist/_chunks/index-CdT0kHZ8.js.map +1 -0
- package/dist/_chunks/{layout-Bau7ZfLV.mjs → layout-BNqvLR_b.mjs} +23 -11
- package/dist/_chunks/layout-BNqvLR_b.mjs.map +1 -0
- package/dist/_chunks/{layout-Dm6fbiQj.js → layout-C6dxWYT7.js} +22 -10
- package/dist/_chunks/layout-C6dxWYT7.js.map +1 -0
- package/dist/_chunks/{relations-BH_kBSJ0.mjs → relations-CkKqKw65.mjs} +2 -2
- package/dist/_chunks/{relations-BH_kBSJ0.mjs.map → relations-CkKqKw65.mjs.map} +1 -1
- package/dist/_chunks/{relations-CKnpRgrN.js → relations-DtFaDnP1.js} +2 -2
- package/dist/_chunks/{relations-CKnpRgrN.js.map → relations-DtFaDnP1.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/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +10 -22
- package/dist/server/index.js +134 -85
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +135 -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 +8 -8
- package/dist/_chunks/EditViewPage-CPj61RMh.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-zT3fBr4Y.js.map +0 -1
- package/dist/_chunks/Field-Boxf9Ajp.js.map +0 -1
- package/dist/_chunks/Field-dha5VnIQ.mjs.map +0 -1
- package/dist/_chunks/Form-DHrru2AV.mjs.map +0 -1
- package/dist/_chunks/Form-y5g1SRsh.js.map +0 -1
- package/dist/_chunks/History-Bru_KoeP.mjs.map +0 -1
- package/dist/_chunks/History-CqN6K7SX.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-D8wGABj0.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-R_p-SbHZ.js.map +0 -1
- package/dist/_chunks/ListViewPage-SID6TRb9.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-pEw_zug9.js.map +0 -1
- package/dist/_chunks/Relations-B9Crnhnn.mjs.map +0 -1
- package/dist/_chunks/Relations-DjTQ5kGB.js.map +0 -1
- package/dist/_chunks/index-DJXJw9V5.mjs.map +0 -1
- package/dist/_chunks/index-DVPWZkbS.js.map +0 -1
- package/dist/_chunks/layout-Bau7ZfLV.mjs.map +0 -1
- package/dist/_chunks/layout-Dm6fbiQj.js.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,20 +200,25 @@ 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": {
|
210
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
211
|
+
if (isMorphRelation) {
|
212
|
+
break;
|
213
|
+
}
|
209
214
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
210
215
|
if (isVisible2) {
|
211
|
-
acc[attributeName] = {
|
216
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
212
217
|
}
|
213
218
|
break;
|
214
219
|
}
|
215
220
|
case "media": {
|
216
|
-
acc[attributeName] = {
|
221
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
217
222
|
break;
|
218
223
|
}
|
219
224
|
case "component": {
|
@@ -464,6 +469,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
464
469
|
}
|
465
470
|
};
|
466
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
|
+
};
|
467
508
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
468
509
|
const state = {
|
469
510
|
deleteExpiredJob: null,
|
@@ -476,63 +517,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
476
517
|
return;
|
477
518
|
}
|
478
519
|
strapi2.documents.use(async (context, next) => {
|
479
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
480
|
-
return next();
|
481
|
-
}
|
482
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
483
|
-
return next();
|
484
|
-
}
|
485
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
486
|
-
return next();
|
487
|
-
}
|
488
|
-
const contentTypeUid = context.contentType.uid;
|
489
|
-
if (!contentTypeUid.startsWith("api::")) {
|
490
|
-
return next();
|
491
|
-
}
|
492
520
|
const result = await next();
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
497
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
498
|
-
const
|
499
|
-
if (
|
500
|
-
|
501
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
502
|
-
);
|
503
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
504
529
|
}
|
505
|
-
const
|
506
|
-
|
507
|
-
|
508
|
-
|
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
|
+
)
|
509
543
|
});
|
510
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
511
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
512
|
-
const componentsSchemas = Object.keys(
|
513
|
-
attributesSchema
|
514
|
-
).reduce((currentComponentSchemas, key) => {
|
515
|
-
const fieldSchema = attributesSchema[key];
|
516
|
-
if (fieldSchema.type === "component") {
|
517
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
518
|
-
return {
|
519
|
-
...currentComponentSchemas,
|
520
|
-
[fieldSchema.component]: componentSchema
|
521
|
-
};
|
522
|
-
}
|
523
|
-
return currentComponentSchemas;
|
524
|
-
}, {});
|
525
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
526
|
-
onCommit(() => {
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
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
|
+
}
|
536
557
|
});
|
537
558
|
});
|
538
559
|
return result;
|
@@ -1565,9 +1586,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1565
1586
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1566
1587
|
);
|
1567
1588
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1568
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1589
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1569
1590
|
const { allowMultipleLocales } = opts;
|
1570
|
-
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;
|
1571
1594
|
const schema = yup$1.object().shape({
|
1572
1595
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1573
1596
|
status: statusSchema
|
@@ -1615,7 +1638,7 @@ const createDocument = async (ctx, opts) => {
|
|
1615
1638
|
const setCreator = setCreatorFields({ user });
|
1616
1639
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1617
1640
|
const sanitizedBody = await sanitizeFn(body);
|
1618
|
-
const { locale, status
|
1641
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1619
1642
|
return documentManager2.create(model, {
|
1620
1643
|
data: sanitizedBody,
|
1621
1644
|
locale,
|
@@ -1634,7 +1657,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1634
1657
|
}
|
1635
1658
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1636
1659
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1637
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1660
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1638
1661
|
const [documentVersion, documentExists] = await Promise.all([
|
1639
1662
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1640
1663
|
documentManager2.exists(model, id)
|
@@ -1672,7 +1695,7 @@ const collectionTypes = {
|
|
1672
1695
|
}
|
1673
1696
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1674
1697
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1675
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1698
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1676
1699
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1677
1700
|
{ ...permissionQuery, populate, locale, status },
|
1678
1701
|
model
|
@@ -1707,7 +1730,7 @@ const collectionTypes = {
|
|
1707
1730
|
}
|
1708
1731
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1709
1732
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1710
|
-
const { locale, status
|
1733
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1711
1734
|
const version = await documentManager2.findOne(id, model, {
|
1712
1735
|
populate,
|
1713
1736
|
locale,
|
@@ -1774,7 +1797,7 @@ const collectionTypes = {
|
|
1774
1797
|
}
|
1775
1798
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1776
1799
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1777
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1800
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1778
1801
|
const document = await documentManager2.findOne(id, model, {
|
1779
1802
|
populate,
|
1780
1803
|
locale,
|
@@ -1819,7 +1842,7 @@ const collectionTypes = {
|
|
1819
1842
|
}
|
1820
1843
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1821
1844
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1822
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1845
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1823
1846
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1824
1847
|
if (documentLocales.length === 0) {
|
1825
1848
|
return ctx.notFound();
|
@@ -1848,11 +1871,28 @@ const collectionTypes = {
|
|
1848
1871
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1849
1872
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1850
1873
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1851
|
-
|
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
|
+
}
|
1852
1893
|
if (permissionChecker2.cannot.publish(document)) {
|
1853
1894
|
throw new errors.ForbiddenError();
|
1854
1895
|
}
|
1855
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1856
1896
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1857
1897
|
locale
|
1858
1898
|
// TODO: Allow setting creator fields on publish
|
@@ -1879,7 +1919,9 @@ const collectionTypes = {
|
|
1879
1919
|
}
|
1880
1920
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1881
1921
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1882
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1922
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1923
|
+
allowMultipleLocales: true
|
1924
|
+
});
|
1883
1925
|
const entityPromises = documentIds.map(
|
1884
1926
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1885
1927
|
);
|
@@ -1906,7 +1948,7 @@ const collectionTypes = {
|
|
1906
1948
|
if (permissionChecker2.cannot.unpublish()) {
|
1907
1949
|
return ctx.forbidden();
|
1908
1950
|
}
|
1909
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1951
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1910
1952
|
const entityPromises = documentIds.map(
|
1911
1953
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1912
1954
|
);
|
@@ -1939,7 +1981,7 @@ const collectionTypes = {
|
|
1939
1981
|
}
|
1940
1982
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1941
1983
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1942
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1984
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1943
1985
|
const document = await documentManager2.findOne(id, model, {
|
1944
1986
|
populate,
|
1945
1987
|
locale,
|
@@ -1976,7 +2018,7 @@ const collectionTypes = {
|
|
1976
2018
|
}
|
1977
2019
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1978
2020
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1979
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2021
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1980
2022
|
const document = await documentManager2.findOne(id, model, {
|
1981
2023
|
populate,
|
1982
2024
|
locale,
|
@@ -2007,7 +2049,7 @@ const collectionTypes = {
|
|
2007
2049
|
}
|
2008
2050
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2009
2051
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2010
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2052
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2011
2053
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2012
2054
|
populate,
|
2013
2055
|
locale
|
@@ -2034,7 +2076,7 @@ const collectionTypes = {
|
|
2034
2076
|
}
|
2035
2077
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2036
2078
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2037
|
-
const { locale, status
|
2079
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2038
2080
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2039
2081
|
if (!entity) {
|
2040
2082
|
return ctx.notFound();
|
@@ -2562,7 +2604,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2562
2604
|
throw new errors.ForbiddenError();
|
2563
2605
|
}
|
2564
2606
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2565
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2607
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2566
2608
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2567
2609
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2568
2610
|
// Find the first document to check if it exists
|
@@ -2603,7 +2645,7 @@ const singleTypes = {
|
|
2603
2645
|
return ctx.forbidden();
|
2604
2646
|
}
|
2605
2647
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2606
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2648
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2607
2649
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2608
2650
|
if (!version) {
|
2609
2651
|
if (permissionChecker2.cannot.create()) {
|
@@ -2648,7 +2690,7 @@ const singleTypes = {
|
|
2648
2690
|
}
|
2649
2691
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2650
2692
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2651
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2693
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2652
2694
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2653
2695
|
populate,
|
2654
2696
|
locale
|
@@ -2685,7 +2727,7 @@ const singleTypes = {
|
|
2685
2727
|
if (permissionChecker2.cannot.publish(document)) {
|
2686
2728
|
throw new errors.ForbiddenError();
|
2687
2729
|
}
|
2688
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2730
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2689
2731
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2690
2732
|
return publishResult.at(0);
|
2691
2733
|
});
|
@@ -2708,7 +2750,7 @@ const singleTypes = {
|
|
2708
2750
|
return ctx.forbidden();
|
2709
2751
|
}
|
2710
2752
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2711
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2753
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2712
2754
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2713
2755
|
if (!document) {
|
2714
2756
|
return ctx.notFound();
|
@@ -2740,7 +2782,7 @@ const singleTypes = {
|
|
2740
2782
|
return ctx.forbidden();
|
2741
2783
|
}
|
2742
2784
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2743
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2785
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2744
2786
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2745
2787
|
if (!document) {
|
2746
2788
|
return ctx.notFound();
|
@@ -2760,7 +2802,7 @@ const singleTypes = {
|
|
2760
2802
|
const { query } = ctx.request;
|
2761
2803
|
const documentManager2 = getService$1("document-manager");
|
2762
2804
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2763
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2805
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2764
2806
|
if (permissionChecker2.cannot.read()) {
|
2765
2807
|
return ctx.forbidden();
|
2766
2808
|
}
|
@@ -2781,7 +2823,7 @@ const uid$1 = {
|
|
2781
2823
|
async generateUID(ctx) {
|
2782
2824
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2783
2825
|
const { query = {} } = ctx.request;
|
2784
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2826
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2785
2827
|
await validateUIDField(contentTypeUID, field);
|
2786
2828
|
const uidService = getService$1("uid");
|
2787
2829
|
ctx.body = {
|
@@ -2793,7 +2835,7 @@ const uid$1 = {
|
|
2793
2835
|
ctx.request.body
|
2794
2836
|
);
|
2795
2837
|
const { query = {} } = ctx.request;
|
2796
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2838
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2797
2839
|
await validateUIDField(contentTypeUID, field);
|
2798
2840
|
const uidService = getService$1("uid");
|
2799
2841
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3718,6 +3760,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3718
3760
|
const attribute = model.attributes[attributeName];
|
3719
3761
|
switch (attribute.type) {
|
3720
3762
|
case "relation": {
|
3763
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3764
|
+
if (isMorphRelation) {
|
3765
|
+
break;
|
3766
|
+
}
|
3721
3767
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3722
3768
|
populateAcc[attributeName] = {
|
3723
3769
|
count: true,
|
@@ -4095,7 +4141,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4095
4141
|
*/
|
4096
4142
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4097
4143
|
if (!document) {
|
4098
|
-
return
|
4144
|
+
return {
|
4145
|
+
data: document,
|
4146
|
+
meta: {
|
4147
|
+
availableLocales: [],
|
4148
|
+
availableStatus: []
|
4149
|
+
}
|
4150
|
+
};
|
4099
4151
|
}
|
4100
4152
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4101
4153
|
if (!hasDraftAndPublish) {
|
@@ -4203,10 +4255,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4203
4255
|
async clone(id, body, uid2) {
|
4204
4256
|
const populate = await buildDeepPopulate(uid2);
|
4205
4257
|
const params = {
|
4206
|
-
data:
|
4207
|
-
...omitIdField(body),
|
4208
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4209
|
-
},
|
4258
|
+
data: omitIdField(body),
|
4210
4259
|
populate
|
4211
4260
|
};
|
4212
4261
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|