@strapi/content-manager 5.0.0-rc.3 → 5.0.0-rc.30
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-BAgyHiMm.mjs → ComponentConfigurationPage-DfFSZQxe.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs.map → ComponentConfigurationPage-DfFSZQxe.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js → ComponentConfigurationPage-FqfsxQ1j.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js.map → ComponentConfigurationPage-FqfsxQ1j.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js → EditConfigurationPage-Cn0e8t3I.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js.map → EditConfigurationPage-Cn0e8t3I.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs → EditConfigurationPage-DdPNAbl3.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs.map → EditConfigurationPage-DdPNAbl3.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-BLsjc5F-.mjs → EditViewPage-B82x_x1b.mjs} +30 -9
- package/dist/_chunks/EditViewPage-B82x_x1b.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-C-ukDOB7.js → EditViewPage-DlxEHhUt.js} +30 -9
- package/dist/_chunks/EditViewPage-DlxEHhUt.js.map +1 -0
- package/dist/_chunks/{Field-Bfph5SOd.js → Field-COL25JiC.js} +174 -102
- package/dist/_chunks/Field-COL25JiC.js.map +1 -0
- package/dist/_chunks/{Field-Cs7duwWd.mjs → Field-DufHXW17.mjs} +172 -100
- package/dist/_chunks/Field-DufHXW17.mjs.map +1 -0
- package/dist/_chunks/{Form-CPYqIWDG.js → Form-BssUwrTO.js} +36 -17
- package/dist/_chunks/Form-BssUwrTO.js.map +1 -0
- package/dist/_chunks/{Form-Dg_GS5TQ.mjs → Form-u_kAOhwB.mjs} +36 -17
- package/dist/_chunks/Form-u_kAOhwB.mjs.map +1 -0
- package/dist/_chunks/{History-DNQkXANT.js → History-C9t9UqpO.js} +23 -10
- package/dist/_chunks/History-C9t9UqpO.js.map +1 -0
- package/dist/_chunks/{History-wrnHqf09.mjs → History-DRwA3oMM.mjs} +24 -11
- package/dist/_chunks/History-DRwA3oMM.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CUQxfpjT.js → ListConfigurationPage-BXYPohh-.js} +14 -4
- package/dist/_chunks/ListConfigurationPage-BXYPohh-.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DScmJVkW.mjs → ListConfigurationPage-BxfQJzPk.mjs} +14 -4
- package/dist/_chunks/ListConfigurationPage-BxfQJzPk.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-C4IvrMgY.mjs → ListViewPage-CELx2ysp.mjs} +47 -38
- package/dist/_chunks/ListViewPage-CELx2ysp.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BsLiH2-2.js → ListViewPage-D2VD8Szg.js} +49 -40
- package/dist/_chunks/ListViewPage-D2VD8Szg.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js → NoContentTypePage-BV9IjJSM.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js.map → NoContentTypePage-BV9IjJSM.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs → NoContentTypePage-DtJ9jcfk.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs.map → NoContentTypePage-DtJ9jcfk.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs → NoPermissionsPage-DWleVYK7.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs.map → NoPermissionsPage-DWleVYK7.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js → NoPermissionsPage-Dp8NpF9I.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js.map → NoPermissionsPage-Dp8NpF9I.js.map} +1 -1
- package/dist/_chunks/{Relations-BZr8tL0R.mjs → Relations-BTcf5xaw.mjs} +33 -24
- package/dist/_chunks/Relations-BTcf5xaw.mjs.map +1 -0
- package/dist/_chunks/{Relations-CtELXYIK.js → Relations-DR7EUgyC.js} +33 -24
- package/dist/_chunks/Relations-DR7EUgyC.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-OerGjbAN.js → index-BdMf2lfT.js} +1921 -1758
- package/dist/_chunks/index-BdMf2lfT.js.map +1 -0
- package/dist/_chunks/{index-c_5DdJi-.mjs → index-wnqzm4Q8.mjs} +1941 -1778
- package/dist/_chunks/index-wnqzm4Q8.mjs.map +1 -0
- package/dist/_chunks/{layout-oPBiO7RY.mjs → layout-2CfjL0T9.mjs} +22 -9
- package/dist/_chunks/layout-2CfjL0T9.mjs.map +1 -0
- package/dist/_chunks/{layout-Ci7qHlFb.js → layout-B2MyZU-_.js} +21 -8
- package/dist/_chunks/layout-B2MyZU-_.js.map +1 -0
- package/dist/_chunks/{relations-COBpStiF.js → relations-BH7JJGGe.js} +2 -2
- package/dist/_chunks/{relations-COBpStiF.js.map → relations-BH7JJGGe.js.map} +1 -1
- package/dist/_chunks/{relations-BIdWFjdq.mjs → relations-C0w0GcXi.mjs} +2 -2
- package/dist/_chunks/{relations-BIdWFjdq.mjs.map → relations-C0w0GcXi.mjs.map} +1 -1
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +170 -92
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +171 -93
- 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 +12 -12
- package/dist/_chunks/EditViewPage-BLsjc5F-.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-C-ukDOB7.js.map +0 -1
- package/dist/_chunks/Field-Bfph5SOd.js.map +0 -1
- package/dist/_chunks/Field-Cs7duwWd.mjs.map +0 -1
- package/dist/_chunks/Form-CPYqIWDG.js.map +0 -1
- package/dist/_chunks/Form-Dg_GS5TQ.mjs.map +0 -1
- package/dist/_chunks/History-DNQkXANT.js.map +0 -1
- package/dist/_chunks/History-wrnHqf09.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-CUQxfpjT.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DScmJVkW.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BsLiH2-2.js.map +0 -1
- package/dist/_chunks/ListViewPage-C4IvrMgY.mjs.map +0 -1
- package/dist/_chunks/Relations-BZr8tL0R.mjs.map +0 -1
- package/dist/_chunks/Relations-CtELXYIK.js.map +0 -1
- package/dist/_chunks/index-OerGjbAN.js.map +0 -1
- package/dist/_chunks/index-c_5DdJi-.mjs.map +0 -1
- package/dist/_chunks/layout-Ci7qHlFb.js.map +0 -1
- package/dist/_chunks/layout-oPBiO7RY.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,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,
|
@@ -383,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
383
393
|
if (userToPopulate == null) {
|
384
394
|
return null;
|
385
395
|
}
|
386
|
-
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
|
+
});
|
387
402
|
})
|
388
403
|
);
|
389
404
|
return {
|
@@ -494,6 +509,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
494
509
|
}
|
495
510
|
};
|
496
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
|
+
};
|
497
548
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
498
549
|
const state = {
|
499
550
|
deleteExpiredJob: null,
|
@@ -506,63 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
506
557
|
return;
|
507
558
|
}
|
508
559
|
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
560
|
const result = await next();
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
561
|
+
if (!shouldCreateHistoryVersion(context)) {
|
562
|
+
return result;
|
563
|
+
}
|
564
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
527
565
|
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();
|
566
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
567
|
+
if (!locales.length) {
|
568
|
+
return result;
|
534
569
|
}
|
535
|
-
const
|
536
|
-
|
537
|
-
|
538
|
-
|
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
|
+
)
|
539
585
|
});
|
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
586
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
556
|
-
onCommit(() => {
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
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
|
+
}
|
566
599
|
});
|
567
600
|
});
|
568
601
|
return result;
|
@@ -1202,6 +1235,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1202
1235
|
const hasPermissions = createPolicy({
|
1203
1236
|
name: "plugin::content-manager.hasPermissions",
|
1204
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
|
+
*/
|
1205
1243
|
handler(ctx, config = {}) {
|
1206
1244
|
const { actions = [], hasAtLeastOne = false } = config;
|
1207
1245
|
const { userAbility } = ctx.state;
|
@@ -1682,7 +1720,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1682
1720
|
throw new strapiUtils.errors.ForbiddenError();
|
1683
1721
|
}
|
1684
1722
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1685
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1723
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1686
1724
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1687
1725
|
const sanitizedBody = await sanitizeFn(body);
|
1688
1726
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1754,7 +1792,7 @@ const collectionTypes = {
|
|
1754
1792
|
permissionChecker2,
|
1755
1793
|
model,
|
1756
1794
|
// @ts-expect-error TODO: fix
|
1757
|
-
{ id, locale, publishedAt: null },
|
1795
|
+
{ documentId: id, locale, publishedAt: null },
|
1758
1796
|
{ availableLocales: true, availableStatus: false }
|
1759
1797
|
);
|
1760
1798
|
ctx.body = { data: {}, meta };
|
@@ -1880,11 +1918,34 @@ const collectionTypes = {
|
|
1880
1918
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1881
1919
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1882
1920
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1883
|
-
|
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
|
+
}
|
1884
1946
|
if (permissionChecker2.cannot.publish(document)) {
|
1885
1947
|
throw new strapiUtils.errors.ForbiddenError();
|
1886
1948
|
}
|
1887
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1888
1949
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1889
1950
|
locale
|
1890
1951
|
// TODO: Allow setting creator fields on publish
|
@@ -1940,7 +2001,9 @@ const collectionTypes = {
|
|
1940
2001
|
if (permissionChecker2.cannot.unpublish()) {
|
1941
2002
|
return ctx.forbidden();
|
1942
2003
|
}
|
1943
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
2004
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2005
|
+
allowMultipleLocales: true
|
2006
|
+
});
|
1944
2007
|
const entityPromises = documentIds.map(
|
1945
2008
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1946
2009
|
);
|
@@ -2291,20 +2354,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2291
2354
|
userAbility,
|
2292
2355
|
model: model.uid
|
2293
2356
|
});
|
2294
|
-
|
2357
|
+
const isMainFieldListable = isListable(model, mainField);
|
2358
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2359
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2295
2360
|
return "id";
|
2296
2361
|
}
|
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";
|
2362
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2363
|
+
return "name";
|
2308
2364
|
}
|
2309
2365
|
return mainField;
|
2310
2366
|
};
|
@@ -2337,11 +2393,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2337
2393
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2338
2394
|
const isSourceLocalized = isLocalized(sourceModel);
|
2339
2395
|
const isTargetLocalized = isLocalized(targetModel);
|
2340
|
-
let validatedLocale = locale;
|
2341
|
-
if (!targetModel || !isTargetLocalized)
|
2342
|
-
validatedLocale = void 0;
|
2343
2396
|
return {
|
2344
|
-
locale
|
2397
|
+
locale,
|
2345
2398
|
isSourceLocalized,
|
2346
2399
|
isTargetLocalized
|
2347
2400
|
};
|
@@ -2444,7 +2497,7 @@ const relations = {
|
|
2444
2497
|
attribute,
|
2445
2498
|
fieldsToSelect,
|
2446
2499
|
mainField,
|
2447
|
-
source: { schema: sourceSchema },
|
2500
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2448
2501
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2449
2502
|
sourceSchema,
|
2450
2503
|
targetSchema,
|
@@ -2466,7 +2519,8 @@ const relations = {
|
|
2466
2519
|
fieldsToSelect,
|
2467
2520
|
mainField,
|
2468
2521
|
source: {
|
2469
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2522
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2523
|
+
isLocalized: isSourceLocalized
|
2470
2524
|
},
|
2471
2525
|
target: {
|
2472
2526
|
schema: { uid: targetUid },
|
@@ -2504,12 +2558,16 @@ const relations = {
|
|
2504
2558
|
} else {
|
2505
2559
|
where.id = id;
|
2506
2560
|
}
|
2507
|
-
|
2508
|
-
|
2561
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2562
|
+
if (!fp.isEmpty(publishedAt)) {
|
2563
|
+
where[`${alias}.published_at`] = publishedAt;
|
2509
2564
|
}
|
2510
|
-
if (
|
2565
|
+
if (isTargetLocalized && locale) {
|
2511
2566
|
where[`${alias}.locale`] = locale;
|
2512
2567
|
}
|
2568
|
+
if (isSourceLocalized && locale) {
|
2569
|
+
where.locale = locale;
|
2570
|
+
}
|
2513
2571
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2514
2572
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2515
2573
|
}
|
@@ -2527,7 +2585,8 @@ const relations = {
|
|
2527
2585
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2528
2586
|
});
|
2529
2587
|
}
|
2530
|
-
const
|
2588
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2589
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2531
2590
|
ctx.body = {
|
2532
2591
|
...res,
|
2533
2592
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2562,9 +2621,7 @@ const relations = {
|
|
2562
2621
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2563
2622
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2564
2623
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2565
|
-
ordering: "desc"
|
2566
|
-
page: ctx.request.query.page,
|
2567
|
-
pageSize: ctx.request.query.pageSize
|
2624
|
+
ordering: "desc"
|
2568
2625
|
});
|
2569
2626
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2570
2627
|
ctx.body = {
|
@@ -2651,7 +2708,7 @@ const singleTypes = {
|
|
2651
2708
|
permissionChecker2,
|
2652
2709
|
model,
|
2653
2710
|
// @ts-expect-error - fix types
|
2654
|
-
{
|
2711
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2655
2712
|
{ availableLocales: true, availableStatus: false }
|
2656
2713
|
);
|
2657
2714
|
ctx.body = { data: {}, meta };
|
@@ -3470,12 +3527,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3470
3527
|
ability: userAbility,
|
3471
3528
|
model
|
3472
3529
|
});
|
3473
|
-
const
|
3530
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3531
|
+
const toSubject = (entity) => {
|
3532
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3533
|
+
};
|
3474
3534
|
const can = (action, entity, field) => {
|
3475
|
-
|
3535
|
+
const subject = toSubject(entity);
|
3536
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3537
|
+
return (
|
3538
|
+
// Test the original action to see if it passes
|
3539
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3540
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3541
|
+
);
|
3476
3542
|
};
|
3477
3543
|
const cannot = (action, entity, field) => {
|
3478
|
-
|
3544
|
+
const subject = toSubject(entity);
|
3545
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3546
|
+
return (
|
3547
|
+
// Test both the original action
|
3548
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3549
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3550
|
+
);
|
3479
3551
|
};
|
3480
3552
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3481
3553
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -4133,7 +4205,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4133
4205
|
*/
|
4134
4206
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4135
4207
|
if (!document) {
|
4136
|
-
return
|
4208
|
+
return {
|
4209
|
+
data: document,
|
4210
|
+
meta: {
|
4211
|
+
availableLocales: [],
|
4212
|
+
availableStatus: []
|
4213
|
+
}
|
4214
|
+
};
|
4137
4215
|
}
|
4138
4216
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4139
4217
|
if (!hasDraftAndPublish) {
|