@strapi/content-manager 0.0.0-experimental.826f263c58b6886b849d3f03b81f7a530bc51c91 → 0.0.0-experimental.86fea32ae4240d73f76516d7238e302b6b927e88
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-CR5XdR33.mjs → ComponentConfigurationPage-B2g3icXu.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-B2g3icXu.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js → ComponentConfigurationPage-CzDn8Uxh.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage-CzDn8Uxh.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-Bcbi6r5y.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-Bcbi6r5y.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-DSA1zONV.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-DSA1zONV.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-BvcMXaP2.js} +68 -47
- package/dist/_chunks/EditViewPage-BvcMXaP2.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DvaV7U9b.mjs → EditViewPage-Ca2EmJpb.mjs} +69 -48
- package/dist/_chunks/EditViewPage-Ca2EmJpb.mjs.map +1 -0
- package/dist/_chunks/{Field-Cz_J9551.mjs → Field-BEYkgCZ0.mjs} +579 -227
- package/dist/_chunks/Field-BEYkgCZ0.mjs.map +1 -0
- package/dist/_chunks/{Field-ZdrmmQ4Y.js → Field-CmaWxdpf.js} +581 -229
- package/dist/_chunks/Field-CmaWxdpf.js.map +1 -0
- package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-BJVbU6w4.mjs} +54 -36
- package/dist/_chunks/Form-BJVbU6w4.mjs.map +1 -0
- package/dist/_chunks/{Form-Bpig5rch.js → Form-DAUpPBVM.js} +52 -34
- package/dist/_chunks/Form-DAUpPBVM.js.map +1 -0
- package/dist/_chunks/{History-BfX6XmZK.js → History-Bw9vfT1k.js} +157 -40
- package/dist/_chunks/History-Bw9vfT1k.js.map +1 -0
- package/dist/_chunks/{History-BZP8n7KT.mjs → History-M6Pk9CoY.mjs} +158 -41
- package/dist/_chunks/History-M6Pk9CoY.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-D7ior2zq.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-D7ior2zq.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-DBVqF5fc.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-DBVqF5fc.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-BH37wONY.mjs} +103 -102
- package/dist/_chunks/ListViewPage-BH37wONY.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-MZu-8OKX.js} +105 -104
- package/dist/_chunks/ListViewPage-MZu-8OKX.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-C9lRMTCa.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-C9lRMTCa.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-DRp7Aem_.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-DRp7Aem_.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-COs61PpB.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-COs61PpB.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-CzhRt5CA.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-CzhRt5CA.mjs.map} +1 -1
- package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-68XxIzPI.mjs} +50 -29
- package/dist/_chunks/Relations-68XxIzPI.mjs.map +1 -0
- package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-CsGlulU_.js} +50 -29
- package/dist/_chunks/Relations-CsGlulU_.js.map +1 -0
- package/dist/_chunks/{en-BN1bvFK7.js → en-Bm0D0IWz.js} +20 -15
- package/dist/_chunks/{en-BN1bvFK7.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-Dzv55oQw.mjs → en-DKV44jRb.mjs} +20 -15
- package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-VHviNMeW.mjs → index-CsfwpRfc.mjs} +1078 -895
- package/dist/_chunks/index-CsfwpRfc.mjs.map +1 -0
- package/dist/_chunks/{index-DzN3kBgx.js → index-oDq3VO9j.js} +1047 -863
- package/dist/_chunks/index-oDq3VO9j.js.map +1 -0
- package/dist/_chunks/{layout-CPn1PM6x.mjs → layout-C5uSVTqi.mjs} +41 -23
- package/dist/_chunks/layout-C5uSVTqi.mjs.map +1 -0
- package/dist/_chunks/{layout-b91XRlD2.js → layout-Euka-kfv.js} +39 -21
- package/dist/_chunks/layout-Euka-kfv.js.map +1 -0
- package/dist/_chunks/{relations-BsqxS6tR.mjs → relations-BpHVgFuV.mjs} +2 -2
- package/dist/_chunks/{relations-BsqxS6tR.mjs.map → relations-BpHVgFuV.mjs.map} +1 -1
- package/dist/_chunks/{relations-CA7IYmcP.js → relations-DG7kmxa0.js} +2 -2
- package/dist/_chunks/{relations-CA7IYmcP.js.map → relations-DG7kmxa0.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 +7 -6
- package/dist/admin/src/exports.d.ts +1 -1
- 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/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -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 +6 -58
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- 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/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 +214 -121
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +215 -122
- 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 +12 -12
- package/dist/_chunks/EditViewPage-CoQEnFlC.js.map +0 -1
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
- package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
- package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
- package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
- package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
- package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
- package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
- package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
- package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
- package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
- package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
- package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
- package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
- package/dist/_chunks/layout-b91XRlD2.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,20 +228,25 @@ 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
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
239
|
+
if (isMorphRelation) {
|
240
|
+
break;
|
241
|
+
}
|
235
242
|
const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
236
243
|
if (isVisible2) {
|
237
|
-
acc[attributeName] = {
|
244
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
238
245
|
}
|
239
246
|
break;
|
240
247
|
}
|
241
248
|
case "media": {
|
242
|
-
acc[attributeName] = {
|
249
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
243
250
|
break;
|
244
251
|
}
|
245
252
|
case "component": {
|
@@ -312,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
312
319
|
getRelationRestoreValue,
|
313
320
|
getMediaRestoreValue,
|
314
321
|
getDefaultLocale,
|
322
|
+
isLocalizedContentType,
|
315
323
|
getLocaleDictionary,
|
316
324
|
getRetentionDays,
|
317
325
|
getVersionStatus,
|
@@ -334,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
334
342
|
});
|
335
343
|
},
|
336
344
|
async findVersionsPage(params) {
|
337
|
-
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
|
+
}
|
338
352
|
const [{ results, pagination }, localeDictionary] = await Promise.all([
|
339
353
|
query.findPage({
|
340
354
|
...params.query,
|
@@ -379,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
379
393
|
if (userToPopulate == null) {
|
380
394
|
return null;
|
381
395
|
}
|
382
|
-
return strapi2.query("admin::user").findOne({
|
396
|
+
return strapi2.query("admin::user").findOne({
|
397
|
+
where: {
|
398
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
399
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
400
|
+
}
|
401
|
+
});
|
383
402
|
})
|
384
403
|
);
|
385
404
|
return {
|
@@ -490,13 +509,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
490
509
|
}
|
491
510
|
};
|
492
511
|
};
|
512
|
+
const shouldCreateHistoryVersion = (context) => {
|
513
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
514
|
+
return false;
|
515
|
+
}
|
516
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
517
|
+
return false;
|
518
|
+
}
|
519
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
520
|
+
return false;
|
521
|
+
}
|
522
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
523
|
+
return false;
|
524
|
+
}
|
525
|
+
return true;
|
526
|
+
};
|
527
|
+
const getSchemas = (uid2) => {
|
528
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
529
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
530
|
+
(currentComponentSchemas, key) => {
|
531
|
+
const fieldSchema = attributesSchema[key];
|
532
|
+
if (fieldSchema.type === "component") {
|
533
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
534
|
+
return {
|
535
|
+
...currentComponentSchemas,
|
536
|
+
[fieldSchema.component]: componentSchema
|
537
|
+
};
|
538
|
+
}
|
539
|
+
return currentComponentSchemas;
|
540
|
+
},
|
541
|
+
{}
|
542
|
+
);
|
543
|
+
return {
|
544
|
+
schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
|
545
|
+
componentsSchemas
|
546
|
+
};
|
547
|
+
};
|
493
548
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
494
549
|
const state = {
|
495
550
|
deleteExpiredJob: null,
|
496
551
|
isInitialized: false
|
497
552
|
};
|
498
|
-
const query = strapi2.db.query(HISTORY_VERSION_UID);
|
499
|
-
const historyService = getService(strapi2, "history");
|
500
553
|
const serviceUtils = createServiceUtils({ strapi: strapi2 });
|
501
554
|
return {
|
502
555
|
async bootstrap() {
|
@@ -504,60 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
504
557
|
return;
|
505
558
|
}
|
506
559
|
strapi2.documents.use(async (context, next) => {
|
507
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
508
|
-
return next();
|
509
|
-
}
|
510
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
511
|
-
return next();
|
512
|
-
}
|
513
|
-
const contentTypeUid = context.contentType.uid;
|
514
|
-
if (!contentTypeUid.startsWith("api::")) {
|
515
|
-
return next();
|
516
|
-
}
|
517
560
|
const result = await next();
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
561
|
+
if (!shouldCreateHistoryVersion(context)) {
|
562
|
+
return result;
|
563
|
+
}
|
564
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
522
565
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
523
|
-
const
|
524
|
-
if (
|
525
|
-
|
526
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
527
|
-
);
|
528
|
-
return next();
|
566
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
567
|
+
if (!locales.length) {
|
568
|
+
return result;
|
529
569
|
}
|
530
|
-
const
|
531
|
-
|
532
|
-
|
533
|
-
|
570
|
+
const uid2 = context.contentType.uid;
|
571
|
+
const schemas = getSchemas(uid2);
|
572
|
+
const model = strapi2.getModel(uid2);
|
573
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
574
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
575
|
+
where: {
|
576
|
+
documentId,
|
577
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
578
|
+
...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
579
|
+
},
|
580
|
+
populate: serviceUtils.getDeepPopulate(
|
581
|
+
uid2,
|
582
|
+
true
|
583
|
+
/* use database syntax */
|
584
|
+
)
|
534
585
|
});
|
535
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
536
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
537
|
-
const componentsSchemas = Object.keys(
|
538
|
-
attributesSchema
|
539
|
-
).reduce((currentComponentSchemas, key) => {
|
540
|
-
const fieldSchema = attributesSchema[key];
|
541
|
-
if (fieldSchema.type === "component") {
|
542
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
543
|
-
return {
|
544
|
-
...currentComponentSchemas,
|
545
|
-
[fieldSchema.component]: componentSchema
|
546
|
-
};
|
547
|
-
}
|
548
|
-
return currentComponentSchemas;
|
549
|
-
}, {});
|
550
586
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
551
|
-
onCommit(() => {
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
587
|
+
onCommit(async () => {
|
588
|
+
for (const entry of localeEntries) {
|
589
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
+
await getService(strapi2, "history").createVersion({
|
591
|
+
contentType: uid2,
|
592
|
+
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
|
+
relatedDocumentId: documentId,
|
594
|
+
locale: entry.locale,
|
595
|
+
status,
|
596
|
+
...schemas
|
597
|
+
});
|
598
|
+
}
|
561
599
|
});
|
562
600
|
});
|
563
601
|
return result;
|
@@ -565,7 +603,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
565
603
|
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
566
604
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
567
605
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
568
|
-
query.deleteMany({
|
606
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
569
607
|
where: {
|
570
608
|
created_at: {
|
571
609
|
$lt: expirationDate.toISOString()
|
@@ -1197,6 +1235,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1197
1235
|
const hasPermissions = createPolicy({
|
1198
1236
|
name: "plugin::content-manager.hasPermissions",
|
1199
1237
|
validator: validateHasPermissionsInput,
|
1238
|
+
/**
|
1239
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1240
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1241
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1242
|
+
*/
|
1200
1243
|
handler(ctx, config = {}) {
|
1201
1244
|
const { actions = [], hasAtLeastOne = false } = config;
|
1202
1245
|
const { userAbility } = ctx.state;
|
@@ -1590,9 +1633,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1590
1633
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1591
1634
|
);
|
1592
1635
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1593
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1636
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1594
1637
|
const { allowMultipleLocales } = opts;
|
1595
|
-
const { locale, status, ...rest } = request || {};
|
1638
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1639
|
+
const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1640
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1596
1641
|
const schema = strapiUtils.yup.object().shape({
|
1597
1642
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1598
1643
|
status: statusSchema
|
@@ -1640,7 +1685,7 @@ const createDocument = async (ctx, opts) => {
|
|
1640
1685
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1641
1686
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1642
1687
|
const sanitizedBody = await sanitizeFn(body);
|
1643
|
-
const { locale, status
|
1688
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1644
1689
|
return documentManager2.create(model, {
|
1645
1690
|
data: sanitizedBody,
|
1646
1691
|
locale,
|
@@ -1659,7 +1704,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1659
1704
|
}
|
1660
1705
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1661
1706
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1662
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1707
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1663
1708
|
const [documentVersion, documentExists] = await Promise.all([
|
1664
1709
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1665
1710
|
documentManager2.exists(model, id)
|
@@ -1675,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1675
1720
|
throw new strapiUtils.errors.ForbiddenError();
|
1676
1721
|
}
|
1677
1722
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1678
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1723
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1679
1724
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1680
1725
|
const sanitizedBody = await sanitizeFn(body);
|
1681
1726
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1697,7 +1742,7 @@ const collectionTypes = {
|
|
1697
1742
|
}
|
1698
1743
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1699
1744
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1700
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1745
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1701
1746
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1702
1747
|
{ ...permissionQuery, populate, locale, status },
|
1703
1748
|
model
|
@@ -1732,7 +1777,7 @@ const collectionTypes = {
|
|
1732
1777
|
}
|
1733
1778
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1734
1779
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1735
|
-
const { locale, status
|
1780
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1736
1781
|
const version = await documentManager2.findOne(id, model, {
|
1737
1782
|
populate,
|
1738
1783
|
locale,
|
@@ -1747,7 +1792,7 @@ const collectionTypes = {
|
|
1747
1792
|
permissionChecker2,
|
1748
1793
|
model,
|
1749
1794
|
// @ts-expect-error TODO: fix
|
1750
|
-
{ id, locale, publishedAt: null },
|
1795
|
+
{ documentId: id, locale, publishedAt: null },
|
1751
1796
|
{ availableLocales: true, availableStatus: false }
|
1752
1797
|
);
|
1753
1798
|
ctx.body = { data: {}, meta };
|
@@ -1799,7 +1844,7 @@ const collectionTypes = {
|
|
1799
1844
|
}
|
1800
1845
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1801
1846
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1802
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1847
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1803
1848
|
const document = await documentManager2.findOne(id, model, {
|
1804
1849
|
populate,
|
1805
1850
|
locale,
|
@@ -1844,7 +1889,7 @@ const collectionTypes = {
|
|
1844
1889
|
}
|
1845
1890
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1846
1891
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1847
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1892
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1848
1893
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1849
1894
|
if (documentLocales.length === 0) {
|
1850
1895
|
return ctx.notFound();
|
@@ -1873,11 +1918,34 @@ const collectionTypes = {
|
|
1873
1918
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1874
1919
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1875
1920
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1876
|
-
|
1921
|
+
let document;
|
1922
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1923
|
+
const isCreate = fp.isNil(id);
|
1924
|
+
if (isCreate) {
|
1925
|
+
if (permissionChecker2.cannot.create()) {
|
1926
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1927
|
+
}
|
1928
|
+
document = await createDocument(ctx, { populate });
|
1929
|
+
}
|
1930
|
+
const isUpdate = !isCreate;
|
1931
|
+
if (isUpdate) {
|
1932
|
+
const documentExists = documentManager2.exists(model, id);
|
1933
|
+
if (!documentExists) {
|
1934
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1935
|
+
}
|
1936
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1937
|
+
if (!document) {
|
1938
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
1939
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1940
|
+
}
|
1941
|
+
document = await updateDocument(ctx);
|
1942
|
+
} else if (permissionChecker2.can.update(document)) {
|
1943
|
+
await updateDocument(ctx);
|
1944
|
+
}
|
1945
|
+
}
|
1877
1946
|
if (permissionChecker2.cannot.publish(document)) {
|
1878
1947
|
throw new strapiUtils.errors.ForbiddenError();
|
1879
1948
|
}
|
1880
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1881
1949
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1882
1950
|
locale
|
1883
1951
|
// TODO: Allow setting creator fields on publish
|
@@ -1904,7 +1972,9 @@ const collectionTypes = {
|
|
1904
1972
|
}
|
1905
1973
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1906
1974
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1907
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1975
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1976
|
+
allowMultipleLocales: true
|
1977
|
+
});
|
1908
1978
|
const entityPromises = documentIds.map(
|
1909
1979
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1910
1980
|
);
|
@@ -1931,7 +2001,9 @@ const collectionTypes = {
|
|
1931
2001
|
if (permissionChecker2.cannot.unpublish()) {
|
1932
2002
|
return ctx.forbidden();
|
1933
2003
|
}
|
1934
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
2004
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2005
|
+
allowMultipleLocales: true
|
2006
|
+
});
|
1935
2007
|
const entityPromises = documentIds.map(
|
1936
2008
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1937
2009
|
);
|
@@ -1964,7 +2036,7 @@ const collectionTypes = {
|
|
1964
2036
|
}
|
1965
2037
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1966
2038
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1967
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2039
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1968
2040
|
const document = await documentManager2.findOne(id, model, {
|
1969
2041
|
populate,
|
1970
2042
|
locale,
|
@@ -2001,7 +2073,7 @@ const collectionTypes = {
|
|
2001
2073
|
}
|
2002
2074
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2003
2075
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2004
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2076
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2005
2077
|
const document = await documentManager2.findOne(id, model, {
|
2006
2078
|
populate,
|
2007
2079
|
locale,
|
@@ -2032,7 +2104,7 @@ const collectionTypes = {
|
|
2032
2104
|
}
|
2033
2105
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2034
2106
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2035
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2107
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2036
2108
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2037
2109
|
populate,
|
2038
2110
|
locale
|
@@ -2059,7 +2131,7 @@ const collectionTypes = {
|
|
2059
2131
|
}
|
2060
2132
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2061
2133
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2062
|
-
const { locale, status
|
2134
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2063
2135
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2064
2136
|
if (!entity) {
|
2065
2137
|
return ctx.notFound();
|
@@ -2082,7 +2154,7 @@ const collectionTypes = {
|
|
2082
2154
|
if (permissionChecker2.cannot.read()) {
|
2083
2155
|
return ctx.forbidden();
|
2084
2156
|
}
|
2085
|
-
const
|
2157
|
+
const documents = await documentManager2.findMany(
|
2086
2158
|
{
|
2087
2159
|
filters: {
|
2088
2160
|
documentId: ids
|
@@ -2091,7 +2163,7 @@ const collectionTypes = {
|
|
2091
2163
|
},
|
2092
2164
|
model
|
2093
2165
|
);
|
2094
|
-
if (!
|
2166
|
+
if (!documents) {
|
2095
2167
|
return ctx.notFound();
|
2096
2168
|
}
|
2097
2169
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2282,20 +2354,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2282
2354
|
userAbility,
|
2283
2355
|
model: model.uid
|
2284
2356
|
});
|
2285
|
-
|
2357
|
+
const isMainFieldListable = isListable(model, mainField);
|
2358
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2359
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2286
2360
|
return "id";
|
2287
2361
|
}
|
2288
|
-
if (
|
2289
|
-
|
2290
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2291
|
-
userAbility,
|
2292
|
-
model: "plugin::users-permissions.user"
|
2293
|
-
});
|
2294
|
-
if (userPermissionChecker.can.read()) {
|
2295
|
-
return "name";
|
2296
|
-
}
|
2297
|
-
}
|
2298
|
-
return "id";
|
2362
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2363
|
+
return "name";
|
2299
2364
|
}
|
2300
2365
|
return mainField;
|
2301
2366
|
};
|
@@ -2328,11 +2393,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2328
2393
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2329
2394
|
const isSourceLocalized = isLocalized(sourceModel);
|
2330
2395
|
const isTargetLocalized = isLocalized(targetModel);
|
2331
|
-
let validatedLocale = locale;
|
2332
|
-
if (!targetModel || !isTargetLocalized)
|
2333
|
-
validatedLocale = void 0;
|
2334
2396
|
return {
|
2335
|
-
locale
|
2397
|
+
locale,
|
2336
2398
|
isSourceLocalized,
|
2337
2399
|
isTargetLocalized
|
2338
2400
|
};
|
@@ -2435,7 +2497,7 @@ const relations = {
|
|
2435
2497
|
attribute,
|
2436
2498
|
fieldsToSelect,
|
2437
2499
|
mainField,
|
2438
|
-
source: { schema: sourceSchema },
|
2500
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2439
2501
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2440
2502
|
sourceSchema,
|
2441
2503
|
targetSchema,
|
@@ -2457,7 +2519,8 @@ const relations = {
|
|
2457
2519
|
fieldsToSelect,
|
2458
2520
|
mainField,
|
2459
2521
|
source: {
|
2460
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2522
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2523
|
+
isLocalized: isSourceLocalized
|
2461
2524
|
},
|
2462
2525
|
target: {
|
2463
2526
|
schema: { uid: targetUid },
|
@@ -2495,12 +2558,16 @@ const relations = {
|
|
2495
2558
|
} else {
|
2496
2559
|
where.id = id;
|
2497
2560
|
}
|
2498
|
-
|
2499
|
-
|
2561
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2562
|
+
if (!fp.isEmpty(publishedAt)) {
|
2563
|
+
where[`${alias}.published_at`] = publishedAt;
|
2500
2564
|
}
|
2501
|
-
if (
|
2565
|
+
if (isTargetLocalized && locale) {
|
2502
2566
|
where[`${alias}.locale`] = locale;
|
2503
2567
|
}
|
2568
|
+
if (isSourceLocalized && locale) {
|
2569
|
+
where.locale = locale;
|
2570
|
+
}
|
2504
2571
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2505
2572
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2506
2573
|
}
|
@@ -2518,7 +2585,8 @@ const relations = {
|
|
2518
2585
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2519
2586
|
});
|
2520
2587
|
}
|
2521
|
-
const
|
2588
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2589
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2522
2590
|
ctx.body = {
|
2523
2591
|
...res,
|
2524
2592
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2553,11 +2621,14 @@ const relations = {
|
|
2553
2621
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2554
2622
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2555
2623
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2556
|
-
ordering: "desc"
|
2557
|
-
page: ctx.request.query.page,
|
2558
|
-
pageSize: ctx.request.query.pageSize
|
2624
|
+
ordering: "desc"
|
2559
2625
|
});
|
2560
|
-
const relationsUnion = fp.uniqBy(
|
2626
|
+
const relationsUnion = fp.uniqBy(
|
2627
|
+
(res2) => {
|
2628
|
+
return res2.locale ? `${res2.documentId}-${res2.locale}` : `${res2.documentId}-`;
|
2629
|
+
},
|
2630
|
+
fp.concat(sanitizedRes.results, res.results)
|
2631
|
+
);
|
2561
2632
|
ctx.body = {
|
2562
2633
|
pagination: res.pagination || {
|
2563
2634
|
page: 1,
|
@@ -2587,7 +2658,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2587
2658
|
throw new strapiUtils.errors.ForbiddenError();
|
2588
2659
|
}
|
2589
2660
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2590
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2661
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2591
2662
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2592
2663
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2593
2664
|
// Find the first document to check if it exists
|
@@ -2628,7 +2699,7 @@ const singleTypes = {
|
|
2628
2699
|
return ctx.forbidden();
|
2629
2700
|
}
|
2630
2701
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2631
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2702
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2632
2703
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2633
2704
|
if (!version) {
|
2634
2705
|
if (permissionChecker2.cannot.create()) {
|
@@ -2642,7 +2713,7 @@ const singleTypes = {
|
|
2642
2713
|
permissionChecker2,
|
2643
2714
|
model,
|
2644
2715
|
// @ts-expect-error - fix types
|
2645
|
-
{
|
2716
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2646
2717
|
{ availableLocales: true, availableStatus: false }
|
2647
2718
|
);
|
2648
2719
|
ctx.body = { data: {}, meta };
|
@@ -2673,7 +2744,7 @@ const singleTypes = {
|
|
2673
2744
|
}
|
2674
2745
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2675
2746
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2676
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2747
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2677
2748
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2678
2749
|
populate,
|
2679
2750
|
locale
|
@@ -2710,7 +2781,7 @@ const singleTypes = {
|
|
2710
2781
|
if (permissionChecker2.cannot.publish(document)) {
|
2711
2782
|
throw new strapiUtils.errors.ForbiddenError();
|
2712
2783
|
}
|
2713
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2784
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2714
2785
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2715
2786
|
return publishResult.at(0);
|
2716
2787
|
});
|
@@ -2733,7 +2804,7 @@ const singleTypes = {
|
|
2733
2804
|
return ctx.forbidden();
|
2734
2805
|
}
|
2735
2806
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2736
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2807
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2737
2808
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2738
2809
|
if (!document) {
|
2739
2810
|
return ctx.notFound();
|
@@ -2765,7 +2836,7 @@ const singleTypes = {
|
|
2765
2836
|
return ctx.forbidden();
|
2766
2837
|
}
|
2767
2838
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2768
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2839
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2769
2840
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2770
2841
|
if (!document) {
|
2771
2842
|
return ctx.notFound();
|
@@ -2785,7 +2856,7 @@ const singleTypes = {
|
|
2785
2856
|
const { query } = ctx.request;
|
2786
2857
|
const documentManager2 = getService$1("document-manager");
|
2787
2858
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2788
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2859
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2789
2860
|
if (permissionChecker2.cannot.read()) {
|
2790
2861
|
return ctx.forbidden();
|
2791
2862
|
}
|
@@ -2806,7 +2877,7 @@ const uid$1 = {
|
|
2806
2877
|
async generateUID(ctx) {
|
2807
2878
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2808
2879
|
const { query = {} } = ctx.request;
|
2809
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2880
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2810
2881
|
await validateUIDField(contentTypeUID, field);
|
2811
2882
|
const uidService = getService$1("uid");
|
2812
2883
|
ctx.body = {
|
@@ -2818,7 +2889,7 @@ const uid$1 = {
|
|
2818
2889
|
ctx.request.body
|
2819
2890
|
);
|
2820
2891
|
const { query = {} } = ctx.request;
|
2821
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2892
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2822
2893
|
await validateUIDField(contentTypeUID, field);
|
2823
2894
|
const uidService = getService$1("uid");
|
2824
2895
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3461,12 +3532,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3461
3532
|
ability: userAbility,
|
3462
3533
|
model
|
3463
3534
|
});
|
3464
|
-
const
|
3535
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3536
|
+
const toSubject = (entity) => {
|
3537
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3538
|
+
};
|
3465
3539
|
const can = (action, entity, field) => {
|
3466
|
-
|
3540
|
+
const subject = toSubject(entity);
|
3541
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3542
|
+
return (
|
3543
|
+
// Test the original action to see if it passes
|
3544
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3545
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3546
|
+
);
|
3467
3547
|
};
|
3468
3548
|
const cannot = (action, entity, field) => {
|
3469
|
-
|
3549
|
+
const subject = toSubject(entity);
|
3550
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3551
|
+
return (
|
3552
|
+
// Test both the original action
|
3553
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3554
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3555
|
+
);
|
3470
3556
|
};
|
3471
3557
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3472
3558
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3743,6 +3829,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3743
3829
|
const attribute = model.attributes[attributeName];
|
3744
3830
|
switch (attribute.type) {
|
3745
3831
|
case "relation": {
|
3832
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3833
|
+
if (isMorphRelation) {
|
3834
|
+
break;
|
3835
|
+
}
|
3746
3836
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3747
3837
|
populateAcc[attributeName] = {
|
3748
3838
|
count: true,
|
@@ -4120,7 +4210,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4120
4210
|
*/
|
4121
4211
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4122
4212
|
if (!document) {
|
4123
|
-
return
|
4213
|
+
return {
|
4214
|
+
data: document,
|
4215
|
+
meta: {
|
4216
|
+
availableLocales: [],
|
4217
|
+
availableStatus: []
|
4218
|
+
}
|
4219
|
+
};
|
4124
4220
|
}
|
4125
4221
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4126
4222
|
if (!hasDraftAndPublish) {
|
@@ -4228,10 +4324,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4228
4324
|
async clone(id, body, uid2) {
|
4229
4325
|
const populate = await buildDeepPopulate(uid2);
|
4230
4326
|
const params = {
|
4231
|
-
data:
|
4232
|
-
...omitIdField(body),
|
4233
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4234
|
-
},
|
4327
|
+
data: omitIdField(body),
|
4235
4328
|
populate
|
4236
4329
|
};
|
4237
4330
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|