@strapi/content-manager 0.0.0-experimental.a9a5a36dd73072c19eadeff5f387e8286b2a4d22 → 0.0.0-experimental.afa3b513b8f95459043f33fb94f4bac03af1474f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs → ComponentConfigurationPage-CnL10QYC.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-B1bIXVuX.mjs.map → ComponentConfigurationPage-CnL10QYC.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js → ComponentConfigurationPage-G4EIirP8.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-Bqgx7Mes.js.map → ComponentConfigurationPage-G4EIirP8.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js → EditConfigurationPage-B2AA1kVF.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-BFEwvdMW.js.map → EditConfigurationPage-B2AA1kVF.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs → EditConfigurationPage-I2kKh9dx.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-ZO0vOO8q.mjs.map → EditConfigurationPage-I2kKh9dx.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-DA95Ha6J.js → EditViewPage-CHgoNwlc.js} +19 -8
- package/dist/_chunks/EditViewPage-CHgoNwlc.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DlLEyUL6.mjs → EditViewPage-zFjJK0s8.mjs} +19 -8
- package/dist/_chunks/EditViewPage-zFjJK0s8.mjs.map +1 -0
- package/dist/_chunks/{Field-CnK8dO8N.js → Field-9DePZh-0.js} +125 -97
- package/dist/_chunks/Field-9DePZh-0.js.map +1 -0
- package/dist/_chunks/{Field-Dq7bDnuh.mjs → Field-DPAzUS1M.mjs} +123 -95
- package/dist/_chunks/Field-DPAzUS1M.mjs.map +1 -0
- package/dist/_chunks/{Form-B_JE0dbz.mjs → Form-CEkENbkF.mjs} +35 -16
- package/dist/_chunks/Form-CEkENbkF.mjs.map +1 -0
- package/dist/_chunks/{Form-BpiR4piS.js → Form-DPm-KZ1A.js} +35 -16
- package/dist/_chunks/Form-DPm-KZ1A.js.map +1 -0
- package/dist/_chunks/{History-DdIstl8b.js → History-DXSbTWez.js} +21 -11
- package/dist/_chunks/History-DXSbTWez.js.map +1 -0
- package/dist/_chunks/{History-CBNGU7a-.mjs → History-utls71em.mjs} +21 -11
- package/dist/_chunks/History-utls71em.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-5dr4qpue.mjs → ListConfigurationPage-CuMXWWqb.mjs} +14 -4
- package/dist/_chunks/ListConfigurationPage-CuMXWWqb.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DkKRparB.js → ListConfigurationPage-D5C7ACZ_.js} +14 -4
- package/dist/_chunks/ListConfigurationPage-D5C7ACZ_.js.map +1 -0
- package/dist/_chunks/{ListViewPage-DecLrYV6.mjs → ListViewPage-CdKd-PS_.mjs} +46 -37
- package/dist/_chunks/ListViewPage-CdKd-PS_.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-wE0lXqoD.js → ListViewPage-DfuwH1tt.js} +48 -39
- package/dist/_chunks/ListViewPage-DfuwH1tt.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js → NoContentTypePage-BIxlkWWi.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DEKR6tf9.js.map → NoContentTypePage-BIxlkWWi.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs → NoContentTypePage-DkToTT7u.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-CiIcfYsd.mjs.map → NoContentTypePage-DkToTT7u.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js → NoPermissionsPage-Bu4GWYb-.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DmNfF2Bb.js.map → NoPermissionsPage-Bu4GWYb-.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs → NoPermissionsPage-DlWi4BAH.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CM5UD8ee.mjs.map → NoPermissionsPage-DlWi4BAH.mjs.map} +1 -1
- package/dist/_chunks/{Relations-L0xYRoSQ.js → Relations-CFjTESWQ.js} +4 -4
- package/dist/_chunks/{Relations-L0xYRoSQ.js.map → Relations-CFjTESWQ.js.map} +1 -1
- package/dist/_chunks/{Relations-Dqz0C1fz.mjs → Relations-QP5yn9_z.mjs} +4 -4
- package/dist/_chunks/{Relations-Dqz0C1fz.mjs.map → Relations-QP5yn9_z.mjs.map} +1 -1
- package/dist/_chunks/{en-uOUIxfcQ.js → en-BVzUkPxZ.js} +6 -5
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BVzUkPxZ.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-CPTj6CjC.mjs} +6 -5
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-CPTj6CjC.mjs.map} +1 -1
- package/dist/_chunks/{index-BSn97i8U.mjs → index-BHfS6_D5.mjs} +253 -136
- package/dist/_chunks/index-BHfS6_D5.mjs.map +1 -0
- package/dist/_chunks/{index-DyvUPg1a.js → index-DXiHxy70.js} +234 -117
- package/dist/_chunks/index-DXiHxy70.js.map +1 -0
- package/dist/_chunks/{layout-DPaHUusj.mjs → layout-DX_52HSH.mjs} +22 -9
- package/dist/_chunks/layout-DX_52HSH.mjs.map +1 -0
- package/dist/_chunks/{layout-TPqF2oJ5.js → layout-bE-WUnQ0.js} +21 -8
- package/dist/_chunks/layout-bE-WUnQ0.js.map +1 -0
- package/dist/_chunks/{relations-BWYS9gkn.js → relations-D706vblp.js} +2 -2
- package/dist/_chunks/{relations-BWYS9gkn.js.map → relations-D706vblp.js.map} +1 -1
- package/dist/_chunks/{relations-Ck7-ecDT.mjs → relations-SCVAL_aJ.mjs} +2 -2
- package/dist/_chunks/{relations-Ck7-ecDT.mjs.map → relations-SCVAL_aJ.mjs.map} +1 -1
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +4 -4
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +10 -11
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +177 -107
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +178 -108
- 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 +11 -11
- package/dist/_chunks/EditViewPage-DA95Ha6J.js.map +0 -1
- package/dist/_chunks/EditViewPage-DlLEyUL6.mjs.map +0 -1
- package/dist/_chunks/Field-CnK8dO8N.js.map +0 -1
- package/dist/_chunks/Field-Dq7bDnuh.mjs.map +0 -1
- package/dist/_chunks/Form-B_JE0dbz.mjs.map +0 -1
- package/dist/_chunks/Form-BpiR4piS.js.map +0 -1
- package/dist/_chunks/History-CBNGU7a-.mjs.map +0 -1
- package/dist/_chunks/History-DdIstl8b.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-5dr4qpue.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DkKRparB.js.map +0 -1
- package/dist/_chunks/ListViewPage-DecLrYV6.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-wE0lXqoD.js.map +0 -1
- package/dist/_chunks/index-BSn97i8U.mjs.map +0 -1
- package/dist/_chunks/index-DyvUPg1a.js.map +0 -1
- package/dist/_chunks/layout-DPaHUusj.mjs.map +0 -1
- package/dist/_chunks/layout-TPqF2oJ5.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.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,9 +202,10 @@ 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,12 +215,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
212
215
|
}
|
213
216
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
214
217
|
if (isVisible2) {
|
215
|
-
acc[attributeName] = {
|
218
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
216
219
|
}
|
217
220
|
break;
|
218
221
|
}
|
219
222
|
case "media": {
|
220
|
-
acc[attributeName] = {
|
223
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
221
224
|
break;
|
222
225
|
}
|
223
226
|
case "component": {
|
@@ -290,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
290
293
|
getRelationRestoreValue,
|
291
294
|
getMediaRestoreValue,
|
292
295
|
getDefaultLocale,
|
296
|
+
isLocalizedContentType,
|
293
297
|
getLocaleDictionary,
|
294
298
|
getRetentionDays,
|
295
299
|
getVersionStatus,
|
@@ -312,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
312
316
|
});
|
313
317
|
},
|
314
318
|
async findVersionsPage(params) {
|
315
|
-
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
|
+
}
|
316
326
|
const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
|
317
327
|
query.findPage({
|
318
328
|
...params.query,
|
@@ -468,6 +478,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
468
478
|
}
|
469
479
|
};
|
470
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
|
+
};
|
471
517
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
472
518
|
const state = {
|
473
519
|
deleteExpiredJob: null,
|
@@ -480,63 +526,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
480
526
|
return;
|
481
527
|
}
|
482
528
|
strapi2.documents.use(async (context, next) => {
|
483
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
484
|
-
return next();
|
485
|
-
}
|
486
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
487
|
-
return next();
|
488
|
-
}
|
489
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
490
|
-
return next();
|
491
|
-
}
|
492
|
-
const contentTypeUid = context.contentType.uid;
|
493
|
-
if (!contentTypeUid.startsWith("api::")) {
|
494
|
-
return next();
|
495
|
-
}
|
496
529
|
const result = await next();
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
530
|
+
if (!shouldCreateHistoryVersion(context)) {
|
531
|
+
return result;
|
532
|
+
}
|
533
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
501
534
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
502
|
-
const
|
503
|
-
if (
|
504
|
-
|
505
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
506
|
-
);
|
507
|
-
return next();
|
535
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
536
|
+
if (!locales.length) {
|
537
|
+
return result;
|
508
538
|
}
|
509
|
-
const
|
510
|
-
|
511
|
-
|
512
|
-
|
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
|
+
)
|
513
554
|
});
|
514
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
515
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
516
|
-
const componentsSchemas = Object.keys(
|
517
|
-
attributesSchema
|
518
|
-
).reduce((currentComponentSchemas, key) => {
|
519
|
-
const fieldSchema = attributesSchema[key];
|
520
|
-
if (fieldSchema.type === "component") {
|
521
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
522
|
-
return {
|
523
|
-
...currentComponentSchemas,
|
524
|
-
[fieldSchema.component]: componentSchema
|
525
|
-
};
|
526
|
-
}
|
527
|
-
return currentComponentSchemas;
|
528
|
-
}, {});
|
529
555
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
530
|
-
onCommit(() => {
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
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
|
+
}
|
540
568
|
});
|
541
569
|
});
|
542
570
|
return result;
|
@@ -1176,6 +1204,11 @@ const { createPolicy } = policy;
|
|
1176
1204
|
const hasPermissions = createPolicy({
|
1177
1205
|
name: "plugin::content-manager.hasPermissions",
|
1178
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
|
+
*/
|
1179
1212
|
handler(ctx, config = {}) {
|
1180
1213
|
const { actions = [], hasAtLeastOne = false } = config;
|
1181
1214
|
const { userAbility } = ctx.state;
|
@@ -1569,9 +1602,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1569
1602
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1570
1603
|
);
|
1571
1604
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1572
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1605
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1573
1606
|
const { allowMultipleLocales } = opts;
|
1574
|
-
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;
|
1575
1610
|
const schema = yup$1.object().shape({
|
1576
1611
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1577
1612
|
status: statusSchema
|
@@ -1619,7 +1654,7 @@ const createDocument = async (ctx, opts) => {
|
|
1619
1654
|
const setCreator = setCreatorFields({ user });
|
1620
1655
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1621
1656
|
const sanitizedBody = await sanitizeFn(body);
|
1622
|
-
const { locale, status
|
1657
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1623
1658
|
return documentManager2.create(model, {
|
1624
1659
|
data: sanitizedBody,
|
1625
1660
|
locale,
|
@@ -1638,7 +1673,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1638
1673
|
}
|
1639
1674
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1640
1675
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1641
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1676
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1642
1677
|
const [documentVersion, documentExists] = await Promise.all([
|
1643
1678
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1644
1679
|
documentManager2.exists(model, id)
|
@@ -1676,7 +1711,7 @@ const collectionTypes = {
|
|
1676
1711
|
}
|
1677
1712
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1678
1713
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1679
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1714
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1680
1715
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1681
1716
|
{ ...permissionQuery, populate, locale, status },
|
1682
1717
|
model
|
@@ -1711,7 +1746,7 @@ const collectionTypes = {
|
|
1711
1746
|
}
|
1712
1747
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1713
1748
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1714
|
-
const { locale, status
|
1749
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1715
1750
|
const version = await documentManager2.findOne(id, model, {
|
1716
1751
|
populate,
|
1717
1752
|
locale,
|
@@ -1726,7 +1761,7 @@ const collectionTypes = {
|
|
1726
1761
|
permissionChecker2,
|
1727
1762
|
model,
|
1728
1763
|
// @ts-expect-error TODO: fix
|
1729
|
-
{ id, locale, publishedAt: null },
|
1764
|
+
{ documentId: id, locale, publishedAt: null },
|
1730
1765
|
{ availableLocales: true, availableStatus: false }
|
1731
1766
|
);
|
1732
1767
|
ctx.body = { data: {}, meta };
|
@@ -1778,7 +1813,7 @@ const collectionTypes = {
|
|
1778
1813
|
}
|
1779
1814
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1780
1815
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1781
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1816
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1782
1817
|
const document = await documentManager2.findOne(id, model, {
|
1783
1818
|
populate,
|
1784
1819
|
locale,
|
@@ -1823,7 +1858,7 @@ const collectionTypes = {
|
|
1823
1858
|
}
|
1824
1859
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1825
1860
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1826
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1861
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1827
1862
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1828
1863
|
if (documentLocales.length === 0) {
|
1829
1864
|
return ctx.notFound();
|
@@ -1852,11 +1887,28 @@ const collectionTypes = {
|
|
1852
1887
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1853
1888
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1854
1889
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1855
|
-
|
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
|
+
}
|
1856
1909
|
if (permissionChecker2.cannot.publish(document)) {
|
1857
1910
|
throw new errors.ForbiddenError();
|
1858
1911
|
}
|
1859
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1860
1912
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1861
1913
|
locale
|
1862
1914
|
// TODO: Allow setting creator fields on publish
|
@@ -1883,7 +1935,9 @@ const collectionTypes = {
|
|
1883
1935
|
}
|
1884
1936
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1885
1937
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1886
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1938
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1939
|
+
allowMultipleLocales: true
|
1940
|
+
});
|
1887
1941
|
const entityPromises = documentIds.map(
|
1888
1942
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1889
1943
|
);
|
@@ -1910,7 +1964,9 @@ const collectionTypes = {
|
|
1910
1964
|
if (permissionChecker2.cannot.unpublish()) {
|
1911
1965
|
return ctx.forbidden();
|
1912
1966
|
}
|
1913
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
1967
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1968
|
+
allowMultipleLocales: true
|
1969
|
+
});
|
1914
1970
|
const entityPromises = documentIds.map(
|
1915
1971
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1916
1972
|
);
|
@@ -1943,7 +1999,7 @@ const collectionTypes = {
|
|
1943
1999
|
}
|
1944
2000
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1945
2001
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1946
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2002
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1947
2003
|
const document = await documentManager2.findOne(id, model, {
|
1948
2004
|
populate,
|
1949
2005
|
locale,
|
@@ -1980,7 +2036,7 @@ const collectionTypes = {
|
|
1980
2036
|
}
|
1981
2037
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1982
2038
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1983
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2039
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1984
2040
|
const document = await documentManager2.findOne(id, model, {
|
1985
2041
|
populate,
|
1986
2042
|
locale,
|
@@ -2011,7 +2067,7 @@ const collectionTypes = {
|
|
2011
2067
|
}
|
2012
2068
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2013
2069
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2014
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2070
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2015
2071
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2016
2072
|
populate,
|
2017
2073
|
locale
|
@@ -2038,7 +2094,7 @@ const collectionTypes = {
|
|
2038
2094
|
}
|
2039
2095
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2040
2096
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2041
|
-
const { locale, status
|
2097
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2042
2098
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2043
2099
|
if (!entity) {
|
2044
2100
|
return ctx.notFound();
|
@@ -2261,20 +2317,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2261
2317
|
userAbility,
|
2262
2318
|
model: model.uid
|
2263
2319
|
});
|
2264
|
-
|
2320
|
+
const isMainFieldListable = isListable(model, mainField);
|
2321
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2322
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2265
2323
|
return "id";
|
2266
2324
|
}
|
2267
|
-
if (
|
2268
|
-
|
2269
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2270
|
-
userAbility,
|
2271
|
-
model: "plugin::users-permissions.user"
|
2272
|
-
});
|
2273
|
-
if (userPermissionChecker.can.read()) {
|
2274
|
-
return "name";
|
2275
|
-
}
|
2276
|
-
}
|
2277
|
-
return "id";
|
2325
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2326
|
+
return "name";
|
2278
2327
|
}
|
2279
2328
|
return mainField;
|
2280
2329
|
};
|
@@ -2474,8 +2523,9 @@ const relations = {
|
|
2474
2523
|
} else {
|
2475
2524
|
where.id = id;
|
2476
2525
|
}
|
2477
|
-
|
2478
|
-
|
2526
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2527
|
+
if (!isEmpty(publishedAt)) {
|
2528
|
+
where[`${alias}.published_at`] = publishedAt;
|
2479
2529
|
}
|
2480
2530
|
if (filterByLocale) {
|
2481
2531
|
where[`${alias}.locale`] = locale;
|
@@ -2532,9 +2582,7 @@ const relations = {
|
|
2532
2582
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2533
2583
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2534
2584
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2535
|
-
ordering: "desc"
|
2536
|
-
page: ctx.request.query.page,
|
2537
|
-
pageSize: ctx.request.query.pageSize
|
2585
|
+
ordering: "desc"
|
2538
2586
|
});
|
2539
2587
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2540
2588
|
ctx.body = {
|
@@ -2566,7 +2614,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2566
2614
|
throw new errors.ForbiddenError();
|
2567
2615
|
}
|
2568
2616
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2569
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2617
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2570
2618
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2571
2619
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2572
2620
|
// Find the first document to check if it exists
|
@@ -2607,7 +2655,7 @@ const singleTypes = {
|
|
2607
2655
|
return ctx.forbidden();
|
2608
2656
|
}
|
2609
2657
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2610
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2658
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2611
2659
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2612
2660
|
if (!version) {
|
2613
2661
|
if (permissionChecker2.cannot.create()) {
|
@@ -2652,7 +2700,7 @@ const singleTypes = {
|
|
2652
2700
|
}
|
2653
2701
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2654
2702
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2655
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2703
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2656
2704
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2657
2705
|
populate,
|
2658
2706
|
locale
|
@@ -2689,7 +2737,7 @@ const singleTypes = {
|
|
2689
2737
|
if (permissionChecker2.cannot.publish(document)) {
|
2690
2738
|
throw new errors.ForbiddenError();
|
2691
2739
|
}
|
2692
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2740
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2693
2741
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2694
2742
|
return publishResult.at(0);
|
2695
2743
|
});
|
@@ -2712,7 +2760,7 @@ const singleTypes = {
|
|
2712
2760
|
return ctx.forbidden();
|
2713
2761
|
}
|
2714
2762
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2715
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2763
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2716
2764
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2717
2765
|
if (!document) {
|
2718
2766
|
return ctx.notFound();
|
@@ -2744,7 +2792,7 @@ const singleTypes = {
|
|
2744
2792
|
return ctx.forbidden();
|
2745
2793
|
}
|
2746
2794
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2747
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2795
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2748
2796
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2749
2797
|
if (!document) {
|
2750
2798
|
return ctx.notFound();
|
@@ -2764,7 +2812,7 @@ const singleTypes = {
|
|
2764
2812
|
const { query } = ctx.request;
|
2765
2813
|
const documentManager2 = getService$1("document-manager");
|
2766
2814
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2767
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2815
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2768
2816
|
if (permissionChecker2.cannot.read()) {
|
2769
2817
|
return ctx.forbidden();
|
2770
2818
|
}
|
@@ -2785,7 +2833,7 @@ const uid$1 = {
|
|
2785
2833
|
async generateUID(ctx) {
|
2786
2834
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2787
2835
|
const { query = {} } = ctx.request;
|
2788
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2836
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2789
2837
|
await validateUIDField(contentTypeUID, field);
|
2790
2838
|
const uidService = getService$1("uid");
|
2791
2839
|
ctx.body = {
|
@@ -2797,7 +2845,7 @@ const uid$1 = {
|
|
2797
2845
|
ctx.request.body
|
2798
2846
|
);
|
2799
2847
|
const { query = {} } = ctx.request;
|
2800
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2848
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2801
2849
|
await validateUIDField(contentTypeUID, field);
|
2802
2850
|
const uidService = getService$1("uid");
|
2803
2851
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3440,12 +3488,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3440
3488
|
ability: userAbility,
|
3441
3489
|
model
|
3442
3490
|
});
|
3443
|
-
const
|
3491
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3492
|
+
const toSubject = (entity) => {
|
3493
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3494
|
+
};
|
3444
3495
|
const can = (action, entity, field) => {
|
3445
|
-
|
3496
|
+
const subject = toSubject(entity);
|
3497
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3498
|
+
return (
|
3499
|
+
// Test the original action to see if it passes
|
3500
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3501
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3502
|
+
);
|
3446
3503
|
};
|
3447
3504
|
const cannot = (action, entity, field) => {
|
3448
|
-
|
3505
|
+
const subject = toSubject(entity);
|
3506
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3507
|
+
return (
|
3508
|
+
// Test both the original action
|
3509
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3510
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3511
|
+
);
|
3449
3512
|
};
|
3450
3513
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3451
3514
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3722,6 +3785,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3722
3785
|
const attribute = model.attributes[attributeName];
|
3723
3786
|
switch (attribute.type) {
|
3724
3787
|
case "relation": {
|
3788
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3789
|
+
if (isMorphRelation) {
|
3790
|
+
break;
|
3791
|
+
}
|
3725
3792
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3726
3793
|
populateAcc[attributeName] = {
|
3727
3794
|
count: true,
|
@@ -4099,7 +4166,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4099
4166
|
*/
|
4100
4167
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4101
4168
|
if (!document) {
|
4102
|
-
return
|
4169
|
+
return {
|
4170
|
+
data: document,
|
4171
|
+
meta: {
|
4172
|
+
availableLocales: [],
|
4173
|
+
availableStatus: []
|
4174
|
+
}
|
4175
|
+
};
|
4103
4176
|
}
|
4104
4177
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4105
4178
|
if (!hasDraftAndPublish) {
|
@@ -4207,10 +4280,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4207
4280
|
async clone(id, body, uid2) {
|
4208
4281
|
const populate = await buildDeepPopulate(uid2);
|
4209
4282
|
const params = {
|
4210
|
-
data:
|
4211
|
-
...omitIdField(body),
|
4212
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4213
|
-
},
|
4283
|
+
data: omitIdField(body),
|
4214
4284
|
populate
|
4215
4285
|
};
|
4216
4286
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|