@strapi/content-manager 0.0.0-experimental.826f263c58b6886b849d3f03b81f7a530bc51c91 → 0.0.0-experimental.93181c8b900e97a04bf10785b368657101ec98d8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +18 -3
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs → ComponentConfigurationPage-DJEJ49QD.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-DJEJ49QD.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js → ComponentConfigurationPage-D_g11bYV.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage-D_g11bYV.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-CeL712KW.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-CeL712KW.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-QBZdUYyG.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-QBZdUYyG.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DvaV7U9b.mjs → EditViewPage-CvRUUpVh.mjs} +58 -47
- package/dist/_chunks/EditViewPage-CvRUUpVh.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-g5TwrgRY.js} +57 -46
- package/dist/_chunks/EditViewPage-g5TwrgRY.js.map +1 -0
- package/dist/_chunks/{Field-ZdrmmQ4Y.js → Field-ncdInvxS.js} +521 -203
- package/dist/_chunks/Field-ncdInvxS.js.map +1 -0
- package/dist/_chunks/{Field-Cz_J9551.mjs → Field-reyvfnop.mjs} +523 -205
- package/dist/_chunks/Field-reyvfnop.mjs.map +1 -0
- package/dist/_chunks/{Form-Bpig5rch.js → Form-BJ7bYiUx.js} +40 -28
- package/dist/_chunks/Form-BJ7bYiUx.js.map +1 -0
- package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-DoMGsYxH.mjs} +42 -30
- package/dist/_chunks/Form-DoMGsYxH.mjs.map +1 -0
- package/dist/_chunks/{History-BZP8n7KT.mjs → History-BseDJOrj.mjs} +141 -37
- package/dist/_chunks/History-BseDJOrj.mjs.map +1 -0
- package/dist/_chunks/{History-BfX6XmZK.js → History-pbhkxIrf.js} +140 -36
- package/dist/_chunks/History-pbhkxIrf.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-Bna8zfjr.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-Bna8zfjr.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-DWE_fr5B.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-DWE_fr5B.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-Dymsvnv6.js} +82 -93
- package/dist/_chunks/ListViewPage-Dymsvnv6.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-lQ-VLV2G.mjs} +84 -95
- package/dist/_chunks/ListViewPage-lQ-VLV2G.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-B4t_OsDR.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-B4t_OsDR.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-VCQOMwlf.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-VCQOMwlf.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-BOwB6hki.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-BOwB6hki.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-TV830k4P.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-TV830k4P.mjs.map} +1 -1
- package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-D6NAlnsl.mjs} +4 -4
- package/dist/_chunks/Relations-D6NAlnsl.mjs.map +1 -0
- package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-DdlstXTu.js} +4 -4
- package/dist/_chunks/Relations-DdlstXTu.js.map +1 -0
- package/dist/_chunks/{en-BN1bvFK7.js → en-Cf41pH5f.js} +12 -7
- package/dist/_chunks/{en-BN1bvFK7.js.map → en-Cf41pH5f.js.map} +1 -1
- package/dist/_chunks/{en-Dzv55oQw.mjs → en-DCszE74t.mjs} +12 -7
- package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-DCszE74t.mjs.map} +1 -1
- package/dist/_chunks/{index-VHviNMeW.mjs → index-BYSWwHBJ.mjs} +515 -463
- package/dist/_chunks/index-BYSWwHBJ.mjs.map +1 -0
- package/dist/_chunks/{index-DzN3kBgx.js → index-CQos-KS0.js} +495 -443
- package/dist/_chunks/index-CQos-KS0.js.map +1 -0
- package/dist/_chunks/{layout-CPn1PM6x.mjs → layout-0TY7UtKO.mjs} +39 -22
- package/dist/_chunks/layout-0TY7UtKO.mjs.map +1 -0
- package/dist/_chunks/{layout-b91XRlD2.js → layout-B4XAqu1v.js} +37 -20
- package/dist/_chunks/layout-B4XAqu1v.js.map +1 -0
- package/dist/_chunks/{relations-BsqxS6tR.mjs → relations-DFDWfa0s.mjs} +2 -2
- package/dist/_chunks/{relations-BsqxS6tR.mjs.map → relations-DFDWfa0s.mjs.map} +1 -1
- package/dist/_chunks/{relations-CA7IYmcP.js → relations-xZ2tMj1G.js} +2 -2
- package/dist/_chunks/{relations-CA7IYmcP.js.map → relations-xZ2tMj1G.js.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +5 -5
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +1 -1
- package/dist/admin/src/history/index.d.ts +3 -0
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/index.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +8 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +6 -58
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +180 -106
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +181 -107
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/uid.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/_chunks/EditViewPage-CoQEnFlC.js.map +0 -1
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
- package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
- package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
- package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
- package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
- package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
- package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
- package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
- package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
- package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
- package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
- package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
- package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
- package/dist/_chunks/layout-b91XRlD2.js.map +0 -1
package/dist/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,
|
@@ -490,13 +504,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
490
504
|
}
|
491
505
|
};
|
492
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
|
+
};
|
493
543
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
494
544
|
const state = {
|
495
545
|
deleteExpiredJob: null,
|
496
546
|
isInitialized: false
|
497
547
|
};
|
498
|
-
const query = strapi2.db.query(HISTORY_VERSION_UID);
|
499
|
-
const historyService = getService(strapi2, "history");
|
500
548
|
const serviceUtils = createServiceUtils({ strapi: strapi2 });
|
501
549
|
return {
|
502
550
|
async bootstrap() {
|
@@ -504,60 +552,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
504
552
|
return;
|
505
553
|
}
|
506
554
|
strapi2.documents.use(async (context, next) => {
|
507
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
508
|
-
return next();
|
509
|
-
}
|
510
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
511
|
-
return next();
|
512
|
-
}
|
513
|
-
const contentTypeUid = context.contentType.uid;
|
514
|
-
if (!contentTypeUid.startsWith("api::")) {
|
515
|
-
return next();
|
516
|
-
}
|
517
555
|
const result = await next();
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
556
|
+
if (!shouldCreateHistoryVersion(context)) {
|
557
|
+
return result;
|
558
|
+
}
|
559
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
522
560
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
523
|
-
const
|
524
|
-
if (
|
525
|
-
|
526
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
527
|
-
);
|
528
|
-
return next();
|
561
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
562
|
+
if (!locales.length) {
|
563
|
+
return result;
|
529
564
|
}
|
530
|
-
const
|
531
|
-
|
532
|
-
|
533
|
-
|
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
|
+
)
|
534
580
|
});
|
535
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
536
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
537
|
-
const componentsSchemas = Object.keys(
|
538
|
-
attributesSchema
|
539
|
-
).reduce((currentComponentSchemas, key) => {
|
540
|
-
const fieldSchema = attributesSchema[key];
|
541
|
-
if (fieldSchema.type === "component") {
|
542
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
543
|
-
return {
|
544
|
-
...currentComponentSchemas,
|
545
|
-
[fieldSchema.component]: componentSchema
|
546
|
-
};
|
547
|
-
}
|
548
|
-
return currentComponentSchemas;
|
549
|
-
}, {});
|
550
581
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
551
|
-
onCommit(() => {
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
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
|
+
}
|
561
594
|
});
|
562
595
|
});
|
563
596
|
return result;
|
@@ -565,7 +598,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
565
598
|
state.deleteExpiredJob = nodeSchedule.scheduleJob("0 0 * * *", () => {
|
566
599
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
567
600
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
568
|
-
query.deleteMany({
|
601
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
569
602
|
where: {
|
570
603
|
created_at: {
|
571
604
|
$lt: expirationDate.toISOString()
|
@@ -1197,6 +1230,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1197
1230
|
const hasPermissions = createPolicy({
|
1198
1231
|
name: "plugin::content-manager.hasPermissions",
|
1199
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
|
+
*/
|
1200
1238
|
handler(ctx, config = {}) {
|
1201
1239
|
const { actions = [], hasAtLeastOne = false } = config;
|
1202
1240
|
const { userAbility } = ctx.state;
|
@@ -1590,9 +1628,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1590
1628
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1591
1629
|
);
|
1592
1630
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1593
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1631
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1594
1632
|
const { allowMultipleLocales } = opts;
|
1595
|
-
const { locale, status, ...rest } = request || {};
|
1633
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1634
|
+
const defaultStatus = strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1635
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1596
1636
|
const schema = strapiUtils.yup.object().shape({
|
1597
1637
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1598
1638
|
status: statusSchema
|
@@ -1640,7 +1680,7 @@ const createDocument = async (ctx, opts) => {
|
|
1640
1680
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1641
1681
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1642
1682
|
const sanitizedBody = await sanitizeFn(body);
|
1643
|
-
const { locale, status
|
1683
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1644
1684
|
return documentManager2.create(model, {
|
1645
1685
|
data: sanitizedBody,
|
1646
1686
|
locale,
|
@@ -1659,7 +1699,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1659
1699
|
}
|
1660
1700
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1661
1701
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1662
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1702
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1663
1703
|
const [documentVersion, documentExists] = await Promise.all([
|
1664
1704
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1665
1705
|
documentManager2.exists(model, id)
|
@@ -1697,7 +1737,7 @@ const collectionTypes = {
|
|
1697
1737
|
}
|
1698
1738
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1699
1739
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1700
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1740
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1701
1741
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1702
1742
|
{ ...permissionQuery, populate, locale, status },
|
1703
1743
|
model
|
@@ -1732,7 +1772,7 @@ const collectionTypes = {
|
|
1732
1772
|
}
|
1733
1773
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1734
1774
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1735
|
-
const { locale, status
|
1775
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1736
1776
|
const version = await documentManager2.findOne(id, model, {
|
1737
1777
|
populate,
|
1738
1778
|
locale,
|
@@ -1799,7 +1839,7 @@ const collectionTypes = {
|
|
1799
1839
|
}
|
1800
1840
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1801
1841
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1802
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1842
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1803
1843
|
const document = await documentManager2.findOne(id, model, {
|
1804
1844
|
populate,
|
1805
1845
|
locale,
|
@@ -1844,7 +1884,7 @@ const collectionTypes = {
|
|
1844
1884
|
}
|
1845
1885
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1846
1886
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1847
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1887
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1848
1888
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1849
1889
|
if (documentLocales.length === 0) {
|
1850
1890
|
return ctx.notFound();
|
@@ -1873,11 +1913,28 @@ const collectionTypes = {
|
|
1873
1913
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1874
1914
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1875
1915
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1876
|
-
|
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
|
+
}
|
1877
1935
|
if (permissionChecker2.cannot.publish(document)) {
|
1878
1936
|
throw new strapiUtils.errors.ForbiddenError();
|
1879
1937
|
}
|
1880
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1881
1938
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1882
1939
|
locale
|
1883
1940
|
// TODO: Allow setting creator fields on publish
|
@@ -1904,7 +1961,9 @@ const collectionTypes = {
|
|
1904
1961
|
}
|
1905
1962
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1906
1963
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1907
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1964
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1965
|
+
allowMultipleLocales: true
|
1966
|
+
});
|
1908
1967
|
const entityPromises = documentIds.map(
|
1909
1968
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1910
1969
|
);
|
@@ -1931,7 +1990,9 @@ const collectionTypes = {
|
|
1931
1990
|
if (permissionChecker2.cannot.unpublish()) {
|
1932
1991
|
return ctx.forbidden();
|
1933
1992
|
}
|
1934
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
1993
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1994
|
+
allowMultipleLocales: true
|
1995
|
+
});
|
1935
1996
|
const entityPromises = documentIds.map(
|
1936
1997
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1937
1998
|
);
|
@@ -1964,7 +2025,7 @@ const collectionTypes = {
|
|
1964
2025
|
}
|
1965
2026
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1966
2027
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1967
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2028
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1968
2029
|
const document = await documentManager2.findOne(id, model, {
|
1969
2030
|
populate,
|
1970
2031
|
locale,
|
@@ -2001,7 +2062,7 @@ const collectionTypes = {
|
|
2001
2062
|
}
|
2002
2063
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2003
2064
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2004
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2065
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2005
2066
|
const document = await documentManager2.findOne(id, model, {
|
2006
2067
|
populate,
|
2007
2068
|
locale,
|
@@ -2032,7 +2093,7 @@ const collectionTypes = {
|
|
2032
2093
|
}
|
2033
2094
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2034
2095
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2035
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2096
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2036
2097
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2037
2098
|
populate,
|
2038
2099
|
locale
|
@@ -2059,7 +2120,7 @@ const collectionTypes = {
|
|
2059
2120
|
}
|
2060
2121
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2061
2122
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2062
|
-
const { locale, status
|
2123
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2063
2124
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2064
2125
|
if (!entity) {
|
2065
2126
|
return ctx.notFound();
|
@@ -2082,7 +2143,7 @@ const collectionTypes = {
|
|
2082
2143
|
if (permissionChecker2.cannot.read()) {
|
2083
2144
|
return ctx.forbidden();
|
2084
2145
|
}
|
2085
|
-
const
|
2146
|
+
const documents = await documentManager2.findMany(
|
2086
2147
|
{
|
2087
2148
|
filters: {
|
2088
2149
|
documentId: ids
|
@@ -2091,7 +2152,7 @@ const collectionTypes = {
|
|
2091
2152
|
},
|
2092
2153
|
model
|
2093
2154
|
);
|
2094
|
-
if (!
|
2155
|
+
if (!documents) {
|
2095
2156
|
return ctx.notFound();
|
2096
2157
|
}
|
2097
2158
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2282,20 +2343,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2282
2343
|
userAbility,
|
2283
2344
|
model: model.uid
|
2284
2345
|
});
|
2285
|
-
|
2346
|
+
const isMainFieldListable = isListable(model, mainField);
|
2347
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2348
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2286
2349
|
return "id";
|
2287
2350
|
}
|
2288
|
-
if (
|
2289
|
-
|
2290
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2291
|
-
userAbility,
|
2292
|
-
model: "plugin::users-permissions.user"
|
2293
|
-
});
|
2294
|
-
if (userPermissionChecker.can.read()) {
|
2295
|
-
return "name";
|
2296
|
-
}
|
2297
|
-
}
|
2298
|
-
return "id";
|
2351
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2352
|
+
return "name";
|
2299
2353
|
}
|
2300
2354
|
return mainField;
|
2301
2355
|
};
|
@@ -2553,9 +2607,7 @@ const relations = {
|
|
2553
2607
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2554
2608
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2555
2609
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2556
|
-
ordering: "desc"
|
2557
|
-
page: ctx.request.query.page,
|
2558
|
-
pageSize: ctx.request.query.pageSize
|
2610
|
+
ordering: "desc"
|
2559
2611
|
});
|
2560
2612
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2561
2613
|
ctx.body = {
|
@@ -2587,7 +2639,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2587
2639
|
throw new strapiUtils.errors.ForbiddenError();
|
2588
2640
|
}
|
2589
2641
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2590
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2642
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2591
2643
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2592
2644
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2593
2645
|
// Find the first document to check if it exists
|
@@ -2628,7 +2680,7 @@ const singleTypes = {
|
|
2628
2680
|
return ctx.forbidden();
|
2629
2681
|
}
|
2630
2682
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2631
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2683
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2632
2684
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2633
2685
|
if (!version) {
|
2634
2686
|
if (permissionChecker2.cannot.create()) {
|
@@ -2673,7 +2725,7 @@ const singleTypes = {
|
|
2673
2725
|
}
|
2674
2726
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2675
2727
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2676
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2728
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2677
2729
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2678
2730
|
populate,
|
2679
2731
|
locale
|
@@ -2710,7 +2762,7 @@ const singleTypes = {
|
|
2710
2762
|
if (permissionChecker2.cannot.publish(document)) {
|
2711
2763
|
throw new strapiUtils.errors.ForbiddenError();
|
2712
2764
|
}
|
2713
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2765
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2714
2766
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2715
2767
|
return publishResult.at(0);
|
2716
2768
|
});
|
@@ -2733,7 +2785,7 @@ const singleTypes = {
|
|
2733
2785
|
return ctx.forbidden();
|
2734
2786
|
}
|
2735
2787
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2736
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2788
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2737
2789
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2738
2790
|
if (!document) {
|
2739
2791
|
return ctx.notFound();
|
@@ -2765,7 +2817,7 @@ const singleTypes = {
|
|
2765
2817
|
return ctx.forbidden();
|
2766
2818
|
}
|
2767
2819
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2768
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2820
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2769
2821
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2770
2822
|
if (!document) {
|
2771
2823
|
return ctx.notFound();
|
@@ -2785,7 +2837,7 @@ const singleTypes = {
|
|
2785
2837
|
const { query } = ctx.request;
|
2786
2838
|
const documentManager2 = getService$1("document-manager");
|
2787
2839
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2788
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2840
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2789
2841
|
if (permissionChecker2.cannot.read()) {
|
2790
2842
|
return ctx.forbidden();
|
2791
2843
|
}
|
@@ -2806,7 +2858,7 @@ const uid$1 = {
|
|
2806
2858
|
async generateUID(ctx) {
|
2807
2859
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2808
2860
|
const { query = {} } = ctx.request;
|
2809
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2861
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2810
2862
|
await validateUIDField(contentTypeUID, field);
|
2811
2863
|
const uidService = getService$1("uid");
|
2812
2864
|
ctx.body = {
|
@@ -2818,7 +2870,7 @@ const uid$1 = {
|
|
2818
2870
|
ctx.request.body
|
2819
2871
|
);
|
2820
2872
|
const { query = {} } = ctx.request;
|
2821
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2873
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2822
2874
|
await validateUIDField(contentTypeUID, field);
|
2823
2875
|
const uidService = getService$1("uid");
|
2824
2876
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3461,12 +3513,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3461
3513
|
ability: userAbility,
|
3462
3514
|
model
|
3463
3515
|
});
|
3464
|
-
const
|
3516
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3517
|
+
const toSubject = (entity) => {
|
3518
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3519
|
+
};
|
3465
3520
|
const can = (action, entity, field) => {
|
3466
|
-
|
3521
|
+
const subject = toSubject(entity);
|
3522
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3523
|
+
return (
|
3524
|
+
// Test the original action to see if it passes
|
3525
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3526
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3527
|
+
);
|
3467
3528
|
};
|
3468
3529
|
const cannot = (action, entity, field) => {
|
3469
|
-
|
3530
|
+
const subject = toSubject(entity);
|
3531
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3532
|
+
return (
|
3533
|
+
// Test both the original action
|
3534
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3535
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3536
|
+
);
|
3470
3537
|
};
|
3471
3538
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3472
3539
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3743,6 +3810,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3743
3810
|
const attribute = model.attributes[attributeName];
|
3744
3811
|
switch (attribute.type) {
|
3745
3812
|
case "relation": {
|
3813
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3814
|
+
if (isMorphRelation) {
|
3815
|
+
break;
|
3816
|
+
}
|
3746
3817
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3747
3818
|
populateAcc[attributeName] = {
|
3748
3819
|
count: true,
|
@@ -4120,7 +4191,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4120
4191
|
*/
|
4121
4192
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4122
4193
|
if (!document) {
|
4123
|
-
return
|
4194
|
+
return {
|
4195
|
+
data: document,
|
4196
|
+
meta: {
|
4197
|
+
availableLocales: [],
|
4198
|
+
availableStatus: []
|
4199
|
+
}
|
4200
|
+
};
|
4124
4201
|
}
|
4125
4202
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4126
4203
|
if (!hasDraftAndPublish) {
|
@@ -4228,10 +4305,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4228
4305
|
async clone(id, body, uid2) {
|
4229
4306
|
const populate = await buildDeepPopulate(uid2);
|
4230
4307
|
const params = {
|
4231
|
-
data:
|
4232
|
-
...omitIdField(body),
|
4233
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4234
|
-
},
|
4308
|
+
data: omitIdField(body),
|
4235
4309
|
populate
|
4236
4310
|
};
|
4237
4311
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|