@strapi/content-manager 0.0.0-experimental.59ce88771272039a9d868fba2f7b503edf715c6a → 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-gdUj_t-O.mjs → ComponentConfigurationPage-B3yDbeU1.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-gdUj_t-O.mjs.map → ComponentConfigurationPage-B3yDbeU1.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-WRPUXGd6.js → ComponentConfigurationPage-KXSuLnQD.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-WRPUXGd6.js.map → ComponentConfigurationPage-KXSuLnQD.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-C1vjMBgy.js → EditConfigurationPage-BQ17--5R.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-C1vjMBgy.js.map → EditConfigurationPage-BQ17--5R.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BwuIPOJG.mjs → EditConfigurationPage-D7PrLO8j.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BwuIPOJG.mjs.map → EditConfigurationPage-D7PrLO8j.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-0MiFkXa8.mjs → EditViewPage-B7VgwJaG.mjs} +18 -7
- package/dist/_chunks/EditViewPage-B7VgwJaG.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-DbcGfyqK.js → EditViewPage-BgjdnGz2.js} +18 -7
- package/dist/_chunks/EditViewPage-BgjdnGz2.js.map +1 -0
- package/dist/_chunks/{Field-BG1xu38N.js → Field-CdK7ZLmv.js} +434 -83
- package/dist/_chunks/Field-CdK7ZLmv.js.map +1 -0
- package/dist/_chunks/{Field-BDMSCcy5.mjs → Field-tHCw4lGA.mjs} +435 -84
- package/dist/_chunks/Field-tHCw4lGA.mjs.map +1 -0
- package/dist/_chunks/{Form-CPVWavB8.mjs → Form-BJxdTv3Q.mjs} +26 -12
- package/dist/_chunks/Form-BJxdTv3Q.mjs.map +1 -0
- package/dist/_chunks/{Form-9BnFyUjy.js → Form-C_0KTVvV.js} +26 -12
- package/dist/_chunks/Form-C_0KTVvV.js.map +1 -0
- package/dist/_chunks/{History-BVpd8LP3.mjs → History-DR2txJLE.mjs} +44 -19
- package/dist/_chunks/History-DR2txJLE.mjs.map +1 -0
- package/dist/_chunks/{History-BWWxLt2Z.js → History-nuEzM5qm.js} +44 -19
- package/dist/_chunks/History-nuEzM5qm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-6swzjdAZ.js → ListConfigurationPage-CnB86Psm.js} +20 -8
- package/dist/_chunks/ListConfigurationPage-CnB86Psm.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DozVMKcR.mjs → ListConfigurationPage-voFVtXu6.mjs} +20 -8
- package/dist/_chunks/ListConfigurationPage-voFVtXu6.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-Ds0ulgfG.mjs → ListViewPage-B_GaWgRH.mjs} +22 -8
- package/dist/_chunks/ListViewPage-B_GaWgRH.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BlzfjS2Q.js → ListViewPage-SXIXm-RM.js} +21 -7
- package/dist/_chunks/ListViewPage-SXIXm-RM.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-D2nCCWEl.js → NoContentTypePage-BzsQ3hLZ.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-D2nCCWEl.js.map → NoContentTypePage-BzsQ3hLZ.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-BH11kaKt.mjs → NoContentTypePage-CYiGpsbj.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-BH11kaKt.mjs.map → NoContentTypePage-CYiGpsbj.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BT2Tn0D_.mjs → NoPermissionsPage-B5baIHal.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BT2Tn0D_.mjs.map → NoPermissionsPage-B5baIHal.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DN_JlsU2.js → NoPermissionsPage-IGkId4C5.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DN_JlsU2.js.map → NoPermissionsPage-IGkId4C5.js.map} +1 -1
- package/dist/_chunks/{Relations-Dnag3fhV.mjs → Relations-CIYDdKU-.mjs} +4 -4
- package/dist/_chunks/Relations-CIYDdKU-.mjs.map +1 -0
- package/dist/_chunks/{Relations-CcgFTcWo.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-JNNNKUHs.mjs → index-C9TJPyni.mjs} +351 -151
- package/dist/_chunks/index-C9TJPyni.mjs.map +1 -0
- package/dist/_chunks/{index-CWpLBSt0.js → index-CdT0kHZ8.js} +336 -136
- package/dist/_chunks/index-CdT0kHZ8.js.map +1 -0
- package/dist/_chunks/{layout-DC503LnF.mjs → layout-BNqvLR_b.mjs} +25 -13
- package/dist/_chunks/layout-BNqvLR_b.mjs.map +1 -0
- package/dist/_chunks/{layout--iHdZzRk.js → layout-C6dxWYT7.js} +23 -11
- package/dist/_chunks/layout-C6dxWYT7.js.map +1 -0
- package/dist/_chunks/{relations-CTje5t-a.mjs → relations-CkKqKw65.mjs} +2 -2
- package/dist/_chunks/{relations-CTje5t-a.mjs.map → relations-CkKqKw65.mjs.map} +1 -1
- package/dist/_chunks/{relations-BbHizA5K.js → relations-DtFaDnP1.js} +2 -2
- package/dist/_chunks/{relations-BbHizA5K.js.map → relations-DtFaDnP1.js.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +4 -4
- 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/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 +10 -22
- package/dist/server/index.js +137 -90
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +138 -91
- 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-0MiFkXa8.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-DbcGfyqK.js.map +0 -1
- package/dist/_chunks/Field-BDMSCcy5.mjs.map +0 -1
- package/dist/_chunks/Field-BG1xu38N.js.map +0 -1
- package/dist/_chunks/Form-9BnFyUjy.js.map +0 -1
- package/dist/_chunks/Form-CPVWavB8.mjs.map +0 -1
- package/dist/_chunks/History-BVpd8LP3.mjs.map +0 -1
- package/dist/_chunks/History-BWWxLt2Z.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-6swzjdAZ.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DozVMKcR.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BlzfjS2Q.js.map +0 -1
- package/dist/_chunks/ListViewPage-Ds0ulgfG.mjs.map +0 -1
- package/dist/_chunks/Relations-CcgFTcWo.js.map +0 -1
- package/dist/_chunks/Relations-Dnag3fhV.mjs.map +0 -1
- package/dist/_chunks/index-CWpLBSt0.js.map +0 -1
- package/dist/_chunks/index-JNNNKUHs.mjs.map +0 -1
- package/dist/_chunks/layout--iHdZzRk.js.map +0 -1
- package/dist/_chunks/layout-DC503LnF.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,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,63 +517,43 @@ 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 !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
485
|
-
return next();
|
486
|
-
}
|
487
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
488
|
-
return next();
|
489
|
-
}
|
490
|
-
const contentTypeUid = context.contentType.uid;
|
491
|
-
if (!contentTypeUid.startsWith("api::")) {
|
492
|
-
return next();
|
493
|
-
}
|
494
520
|
const result = await next();
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
499
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
500
|
-
const
|
501
|
-
if (
|
502
|
-
|
503
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
504
|
-
);
|
505
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
506
529
|
}
|
507
|
-
const
|
508
|
-
|
509
|
-
|
510
|
-
|
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
|
+
)
|
511
543
|
});
|
512
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
513
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
514
|
-
const componentsSchemas = Object.keys(
|
515
|
-
attributesSchema
|
516
|
-
).reduce((currentComponentSchemas, key) => {
|
517
|
-
const fieldSchema = attributesSchema[key];
|
518
|
-
if (fieldSchema.type === "component") {
|
519
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
520
|
-
return {
|
521
|
-
...currentComponentSchemas,
|
522
|
-
[fieldSchema.component]: componentSchema
|
523
|
-
};
|
524
|
-
}
|
525
|
-
return currentComponentSchemas;
|
526
|
-
}, {});
|
527
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
528
|
-
onCommit(() => {
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
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
|
+
}
|
538
557
|
});
|
539
558
|
});
|
540
559
|
return result;
|
@@ -542,7 +561,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
542
561
|
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
543
562
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
544
563
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
545
|
-
query.deleteMany({
|
564
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
546
565
|
where: {
|
547
566
|
created_at: {
|
548
567
|
$lt: expirationDate.toISOString()
|
@@ -1567,9 +1586,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1567
1586
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1568
1587
|
);
|
1569
1588
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1570
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1589
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1571
1590
|
const { allowMultipleLocales } = opts;
|
1572
|
-
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;
|
1573
1594
|
const schema = yup$1.object().shape({
|
1574
1595
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1575
1596
|
status: statusSchema
|
@@ -1617,7 +1638,7 @@ const createDocument = async (ctx, opts) => {
|
|
1617
1638
|
const setCreator = setCreatorFields({ user });
|
1618
1639
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1619
1640
|
const sanitizedBody = await sanitizeFn(body);
|
1620
|
-
const { locale, status
|
1641
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1621
1642
|
return documentManager2.create(model, {
|
1622
1643
|
data: sanitizedBody,
|
1623
1644
|
locale,
|
@@ -1636,7 +1657,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1636
1657
|
}
|
1637
1658
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1638
1659
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1639
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1660
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1640
1661
|
const [documentVersion, documentExists] = await Promise.all([
|
1641
1662
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1642
1663
|
documentManager2.exists(model, id)
|
@@ -1674,7 +1695,7 @@ const collectionTypes = {
|
|
1674
1695
|
}
|
1675
1696
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1676
1697
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1677
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1698
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1678
1699
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1679
1700
|
{ ...permissionQuery, populate, locale, status },
|
1680
1701
|
model
|
@@ -1709,7 +1730,7 @@ const collectionTypes = {
|
|
1709
1730
|
}
|
1710
1731
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1711
1732
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1712
|
-
const { locale, status
|
1733
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1713
1734
|
const version = await documentManager2.findOne(id, model, {
|
1714
1735
|
populate,
|
1715
1736
|
locale,
|
@@ -1776,7 +1797,7 @@ const collectionTypes = {
|
|
1776
1797
|
}
|
1777
1798
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1778
1799
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1779
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1800
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1780
1801
|
const document = await documentManager2.findOne(id, model, {
|
1781
1802
|
populate,
|
1782
1803
|
locale,
|
@@ -1821,7 +1842,7 @@ const collectionTypes = {
|
|
1821
1842
|
}
|
1822
1843
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1823
1844
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1824
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1845
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1825
1846
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1826
1847
|
if (documentLocales.length === 0) {
|
1827
1848
|
return ctx.notFound();
|
@@ -1850,11 +1871,28 @@ const collectionTypes = {
|
|
1850
1871
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1851
1872
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1852
1873
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1853
|
-
|
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
|
+
}
|
1854
1893
|
if (permissionChecker2.cannot.publish(document)) {
|
1855
1894
|
throw new errors.ForbiddenError();
|
1856
1895
|
}
|
1857
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1858
1896
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1859
1897
|
locale
|
1860
1898
|
// TODO: Allow setting creator fields on publish
|
@@ -1881,7 +1919,9 @@ const collectionTypes = {
|
|
1881
1919
|
}
|
1882
1920
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1883
1921
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1884
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1922
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1923
|
+
allowMultipleLocales: true
|
1924
|
+
});
|
1885
1925
|
const entityPromises = documentIds.map(
|
1886
1926
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1887
1927
|
);
|
@@ -1908,7 +1948,7 @@ const collectionTypes = {
|
|
1908
1948
|
if (permissionChecker2.cannot.unpublish()) {
|
1909
1949
|
return ctx.forbidden();
|
1910
1950
|
}
|
1911
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1951
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1912
1952
|
const entityPromises = documentIds.map(
|
1913
1953
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1914
1954
|
);
|
@@ -1941,7 +1981,7 @@ const collectionTypes = {
|
|
1941
1981
|
}
|
1942
1982
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1943
1983
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1944
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1984
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1945
1985
|
const document = await documentManager2.findOne(id, model, {
|
1946
1986
|
populate,
|
1947
1987
|
locale,
|
@@ -1978,7 +2018,7 @@ const collectionTypes = {
|
|
1978
2018
|
}
|
1979
2019
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1980
2020
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1981
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2021
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1982
2022
|
const document = await documentManager2.findOne(id, model, {
|
1983
2023
|
populate,
|
1984
2024
|
locale,
|
@@ -2009,7 +2049,7 @@ const collectionTypes = {
|
|
2009
2049
|
}
|
2010
2050
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2011
2051
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2012
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2052
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2013
2053
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2014
2054
|
populate,
|
2015
2055
|
locale
|
@@ -2036,7 +2076,7 @@ const collectionTypes = {
|
|
2036
2076
|
}
|
2037
2077
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2038
2078
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2039
|
-
const { locale, status
|
2079
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2040
2080
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2041
2081
|
if (!entity) {
|
2042
2082
|
return ctx.notFound();
|
@@ -2059,7 +2099,7 @@ const collectionTypes = {
|
|
2059
2099
|
if (permissionChecker2.cannot.read()) {
|
2060
2100
|
return ctx.forbidden();
|
2061
2101
|
}
|
2062
|
-
const
|
2102
|
+
const documents = await documentManager2.findMany(
|
2063
2103
|
{
|
2064
2104
|
filters: {
|
2065
2105
|
documentId: ids
|
@@ -2068,7 +2108,7 @@ const collectionTypes = {
|
|
2068
2108
|
},
|
2069
2109
|
model
|
2070
2110
|
);
|
2071
|
-
if (!
|
2111
|
+
if (!documents) {
|
2072
2112
|
return ctx.notFound();
|
2073
2113
|
}
|
2074
2114
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2564,7 +2604,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2564
2604
|
throw new errors.ForbiddenError();
|
2565
2605
|
}
|
2566
2606
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2567
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2607
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2568
2608
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2569
2609
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2570
2610
|
// Find the first document to check if it exists
|
@@ -2605,7 +2645,7 @@ const singleTypes = {
|
|
2605
2645
|
return ctx.forbidden();
|
2606
2646
|
}
|
2607
2647
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2608
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2648
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2609
2649
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2610
2650
|
if (!version) {
|
2611
2651
|
if (permissionChecker2.cannot.create()) {
|
@@ -2650,7 +2690,7 @@ const singleTypes = {
|
|
2650
2690
|
}
|
2651
2691
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2652
2692
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2653
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2693
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2654
2694
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2655
2695
|
populate,
|
2656
2696
|
locale
|
@@ -2687,7 +2727,7 @@ const singleTypes = {
|
|
2687
2727
|
if (permissionChecker2.cannot.publish(document)) {
|
2688
2728
|
throw new errors.ForbiddenError();
|
2689
2729
|
}
|
2690
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2730
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2691
2731
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2692
2732
|
return publishResult.at(0);
|
2693
2733
|
});
|
@@ -2710,7 +2750,7 @@ const singleTypes = {
|
|
2710
2750
|
return ctx.forbidden();
|
2711
2751
|
}
|
2712
2752
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2713
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2753
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2714
2754
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2715
2755
|
if (!document) {
|
2716
2756
|
return ctx.notFound();
|
@@ -2742,7 +2782,7 @@ const singleTypes = {
|
|
2742
2782
|
return ctx.forbidden();
|
2743
2783
|
}
|
2744
2784
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2745
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2785
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2746
2786
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2747
2787
|
if (!document) {
|
2748
2788
|
return ctx.notFound();
|
@@ -2762,7 +2802,7 @@ const singleTypes = {
|
|
2762
2802
|
const { query } = ctx.request;
|
2763
2803
|
const documentManager2 = getService$1("document-manager");
|
2764
2804
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2765
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2805
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2766
2806
|
if (permissionChecker2.cannot.read()) {
|
2767
2807
|
return ctx.forbidden();
|
2768
2808
|
}
|
@@ -2783,7 +2823,7 @@ const uid$1 = {
|
|
2783
2823
|
async generateUID(ctx) {
|
2784
2824
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2785
2825
|
const { query = {} } = ctx.request;
|
2786
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2826
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2787
2827
|
await validateUIDField(contentTypeUID, field);
|
2788
2828
|
const uidService = getService$1("uid");
|
2789
2829
|
ctx.body = {
|
@@ -2795,7 +2835,7 @@ const uid$1 = {
|
|
2795
2835
|
ctx.request.body
|
2796
2836
|
);
|
2797
2837
|
const { query = {} } = ctx.request;
|
2798
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2838
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2799
2839
|
await validateUIDField(contentTypeUID, field);
|
2800
2840
|
const uidService = getService$1("uid");
|
2801
2841
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3720,6 +3760,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3720
3760
|
const attribute = model.attributes[attributeName];
|
3721
3761
|
switch (attribute.type) {
|
3722
3762
|
case "relation": {
|
3763
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3764
|
+
if (isMorphRelation) {
|
3765
|
+
break;
|
3766
|
+
}
|
3723
3767
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3724
3768
|
populateAcc[attributeName] = {
|
3725
3769
|
count: true,
|
@@ -4097,7 +4141,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4097
4141
|
*/
|
4098
4142
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4099
4143
|
if (!document) {
|
4100
|
-
return
|
4144
|
+
return {
|
4145
|
+
data: document,
|
4146
|
+
meta: {
|
4147
|
+
availableLocales: [],
|
4148
|
+
availableStatus: []
|
4149
|
+
}
|
4150
|
+
};
|
4101
4151
|
}
|
4102
4152
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4103
4153
|
if (!hasDraftAndPublish) {
|
@@ -4205,10 +4255,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4205
4255
|
async clone(id, body, uid2) {
|
4206
4256
|
const populate = await buildDeepPopulate(uid2);
|
4207
4257
|
const params = {
|
4208
|
-
data:
|
4209
|
-
...omitIdField(body),
|
4210
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4211
|
-
},
|
4258
|
+
data: omitIdField(body),
|
4212
4259
|
populate
|
4213
4260
|
};
|
4214
4261
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|