@strapi/content-manager 0.0.0-experimental.f75e3c6d67cc47c64ab37479efdbb7b43be50b78 → 0.0.0-experimental.fb442e5e12dd3f611303691bf85a249520ba348b
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-CuWgXugY.mjs → ComponentConfigurationPage-B3yDbeU1.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CuWgXugY.mjs.map → ComponentConfigurationPage-B3yDbeU1.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-by0e_kNd.js → ComponentConfigurationPage-KXSuLnQD.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-by0e_kNd.js.map → ComponentConfigurationPage-KXSuLnQD.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CqBeCPGH.js → EditConfigurationPage-BQ17--5R.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CqBeCPGH.js.map → EditConfigurationPage-BQ17--5R.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DbI4KMyz.mjs → EditConfigurationPage-D7PrLO8j.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DbI4KMyz.mjs.map → EditConfigurationPage-D7PrLO8j.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-dFPBya9U.mjs → EditViewPage-B7VgwJaG.mjs} +57 -46
- package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-ChgloMyO.js → EditViewPage-BgjdnGz2.js} +56 -45
- package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +1 -0
- package/dist/_chunks/{Field-dLk-vgLL.js → Field-CdK7ZLmv.js} +504 -165
- package/dist/_chunks/Field-CdK7ZLmv.js.map +1 -0
- package/dist/_chunks/{Field-C1nUKcdS.mjs → Field-tHCw4lGA.mjs} +505 -166
- package/dist/_chunks/Field-tHCw4lGA.mjs.map +1 -0
- package/dist/_chunks/{Form-DOlpi7Js.mjs → Form-BJxdTv3Q.mjs} +40 -30
- package/dist/_chunks/Form-BJxdTv3Q.mjs.map +1 -0
- package/dist/_chunks/{Form-CbXtmHC_.js → Form-C_0KTVvV.js} +38 -28
- package/dist/_chunks/Form-C_0KTVvV.js.map +1 -0
- package/dist/_chunks/{History-BFNUAiGc.mjs → History-DR2txJLE.mjs} +142 -37
- package/dist/_chunks/History-DR2txJLE.mjs.map +1 -0
- package/dist/_chunks/{History-BjDfohBr.js → History-nuEzM5qm.js} +141 -36
- package/dist/_chunks/History-nuEzM5qm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-IQBgWTaa.js → ListConfigurationPage-CnB86Psm.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-CnB86Psm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DDi0KqFm.mjs → ListConfigurationPage-voFVtXu6.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-voFVtXu6.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BPjljUsH.mjs → ListViewPage-B_GaWgRH.mjs} +80 -71
- package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CZYGqlvF.js → ListViewPage-SXIXm-RM.js} +78 -69
- package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BOAI6VZ1.js → NoContentTypePage-BzsQ3hLZ.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BOAI6VZ1.js.map → NoContentTypePage-BzsQ3hLZ.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DaWw67K-.mjs → NoContentTypePage-CYiGpsbj.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DaWw67K-.mjs.map → NoContentTypePage-CYiGpsbj.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CZrJH00p.mjs → NoPermissionsPage-B5baIHal.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CZrJH00p.mjs.map → NoPermissionsPage-B5baIHal.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-cYEtLc_e.js → NoPermissionsPage-IGkId4C5.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-cYEtLc_e.js.map → NoPermissionsPage-IGkId4C5.js.map} +1 -1
- package/dist/_chunks/{Relations-DTowyge2.mjs → Relations-CIYDdKU-.mjs} +5 -5
- package/dist/_chunks/Relations-CIYDdKU-.mjs.map +1 -0
- package/dist/_chunks/{Relations-DU6B7irU.js → Relations-Dhuurpx2.js} +5 -5
- package/dist/_chunks/Relations-Dhuurpx2.js.map +1 -0
- package/dist/_chunks/{en-GCOTL6jR.mjs → en-BrCTWlZv.mjs} +9 -4
- package/dist/_chunks/{en-GCOTL6jR.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
- package/dist/_chunks/{en-DTULi5-d.js → en-uOUIxfcQ.js} +9 -4
- package/dist/_chunks/{en-DTULi5-d.js.map → en-uOUIxfcQ.js.map} +1 -1
- package/dist/_chunks/{index-BaGHmIir.mjs → index-C9TJPyni.mjs} +1542 -1063
- package/dist/_chunks/index-C9TJPyni.mjs.map +1 -0
- package/dist/_chunks/{index-CCJeB7Rw.js → index-CdT0kHZ8.js} +1510 -1031
- package/dist/_chunks/index-CdT0kHZ8.js.map +1 -0
- package/dist/_chunks/{layout-BinjszSQ.mjs → layout-BNqvLR_b.mjs} +39 -22
- package/dist/_chunks/layout-BNqvLR_b.mjs.map +1 -0
- package/dist/_chunks/{layout-ni_L9kT1.js → layout-C6dxWYT7.js} +37 -20
- package/dist/_chunks/layout-C6dxWYT7.js.map +1 -0
- package/dist/_chunks/{relations-c91ji5eR.mjs → relations-CkKqKw65.mjs} +2 -2
- package/dist/_chunks/{relations-c91ji5eR.mjs.map → relations-CkKqKw65.mjs.map} +1 -1
- package/dist/_chunks/{relations-CeJAJc5I.js → relations-DtFaDnP1.js} +2 -2
- package/dist/_chunks/{relations-CeJAJc5I.js.map → relations-DtFaDnP1.js.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +8 -8
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/hooks/useDocumentActions.d.ts +1 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -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 +12 -32
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/pages/ListView/components/BulkActions/PublishAction.d.ts +14 -0
- package/dist/server/index.js +147 -93
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +148 -94
- 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/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-ChgloMyO.js.map +0 -1
- package/dist/_chunks/EditViewPage-dFPBya9U.mjs.map +0 -1
- package/dist/_chunks/Field-C1nUKcdS.mjs.map +0 -1
- package/dist/_chunks/Field-dLk-vgLL.js.map +0 -1
- package/dist/_chunks/Form-CbXtmHC_.js.map +0 -1
- package/dist/_chunks/Form-DOlpi7Js.mjs.map +0 -1
- package/dist/_chunks/History-BFNUAiGc.mjs.map +0 -1
- package/dist/_chunks/History-BjDfohBr.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DDi0KqFm.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-IQBgWTaa.js.map +0 -1
- package/dist/_chunks/ListViewPage-BPjljUsH.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CZYGqlvF.js.map +0 -1
- package/dist/_chunks/Relations-DTowyge2.mjs.map +0 -1
- package/dist/_chunks/Relations-DU6B7irU.js.map +0 -1
- package/dist/_chunks/index-BaGHmIir.mjs.map +0 -1
- package/dist/_chunks/index-CCJeB7Rw.js.map +0 -1
- package/dist/_chunks/layout-BinjszSQ.mjs.map +0 -1
- package/dist/_chunks/layout-ni_L9kT1.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,13 +469,47 @@ 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,
|
470
511
|
isInitialized: false
|
471
512
|
};
|
472
|
-
const query = strapi2.db.query(HISTORY_VERSION_UID);
|
473
|
-
const historyService = getService(strapi2, "history");
|
474
513
|
const serviceUtils = createServiceUtils({ strapi: strapi2 });
|
475
514
|
return {
|
476
515
|
async bootstrap() {
|
@@ -478,66 +517,51 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
478
517
|
return;
|
479
518
|
}
|
480
519
|
strapi2.documents.use(async (context, next) => {
|
481
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
482
|
-
return next();
|
483
|
-
}
|
484
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
485
|
-
return next();
|
486
|
-
}
|
487
|
-
const contentTypeUid = context.contentType.uid;
|
488
|
-
if (!contentTypeUid.startsWith("api::")) {
|
489
|
-
return next();
|
490
|
-
}
|
491
520
|
const result = await next();
|
492
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
493
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
494
|
-
const
|
495
|
-
if (
|
496
|
-
|
497
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
498
|
-
);
|
499
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
500
529
|
}
|
501
|
-
const
|
502
|
-
|
503
|
-
|
504
|
-
|
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
|
+
)
|
505
543
|
});
|
506
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
507
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
508
|
-
const componentsSchemas = Object.keys(
|
509
|
-
attributesSchema
|
510
|
-
).reduce((currentComponentSchemas, key) => {
|
511
|
-
const fieldSchema = attributesSchema[key];
|
512
|
-
if (fieldSchema.type === "component") {
|
513
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
514
|
-
return {
|
515
|
-
...currentComponentSchemas,
|
516
|
-
[fieldSchema.component]: componentSchema
|
517
|
-
};
|
518
|
-
}
|
519
|
-
return currentComponentSchemas;
|
520
|
-
}, {});
|
521
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
522
|
-
onCommit(() => {
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
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
|
+
}
|
532
557
|
});
|
533
558
|
});
|
534
559
|
return result;
|
535
560
|
});
|
536
|
-
const retentionDays = serviceUtils.getRetentionDays();
|
537
561
|
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
538
|
-
const retentionDaysInMilliseconds =
|
562
|
+
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
539
563
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
540
|
-
query.deleteMany({
|
564
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
541
565
|
where: {
|
542
566
|
created_at: {
|
543
567
|
$lt: expirationDate.toISOString()
|
@@ -1562,9 +1586,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1562
1586
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1563
1587
|
);
|
1564
1588
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1565
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1589
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1566
1590
|
const { allowMultipleLocales } = opts;
|
1567
|
-
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;
|
1568
1594
|
const schema = yup$1.object().shape({
|
1569
1595
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1570
1596
|
status: statusSchema
|
@@ -1612,7 +1638,7 @@ const createDocument = async (ctx, opts) => {
|
|
1612
1638
|
const setCreator = setCreatorFields({ user });
|
1613
1639
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1614
1640
|
const sanitizedBody = await sanitizeFn(body);
|
1615
|
-
const { locale, status
|
1641
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1616
1642
|
return documentManager2.create(model, {
|
1617
1643
|
data: sanitizedBody,
|
1618
1644
|
locale,
|
@@ -1631,7 +1657,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1631
1657
|
}
|
1632
1658
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1633
1659
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1634
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1660
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1635
1661
|
const [documentVersion, documentExists] = await Promise.all([
|
1636
1662
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1637
1663
|
documentManager2.exists(model, id)
|
@@ -1669,7 +1695,7 @@ const collectionTypes = {
|
|
1669
1695
|
}
|
1670
1696
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1671
1697
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1672
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1698
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1673
1699
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1674
1700
|
{ ...permissionQuery, populate, locale, status },
|
1675
1701
|
model
|
@@ -1704,7 +1730,7 @@ const collectionTypes = {
|
|
1704
1730
|
}
|
1705
1731
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1706
1732
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1707
|
-
const { locale, status
|
1733
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1708
1734
|
const version = await documentManager2.findOne(id, model, {
|
1709
1735
|
populate,
|
1710
1736
|
locale,
|
@@ -1771,7 +1797,7 @@ const collectionTypes = {
|
|
1771
1797
|
}
|
1772
1798
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1773
1799
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1774
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1800
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1775
1801
|
const document = await documentManager2.findOne(id, model, {
|
1776
1802
|
populate,
|
1777
1803
|
locale,
|
@@ -1816,7 +1842,7 @@ const collectionTypes = {
|
|
1816
1842
|
}
|
1817
1843
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1818
1844
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1819
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1845
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1820
1846
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1821
1847
|
if (documentLocales.length === 0) {
|
1822
1848
|
return ctx.notFound();
|
@@ -1845,11 +1871,28 @@ const collectionTypes = {
|
|
1845
1871
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1846
1872
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1847
1873
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1848
|
-
|
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
|
+
}
|
1849
1893
|
if (permissionChecker2.cannot.publish(document)) {
|
1850
1894
|
throw new errors.ForbiddenError();
|
1851
1895
|
}
|
1852
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1853
1896
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1854
1897
|
locale
|
1855
1898
|
// TODO: Allow setting creator fields on publish
|
@@ -1876,7 +1919,9 @@ const collectionTypes = {
|
|
1876
1919
|
}
|
1877
1920
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1878
1921
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1879
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1922
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1923
|
+
allowMultipleLocales: true
|
1924
|
+
});
|
1880
1925
|
const entityPromises = documentIds.map(
|
1881
1926
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1882
1927
|
);
|
@@ -1903,7 +1948,7 @@ const collectionTypes = {
|
|
1903
1948
|
if (permissionChecker2.cannot.unpublish()) {
|
1904
1949
|
return ctx.forbidden();
|
1905
1950
|
}
|
1906
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1951
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1907
1952
|
const entityPromises = documentIds.map(
|
1908
1953
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1909
1954
|
);
|
@@ -1936,7 +1981,7 @@ const collectionTypes = {
|
|
1936
1981
|
}
|
1937
1982
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1938
1983
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1939
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1984
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1940
1985
|
const document = await documentManager2.findOne(id, model, {
|
1941
1986
|
populate,
|
1942
1987
|
locale,
|
@@ -1973,7 +2018,7 @@ const collectionTypes = {
|
|
1973
2018
|
}
|
1974
2019
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1975
2020
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1976
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2021
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1977
2022
|
const document = await documentManager2.findOne(id, model, {
|
1978
2023
|
populate,
|
1979
2024
|
locale,
|
@@ -2004,7 +2049,7 @@ const collectionTypes = {
|
|
2004
2049
|
}
|
2005
2050
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2006
2051
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2007
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2052
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2008
2053
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2009
2054
|
populate,
|
2010
2055
|
locale
|
@@ -2031,7 +2076,7 @@ const collectionTypes = {
|
|
2031
2076
|
}
|
2032
2077
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2033
2078
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2034
|
-
const { locale, status
|
2079
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2035
2080
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2036
2081
|
if (!entity) {
|
2037
2082
|
return ctx.notFound();
|
@@ -2054,7 +2099,7 @@ const collectionTypes = {
|
|
2054
2099
|
if (permissionChecker2.cannot.read()) {
|
2055
2100
|
return ctx.forbidden();
|
2056
2101
|
}
|
2057
|
-
const
|
2102
|
+
const documents = await documentManager2.findMany(
|
2058
2103
|
{
|
2059
2104
|
filters: {
|
2060
2105
|
documentId: ids
|
@@ -2063,7 +2108,7 @@ const collectionTypes = {
|
|
2063
2108
|
},
|
2064
2109
|
model
|
2065
2110
|
);
|
2066
|
-
if (!
|
2111
|
+
if (!documents) {
|
2067
2112
|
return ctx.notFound();
|
2068
2113
|
}
|
2069
2114
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2559,7 +2604,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2559
2604
|
throw new errors.ForbiddenError();
|
2560
2605
|
}
|
2561
2606
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2562
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2607
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2563
2608
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2564
2609
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2565
2610
|
// Find the first document to check if it exists
|
@@ -2600,7 +2645,7 @@ const singleTypes = {
|
|
2600
2645
|
return ctx.forbidden();
|
2601
2646
|
}
|
2602
2647
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2603
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2648
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2604
2649
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2605
2650
|
if (!version) {
|
2606
2651
|
if (permissionChecker2.cannot.create()) {
|
@@ -2645,7 +2690,7 @@ const singleTypes = {
|
|
2645
2690
|
}
|
2646
2691
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2647
2692
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2648
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2693
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2649
2694
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2650
2695
|
populate,
|
2651
2696
|
locale
|
@@ -2682,7 +2727,7 @@ const singleTypes = {
|
|
2682
2727
|
if (permissionChecker2.cannot.publish(document)) {
|
2683
2728
|
throw new errors.ForbiddenError();
|
2684
2729
|
}
|
2685
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2730
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2686
2731
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2687
2732
|
return publishResult.at(0);
|
2688
2733
|
});
|
@@ -2705,7 +2750,7 @@ const singleTypes = {
|
|
2705
2750
|
return ctx.forbidden();
|
2706
2751
|
}
|
2707
2752
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2708
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2753
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2709
2754
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2710
2755
|
if (!document) {
|
2711
2756
|
return ctx.notFound();
|
@@ -2737,7 +2782,7 @@ const singleTypes = {
|
|
2737
2782
|
return ctx.forbidden();
|
2738
2783
|
}
|
2739
2784
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2740
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2785
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2741
2786
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2742
2787
|
if (!document) {
|
2743
2788
|
return ctx.notFound();
|
@@ -2757,7 +2802,7 @@ const singleTypes = {
|
|
2757
2802
|
const { query } = ctx.request;
|
2758
2803
|
const documentManager2 = getService$1("document-manager");
|
2759
2804
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2760
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2805
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2761
2806
|
if (permissionChecker2.cannot.read()) {
|
2762
2807
|
return ctx.forbidden();
|
2763
2808
|
}
|
@@ -2778,7 +2823,7 @@ const uid$1 = {
|
|
2778
2823
|
async generateUID(ctx) {
|
2779
2824
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2780
2825
|
const { query = {} } = ctx.request;
|
2781
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2826
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2782
2827
|
await validateUIDField(contentTypeUID, field);
|
2783
2828
|
const uidService = getService$1("uid");
|
2784
2829
|
ctx.body = {
|
@@ -2790,7 +2835,7 @@ const uid$1 = {
|
|
2790
2835
|
ctx.request.body
|
2791
2836
|
);
|
2792
2837
|
const { query = {} } = ctx.request;
|
2793
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2838
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2794
2839
|
await validateUIDField(contentTypeUID, field);
|
2795
2840
|
const uidService = getService$1("uid");
|
2796
2841
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3715,6 +3760,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3715
3760
|
const attribute = model.attributes[attributeName];
|
3716
3761
|
switch (attribute.type) {
|
3717
3762
|
case "relation": {
|
3763
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3764
|
+
if (isMorphRelation) {
|
3765
|
+
break;
|
3766
|
+
}
|
3718
3767
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3719
3768
|
populateAcc[attributeName] = {
|
3720
3769
|
count: true,
|
@@ -3729,22 +3778,24 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3729
3778
|
attribute.component
|
3730
3779
|
);
|
3731
3780
|
if (childHasRelations) {
|
3732
|
-
populateAcc[attributeName] = {
|
3781
|
+
populateAcc[attributeName] = {
|
3782
|
+
populate: populate2
|
3783
|
+
};
|
3733
3784
|
hasRelations = true;
|
3734
3785
|
}
|
3735
3786
|
break;
|
3736
3787
|
}
|
3737
3788
|
case "dynamiczone": {
|
3738
|
-
const
|
3739
|
-
const { populate:
|
3740
|
-
if (
|
3789
|
+
const dzPopulateFragment = attribute.components?.reduce((acc, componentUID) => {
|
3790
|
+
const { populate: componentPopulate, hasRelations: componentHasRelations } = getDeepPopulateDraftCount(componentUID);
|
3791
|
+
if (componentHasRelations) {
|
3741
3792
|
hasRelations = true;
|
3742
|
-
return
|
3793
|
+
return { ...acc, [componentUID]: { populate: componentPopulate } };
|
3743
3794
|
}
|
3744
3795
|
return acc;
|
3745
3796
|
}, {});
|
3746
|
-
if (!isEmpty(
|
3747
|
-
populateAcc[attributeName] = {
|
3797
|
+
if (!isEmpty(dzPopulateFragment)) {
|
3798
|
+
populateAcc[attributeName] = { on: dzPopulateFragment };
|
3748
3799
|
}
|
3749
3800
|
break;
|
3750
3801
|
}
|
@@ -4090,7 +4141,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4090
4141
|
*/
|
4091
4142
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4092
4143
|
if (!document) {
|
4093
|
-
return
|
4144
|
+
return {
|
4145
|
+
data: document,
|
4146
|
+
meta: {
|
4147
|
+
availableLocales: [],
|
4148
|
+
availableStatus: []
|
4149
|
+
}
|
4150
|
+
};
|
4094
4151
|
}
|
4095
4152
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4096
4153
|
if (!hasDraftAndPublish) {
|
@@ -4198,10 +4255,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4198
4255
|
async clone(id, body, uid2) {
|
4199
4256
|
const populate = await buildDeepPopulate(uid2);
|
4200
4257
|
const params = {
|
4201
|
-
data:
|
4202
|
-
...omitIdField(body),
|
4203
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4204
|
-
},
|
4258
|
+
data: omitIdField(body),
|
4205
4259
|
populate
|
4206
4260
|
};
|
4207
4261
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|