@strapi/content-manager 0.0.0-experimental.62ce06180fe9a772eaeb3d43d238b26644f39f7c → 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.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import strapiUtils, { validateYupSchema, errors, async, contentTypes as contentTypes$1, yup as yup$1, validateYupSchemaSync, policy, traverse, setCreatorFields, isOperatorOfType, relations as relations$1, traverseEntity, pagination } from "@strapi/utils";
|
2
|
-
import { pick, omit, difference, intersection, pipe, propOr, isEqual, isEmpty, set, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat,
|
2
|
+
import { pick, omit, difference, castArray, intersection, pipe, propOr, isEqual, isEmpty, set, isNil as isNil$1, has, prop, assoc, mapValues, flow, uniq, uniqBy, concat, getOr, propEq, merge, groupBy } from "lodash/fp";
|
3
3
|
import "@strapi/types";
|
4
4
|
import * as yup from "yup";
|
5
5
|
import { scheduleJob } from "node-schedule";
|
@@ -173,7 +173,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
173
173
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
|
174
174
|
};
|
175
175
|
const localesService = strapi2.plugin("i18n")?.service("locales");
|
176
|
+
const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
|
176
177
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
178
|
+
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
177
179
|
const getLocaleDictionary = async () => {
|
178
180
|
if (!localesService)
|
179
181
|
return {};
|
@@ -200,20 +202,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
200
202
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
201
203
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
202
204
|
};
|
203
|
-
const getDeepPopulate2 = (uid2) => {
|
205
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
204
206
|
const model = strapi2.getModel(uid2);
|
205
207
|
const attributes = Object.entries(model.attributes);
|
208
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
206
209
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
207
210
|
switch (attribute.type) {
|
208
211
|
case "relation": {
|
212
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
213
|
+
if (isMorphRelation) {
|
214
|
+
break;
|
215
|
+
}
|
209
216
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
210
217
|
if (isVisible2) {
|
211
|
-
acc[attributeName] = {
|
218
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
212
219
|
}
|
213
220
|
break;
|
214
221
|
}
|
215
222
|
case "media": {
|
216
|
-
acc[attributeName] = {
|
223
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
217
224
|
break;
|
218
225
|
}
|
219
226
|
case "component": {
|
@@ -286,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
286
293
|
getRelationRestoreValue,
|
287
294
|
getMediaRestoreValue,
|
288
295
|
getDefaultLocale,
|
296
|
+
isLocalizedContentType,
|
289
297
|
getLocaleDictionary,
|
290
298
|
getRetentionDays,
|
291
299
|
getVersionStatus,
|
@@ -308,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
308
316
|
});
|
309
317
|
},
|
310
318
|
async findVersionsPage(params) {
|
311
|
-
const
|
319
|
+
const model = strapi2.getModel(params.query.contentType);
|
320
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
321
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
322
|
+
let locale = null;
|
323
|
+
if (isLocalizedContentType) {
|
324
|
+
locale = params.query.locale || defaultLocale;
|
325
|
+
}
|
312
326
|
const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
|
313
327
|
query.findPage({
|
314
328
|
...params.query,
|
@@ -464,6 +478,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
464
478
|
}
|
465
479
|
};
|
466
480
|
};
|
481
|
+
const shouldCreateHistoryVersion = (context) => {
|
482
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
486
|
+
return false;
|
487
|
+
}
|
488
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
489
|
+
return false;
|
490
|
+
}
|
491
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
492
|
+
return false;
|
493
|
+
}
|
494
|
+
return true;
|
495
|
+
};
|
496
|
+
const getSchemas = (uid2) => {
|
497
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
498
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
499
|
+
(currentComponentSchemas, key) => {
|
500
|
+
const fieldSchema = attributesSchema[key];
|
501
|
+
if (fieldSchema.type === "component") {
|
502
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
503
|
+
return {
|
504
|
+
...currentComponentSchemas,
|
505
|
+
[fieldSchema.component]: componentSchema
|
506
|
+
};
|
507
|
+
}
|
508
|
+
return currentComponentSchemas;
|
509
|
+
},
|
510
|
+
{}
|
511
|
+
);
|
512
|
+
return {
|
513
|
+
schema: omit(FIELDS_TO_IGNORE, attributesSchema),
|
514
|
+
componentsSchemas
|
515
|
+
};
|
516
|
+
};
|
467
517
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
468
518
|
const state = {
|
469
519
|
deleteExpiredJob: null,
|
@@ -476,63 +526,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
476
526
|
return;
|
477
527
|
}
|
478
528
|
strapi2.documents.use(async (context, next) => {
|
479
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
480
|
-
return next();
|
481
|
-
}
|
482
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
483
|
-
return next();
|
484
|
-
}
|
485
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
486
|
-
return next();
|
487
|
-
}
|
488
|
-
const contentTypeUid = context.contentType.uid;
|
489
|
-
if (!contentTypeUid.startsWith("api::")) {
|
490
|
-
return next();
|
491
|
-
}
|
492
529
|
const result = await next();
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
530
|
+
if (!shouldCreateHistoryVersion(context)) {
|
531
|
+
return result;
|
532
|
+
}
|
533
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
497
534
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
498
|
-
const
|
499
|
-
if (
|
500
|
-
|
501
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
502
|
-
);
|
503
|
-
return next();
|
535
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
536
|
+
if (!locales.length) {
|
537
|
+
return result;
|
504
538
|
}
|
505
|
-
const
|
506
|
-
|
507
|
-
|
508
|
-
|
539
|
+
const uid2 = context.contentType.uid;
|
540
|
+
const schemas = getSchemas(uid2);
|
541
|
+
const model = strapi2.getModel(uid2);
|
542
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
543
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
544
|
+
where: {
|
545
|
+
documentId,
|
546
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
547
|
+
...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
548
|
+
},
|
549
|
+
populate: serviceUtils.getDeepPopulate(
|
550
|
+
uid2,
|
551
|
+
true
|
552
|
+
/* use database syntax */
|
553
|
+
)
|
509
554
|
});
|
510
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
511
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
512
|
-
const componentsSchemas = Object.keys(
|
513
|
-
attributesSchema
|
514
|
-
).reduce((currentComponentSchemas, key) => {
|
515
|
-
const fieldSchema = attributesSchema[key];
|
516
|
-
if (fieldSchema.type === "component") {
|
517
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
518
|
-
return {
|
519
|
-
...currentComponentSchemas,
|
520
|
-
[fieldSchema.component]: componentSchema
|
521
|
-
};
|
522
|
-
}
|
523
|
-
return currentComponentSchemas;
|
524
|
-
}, {});
|
525
555
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
526
|
-
onCommit(() => {
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
556
|
+
onCommit(async () => {
|
557
|
+
for (const entry of localeEntries) {
|
558
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
559
|
+
await getService(strapi2, "history").createVersion({
|
560
|
+
contentType: uid2,
|
561
|
+
data: omit(FIELDS_TO_IGNORE, entry),
|
562
|
+
relatedDocumentId: documentId,
|
563
|
+
locale: entry.locale,
|
564
|
+
status,
|
565
|
+
...schemas
|
566
|
+
});
|
567
|
+
}
|
536
568
|
});
|
537
569
|
});
|
538
570
|
return result;
|
@@ -1172,6 +1204,11 @@ const { createPolicy } = policy;
|
|
1172
1204
|
const hasPermissions = createPolicy({
|
1173
1205
|
name: "plugin::content-manager.hasPermissions",
|
1174
1206
|
validator: validateHasPermissionsInput,
|
1207
|
+
/**
|
1208
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1209
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1210
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1211
|
+
*/
|
1175
1212
|
handler(ctx, config = {}) {
|
1176
1213
|
const { actions = [], hasAtLeastOne = false } = config;
|
1177
1214
|
const { userAbility } = ctx.state;
|
@@ -1565,9 +1602,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1565
1602
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1566
1603
|
);
|
1567
1604
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1568
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1605
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1569
1606
|
const { allowMultipleLocales } = opts;
|
1570
|
-
const { locale, status, ...rest } = request || {};
|
1607
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1608
|
+
const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1609
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1571
1610
|
const schema = yup$1.object().shape({
|
1572
1611
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1573
1612
|
status: statusSchema
|
@@ -1615,7 +1654,7 @@ const createDocument = async (ctx, opts) => {
|
|
1615
1654
|
const setCreator = setCreatorFields({ user });
|
1616
1655
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1617
1656
|
const sanitizedBody = await sanitizeFn(body);
|
1618
|
-
const { locale, status
|
1657
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1619
1658
|
return documentManager2.create(model, {
|
1620
1659
|
data: sanitizedBody,
|
1621
1660
|
locale,
|
@@ -1634,7 +1673,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1634
1673
|
}
|
1635
1674
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1636
1675
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1637
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1676
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1638
1677
|
const [documentVersion, documentExists] = await Promise.all([
|
1639
1678
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1640
1679
|
documentManager2.exists(model, id)
|
@@ -1672,7 +1711,7 @@ const collectionTypes = {
|
|
1672
1711
|
}
|
1673
1712
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1674
1713
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1675
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1714
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1676
1715
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1677
1716
|
{ ...permissionQuery, populate, locale, status },
|
1678
1717
|
model
|
@@ -1707,7 +1746,7 @@ const collectionTypes = {
|
|
1707
1746
|
}
|
1708
1747
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1709
1748
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1710
|
-
const { locale, status
|
1749
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1711
1750
|
const version = await documentManager2.findOne(id, model, {
|
1712
1751
|
populate,
|
1713
1752
|
locale,
|
@@ -1774,7 +1813,7 @@ const collectionTypes = {
|
|
1774
1813
|
}
|
1775
1814
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1776
1815
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1777
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1816
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1778
1817
|
const document = await documentManager2.findOne(id, model, {
|
1779
1818
|
populate,
|
1780
1819
|
locale,
|
@@ -1819,7 +1858,7 @@ const collectionTypes = {
|
|
1819
1858
|
}
|
1820
1859
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1821
1860
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1822
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1861
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1823
1862
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1824
1863
|
if (documentLocales.length === 0) {
|
1825
1864
|
return ctx.notFound();
|
@@ -1848,11 +1887,28 @@ const collectionTypes = {
|
|
1848
1887
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1849
1888
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1850
1889
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1851
|
-
|
1890
|
+
let document;
|
1891
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1892
|
+
const isCreate = isNil$1(id);
|
1893
|
+
if (isCreate) {
|
1894
|
+
if (permissionChecker2.cannot.create()) {
|
1895
|
+
throw new errors.ForbiddenError();
|
1896
|
+
}
|
1897
|
+
document = await createDocument(ctx, { populate });
|
1898
|
+
}
|
1899
|
+
const isUpdate = !isCreate;
|
1900
|
+
if (isUpdate) {
|
1901
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1902
|
+
if (!document) {
|
1903
|
+
throw new errors.NotFoundError("Document not found");
|
1904
|
+
}
|
1905
|
+
if (permissionChecker2.can.update(document)) {
|
1906
|
+
await updateDocument(ctx);
|
1907
|
+
}
|
1908
|
+
}
|
1852
1909
|
if (permissionChecker2.cannot.publish(document)) {
|
1853
1910
|
throw new errors.ForbiddenError();
|
1854
1911
|
}
|
1855
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1856
1912
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1857
1913
|
locale
|
1858
1914
|
// TODO: Allow setting creator fields on publish
|
@@ -1879,7 +1935,9 @@ const collectionTypes = {
|
|
1879
1935
|
}
|
1880
1936
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1881
1937
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1882
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1938
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1939
|
+
allowMultipleLocales: true
|
1940
|
+
});
|
1883
1941
|
const entityPromises = documentIds.map(
|
1884
1942
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1885
1943
|
);
|
@@ -1906,7 +1964,7 @@ const collectionTypes = {
|
|
1906
1964
|
if (permissionChecker2.cannot.unpublish()) {
|
1907
1965
|
return ctx.forbidden();
|
1908
1966
|
}
|
1909
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1967
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1910
1968
|
const entityPromises = documentIds.map(
|
1911
1969
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1912
1970
|
);
|
@@ -1939,7 +1997,7 @@ const collectionTypes = {
|
|
1939
1997
|
}
|
1940
1998
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1941
1999
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1942
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2000
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1943
2001
|
const document = await documentManager2.findOne(id, model, {
|
1944
2002
|
populate,
|
1945
2003
|
locale,
|
@@ -1976,7 +2034,7 @@ const collectionTypes = {
|
|
1976
2034
|
}
|
1977
2035
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1978
2036
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1979
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2037
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1980
2038
|
const document = await documentManager2.findOne(id, model, {
|
1981
2039
|
populate,
|
1982
2040
|
locale,
|
@@ -2007,7 +2065,7 @@ const collectionTypes = {
|
|
2007
2065
|
}
|
2008
2066
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2009
2067
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2010
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2068
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2011
2069
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2012
2070
|
populate,
|
2013
2071
|
locale
|
@@ -2034,7 +2092,7 @@ const collectionTypes = {
|
|
2034
2092
|
}
|
2035
2093
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2036
2094
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2037
|
-
const { locale, status
|
2095
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2038
2096
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2039
2097
|
if (!entity) {
|
2040
2098
|
return ctx.notFound();
|
@@ -2257,20 +2315,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2257
2315
|
userAbility,
|
2258
2316
|
model: model.uid
|
2259
2317
|
});
|
2260
|
-
|
2318
|
+
const isMainFieldListable = isListable(model, mainField);
|
2319
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2320
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2261
2321
|
return "id";
|
2262
2322
|
}
|
2263
|
-
if (
|
2264
|
-
|
2265
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2266
|
-
userAbility,
|
2267
|
-
model: "plugin::users-permissions.user"
|
2268
|
-
});
|
2269
|
-
if (userPermissionChecker.can.read()) {
|
2270
|
-
return "name";
|
2271
|
-
}
|
2272
|
-
}
|
2273
|
-
return "id";
|
2323
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2324
|
+
return "name";
|
2274
2325
|
}
|
2275
2326
|
return mainField;
|
2276
2327
|
};
|
@@ -2528,9 +2579,7 @@ const relations = {
|
|
2528
2579
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2529
2580
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2530
2581
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2531
|
-
ordering: "desc"
|
2532
|
-
page: ctx.request.query.page,
|
2533
|
-
pageSize: ctx.request.query.pageSize
|
2582
|
+
ordering: "desc"
|
2534
2583
|
});
|
2535
2584
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2536
2585
|
ctx.body = {
|
@@ -2562,7 +2611,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2562
2611
|
throw new errors.ForbiddenError();
|
2563
2612
|
}
|
2564
2613
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2565
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2614
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2566
2615
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2567
2616
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2568
2617
|
// Find the first document to check if it exists
|
@@ -2603,7 +2652,7 @@ const singleTypes = {
|
|
2603
2652
|
return ctx.forbidden();
|
2604
2653
|
}
|
2605
2654
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2606
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2655
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2607
2656
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2608
2657
|
if (!version) {
|
2609
2658
|
if (permissionChecker2.cannot.create()) {
|
@@ -2648,7 +2697,7 @@ const singleTypes = {
|
|
2648
2697
|
}
|
2649
2698
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2650
2699
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2651
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2700
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2652
2701
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2653
2702
|
populate,
|
2654
2703
|
locale
|
@@ -2685,7 +2734,7 @@ const singleTypes = {
|
|
2685
2734
|
if (permissionChecker2.cannot.publish(document)) {
|
2686
2735
|
throw new errors.ForbiddenError();
|
2687
2736
|
}
|
2688
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2737
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2689
2738
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2690
2739
|
return publishResult.at(0);
|
2691
2740
|
});
|
@@ -2708,7 +2757,7 @@ const singleTypes = {
|
|
2708
2757
|
return ctx.forbidden();
|
2709
2758
|
}
|
2710
2759
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2711
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2760
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2712
2761
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2713
2762
|
if (!document) {
|
2714
2763
|
return ctx.notFound();
|
@@ -2740,7 +2789,7 @@ const singleTypes = {
|
|
2740
2789
|
return ctx.forbidden();
|
2741
2790
|
}
|
2742
2791
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2743
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2792
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2744
2793
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2745
2794
|
if (!document) {
|
2746
2795
|
return ctx.notFound();
|
@@ -2760,7 +2809,7 @@ const singleTypes = {
|
|
2760
2809
|
const { query } = ctx.request;
|
2761
2810
|
const documentManager2 = getService$1("document-manager");
|
2762
2811
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2763
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2812
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2764
2813
|
if (permissionChecker2.cannot.read()) {
|
2765
2814
|
return ctx.forbidden();
|
2766
2815
|
}
|
@@ -2781,7 +2830,7 @@ const uid$1 = {
|
|
2781
2830
|
async generateUID(ctx) {
|
2782
2831
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2783
2832
|
const { query = {} } = ctx.request;
|
2784
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2833
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2785
2834
|
await validateUIDField(contentTypeUID, field);
|
2786
2835
|
const uidService = getService$1("uid");
|
2787
2836
|
ctx.body = {
|
@@ -2793,7 +2842,7 @@ const uid$1 = {
|
|
2793
2842
|
ctx.request.body
|
2794
2843
|
);
|
2795
2844
|
const { query = {} } = ctx.request;
|
2796
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2845
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2797
2846
|
await validateUIDField(contentTypeUID, field);
|
2798
2847
|
const uidService = getService$1("uid");
|
2799
2848
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3436,12 +3485,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3436
3485
|
ability: userAbility,
|
3437
3486
|
model
|
3438
3487
|
});
|
3439
|
-
const
|
3488
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3489
|
+
const toSubject = (entity) => {
|
3490
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3491
|
+
};
|
3440
3492
|
const can = (action, entity, field) => {
|
3441
|
-
|
3493
|
+
const subject = toSubject(entity);
|
3494
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3495
|
+
return (
|
3496
|
+
// Test the original action to see if it passes
|
3497
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3498
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3499
|
+
);
|
3442
3500
|
};
|
3443
3501
|
const cannot = (action, entity, field) => {
|
3444
|
-
|
3502
|
+
const subject = toSubject(entity);
|
3503
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3504
|
+
return (
|
3505
|
+
// Test both the original action
|
3506
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3507
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3508
|
+
);
|
3445
3509
|
};
|
3446
3510
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3447
3511
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3718,6 +3782,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3718
3782
|
const attribute = model.attributes[attributeName];
|
3719
3783
|
switch (attribute.type) {
|
3720
3784
|
case "relation": {
|
3785
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3786
|
+
if (isMorphRelation) {
|
3787
|
+
break;
|
3788
|
+
}
|
3721
3789
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3722
3790
|
populateAcc[attributeName] = {
|
3723
3791
|
count: true,
|
@@ -4095,7 +4163,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4095
4163
|
*/
|
4096
4164
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4097
4165
|
if (!document) {
|
4098
|
-
return
|
4166
|
+
return {
|
4167
|
+
data: document,
|
4168
|
+
meta: {
|
4169
|
+
availableLocales: [],
|
4170
|
+
availableStatus: []
|
4171
|
+
}
|
4172
|
+
};
|
4099
4173
|
}
|
4100
4174
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4101
4175
|
if (!hasDraftAndPublish) {
|
@@ -4203,10 +4277,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4203
4277
|
async clone(id, body, uid2) {
|
4204
4278
|
const populate = await buildDeepPopulate(uid2);
|
4205
4279
|
const params = {
|
4206
|
-
data:
|
4207
|
-
...omitIdField(body),
|
4208
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4209
|
-
},
|
4280
|
+
data: omitIdField(body),
|
4210
4281
|
populate
|
4211
4282
|
};
|
4212
4283
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|