@strapi/content-manager 0.0.0-experimental.60f3ded53a22a24d208ebf6df9b84c118aa97abf → 0.0.0-experimental.6d27139261823fc4b18da9f3c10b271d5010dbf0
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-DErJQEVW.mjs → ComponentConfigurationPage-9lRmRdIr.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DErJQEVW.mjs.map → ComponentConfigurationPage-9lRmRdIr.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-Cl7eB3s4.js → ComponentConfigurationPage-DyDkPajU.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Cl7eB3s4.js.map → ComponentConfigurationPage-DyDkPajU.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CBosWqQ7.mjs → EditConfigurationPage-Bk893vVY.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CBosWqQ7.mjs.map → EditConfigurationPage-Bk893vVY.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CyfFvH6-.js → EditConfigurationPage-DValmA0m.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CyfFvH6-.js.map → EditConfigurationPage-DValmA0m.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-ClIueJnM.mjs → EditViewPage-DiNFdFqP.mjs} +19 -8
- package/dist/_chunks/EditViewPage-DiNFdFqP.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-DxyAOItK.js → EditViewPage-Dk7Eaft4.js} +19 -8
- package/dist/_chunks/EditViewPage-Dk7Eaft4.js.map +1 -0
- package/dist/_chunks/{Field-C0Y_SR9e.js → Field-DH2OaqUP.js} +458 -128
- package/dist/_chunks/Field-DH2OaqUP.js.map +1 -0
- package/dist/_chunks/{Field-BZBYmvaf.mjs → Field-Dv_HTFTa.mjs} +460 -130
- package/dist/_chunks/Field-Dv_HTFTa.mjs.map +1 -0
- package/dist/_chunks/{Form-DwvGnISS.js → Form-B_dUDizM.js} +22 -11
- package/dist/_chunks/Form-B_dUDizM.js.map +1 -0
- package/dist/_chunks/{Form-jwRSC2kV.mjs → Form-Dy6P4HgH.mjs} +22 -11
- package/dist/_chunks/Form-Dy6P4HgH.mjs.map +1 -0
- package/dist/_chunks/{History-Cda0Yjzz.js → History-BT4w83Oa.js} +44 -19
- package/dist/_chunks/History-BT4w83Oa.js.map +1 -0
- package/dist/_chunks/{History-BgzAIj0G.mjs → History-DrwsD1Vc.mjs} +44 -19
- package/dist/_chunks/History-DrwsD1Vc.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-GH55qfoT.mjs → ListConfigurationPage-BxIP0jRy.mjs} +20 -8
- package/dist/_chunks/ListConfigurationPage-BxIP0jRy.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-C29EF97r.js → ListConfigurationPage-CuYrMcW3.js} +20 -8
- package/dist/_chunks/ListConfigurationPage-CuYrMcW3.js.map +1 -0
- package/dist/_chunks/{ListViewPage-QU03PFj1.mjs → ListViewPage-5a1vw-OK.mjs} +40 -34
- package/dist/_chunks/ListViewPage-5a1vw-OK.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CnRt0UT7.js → ListViewPage-BvpwNur7.js} +38 -32
- package/dist/_chunks/ListViewPage-BvpwNur7.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-CPs2CnzH.mjs → NoContentTypePage-Bm6tRcd3.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CPs2CnzH.mjs.map → NoContentTypePage-Bm6tRcd3.mjs.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DFDjxByI.js → NoContentTypePage-UqEiWKkM.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DFDjxByI.js.map → NoContentTypePage-UqEiWKkM.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-ct58lcY0.mjs → NoPermissionsPage-BHPqn_tQ.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-ct58lcY0.mjs.map → NoPermissionsPage-BHPqn_tQ.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BVHI-jv5.js → NoPermissionsPage-C_vGRo8Q.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BVHI-jv5.js.map → NoPermissionsPage-C_vGRo8Q.js.map} +1 -1
- package/dist/_chunks/{Relations-KMf5qEN0.mjs → Relations-C7fPyh5P.mjs} +4 -4
- package/dist/_chunks/Relations-C7fPyh5P.mjs.map +1 -0
- package/dist/_chunks/{Relations-BjpPPCKp.js → Relations-CznVF6LS.js} +4 -4
- package/dist/_chunks/Relations-CznVF6LS.js.map +1 -0
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-CbaIuYoB.mjs} +6 -5
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-CbaIuYoB.mjs.map} +1 -1
- package/dist/_chunks/{en-fbKQxLGn.js → en-otD_UBJi.js} +6 -5
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-otD_UBJi.js.map} +1 -1
- package/dist/_chunks/{index-6kKXK7y8.mjs → index-BJ6uTqLL.mjs} +381 -190
- package/dist/_chunks/index-BJ6uTqLL.mjs.map +1 -0
- package/dist/_chunks/{index-D9ZwczCV.js → index-D9UmmBcM.js} +374 -183
- package/dist/_chunks/index-D9UmmBcM.js.map +1 -0
- package/dist/_chunks/{layout-BJfBoBiF.js → layout-kfu5Wtix.js} +23 -11
- package/dist/_chunks/layout-kfu5Wtix.js.map +1 -0
- package/dist/_chunks/{layout-B1Z-9koY.mjs → layout-uomiIGbG.mjs} +25 -13
- package/dist/_chunks/layout-uomiIGbG.mjs.map +1 -0
- package/dist/_chunks/{relations-CMvjzyU3.js → relations-DKENrxko.js} +2 -2
- package/dist/_chunks/{relations-CMvjzyU3.js.map → relations-DKENrxko.js.map} +1 -1
- package/dist/_chunks/{relations-CgZg7Pyx.mjs → relations-DiDufGSA.mjs} +2 -2
- package/dist/_chunks/{relations-CgZg7Pyx.mjs.map → relations-DiDufGSA.mjs.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +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 +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/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 +16 -16
- 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 +175 -104
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +176 -105
- 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/package.json +8 -8
- 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/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,6 +504,42 @@ 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,
|
@@ -502,63 +552,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
502
552
|
return;
|
503
553
|
}
|
504
554
|
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
555
|
const result = await next();
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
556
|
+
if (!shouldCreateHistoryVersion(context)) {
|
557
|
+
return result;
|
558
|
+
}
|
559
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
523
560
|
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();
|
561
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
562
|
+
if (!locales.length) {
|
563
|
+
return result;
|
530
564
|
}
|
531
|
-
const
|
532
|
-
|
533
|
-
|
534
|
-
|
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
|
+
)
|
535
580
|
});
|
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
581
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
552
|
-
onCommit(() => {
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
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
|
+
}
|
562
594
|
});
|
563
595
|
});
|
564
596
|
return result;
|
@@ -1198,6 +1230,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1198
1230
|
const hasPermissions = createPolicy({
|
1199
1231
|
name: "plugin::content-manager.hasPermissions",
|
1200
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
|
+
*/
|
1201
1238
|
handler(ctx, config = {}) {
|
1202
1239
|
const { actions = [], hasAtLeastOne = false } = config;
|
1203
1240
|
const { userAbility } = ctx.state;
|
@@ -1591,9 +1628,11 @@ const multipleLocaleSchema = strapiUtils.yup.lazy(
|
|
1591
1628
|
(value) => Array.isArray(value) ? strapiUtils.yup.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1592
1629
|
);
|
1593
1630
|
const statusSchema = strapiUtils.yup.mixed().oneOf(["draft", "published"], "Invalid status");
|
1594
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1631
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1595
1632
|
const { allowMultipleLocales } = opts;
|
1596
|
-
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;
|
1597
1636
|
const schema = strapiUtils.yup.object().shape({
|
1598
1637
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1599
1638
|
status: statusSchema
|
@@ -1641,7 +1680,7 @@ const createDocument = async (ctx, opts) => {
|
|
1641
1680
|
const setCreator = strapiUtils.setCreatorFields({ user });
|
1642
1681
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1643
1682
|
const sanitizedBody = await sanitizeFn(body);
|
1644
|
-
const { locale, status
|
1683
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1645
1684
|
return documentManager2.create(model, {
|
1646
1685
|
data: sanitizedBody,
|
1647
1686
|
locale,
|
@@ -1660,7 +1699,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1660
1699
|
}
|
1661
1700
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1662
1701
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1663
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1702
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1664
1703
|
const [documentVersion, documentExists] = await Promise.all([
|
1665
1704
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1666
1705
|
documentManager2.exists(model, id)
|
@@ -1698,7 +1737,7 @@ const collectionTypes = {
|
|
1698
1737
|
}
|
1699
1738
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1700
1739
|
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);
|
1740
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1702
1741
|
const { results: documents, pagination } = await documentManager2.findPage(
|
1703
1742
|
{ ...permissionQuery, populate, locale, status },
|
1704
1743
|
model
|
@@ -1733,7 +1772,7 @@ const collectionTypes = {
|
|
1733
1772
|
}
|
1734
1773
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1735
1774
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1736
|
-
const { locale, status
|
1775
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1737
1776
|
const version = await documentManager2.findOne(id, model, {
|
1738
1777
|
populate,
|
1739
1778
|
locale,
|
@@ -1800,7 +1839,7 @@ const collectionTypes = {
|
|
1800
1839
|
}
|
1801
1840
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1802
1841
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1803
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1842
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1804
1843
|
const document = await documentManager2.findOne(id, model, {
|
1805
1844
|
populate,
|
1806
1845
|
locale,
|
@@ -1845,7 +1884,7 @@ const collectionTypes = {
|
|
1845
1884
|
}
|
1846
1885
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1847
1886
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1848
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1887
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1849
1888
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1850
1889
|
if (documentLocales.length === 0) {
|
1851
1890
|
return ctx.notFound();
|
@@ -1874,11 +1913,28 @@ const collectionTypes = {
|
|
1874
1913
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1875
1914
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1876
1915
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1877
|
-
|
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
|
+
}
|
1878
1935
|
if (permissionChecker2.cannot.publish(document)) {
|
1879
1936
|
throw new strapiUtils.errors.ForbiddenError();
|
1880
1937
|
}
|
1881
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1882
1938
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1883
1939
|
locale
|
1884
1940
|
// TODO: Allow setting creator fields on publish
|
@@ -1905,7 +1961,9 @@ const collectionTypes = {
|
|
1905
1961
|
}
|
1906
1962
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1907
1963
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1908
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1964
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1965
|
+
allowMultipleLocales: true
|
1966
|
+
});
|
1909
1967
|
const entityPromises = documentIds.map(
|
1910
1968
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1911
1969
|
);
|
@@ -1932,7 +1990,7 @@ const collectionTypes = {
|
|
1932
1990
|
if (permissionChecker2.cannot.unpublish()) {
|
1933
1991
|
return ctx.forbidden();
|
1934
1992
|
}
|
1935
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1993
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1936
1994
|
const entityPromises = documentIds.map(
|
1937
1995
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1938
1996
|
);
|
@@ -1965,7 +2023,7 @@ const collectionTypes = {
|
|
1965
2023
|
}
|
1966
2024
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1967
2025
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1968
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2026
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1969
2027
|
const document = await documentManager2.findOne(id, model, {
|
1970
2028
|
populate,
|
1971
2029
|
locale,
|
@@ -2002,7 +2060,7 @@ const collectionTypes = {
|
|
2002
2060
|
}
|
2003
2061
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
2004
2062
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2005
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2063
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2006
2064
|
const document = await documentManager2.findOne(id, model, {
|
2007
2065
|
populate,
|
2008
2066
|
locale,
|
@@ -2033,7 +2091,7 @@ const collectionTypes = {
|
|
2033
2091
|
}
|
2034
2092
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2035
2093
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2036
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2094
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2037
2095
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2038
2096
|
populate,
|
2039
2097
|
locale
|
@@ -2060,7 +2118,7 @@ const collectionTypes = {
|
|
2060
2118
|
}
|
2061
2119
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2062
2120
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2063
|
-
const { locale, status
|
2121
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2064
2122
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2065
2123
|
if (!entity) {
|
2066
2124
|
return ctx.notFound();
|
@@ -2283,20 +2341,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2283
2341
|
userAbility,
|
2284
2342
|
model: model.uid
|
2285
2343
|
});
|
2286
|
-
|
2344
|
+
const isMainFieldListable = isListable(model, mainField);
|
2345
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2346
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2287
2347
|
return "id";
|
2288
2348
|
}
|
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";
|
2349
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2350
|
+
return "name";
|
2300
2351
|
}
|
2301
2352
|
return mainField;
|
2302
2353
|
};
|
@@ -2554,9 +2605,7 @@ const relations = {
|
|
2554
2605
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2555
2606
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2556
2607
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2557
|
-
ordering: "desc"
|
2558
|
-
page: ctx.request.query.page,
|
2559
|
-
pageSize: ctx.request.query.pageSize
|
2608
|
+
ordering: "desc"
|
2560
2609
|
});
|
2561
2610
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2562
2611
|
ctx.body = {
|
@@ -2588,7 +2637,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2588
2637
|
throw new strapiUtils.errors.ForbiddenError();
|
2589
2638
|
}
|
2590
2639
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2591
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2640
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2592
2641
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2593
2642
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2594
2643
|
// Find the first document to check if it exists
|
@@ -2629,7 +2678,7 @@ const singleTypes = {
|
|
2629
2678
|
return ctx.forbidden();
|
2630
2679
|
}
|
2631
2680
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2632
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2681
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2633
2682
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2634
2683
|
if (!version) {
|
2635
2684
|
if (permissionChecker2.cannot.create()) {
|
@@ -2674,7 +2723,7 @@ const singleTypes = {
|
|
2674
2723
|
}
|
2675
2724
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2676
2725
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2677
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2726
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2678
2727
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2679
2728
|
populate,
|
2680
2729
|
locale
|
@@ -2711,7 +2760,7 @@ const singleTypes = {
|
|
2711
2760
|
if (permissionChecker2.cannot.publish(document)) {
|
2712
2761
|
throw new strapiUtils.errors.ForbiddenError();
|
2713
2762
|
}
|
2714
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2763
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2715
2764
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2716
2765
|
return publishResult.at(0);
|
2717
2766
|
});
|
@@ -2734,7 +2783,7 @@ const singleTypes = {
|
|
2734
2783
|
return ctx.forbidden();
|
2735
2784
|
}
|
2736
2785
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2737
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2786
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2738
2787
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2739
2788
|
if (!document) {
|
2740
2789
|
return ctx.notFound();
|
@@ -2766,7 +2815,7 @@ const singleTypes = {
|
|
2766
2815
|
return ctx.forbidden();
|
2767
2816
|
}
|
2768
2817
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2769
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2818
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2770
2819
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2771
2820
|
if (!document) {
|
2772
2821
|
return ctx.notFound();
|
@@ -2786,7 +2835,7 @@ const singleTypes = {
|
|
2786
2835
|
const { query } = ctx.request;
|
2787
2836
|
const documentManager2 = getService$1("document-manager");
|
2788
2837
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2789
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2838
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2790
2839
|
if (permissionChecker2.cannot.read()) {
|
2791
2840
|
return ctx.forbidden();
|
2792
2841
|
}
|
@@ -2807,7 +2856,7 @@ const uid$1 = {
|
|
2807
2856
|
async generateUID(ctx) {
|
2808
2857
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2809
2858
|
const { query = {} } = ctx.request;
|
2810
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2859
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2811
2860
|
await validateUIDField(contentTypeUID, field);
|
2812
2861
|
const uidService = getService$1("uid");
|
2813
2862
|
ctx.body = {
|
@@ -2819,7 +2868,7 @@ const uid$1 = {
|
|
2819
2868
|
ctx.request.body
|
2820
2869
|
);
|
2821
2870
|
const { query = {} } = ctx.request;
|
2822
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2871
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2823
2872
|
await validateUIDField(contentTypeUID, field);
|
2824
2873
|
const uidService = getService$1("uid");
|
2825
2874
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3462,12 +3511,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3462
3511
|
ability: userAbility,
|
3463
3512
|
model
|
3464
3513
|
});
|
3465
|
-
const
|
3514
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3515
|
+
const toSubject = (entity) => {
|
3516
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3517
|
+
};
|
3466
3518
|
const can = (action, entity, field) => {
|
3467
|
-
|
3519
|
+
const subject = toSubject(entity);
|
3520
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3521
|
+
return (
|
3522
|
+
// Test the original action to see if it passes
|
3523
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3524
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3525
|
+
);
|
3468
3526
|
};
|
3469
3527
|
const cannot = (action, entity, field) => {
|
3470
|
-
|
3528
|
+
const subject = toSubject(entity);
|
3529
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3530
|
+
return (
|
3531
|
+
// Test both the original action
|
3532
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3533
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3534
|
+
);
|
3471
3535
|
};
|
3472
3536
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3473
3537
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3744,6 +3808,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3744
3808
|
const attribute = model.attributes[attributeName];
|
3745
3809
|
switch (attribute.type) {
|
3746
3810
|
case "relation": {
|
3811
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3812
|
+
if (isMorphRelation) {
|
3813
|
+
break;
|
3814
|
+
}
|
3747
3815
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3748
3816
|
populateAcc[attributeName] = {
|
3749
3817
|
count: true,
|
@@ -4121,7 +4189,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4121
4189
|
*/
|
4122
4190
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4123
4191
|
if (!document) {
|
4124
|
-
return
|
4192
|
+
return {
|
4193
|
+
data: document,
|
4194
|
+
meta: {
|
4195
|
+
availableLocales: [],
|
4196
|
+
availableStatus: []
|
4197
|
+
}
|
4198
|
+
};
|
4125
4199
|
}
|
4126
4200
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4127
4201
|
if (!hasDraftAndPublish) {
|
@@ -4229,10 +4303,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4229
4303
|
async clone(id, body, uid2) {
|
4230
4304
|
const populate = await buildDeepPopulate(uid2);
|
4231
4305
|
const params = {
|
4232
|
-
data:
|
4233
|
-
...omitIdField(body),
|
4234
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4235
|
-
},
|
4306
|
+
data: omitIdField(body),
|
4236
4307
|
populate
|
4237
4308
|
};
|
4238
4309
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|