@strapi/content-manager 0.0.0-experimental.545ccead2ee1717bbc7ab950455dbb0ddb9924a3 → 0.0.0-experimental.5788c38836be65c0321a2dcadbdf44f04b798e8a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js → ComponentConfigurationPage-B42mQr1K.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js.map → ComponentConfigurationPage-B42mQr1K.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs → ComponentConfigurationPage-D1YuKq8j.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs.map → ComponentConfigurationPage-D1YuKq8j.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs → EditConfigurationPage-C9yiwgI_.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs.map → EditConfigurationPage-C9yiwgI_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js → EditConfigurationPage-NC89F29V.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js.map → EditConfigurationPage-NC89F29V.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-DA95Ha6J.js → EditViewPage-DYDpe5Wi.js} +30 -9
- package/dist/_chunks/EditViewPage-DYDpe5Wi.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DlLEyUL6.mjs → EditViewPage-k8UcfVwt.mjs} +30 -9
- package/dist/_chunks/EditViewPage-k8UcfVwt.mjs.map +1 -0
- package/dist/_chunks/{Field-Dq7bDnuh.mjs → Field-BLL5lknV.mjs} +170 -102
- package/dist/_chunks/Field-BLL5lknV.mjs.map +1 -0
- package/dist/_chunks/{Field-CnK8dO8N.js → Field-Crhugun2.js} +172 -104
- package/dist/_chunks/Field-Crhugun2.js.map +1 -0
- package/dist/_chunks/{Form-BpiR4piS.js → Form-DUU19g6M.js} +35 -16
- package/dist/_chunks/Form-DUU19g6M.js.map +1 -0
- package/dist/_chunks/{Form-B_JE0dbz.mjs → Form-UHu2eOuG.mjs} +35 -16
- package/dist/_chunks/Form-UHu2eOuG.mjs.map +1 -0
- package/dist/_chunks/{History-CBNGU7a-.mjs → History-CpxkZXS3.mjs} +21 -11
- package/dist/_chunks/History-CpxkZXS3.mjs.map +1 -0
- package/dist/_chunks/{History-DdIstl8b.js → History-CyA8tvJZ.js} +21 -11
- package/dist/_chunks/History-CyA8tvJZ.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-5dr4qpue.mjs → ListConfigurationPage-OUwV8QF1.mjs} +14 -4
- package/dist/_chunks/ListConfigurationPage-OUwV8QF1.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DkKRparB.js → ListConfigurationPage-pJV7aG2V.js} +14 -4
- package/dist/_chunks/ListConfigurationPage-pJV7aG2V.js.map +1 -0
- package/dist/_chunks/{ListViewPage-wE0lXqoD.js → ListViewPage-BIT0M8VG.js} +49 -40
- package/dist/_chunks/ListViewPage-BIT0M8VG.js.map +1 -0
- package/dist/_chunks/{ListViewPage-DecLrYV6.mjs → ListViewPage-BOnhCGkE.mjs} +47 -38
- package/dist/_chunks/ListViewPage-BOnhCGkE.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs → NoContentTypePage-CwjlHGTn.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs.map → NoContentTypePage-CwjlHGTn.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js → NoContentTypePage-uIBsBUmH.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js.map → NoContentTypePage-uIBsBUmH.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js → NoPermissionsPage-C8wkEaOF.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js.map → NoPermissionsPage-C8wkEaOF.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs → NoPermissionsPage-CcWbyT_z.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs.map → NoPermissionsPage-CcWbyT_z.mjs.map} +1 -1
- package/dist/_chunks/{Relations-L0xYRoSQ.js → Relations-CwRu_eZv.js} +33 -24
- package/dist/_chunks/Relations-CwRu_eZv.js.map +1 -0
- package/dist/_chunks/{Relations-Dqz0C1fz.mjs → Relations-wIdWJnA9.mjs} +33 -24
- package/dist/_chunks/Relations-wIdWJnA9.mjs.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-DyvUPg1a.js → index-BO-T2BdP.js} +693 -524
- package/dist/_chunks/index-BO-T2BdP.js.map +1 -0
- package/dist/_chunks/{index-BSn97i8U.mjs → index-BQ8DxaCa.mjs} +713 -544
- package/dist/_chunks/index-BQ8DxaCa.mjs.map +1 -0
- package/dist/_chunks/{layout-TPqF2oJ5.js → layout-BTB1_M8g.js} +21 -8
- package/dist/_chunks/layout-BTB1_M8g.js.map +1 -0
- package/dist/_chunks/{layout-DPaHUusj.mjs → layout-N63eyE5E.mjs} +22 -9
- package/dist/_chunks/layout-N63eyE5E.mjs.map +1 -0
- package/dist/_chunks/{relations-Ck7-ecDT.mjs → relations-Bh9r0CVE.mjs} +2 -2
- package/dist/_chunks/{relations-Ck7-ecDT.mjs.map → relations-Bh9r0CVE.mjs.map} +1 -1
- package/dist/_chunks/{relations-BWYS9gkn.js → relations-C9AQuM2z.js} +2 -2
- package/dist/_chunks/{relations-BWYS9gkn.js.map → relations-C9AQuM2z.js.map} +1 -1
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- 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 +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +195 -117
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +196 -118
- 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/relations.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/history.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 +2 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.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/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +11 -11
- package/dist/_chunks/EditViewPage-DA95Ha6J.js.map +0 -1
- package/dist/_chunks/EditViewPage-DlLEyUL6.mjs.map +0 -1
- package/dist/_chunks/Field-CnK8dO8N.js.map +0 -1
- package/dist/_chunks/Field-Dq7bDnuh.mjs.map +0 -1
- package/dist/_chunks/Form-B_JE0dbz.mjs.map +0 -1
- package/dist/_chunks/Form-BpiR4piS.js.map +0 -1
- package/dist/_chunks/History-CBNGU7a-.mjs.map +0 -1
- package/dist/_chunks/History-DdIstl8b.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-5dr4qpue.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DkKRparB.js.map +0 -1
- package/dist/_chunks/ListViewPage-DecLrYV6.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-wE0lXqoD.js.map +0 -1
- package/dist/_chunks/Relations-Dqz0C1fz.mjs.map +0 -1
- package/dist/_chunks/Relations-L0xYRoSQ.js.map +0 -1
- package/dist/_chunks/index-BSn97i8U.mjs.map +0 -1
- package/dist/_chunks/index-DyvUPg1a.js.map +0 -1
- package/dist/_chunks/layout-DPaHUusj.mjs.map +0 -1
- package/dist/_chunks/layout-TPqF2oJ5.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.js
CHANGED
@@ -199,7 +199,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
199
199
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
|
200
200
|
};
|
201
201
|
const localesService = strapi2.plugin("i18n")?.service("locales");
|
202
|
+
const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
|
202
203
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
|
+
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
203
205
|
const getLocaleDictionary = async () => {
|
204
206
|
if (!localesService)
|
205
207
|
return {};
|
@@ -226,9 +228,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
226
228
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
227
229
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
228
230
|
};
|
229
|
-
const getDeepPopulate2 = (uid2) => {
|
231
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
230
232
|
const model = strapi2.getModel(uid2);
|
231
233
|
const attributes = Object.entries(model.attributes);
|
234
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
232
235
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
233
236
|
switch (attribute.type) {
|
234
237
|
case "relation": {
|
@@ -238,12 +241,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
238
241
|
}
|
239
242
|
const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
240
243
|
if (isVisible2) {
|
241
|
-
acc[attributeName] = {
|
244
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
242
245
|
}
|
243
246
|
break;
|
244
247
|
}
|
245
248
|
case "media": {
|
246
|
-
acc[attributeName] = {
|
249
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
247
250
|
break;
|
248
251
|
}
|
249
252
|
case "component": {
|
@@ -316,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
316
319
|
getRelationRestoreValue,
|
317
320
|
getMediaRestoreValue,
|
318
321
|
getDefaultLocale,
|
322
|
+
isLocalizedContentType,
|
319
323
|
getLocaleDictionary,
|
320
324
|
getRetentionDays,
|
321
325
|
getVersionStatus,
|
@@ -338,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
338
342
|
});
|
339
343
|
},
|
340
344
|
async findVersionsPage(params) {
|
341
|
-
const
|
345
|
+
const model = strapi2.getModel(params.query.contentType);
|
346
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
347
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
348
|
+
let locale = null;
|
349
|
+
if (isLocalizedContentType) {
|
350
|
+
locale = params.query.locale || defaultLocale;
|
351
|
+
}
|
342
352
|
const [{ results, pagination }, localeDictionary] = await Promise.all([
|
343
353
|
query.findPage({
|
344
354
|
...params.query,
|
@@ -494,6 +504,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
494
504
|
}
|
495
505
|
};
|
496
506
|
};
|
507
|
+
const shouldCreateHistoryVersion = (context) => {
|
508
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
509
|
+
return false;
|
510
|
+
}
|
511
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
512
|
+
return false;
|
513
|
+
}
|
514
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
515
|
+
return false;
|
516
|
+
}
|
517
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
518
|
+
return false;
|
519
|
+
}
|
520
|
+
return true;
|
521
|
+
};
|
522
|
+
const getSchemas = (uid2) => {
|
523
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
524
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
525
|
+
(currentComponentSchemas, key) => {
|
526
|
+
const fieldSchema = attributesSchema[key];
|
527
|
+
if (fieldSchema.type === "component") {
|
528
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
529
|
+
return {
|
530
|
+
...currentComponentSchemas,
|
531
|
+
[fieldSchema.component]: componentSchema
|
532
|
+
};
|
533
|
+
}
|
534
|
+
return currentComponentSchemas;
|
535
|
+
},
|
536
|
+
{}
|
537
|
+
);
|
538
|
+
return {
|
539
|
+
schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
|
540
|
+
componentsSchemas
|
541
|
+
};
|
542
|
+
};
|
497
543
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
498
544
|
const state = {
|
499
545
|
deleteExpiredJob: null,
|
@@ -506,63 +552,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
506
552
|
return;
|
507
553
|
}
|
508
554
|
strapi2.documents.use(async (context, next) => {
|
509
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
510
|
-
return next();
|
511
|
-
}
|
512
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
513
|
-
return next();
|
514
|
-
}
|
515
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
516
|
-
return next();
|
517
|
-
}
|
518
|
-
const contentTypeUid = context.contentType.uid;
|
519
|
-
if (!contentTypeUid.startsWith("api::")) {
|
520
|
-
return next();
|
521
|
-
}
|
522
555
|
const result = await next();
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
556
|
+
if (!shouldCreateHistoryVersion(context)) {
|
557
|
+
return result;
|
558
|
+
}
|
559
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
527
560
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
528
|
-
const
|
529
|
-
if (
|
530
|
-
|
531
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
532
|
-
);
|
533
|
-
return next();
|
561
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
562
|
+
if (!locales.length) {
|
563
|
+
return result;
|
534
564
|
}
|
535
|
-
const
|
536
|
-
|
537
|
-
|
538
|
-
|
565
|
+
const uid2 = context.contentType.uid;
|
566
|
+
const schemas = getSchemas(uid2);
|
567
|
+
const model = strapi2.getModel(uid2);
|
568
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
569
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
570
|
+
where: {
|
571
|
+
documentId,
|
572
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
573
|
+
...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
574
|
+
},
|
575
|
+
populate: serviceUtils.getDeepPopulate(
|
576
|
+
uid2,
|
577
|
+
true
|
578
|
+
/* use database syntax */
|
579
|
+
)
|
539
580
|
});
|
540
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
541
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
542
|
-
const componentsSchemas = Object.keys(
|
543
|
-
attributesSchema
|
544
|
-
).reduce((currentComponentSchemas, key) => {
|
545
|
-
const fieldSchema = attributesSchema[key];
|
546
|
-
if (fieldSchema.type === "component") {
|
547
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
548
|
-
return {
|
549
|
-
...currentComponentSchemas,
|
550
|
-
[fieldSchema.component]: componentSchema
|
551
|
-
};
|
552
|
-
}
|
553
|
-
return currentComponentSchemas;
|
554
|
-
}, {});
|
555
581
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
556
|
-
onCommit(() => {
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
582
|
+
onCommit(async () => {
|
583
|
+
for (const entry of localeEntries) {
|
584
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
585
|
+
await getService(strapi2, "history").createVersion({
|
586
|
+
contentType: uid2,
|
587
|
+
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
588
|
+
relatedDocumentId: documentId,
|
589
|
+
locale: entry.locale,
|
590
|
+
status,
|
591
|
+
...schemas
|
592
|
+
});
|
593
|
+
}
|
566
594
|
});
|
567
595
|
});
|
568
596
|
return result;
|
@@ -1202,6 +1230,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1202
1230
|
const hasPermissions = createPolicy({
|
1203
1231
|
name: "plugin::content-manager.hasPermissions",
|
1204
1232
|
validator: validateHasPermissionsInput,
|
1233
|
+
/**
|
1234
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1235
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1236
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1237
|
+
*/
|
1205
1238
|
handler(ctx, config = {}) {
|
1206
1239
|
const { actions = [], hasAtLeastOne = false } = config;
|
1207
1240
|
const { userAbility } = ctx.state;
|
@@ -1595,9 +1628,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1595
1628
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1596
1629
|
);
|
1597
1630
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1598
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1631
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1599
1632
|
const { allowMultipleLocales } = opts;
|
1600
|
-
const { locale, status, ...rest } = request || {};
|
1633
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1634
|
+
const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1635
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1601
1636
|
const schema = strapiUtils.yup.object().shape({
|
1602
1637
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1603
1638
|
status: statusSchema
|
@@ -1645,7 +1680,7 @@ const createDocument = async (ctx, opts) => {
|
|
1645
1680
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1646
1681
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1647
1682
|
const sanitizedBody = await sanitizeFn(body);
|
1648
|
-
const { locale, status
|
1683
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1649
1684
|
return documentManager2.create(model, {
|
1650
1685
|
data: sanitizedBody,
|
1651
1686
|
locale,
|
@@ -1664,7 +1699,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1664
1699
|
}
|
1665
1700
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1666
1701
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1667
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1702
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1668
1703
|
const [documentVersion, documentExists] = await Promise.all([
|
1669
1704
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1670
1705
|
documentManager2.exists(model, id)
|
@@ -1680,7 +1715,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1680
1715
|
throw new strapiUtils.errors.ForbiddenError();
|
1681
1716
|
}
|
1682
1717
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1683
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1718
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1684
1719
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1685
1720
|
const sanitizedBody = await sanitizeFn(body);
|
1686
1721
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1702,7 +1737,7 @@ const collectionTypes = {
|
|
1702
1737
|
}
|
1703
1738
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1704
1739
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1705
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1740
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1706
1741
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1707
1742
|
{ ...permissionQuery, populate, locale, status },
|
1708
1743
|
model
|
@@ -1737,7 +1772,7 @@ const collectionTypes = {
|
|
1737
1772
|
}
|
1738
1773
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1739
1774
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1740
|
-
const { locale, status
|
1775
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1741
1776
|
const version = await documentManager2.findOne(id, model, {
|
1742
1777
|
populate,
|
1743
1778
|
locale,
|
@@ -1752,7 +1787,7 @@ const collectionTypes = {
|
|
1752
1787
|
permissionChecker2,
|
1753
1788
|
model,
|
1754
1789
|
// @ts-expect-error TODO: fix
|
1755
|
-
{ id, locale, publishedAt: null },
|
1790
|
+
{ documentId: id, locale, publishedAt: null },
|
1756
1791
|
{ availableLocales: true, availableStatus: false }
|
1757
1792
|
);
|
1758
1793
|
ctx.body = { data: {}, meta };
|
@@ -1804,7 +1839,7 @@ const collectionTypes = {
|
|
1804
1839
|
}
|
1805
1840
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1806
1841
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1807
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1842
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1808
1843
|
const document = await documentManager2.findOne(id, model, {
|
1809
1844
|
populate,
|
1810
1845
|
locale,
|
@@ -1849,7 +1884,7 @@ const collectionTypes = {
|
|
1849
1884
|
}
|
1850
1885
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1851
1886
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1852
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1887
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1853
1888
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1854
1889
|
if (documentLocales.length === 0) {
|
1855
1890
|
return ctx.notFound();
|
@@ -1878,11 +1913,34 @@ const collectionTypes = {
|
|
1878
1913
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1879
1914
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1880
1915
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1881
|
-
|
1916
|
+
let document;
|
1917
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1918
|
+
const isCreate = fp.isNil(id);
|
1919
|
+
if (isCreate) {
|
1920
|
+
if (permissionChecker2.cannot.create()) {
|
1921
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1922
|
+
}
|
1923
|
+
document = await createDocument(ctx, { populate });
|
1924
|
+
}
|
1925
|
+
const isUpdate = !isCreate;
|
1926
|
+
if (isUpdate) {
|
1927
|
+
const documentExists = documentManager2.exists(model, id);
|
1928
|
+
if (!documentExists) {
|
1929
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1930
|
+
}
|
1931
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1932
|
+
if (!document) {
|
1933
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
1934
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1935
|
+
}
|
1936
|
+
document = await updateDocument(ctx);
|
1937
|
+
} else if (permissionChecker2.can.update(document)) {
|
1938
|
+
await updateDocument(ctx);
|
1939
|
+
}
|
1940
|
+
}
|
1882
1941
|
if (permissionChecker2.cannot.publish(document)) {
|
1883
1942
|
throw new strapiUtils.errors.ForbiddenError();
|
1884
1943
|
}
|
1885
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1886
1944
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1887
1945
|
locale
|
1888
1946
|
// TODO: Allow setting creator fields on publish
|
@@ -1909,7 +1967,9 @@ const collectionTypes = {
|
|
1909
1967
|
}
|
1910
1968
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1911
1969
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1912
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1970
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1971
|
+
allowMultipleLocales: true
|
1972
|
+
});
|
1913
1973
|
const entityPromises = documentIds.map(
|
1914
1974
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1915
1975
|
);
|
@@ -1936,7 +1996,9 @@ const collectionTypes = {
|
|
1936
1996
|
if (permissionChecker2.cannot.unpublish()) {
|
1937
1997
|
return ctx.forbidden();
|
1938
1998
|
}
|
1939
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
1999
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2000
|
+
allowMultipleLocales: true
|
2001
|
+
});
|
1940
2002
|
const entityPromises = documentIds.map(
|
1941
2003
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1942
2004
|
);
|
@@ -1969,7 +2031,7 @@ const collectionTypes = {
|
|
1969
2031
|
}
|
1970
2032
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1971
2033
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1972
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2034
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1973
2035
|
const document = await documentManager2.findOne(id, model, {
|
1974
2036
|
populate,
|
1975
2037
|
locale,
|
@@ -2006,7 +2068,7 @@ const collectionTypes = {
|
|
2006
2068
|
}
|
2007
2069
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2008
2070
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2009
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2071
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2010
2072
|
const document = await documentManager2.findOne(id, model, {
|
2011
2073
|
populate,
|
2012
2074
|
locale,
|
@@ -2037,7 +2099,7 @@ const collectionTypes = {
|
|
2037
2099
|
}
|
2038
2100
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2039
2101
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2040
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2102
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2041
2103
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2042
2104
|
populate,
|
2043
2105
|
locale
|
@@ -2064,7 +2126,7 @@ const collectionTypes = {
|
|
2064
2126
|
}
|
2065
2127
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2066
2128
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2067
|
-
const { locale, status
|
2129
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2068
2130
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2069
2131
|
if (!entity) {
|
2070
2132
|
return ctx.notFound();
|
@@ -2287,20 +2349,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2287
2349
|
userAbility,
|
2288
2350
|
model: model.uid
|
2289
2351
|
});
|
2290
|
-
|
2352
|
+
const isMainFieldListable = isListable(model, mainField);
|
2353
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2354
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2291
2355
|
return "id";
|
2292
2356
|
}
|
2293
|
-
if (
|
2294
|
-
|
2295
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2296
|
-
userAbility,
|
2297
|
-
model: "plugin::users-permissions.user"
|
2298
|
-
});
|
2299
|
-
if (userPermissionChecker.can.read()) {
|
2300
|
-
return "name";
|
2301
|
-
}
|
2302
|
-
}
|
2303
|
-
return "id";
|
2357
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2358
|
+
return "name";
|
2304
2359
|
}
|
2305
2360
|
return mainField;
|
2306
2361
|
};
|
@@ -2333,11 +2388,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2333
2388
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2334
2389
|
const isSourceLocalized = isLocalized(sourceModel);
|
2335
2390
|
const isTargetLocalized = isLocalized(targetModel);
|
2336
|
-
let validatedLocale = locale;
|
2337
|
-
if (!targetModel || !isTargetLocalized)
|
2338
|
-
validatedLocale = void 0;
|
2339
2391
|
return {
|
2340
|
-
locale
|
2392
|
+
locale,
|
2341
2393
|
isSourceLocalized,
|
2342
2394
|
isTargetLocalized
|
2343
2395
|
};
|
@@ -2440,7 +2492,7 @@ const relations = {
|
|
2440
2492
|
attribute,
|
2441
2493
|
fieldsToSelect,
|
2442
2494
|
mainField,
|
2443
|
-
source: { schema: sourceSchema },
|
2495
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2444
2496
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2445
2497
|
sourceSchema,
|
2446
2498
|
targetSchema,
|
@@ -2462,7 +2514,8 @@ const relations = {
|
|
2462
2514
|
fieldsToSelect,
|
2463
2515
|
mainField,
|
2464
2516
|
source: {
|
2465
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2517
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2518
|
+
isLocalized: isSourceLocalized
|
2466
2519
|
},
|
2467
2520
|
target: {
|
2468
2521
|
schema: { uid: targetUid },
|
@@ -2500,12 +2553,16 @@ const relations = {
|
|
2500
2553
|
} else {
|
2501
2554
|
where.id = id;
|
2502
2555
|
}
|
2503
|
-
|
2504
|
-
|
2556
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2557
|
+
if (!fp.isEmpty(publishedAt)) {
|
2558
|
+
where[`${alias}.published_at`] = publishedAt;
|
2505
2559
|
}
|
2506
|
-
if (
|
2560
|
+
if (isTargetLocalized && locale) {
|
2507
2561
|
where[`${alias}.locale`] = locale;
|
2508
2562
|
}
|
2563
|
+
if (isSourceLocalized && locale) {
|
2564
|
+
where.locale = locale;
|
2565
|
+
}
|
2509
2566
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2510
2567
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2511
2568
|
}
|
@@ -2523,7 +2580,8 @@ const relations = {
|
|
2523
2580
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2524
2581
|
});
|
2525
2582
|
}
|
2526
|
-
const
|
2583
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2584
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2527
2585
|
ctx.body = {
|
2528
2586
|
...res,
|
2529
2587
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2558,9 +2616,7 @@ const relations = {
|
|
2558
2616
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2559
2617
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2560
2618
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2561
|
-
ordering: "desc"
|
2562
|
-
page: ctx.request.query.page,
|
2563
|
-
pageSize: ctx.request.query.pageSize
|
2619
|
+
ordering: "desc"
|
2564
2620
|
});
|
2565
2621
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2566
2622
|
ctx.body = {
|
@@ -2592,7 +2648,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2592
2648
|
throw new strapiUtils.errors.ForbiddenError();
|
2593
2649
|
}
|
2594
2650
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2595
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2651
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2596
2652
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2597
2653
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2598
2654
|
// Find the first document to check if it exists
|
@@ -2633,7 +2689,7 @@ const singleTypes = {
|
|
2633
2689
|
return ctx.forbidden();
|
2634
2690
|
}
|
2635
2691
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2636
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2692
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2637
2693
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2638
2694
|
if (!version) {
|
2639
2695
|
if (permissionChecker2.cannot.create()) {
|
@@ -2647,7 +2703,7 @@ const singleTypes = {
|
|
2647
2703
|
permissionChecker2,
|
2648
2704
|
model,
|
2649
2705
|
// @ts-expect-error - fix types
|
2650
|
-
{
|
2706
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2651
2707
|
{ availableLocales: true, availableStatus: false }
|
2652
2708
|
);
|
2653
2709
|
ctx.body = { data: {}, meta };
|
@@ -2678,7 +2734,7 @@ const singleTypes = {
|
|
2678
2734
|
}
|
2679
2735
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2680
2736
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2681
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2737
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2682
2738
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2683
2739
|
populate,
|
2684
2740
|
locale
|
@@ -2715,7 +2771,7 @@ const singleTypes = {
|
|
2715
2771
|
if (permissionChecker2.cannot.publish(document)) {
|
2716
2772
|
throw new strapiUtils.errors.ForbiddenError();
|
2717
2773
|
}
|
2718
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2774
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2719
2775
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2720
2776
|
return publishResult.at(0);
|
2721
2777
|
});
|
@@ -2738,7 +2794,7 @@ const singleTypes = {
|
|
2738
2794
|
return ctx.forbidden();
|
2739
2795
|
}
|
2740
2796
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2741
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2797
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2742
2798
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2743
2799
|
if (!document) {
|
2744
2800
|
return ctx.notFound();
|
@@ -2770,7 +2826,7 @@ const singleTypes = {
|
|
2770
2826
|
return ctx.forbidden();
|
2771
2827
|
}
|
2772
2828
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2773
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2829
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2774
2830
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2775
2831
|
if (!document) {
|
2776
2832
|
return ctx.notFound();
|
@@ -2790,7 +2846,7 @@ const singleTypes = {
|
|
2790
2846
|
const { query } = ctx.request;
|
2791
2847
|
const documentManager2 = getService$1("document-manager");
|
2792
2848
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2793
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2849
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2794
2850
|
if (permissionChecker2.cannot.read()) {
|
2795
2851
|
return ctx.forbidden();
|
2796
2852
|
}
|
@@ -2811,7 +2867,7 @@ const uid$1 = {
|
|
2811
2867
|
async generateUID(ctx) {
|
2812
2868
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2813
2869
|
const { query = {} } = ctx.request;
|
2814
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2870
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2815
2871
|
await validateUIDField(contentTypeUID, field);
|
2816
2872
|
const uidService = getService$1("uid");
|
2817
2873
|
ctx.body = {
|
@@ -2823,7 +2879,7 @@ const uid$1 = {
|
|
2823
2879
|
ctx.request.body
|
2824
2880
|
);
|
2825
2881
|
const { query = {} } = ctx.request;
|
2826
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2882
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2827
2883
|
await validateUIDField(contentTypeUID, field);
|
2828
2884
|
const uidService = getService$1("uid");
|
2829
2885
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3466,12 +3522,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3466
3522
|
ability: userAbility,
|
3467
3523
|
model
|
3468
3524
|
});
|
3469
|
-
const
|
3525
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3526
|
+
const toSubject = (entity) => {
|
3527
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3528
|
+
};
|
3470
3529
|
const can = (action, entity, field) => {
|
3471
|
-
|
3530
|
+
const subject = toSubject(entity);
|
3531
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3532
|
+
return (
|
3533
|
+
// Test the original action to see if it passes
|
3534
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3535
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3536
|
+
);
|
3472
3537
|
};
|
3473
3538
|
const cannot = (action, entity, field) => {
|
3474
|
-
|
3539
|
+
const subject = toSubject(entity);
|
3540
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3541
|
+
return (
|
3542
|
+
// Test both the original action
|
3543
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3544
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3545
|
+
);
|
3475
3546
|
};
|
3476
3547
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3477
3548
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3748,6 +3819,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3748
3819
|
const attribute = model.attributes[attributeName];
|
3749
3820
|
switch (attribute.type) {
|
3750
3821
|
case "relation": {
|
3822
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3823
|
+
if (isMorphRelation) {
|
3824
|
+
break;
|
3825
|
+
}
|
3751
3826
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3752
3827
|
populateAcc[attributeName] = {
|
3753
3828
|
count: true,
|
@@ -4125,7 +4200,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4125
4200
|
*/
|
4126
4201
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4127
4202
|
if (!document) {
|
4128
|
-
return
|
4203
|
+
return {
|
4204
|
+
data: document,
|
4205
|
+
meta: {
|
4206
|
+
availableLocales: [],
|
4207
|
+
availableStatus: []
|
4208
|
+
}
|
4209
|
+
};
|
4129
4210
|
}
|
4130
4211
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4131
4212
|
if (!hasDraftAndPublish) {
|
@@ -4233,10 +4314,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4233
4314
|
async clone(id, body, uid2) {
|
4234
4315
|
const populate = await buildDeepPopulate(uid2);
|
4235
4316
|
const params = {
|
4236
|
-
data:
|
4237
|
-
...omitIdField(body),
|
4238
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4239
|
-
},
|
4317
|
+
data: omitIdField(body),
|
4240
4318
|
populate
|
4241
4319
|
};
|
4242
4320
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|