@strapi/content-manager 0.0.0-experimental.62ce06180fe9a772eaeb3d43d238b26644f39f7c → 0.0.0-experimental.646ad2aaf2b8f9970409242af8d77b0512d19bd1
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-Cl7eB3s4.js → ComponentConfigurationPage-D1SEOQBu.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Cl7eB3s4.js.map → ComponentConfigurationPage-D1SEOQBu.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DErJQEVW.mjs → ComponentConfigurationPage-oqdZo6l8.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DErJQEVW.mjs.map → ComponentConfigurationPage-oqdZo6l8.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CyfFvH6-.js → EditConfigurationPage-BP94U6vG.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CyfFvH6-.js.map → EditConfigurationPage-BP94U6vG.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CBosWqQ7.mjs → EditConfigurationPage-DVLmpXPs.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CBosWqQ7.mjs.map → EditConfigurationPage-DVLmpXPs.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DxyAOItK.js → EditViewPage-BfAywbBE.js} +30 -9
- package/dist/_chunks/EditViewPage-BfAywbBE.js.map +1 -0
- package/dist/_chunks/{EditViewPage-ClIueJnM.mjs → EditViewPage-Cvjs7D6M.mjs} +30 -9
- package/dist/_chunks/EditViewPage-Cvjs7D6M.mjs.map +1 -0
- package/dist/_chunks/{Field-BZBYmvaf.mjs → Field-CJrfStLX.mjs} +517 -153
- package/dist/_chunks/Field-CJrfStLX.mjs.map +1 -0
- package/dist/_chunks/{Field-C0Y_SR9e.js → Field-DC7FM64m.js} +519 -155
- package/dist/_chunks/Field-DC7FM64m.js.map +1 -0
- package/dist/_chunks/{Form-DwvGnISS.js → Form-Ahp2hi7E.js} +36 -17
- package/dist/_chunks/Form-Ahp2hi7E.js.map +1 -0
- package/dist/_chunks/{Form-jwRSC2kV.mjs → Form-BTgUlCEm.mjs} +36 -17
- package/dist/_chunks/Form-BTgUlCEm.mjs.map +1 -0
- package/dist/_chunks/{History-Cda0Yjzz.js → History-DZ9T1ZL6.js} +63 -25
- package/dist/_chunks/History-DZ9T1ZL6.js.map +1 -0
- package/dist/_chunks/{History-BgzAIj0G.mjs → History-Drr6mxnK.mjs} +64 -26
- package/dist/_chunks/History-Drr6mxnK.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-C29EF97r.js → ListConfigurationPage-B8bYMcVE.js} +20 -8
- package/dist/_chunks/ListConfigurationPage-B8bYMcVE.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-GH55qfoT.mjs → ListConfigurationPage-C6calJtW.mjs} +20 -8
- package/dist/_chunks/ListConfigurationPage-C6calJtW.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CnRt0UT7.js → ListViewPage-BfiTNTUl.js} +61 -43
- package/dist/_chunks/ListViewPage-BfiTNTUl.js.map +1 -0
- package/dist/_chunks/{ListViewPage-QU03PFj1.mjs → ListViewPage-CQb0CL40.mjs} +59 -41
- package/dist/_chunks/ListViewPage-CQb0CL40.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-CPs2CnzH.mjs → NoContentTypePage-C-BK38Ai.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CPs2CnzH.mjs.map → NoContentTypePage-C-BK38Ai.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DFDjxByI.js → NoContentTypePage-wJwVyqoZ.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DFDjxByI.js.map → NoContentTypePage-wJwVyqoZ.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-ct58lcY0.mjs → NoPermissionsPage-BBdxJ-4m.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-ct58lcY0.mjs.map → NoPermissionsPage-BBdxJ-4m.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BVHI-jv5.js → NoPermissionsPage-DKaXyuK9.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BVHI-jv5.js.map → NoPermissionsPage-DKaXyuK9.js.map} +1 -1
- package/dist/_chunks/{Relations-BjpPPCKp.js → Relations-D7NskJzt.js} +69 -36
- package/dist/_chunks/Relations-D7NskJzt.js.map +1 -0
- package/dist/_chunks/{Relations-KMf5qEN0.mjs → Relations-DApDLUXv.mjs} +70 -37
- package/dist/_chunks/Relations-DApDLUXv.mjs.map +1 -0
- package/dist/_chunks/{en-fbKQxLGn.js → en-Bm0D0IWz.js} +17 -15
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-DKV44jRb.mjs} +17 -15
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-6kKXK7y8.mjs → index-Bz1SCyIj.mjs} +1005 -686
- package/dist/_chunks/index-Bz1SCyIj.mjs.map +1 -0
- package/dist/_chunks/{index-D9ZwczCV.js → index-D3u7haqj.js} +998 -678
- package/dist/_chunks/index-D3u7haqj.js.map +1 -0
- package/dist/_chunks/{layout-BJfBoBiF.js → layout-C_0aK53L.js} +25 -12
- package/dist/_chunks/layout-C_0aK53L.js.map +1 -0
- package/dist/_chunks/{layout-B1Z-9koY.mjs → layout-PNlIceEV.mjs} +27 -14
- package/dist/_chunks/layout-PNlIceEV.mjs.map +1 -0
- package/dist/_chunks/{relations-CgZg7Pyx.mjs → relations-BAIQsBLx.mjs} +3 -7
- package/dist/_chunks/relations-BAIQsBLx.mjs.map +1 -0
- package/dist/_chunks/{relations-CMvjzyU3.js → relations-ClRXiXcM.js} +3 -7
- package/dist/_chunks/relations-ClRXiXcM.js.map +1 -0
- 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 +3 -2
- package/dist/admin/src/exports.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 +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 +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 +245 -132
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +246 -133
- 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/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.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/index.d.ts +4 -4
- 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 +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.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-ClIueJnM.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-DxyAOItK.js.map +0 -1
- package/dist/_chunks/Field-BZBYmvaf.mjs.map +0 -1
- package/dist/_chunks/Field-C0Y_SR9e.js.map +0 -1
- package/dist/_chunks/Form-DwvGnISS.js.map +0 -1
- package/dist/_chunks/Form-jwRSC2kV.mjs.map +0 -1
- package/dist/_chunks/History-BgzAIj0G.mjs.map +0 -1
- package/dist/_chunks/History-Cda0Yjzz.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-C29EF97r.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-GH55qfoT.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CnRt0UT7.js.map +0 -1
- package/dist/_chunks/ListViewPage-QU03PFj1.mjs.map +0 -1
- package/dist/_chunks/Relations-BjpPPCKp.js.map +0 -1
- package/dist/_chunks/Relations-KMf5qEN0.mjs.map +0 -1
- package/dist/_chunks/index-6kKXK7y8.mjs.map +0 -1
- package/dist/_chunks/index-D9ZwczCV.js.map +0 -1
- package/dist/_chunks/layout-B1Z-9koY.mjs.map +0 -1
- package/dist/_chunks/layout-BJfBoBiF.js.map +0 -1
- package/dist/_chunks/relations-CMvjzyU3.js.map +0 -1
- package/dist/_chunks/relations-CgZg7Pyx.mjs.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,6 +509,42 @@ 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,
|
@@ -502,63 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
502
557
|
return;
|
503
558
|
}
|
504
559
|
strapi2.documents.use(async (context, next) => {
|
505
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
506
|
-
return next();
|
507
|
-
}
|
508
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
509
|
-
return next();
|
510
|
-
}
|
511
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
512
|
-
return next();
|
513
|
-
}
|
514
|
-
const contentTypeUid = context.contentType.uid;
|
515
|
-
if (!contentTypeUid.startsWith("api::")) {
|
516
|
-
return next();
|
517
|
-
}
|
518
560
|
const result = await next();
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
561
|
+
if (!shouldCreateHistoryVersion(context)) {
|
562
|
+
return result;
|
563
|
+
}
|
564
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
523
565
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
524
|
-
const
|
525
|
-
if (
|
526
|
-
|
527
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
528
|
-
);
|
529
|
-
return next();
|
566
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
567
|
+
if (!locales.length) {
|
568
|
+
return result;
|
530
569
|
}
|
531
|
-
const
|
532
|
-
|
533
|
-
|
534
|
-
|
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
|
+
)
|
535
585
|
});
|
536
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
537
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
538
|
-
const componentsSchemas = Object.keys(
|
539
|
-
attributesSchema
|
540
|
-
).reduce((currentComponentSchemas, key) => {
|
541
|
-
const fieldSchema = attributesSchema[key];
|
542
|
-
if (fieldSchema.type === "component") {
|
543
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
544
|
-
return {
|
545
|
-
...currentComponentSchemas,
|
546
|
-
[fieldSchema.component]: componentSchema
|
547
|
-
};
|
548
|
-
}
|
549
|
-
return currentComponentSchemas;
|
550
|
-
}, {});
|
551
586
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
552
|
-
onCommit(() => {
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
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
|
+
}
|
562
599
|
});
|
563
600
|
});
|
564
601
|
return result;
|
@@ -1198,6 +1235,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1198
1235
|
const hasPermissions = createPolicy({
|
1199
1236
|
name: "plugin::content-manager.hasPermissions",
|
1200
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
|
+
*/
|
1201
1243
|
handler(ctx, config = {}) {
|
1202
1244
|
const { actions = [], hasAtLeastOne = false } = config;
|
1203
1245
|
const { userAbility } = ctx.state;
|
@@ -1591,9 +1633,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1591
1633
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1592
1634
|
);
|
1593
1635
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1594
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1636
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1595
1637
|
const { allowMultipleLocales } = opts;
|
1596
|
-
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;
|
1597
1641
|
const schema = strapiUtils.yup.object().shape({
|
1598
1642
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1599
1643
|
status: statusSchema
|
@@ -1641,7 +1685,7 @@ const createDocument = async (ctx, opts) => {
|
|
1641
1685
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1642
1686
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1643
1687
|
const sanitizedBody = await sanitizeFn(body);
|
1644
|
-
const { locale, status
|
1688
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1645
1689
|
return documentManager2.create(model, {
|
1646
1690
|
data: sanitizedBody,
|
1647
1691
|
locale,
|
@@ -1660,7 +1704,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1660
1704
|
}
|
1661
1705
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1662
1706
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1663
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1707
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1664
1708
|
const [documentVersion, documentExists] = await Promise.all([
|
1665
1709
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1666
1710
|
documentManager2.exists(model, id)
|
@@ -1676,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1676
1720
|
throw new strapiUtils.errors.ForbiddenError();
|
1677
1721
|
}
|
1678
1722
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1679
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1723
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1680
1724
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1681
1725
|
const sanitizedBody = await sanitizeFn(body);
|
1682
1726
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1698,7 +1742,7 @@ const collectionTypes = {
|
|
1698
1742
|
}
|
1699
1743
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1700
1744
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1701
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1745
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1702
1746
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1703
1747
|
{ ...permissionQuery, populate, locale, status },
|
1704
1748
|
model
|
@@ -1733,7 +1777,7 @@ const collectionTypes = {
|
|
1733
1777
|
}
|
1734
1778
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1735
1779
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1736
|
-
const { locale, status
|
1780
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1737
1781
|
const version = await documentManager2.findOne(id, model, {
|
1738
1782
|
populate,
|
1739
1783
|
locale,
|
@@ -1748,7 +1792,7 @@ const collectionTypes = {
|
|
1748
1792
|
permissionChecker2,
|
1749
1793
|
model,
|
1750
1794
|
// @ts-expect-error TODO: fix
|
1751
|
-
{ id, locale, publishedAt: null },
|
1795
|
+
{ documentId: id, locale, publishedAt: null },
|
1752
1796
|
{ availableLocales: true, availableStatus: false }
|
1753
1797
|
);
|
1754
1798
|
ctx.body = { data: {}, meta };
|
@@ -1800,7 +1844,7 @@ const collectionTypes = {
|
|
1800
1844
|
}
|
1801
1845
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1802
1846
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1803
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1847
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1804
1848
|
const document = await documentManager2.findOne(id, model, {
|
1805
1849
|
populate,
|
1806
1850
|
locale,
|
@@ -1845,7 +1889,7 @@ const collectionTypes = {
|
|
1845
1889
|
}
|
1846
1890
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1847
1891
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1848
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1892
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1849
1893
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1850
1894
|
if (documentLocales.length === 0) {
|
1851
1895
|
return ctx.notFound();
|
@@ -1874,11 +1918,34 @@ const collectionTypes = {
|
|
1874
1918
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1875
1919
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1876
1920
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1877
|
-
|
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
|
+
}
|
1878
1946
|
if (permissionChecker2.cannot.publish(document)) {
|
1879
1947
|
throw new strapiUtils.errors.ForbiddenError();
|
1880
1948
|
}
|
1881
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1882
1949
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1883
1950
|
locale
|
1884
1951
|
// TODO: Allow setting creator fields on publish
|
@@ -1905,7 +1972,9 @@ const collectionTypes = {
|
|
1905
1972
|
}
|
1906
1973
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1907
1974
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1908
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1975
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1976
|
+
allowMultipleLocales: true
|
1977
|
+
});
|
1909
1978
|
const entityPromises = documentIds.map(
|
1910
1979
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1911
1980
|
);
|
@@ -1932,7 +2001,9 @@ const collectionTypes = {
|
|
1932
2001
|
if (permissionChecker2.cannot.unpublish()) {
|
1933
2002
|
return ctx.forbidden();
|
1934
2003
|
}
|
1935
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
2004
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2005
|
+
allowMultipleLocales: true
|
2006
|
+
});
|
1936
2007
|
const entityPromises = documentIds.map(
|
1937
2008
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1938
2009
|
);
|
@@ -1965,7 +2036,7 @@ const collectionTypes = {
|
|
1965
2036
|
}
|
1966
2037
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1967
2038
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1968
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2039
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1969
2040
|
const document = await documentManager2.findOne(id, model, {
|
1970
2041
|
populate,
|
1971
2042
|
locale,
|
@@ -2002,7 +2073,7 @@ const collectionTypes = {
|
|
2002
2073
|
}
|
2003
2074
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2004
2075
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2005
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2076
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2006
2077
|
const document = await documentManager2.findOne(id, model, {
|
2007
2078
|
populate,
|
2008
2079
|
locale,
|
@@ -2033,7 +2104,7 @@ const collectionTypes = {
|
|
2033
2104
|
}
|
2034
2105
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2035
2106
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2036
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2107
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2037
2108
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2038
2109
|
populate,
|
2039
2110
|
locale
|
@@ -2060,7 +2131,7 @@ const collectionTypes = {
|
|
2060
2131
|
}
|
2061
2132
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2062
2133
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2063
|
-
const { locale, status
|
2134
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2064
2135
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2065
2136
|
if (!entity) {
|
2066
2137
|
return ctx.notFound();
|
@@ -2283,32 +2354,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2283
2354
|
userAbility,
|
2284
2355
|
model: model.uid
|
2285
2356
|
});
|
2286
|
-
|
2357
|
+
const isMainFieldListable = isListable(model, mainField);
|
2358
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2359
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2287
2360
|
return "id";
|
2288
2361
|
}
|
2289
|
-
if (
|
2290
|
-
|
2291
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2292
|
-
userAbility,
|
2293
|
-
model: "plugin::users-permissions.user"
|
2294
|
-
});
|
2295
|
-
if (userPermissionChecker.can.read()) {
|
2296
|
-
return "name";
|
2297
|
-
}
|
2298
|
-
}
|
2299
|
-
return "id";
|
2362
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2363
|
+
return "name";
|
2300
2364
|
}
|
2301
2365
|
return mainField;
|
2302
2366
|
};
|
2303
|
-
const addStatusToRelations = async (
|
2304
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2367
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2368
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2305
2369
|
return relations2;
|
2306
2370
|
}
|
2307
2371
|
const documentMetadata2 = getService$1("document-metadata");
|
2308
|
-
|
2372
|
+
if (!relations2.length) {
|
2373
|
+
return relations2;
|
2374
|
+
}
|
2375
|
+
const firstRelation = relations2[0];
|
2376
|
+
const filters = {
|
2377
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2378
|
+
// NOTE: find the "opposite" status
|
2379
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2380
|
+
};
|
2381
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2382
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2383
|
+
filters
|
2384
|
+
});
|
2309
2385
|
return relations2.map((relation) => {
|
2310
|
-
const availableStatuses =
|
2311
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2386
|
+
const availableStatuses = availableStatus.filter(
|
2387
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2312
2388
|
);
|
2313
2389
|
return {
|
2314
2390
|
...relation,
|
@@ -2329,11 +2405,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2329
2405
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2330
2406
|
const isSourceLocalized = isLocalized(sourceModel);
|
2331
2407
|
const isTargetLocalized = isLocalized(targetModel);
|
2332
|
-
let validatedLocale = locale;
|
2333
|
-
if (!targetModel || !isTargetLocalized)
|
2334
|
-
validatedLocale = void 0;
|
2335
2408
|
return {
|
2336
|
-
locale
|
2409
|
+
locale,
|
2337
2410
|
isSourceLocalized,
|
2338
2411
|
isTargetLocalized
|
2339
2412
|
};
|
@@ -2436,7 +2509,7 @@ const relations = {
|
|
2436
2509
|
attribute,
|
2437
2510
|
fieldsToSelect,
|
2438
2511
|
mainField,
|
2439
|
-
source: { schema: sourceSchema },
|
2512
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2440
2513
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2441
2514
|
sourceSchema,
|
2442
2515
|
targetSchema,
|
@@ -2458,7 +2531,8 @@ const relations = {
|
|
2458
2531
|
fieldsToSelect,
|
2459
2532
|
mainField,
|
2460
2533
|
source: {
|
2461
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2534
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2535
|
+
isLocalized: isSourceLocalized
|
2462
2536
|
},
|
2463
2537
|
target: {
|
2464
2538
|
schema: { uid: targetUid },
|
@@ -2496,12 +2570,16 @@ const relations = {
|
|
2496
2570
|
} else {
|
2497
2571
|
where.id = id;
|
2498
2572
|
}
|
2499
|
-
|
2500
|
-
|
2573
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2574
|
+
if (!fp.isEmpty(publishedAt)) {
|
2575
|
+
where[`${alias}.published_at`] = publishedAt;
|
2501
2576
|
}
|
2502
|
-
if (
|
2577
|
+
if (isTargetLocalized && locale) {
|
2503
2578
|
where[`${alias}.locale`] = locale;
|
2504
2579
|
}
|
2580
|
+
if (isSourceLocalized && locale) {
|
2581
|
+
where.locale = locale;
|
2582
|
+
}
|
2505
2583
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2506
2584
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2507
2585
|
}
|
@@ -2519,7 +2597,8 @@ const relations = {
|
|
2519
2597
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2520
2598
|
});
|
2521
2599
|
}
|
2522
|
-
const
|
2600
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2601
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2523
2602
|
ctx.body = {
|
2524
2603
|
...res,
|
2525
2604
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2534,29 +2613,39 @@ const relations = {
|
|
2534
2613
|
attribute,
|
2535
2614
|
targetField,
|
2536
2615
|
fieldsToSelect,
|
2537
|
-
|
2538
|
-
|
2539
|
-
}
|
2540
|
-
target: {
|
2541
|
-
schema: { uid: targetUid }
|
2542
|
-
}
|
2616
|
+
status,
|
2617
|
+
source: { schema: sourceSchema },
|
2618
|
+
target: { schema: targetSchema }
|
2543
2619
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2620
|
+
const { uid: sourceUid } = sourceSchema;
|
2621
|
+
const { uid: targetUid } = targetSchema;
|
2544
2622
|
const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2545
2623
|
const dbQuery = strapi.db.query(sourceUid);
|
2546
2624
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2625
|
+
const filters = {};
|
2626
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2627
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2628
|
+
if (status === "published") {
|
2629
|
+
filters.publishedAt = { $notNull: true };
|
2630
|
+
} else {
|
2631
|
+
filters.publishedAt = { $null: true };
|
2632
|
+
}
|
2633
|
+
}
|
2634
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2635
|
+
filters.publishedAt = { $null: true };
|
2636
|
+
}
|
2547
2637
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2548
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2638
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2549
2639
|
ordering: "desc",
|
2550
2640
|
page: ctx.request.query.page,
|
2551
|
-
pageSize: ctx.request.query.pageSize
|
2641
|
+
pageSize: ctx.request.query.pageSize,
|
2642
|
+
filters
|
2552
2643
|
});
|
2553
2644
|
const loadedIds = res.results.map((item) => item.id);
|
2554
2645
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2555
2646
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2556
2647
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2557
|
-
ordering: "desc"
|
2558
|
-
page: ctx.request.query.page,
|
2559
|
-
pageSize: ctx.request.query.pageSize
|
2648
|
+
ordering: "desc"
|
2560
2649
|
});
|
2561
2650
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2562
2651
|
ctx.body = {
|
@@ -2588,7 +2677,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2588
2677
|
throw new strapiUtils.errors.ForbiddenError();
|
2589
2678
|
}
|
2590
2679
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2591
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2680
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2592
2681
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2593
2682
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2594
2683
|
// Find the first document to check if it exists
|
@@ -2629,7 +2718,7 @@ const singleTypes = {
|
|
2629
2718
|
return ctx.forbidden();
|
2630
2719
|
}
|
2631
2720
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2632
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2721
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2633
2722
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2634
2723
|
if (!version) {
|
2635
2724
|
if (permissionChecker2.cannot.create()) {
|
@@ -2643,7 +2732,7 @@ const singleTypes = {
|
|
2643
2732
|
permissionChecker2,
|
2644
2733
|
model,
|
2645
2734
|
// @ts-expect-error - fix types
|
2646
|
-
{
|
2735
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2647
2736
|
{ availableLocales: true, availableStatus: false }
|
2648
2737
|
);
|
2649
2738
|
ctx.body = { data: {}, meta };
|
@@ -2674,7 +2763,7 @@ const singleTypes = {
|
|
2674
2763
|
}
|
2675
2764
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2676
2765
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2677
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2766
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2678
2767
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2679
2768
|
populate,
|
2680
2769
|
locale
|
@@ -2711,7 +2800,7 @@ const singleTypes = {
|
|
2711
2800
|
if (permissionChecker2.cannot.publish(document)) {
|
2712
2801
|
throw new strapiUtils.errors.ForbiddenError();
|
2713
2802
|
}
|
2714
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2803
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2715
2804
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2716
2805
|
return publishResult.at(0);
|
2717
2806
|
});
|
@@ -2734,7 +2823,7 @@ const singleTypes = {
|
|
2734
2823
|
return ctx.forbidden();
|
2735
2824
|
}
|
2736
2825
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2737
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2826
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2738
2827
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2739
2828
|
if (!document) {
|
2740
2829
|
return ctx.notFound();
|
@@ -2766,7 +2855,7 @@ const singleTypes = {
|
|
2766
2855
|
return ctx.forbidden();
|
2767
2856
|
}
|
2768
2857
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2769
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2858
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2770
2859
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2771
2860
|
if (!document) {
|
2772
2861
|
return ctx.notFound();
|
@@ -2786,7 +2875,7 @@ const singleTypes = {
|
|
2786
2875
|
const { query } = ctx.request;
|
2787
2876
|
const documentManager2 = getService$1("document-manager");
|
2788
2877
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2789
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2878
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2790
2879
|
if (permissionChecker2.cannot.read()) {
|
2791
2880
|
return ctx.forbidden();
|
2792
2881
|
}
|
@@ -2807,7 +2896,7 @@ const uid$1 = {
|
|
2807
2896
|
async generateUID(ctx) {
|
2808
2897
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2809
2898
|
const { query = {} } = ctx.request;
|
2810
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2899
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2811
2900
|
await validateUIDField(contentTypeUID, field);
|
2812
2901
|
const uidService = getService$1("uid");
|
2813
2902
|
ctx.body = {
|
@@ -2819,7 +2908,7 @@ const uid$1 = {
|
|
2819
2908
|
ctx.request.body
|
2820
2909
|
);
|
2821
2910
|
const { query = {} } = ctx.request;
|
2822
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2911
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2823
2912
|
await validateUIDField(contentTypeUID, field);
|
2824
2913
|
const uidService = getService$1("uid");
|
2825
2914
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3462,12 +3551,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3462
3551
|
ability: userAbility,
|
3463
3552
|
model
|
3464
3553
|
});
|
3465
|
-
const
|
3554
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3555
|
+
const toSubject = (entity) => {
|
3556
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3557
|
+
};
|
3466
3558
|
const can = (action, entity, field) => {
|
3467
|
-
|
3559
|
+
const subject = toSubject(entity);
|
3560
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3561
|
+
return (
|
3562
|
+
// Test the original action to see if it passes
|
3563
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3564
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3565
|
+
);
|
3468
3566
|
};
|
3469
3567
|
const cannot = (action, entity, field) => {
|
3470
|
-
|
3568
|
+
const subject = toSubject(entity);
|
3569
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3570
|
+
return (
|
3571
|
+
// Test both the original action
|
3572
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3573
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3574
|
+
);
|
3471
3575
|
};
|
3472
3576
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3473
3577
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3744,6 +3848,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3744
3848
|
const attribute = model.attributes[attributeName];
|
3745
3849
|
switch (attribute.type) {
|
3746
3850
|
case "relation": {
|
3851
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3852
|
+
if (isMorphRelation) {
|
3853
|
+
break;
|
3854
|
+
}
|
3747
3855
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3748
3856
|
populateAcc[attributeName] = {
|
3749
3857
|
count: true,
|
@@ -3995,7 +4103,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
3995
4103
|
*/
|
3996
4104
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
3997
4105
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
3998
|
-
|
4106
|
+
if (version.locale) {
|
4107
|
+
delete versionsByLocale[version.locale];
|
4108
|
+
}
|
3999
4109
|
const model = strapi2.getModel(uid2);
|
4000
4110
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4001
4111
|
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
@@ -4121,7 +4231,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4121
4231
|
*/
|
4122
4232
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4123
4233
|
if (!document) {
|
4124
|
-
return
|
4234
|
+
return {
|
4235
|
+
data: document,
|
4236
|
+
meta: {
|
4237
|
+
availableLocales: [],
|
4238
|
+
availableStatus: []
|
4239
|
+
}
|
4240
|
+
};
|
4125
4241
|
}
|
4126
4242
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4127
4243
|
if (!hasDraftAndPublish) {
|
@@ -4229,10 +4345,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4229
4345
|
async clone(id, body, uid2) {
|
4230
4346
|
const populate = await buildDeepPopulate(uid2);
|
4231
4347
|
const params = {
|
4232
|
-
data:
|
4233
|
-
...omitIdField(body),
|
4234
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4235
|
-
},
|
4348
|
+
data: omitIdField(body),
|
4236
4349
|
populate
|
4237
4350
|
};
|
4238
4351
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|