@strapi/content-manager 5.0.0-rc.2 → 5.0.0-rc.21
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-Bv-IXOYu.js → ComponentConfigurationPage-DnnZJc1F.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Bv-IXOYu.js.map → ComponentConfigurationPage-DnnZJc1F.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-BxJCkKZV.mjs → ComponentConfigurationPage-hLMNf7KI.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BxJCkKZV.mjs.map → ComponentConfigurationPage-hLMNf7KI.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-QZl5zOz-.js → EditConfigurationPage-CpLj5gYZ.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-QZl5zOz-.js.map → EditConfigurationPage-CpLj5gYZ.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BGwHNypQ.mjs → EditConfigurationPage-Dh6sq-G4.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BGwHNypQ.mjs.map → EditConfigurationPage-Dh6sq-G4.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CtdtssrH.mjs → EditViewPage-BU1ugeVi.mjs} +19 -8
- package/dist/_chunks/EditViewPage-BU1ugeVi.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-DxKueadW.js → EditViewPage-D2QVRr_2.js} +19 -8
- package/dist/_chunks/EditViewPage-D2QVRr_2.js.map +1 -0
- package/dist/_chunks/{Field-BPw8fE3W.js → Field-BEDX9i_V.js} +120 -92
- package/dist/_chunks/Field-BEDX9i_V.js.map +1 -0
- package/dist/_chunks/{Field-BU7_nR4F.mjs → Field-VSPY6uzs.mjs} +118 -90
- package/dist/_chunks/Field-VSPY6uzs.mjs.map +1 -0
- package/dist/_chunks/{Form-ffghBTPI.mjs → Form-05Oaes1N.mjs} +35 -16
- package/dist/_chunks/Form-05Oaes1N.mjs.map +1 -0
- package/dist/_chunks/{Form-DtvmbGdZ.js → Form-DCaY8xBX.js} +35 -16
- package/dist/_chunks/Form-DCaY8xBX.js.map +1 -0
- package/dist/_chunks/{History-D6PRyNcx.mjs → History-BqO2G3MV.mjs} +4 -4
- package/dist/_chunks/{History-D6PRyNcx.mjs.map → History-BqO2G3MV.mjs.map} +1 -1
- package/dist/_chunks/{History-CSr8y9KM.js → History-BrJ1tUvt.js} +4 -4
- package/dist/_chunks/{History-CSr8y9KM.js.map → History-BrJ1tUvt.js.map} +1 -1
- package/dist/_chunks/{ListConfigurationPage-BC9bCi9k.mjs → ListConfigurationPage-C6rsFlme.mjs} +14 -4
- package/dist/_chunks/ListConfigurationPage-C6rsFlme.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DsmAQ3YM.js → ListConfigurationPage-Eane5LKE.js} +14 -4
- package/dist/_chunks/ListConfigurationPage-Eane5LKE.js.map +1 -0
- package/dist/_chunks/{ListViewPage-DqAIb_ie.js → ListViewPage-Coj-RPsx.js} +49 -40
- package/dist/_chunks/ListViewPage-Coj-RPsx.js.map +1 -0
- package/dist/_chunks/{ListViewPage-B1GyNqfn.mjs → ListViewPage-yE_zYhcI.mjs} +47 -38
- package/dist/_chunks/ListViewPage-yE_zYhcI.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-xjvn5XwY.js → NoContentTypePage-BDJ0dshy.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-xjvn5XwY.js.map → NoContentTypePage-BDJ0dshy.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CJ-HJriz.mjs → NoContentTypePage-NW_FSVdY.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CJ-HJriz.mjs.map → NoContentTypePage-NW_FSVdY.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DObTkKmZ.js → NoPermissionsPage-BOtb5FTM.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DObTkKmZ.js.map → NoPermissionsPage-BOtb5FTM.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage--afHbbbD.mjs → NoPermissionsPage-h0I3ImsX.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage--afHbbbD.mjs.map → NoPermissionsPage-h0I3ImsX.mjs.map} +1 -1
- package/dist/_chunks/{Relations-t4Q0DpqW.js → Relations-CVh0DOKv.js} +4 -4
- package/dist/_chunks/{Relations-t4Q0DpqW.js.map → Relations-CVh0DOKv.js.map} +1 -1
- package/dist/_chunks/{Relations-heq-nLGU.mjs → Relations-FP0uWpBz.mjs} +4 -4
- package/dist/_chunks/{Relations-heq-nLGU.mjs.map → Relations-FP0uWpBz.mjs.map} +1 -1
- package/dist/_chunks/{en-uOUIxfcQ.js → en-BlhnxQfj.js} +7 -6
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BlhnxQfj.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-C8YBvRrK.mjs} +7 -6
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-C8YBvRrK.mjs.map} +1 -1
- package/dist/_chunks/{index-BcQ8cRyl.mjs → index-CPCHQ3X_.mjs} +1927 -1765
- package/dist/_chunks/index-CPCHQ3X_.mjs.map +1 -0
- package/dist/_chunks/{index-1zxclxo_.js → index-DTKVhcla.js} +1907 -1745
- package/dist/_chunks/index-DTKVhcla.js.map +1 -0
- package/dist/_chunks/{layout-Jl9mJFJZ.mjs → layout-B4UhJ8MJ.mjs} +22 -9
- package/dist/_chunks/layout-B4UhJ8MJ.mjs.map +1 -0
- package/dist/_chunks/{layout-tVvbqota.js → layout-CWgZzMYf.js} +21 -8
- package/dist/_chunks/layout-CWgZzMYf.js.map +1 -0
- package/dist/_chunks/{relations-f4Pv7Kgo.mjs → relations-B83Ge9a7.mjs} +2 -2
- package/dist/_chunks/{relations-f4Pv7Kgo.mjs.map → relations-B83Ge9a7.mjs.map} +1 -1
- package/dist/_chunks/{relations-CK2Jd0HM.js → relations-D81a_2zw.js} +2 -2
- package/dist/_chunks/{relations-CK2Jd0HM.js.map → relations-D81a_2zw.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 +30 -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 +10 -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 +147 -82
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +148 -83
- 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/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-metadata.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.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-CtdtssrH.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-DxKueadW.js.map +0 -1
- package/dist/_chunks/Field-BPw8fE3W.js.map +0 -1
- package/dist/_chunks/Field-BU7_nR4F.mjs.map +0 -1
- package/dist/_chunks/Form-DtvmbGdZ.js.map +0 -1
- package/dist/_chunks/Form-ffghBTPI.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-BC9bCi9k.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DsmAQ3YM.js.map +0 -1
- package/dist/_chunks/ListViewPage-B1GyNqfn.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-DqAIb_ie.js.map +0 -1
- package/dist/_chunks/index-1zxclxo_.js.map +0 -1
- package/dist/_chunks/index-BcQ8cRyl.mjs.map +0 -1
- package/dist/_chunks/layout-Jl9mJFJZ.mjs.map +0 -1
- package/dist/_chunks/layout-tVvbqota.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;
|
@@ -1754,7 +1787,7 @@ const collectionTypes = {
|
|
1754
1787
|
permissionChecker2,
|
1755
1788
|
model,
|
1756
1789
|
// @ts-expect-error TODO: fix
|
1757
|
-
{ id, locale, publishedAt: null },
|
1790
|
+
{ documentId: id, locale, publishedAt: null },
|
1758
1791
|
{ availableLocales: true, availableStatus: false }
|
1759
1792
|
);
|
1760
1793
|
ctx.body = { data: {}, meta };
|
@@ -1880,11 +1913,28 @@ const collectionTypes = {
|
|
1880
1913
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1881
1914
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1882
1915
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1883
|
-
|
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
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1928
|
+
if (!document) {
|
1929
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1930
|
+
}
|
1931
|
+
if (permissionChecker2.can.update(document)) {
|
1932
|
+
await updateDocument(ctx);
|
1933
|
+
}
|
1934
|
+
}
|
1884
1935
|
if (permissionChecker2.cannot.publish(document)) {
|
1885
1936
|
throw new strapiUtils.errors.ForbiddenError();
|
1886
1937
|
}
|
1887
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1888
1938
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1889
1939
|
locale
|
1890
1940
|
// TODO: Allow setting creator fields on publish
|
@@ -1940,7 +1990,9 @@ const collectionTypes = {
|
|
1940
1990
|
if (permissionChecker2.cannot.unpublish()) {
|
1941
1991
|
return ctx.forbidden();
|
1942
1992
|
}
|
1943
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
1993
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1994
|
+
allowMultipleLocales: true
|
1995
|
+
});
|
1944
1996
|
const entityPromises = documentIds.map(
|
1945
1997
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1946
1998
|
);
|
@@ -2291,20 +2343,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2291
2343
|
userAbility,
|
2292
2344
|
model: model.uid
|
2293
2345
|
});
|
2294
|
-
|
2346
|
+
const isMainFieldListable = isListable(model, mainField);
|
2347
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2348
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2295
2349
|
return "id";
|
2296
2350
|
}
|
2297
|
-
if (
|
2298
|
-
|
2299
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2300
|
-
userAbility,
|
2301
|
-
model: "plugin::users-permissions.user"
|
2302
|
-
});
|
2303
|
-
if (userPermissionChecker.can.read()) {
|
2304
|
-
return "name";
|
2305
|
-
}
|
2306
|
-
}
|
2307
|
-
return "id";
|
2351
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2352
|
+
return "name";
|
2308
2353
|
}
|
2309
2354
|
return mainField;
|
2310
2355
|
};
|
@@ -2504,8 +2549,9 @@ const relations = {
|
|
2504
2549
|
} else {
|
2505
2550
|
where.id = id;
|
2506
2551
|
}
|
2507
|
-
|
2508
|
-
|
2552
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2553
|
+
if (!fp.isEmpty(publishedAt)) {
|
2554
|
+
where[`${alias}.published_at`] = publishedAt;
|
2509
2555
|
}
|
2510
2556
|
if (filterByLocale) {
|
2511
2557
|
where[`${alias}.locale`] = locale;
|
@@ -2562,9 +2608,7 @@ const relations = {
|
|
2562
2608
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2563
2609
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2564
2610
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2565
|
-
ordering: "desc"
|
2566
|
-
page: ctx.request.query.page,
|
2567
|
-
pageSize: ctx.request.query.pageSize
|
2611
|
+
ordering: "desc"
|
2568
2612
|
});
|
2569
2613
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2570
2614
|
ctx.body = {
|
@@ -2651,7 +2695,7 @@ const singleTypes = {
|
|
2651
2695
|
permissionChecker2,
|
2652
2696
|
model,
|
2653
2697
|
// @ts-expect-error - fix types
|
2654
|
-
{
|
2698
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2655
2699
|
{ availableLocales: true, availableStatus: false }
|
2656
2700
|
);
|
2657
2701
|
ctx.body = { data: {}, meta };
|
@@ -3470,12 +3514,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3470
3514
|
ability: userAbility,
|
3471
3515
|
model
|
3472
3516
|
});
|
3473
|
-
const
|
3517
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3518
|
+
const toSubject = (entity) => {
|
3519
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3520
|
+
};
|
3474
3521
|
const can = (action, entity, field) => {
|
3475
|
-
|
3522
|
+
const subject = toSubject(entity);
|
3523
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3524
|
+
return (
|
3525
|
+
// Test the original action to see if it passes
|
3526
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3527
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3528
|
+
);
|
3476
3529
|
};
|
3477
3530
|
const cannot = (action, entity, field) => {
|
3478
|
-
|
3531
|
+
const subject = toSubject(entity);
|
3532
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3533
|
+
return (
|
3534
|
+
// Test both the original action
|
3535
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3536
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3537
|
+
);
|
3479
3538
|
};
|
3480
3539
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3481
3540
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -4133,7 +4192,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4133
4192
|
*/
|
4134
4193
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4135
4194
|
if (!document) {
|
4136
|
-
return
|
4195
|
+
return {
|
4196
|
+
data: document,
|
4197
|
+
meta: {
|
4198
|
+
availableLocales: [],
|
4199
|
+
availableStatus: []
|
4200
|
+
}
|
4201
|
+
};
|
4137
4202
|
}
|
4138
4203
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4139
4204
|
if (!hasDraftAndPublish) {
|