@strapi/content-manager 5.0.0-rc.3 → 5.0.0-rc.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs → ComponentConfigurationPage-DfFSZQxe.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs.map → ComponentConfigurationPage-DfFSZQxe.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js → ComponentConfigurationPage-FqfsxQ1j.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js.map → ComponentConfigurationPage-FqfsxQ1j.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js → EditConfigurationPage-Cn0e8t3I.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js.map → EditConfigurationPage-Cn0e8t3I.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs → EditConfigurationPage-DdPNAbl3.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs.map → EditConfigurationPage-DdPNAbl3.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-BLsjc5F-.mjs → EditViewPage-B82x_x1b.mjs} +30 -9
- package/dist/_chunks/EditViewPage-B82x_x1b.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-C-ukDOB7.js → EditViewPage-DlxEHhUt.js} +30 -9
- package/dist/_chunks/EditViewPage-DlxEHhUt.js.map +1 -0
- package/dist/_chunks/{Field-Bfph5SOd.js → Field-COL25JiC.js} +174 -102
- package/dist/_chunks/Field-COL25JiC.js.map +1 -0
- package/dist/_chunks/{Field-Cs7duwWd.mjs → Field-DufHXW17.mjs} +172 -100
- package/dist/_chunks/Field-DufHXW17.mjs.map +1 -0
- package/dist/_chunks/{Form-CPYqIWDG.js → Form-BssUwrTO.js} +36 -17
- package/dist/_chunks/Form-BssUwrTO.js.map +1 -0
- package/dist/_chunks/{Form-Dg_GS5TQ.mjs → Form-u_kAOhwB.mjs} +36 -17
- package/dist/_chunks/Form-u_kAOhwB.mjs.map +1 -0
- package/dist/_chunks/{History-DNQkXANT.js → History-C9t9UqpO.js} +23 -10
- package/dist/_chunks/History-C9t9UqpO.js.map +1 -0
- package/dist/_chunks/{History-wrnHqf09.mjs → History-DRwA3oMM.mjs} +24 -11
- package/dist/_chunks/History-DRwA3oMM.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CUQxfpjT.js → ListConfigurationPage-BXYPohh-.js} +14 -4
- package/dist/_chunks/ListConfigurationPage-BXYPohh-.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DScmJVkW.mjs → ListConfigurationPage-BxfQJzPk.mjs} +14 -4
- package/dist/_chunks/ListConfigurationPage-BxfQJzPk.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-C4IvrMgY.mjs → ListViewPage-CELx2ysp.mjs} +47 -38
- package/dist/_chunks/ListViewPage-CELx2ysp.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BsLiH2-2.js → ListViewPage-D2VD8Szg.js} +49 -40
- package/dist/_chunks/ListViewPage-D2VD8Szg.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js → NoContentTypePage-BV9IjJSM.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js.map → NoContentTypePage-BV9IjJSM.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs → NoContentTypePage-DtJ9jcfk.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs.map → NoContentTypePage-DtJ9jcfk.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs → NoPermissionsPage-DWleVYK7.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs.map → NoPermissionsPage-DWleVYK7.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js → NoPermissionsPage-Dp8NpF9I.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js.map → NoPermissionsPage-Dp8NpF9I.js.map} +1 -1
- package/dist/_chunks/{Relations-BZr8tL0R.mjs → Relations-BTcf5xaw.mjs} +33 -24
- package/dist/_chunks/Relations-BTcf5xaw.mjs.map +1 -0
- package/dist/_chunks/{Relations-CtELXYIK.js → Relations-DR7EUgyC.js} +33 -24
- package/dist/_chunks/Relations-DR7EUgyC.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-OerGjbAN.js → index-BdMf2lfT.js} +1921 -1758
- package/dist/_chunks/index-BdMf2lfT.js.map +1 -0
- package/dist/_chunks/{index-c_5DdJi-.mjs → index-wnqzm4Q8.mjs} +1941 -1778
- package/dist/_chunks/index-wnqzm4Q8.mjs.map +1 -0
- package/dist/_chunks/{layout-oPBiO7RY.mjs → layout-2CfjL0T9.mjs} +22 -9
- package/dist/_chunks/layout-2CfjL0T9.mjs.map +1 -0
- package/dist/_chunks/{layout-Ci7qHlFb.js → layout-B2MyZU-_.js} +21 -8
- package/dist/_chunks/layout-B2MyZU-_.js.map +1 -0
- package/dist/_chunks/{relations-COBpStiF.js → relations-BH7JJGGe.js} +2 -2
- package/dist/_chunks/{relations-COBpStiF.js.map → relations-BH7JJGGe.js.map} +1 -1
- package/dist/_chunks/{relations-BIdWFjdq.mjs → relations-C0w0GcXi.mjs} +2 -2
- package/dist/_chunks/{relations-BIdWFjdq.mjs.map → relations-C0w0GcXi.mjs.map} +1 -1
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +19 -17
- package/dist/admin/src/services/init.d.ts +1 -1
- package/dist/admin/src/services/relations.d.ts +2 -2
- package/dist/admin/src/services/uid.d.ts +3 -3
- package/dist/admin/src/utils/validation.d.ts +4 -1
- package/dist/server/index.js +170 -92
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +171 -93
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/_chunks/EditViewPage-BLsjc5F-.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-C-ukDOB7.js.map +0 -1
- package/dist/_chunks/Field-Bfph5SOd.js.map +0 -1
- package/dist/_chunks/Field-Cs7duwWd.mjs.map +0 -1
- package/dist/_chunks/Form-CPYqIWDG.js.map +0 -1
- package/dist/_chunks/Form-Dg_GS5TQ.mjs.map +0 -1
- package/dist/_chunks/History-DNQkXANT.js.map +0 -1
- package/dist/_chunks/History-wrnHqf09.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-CUQxfpjT.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DScmJVkW.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BsLiH2-2.js.map +0 -1
- package/dist/_chunks/ListViewPage-C4IvrMgY.mjs.map +0 -1
- package/dist/_chunks/Relations-BZr8tL0R.mjs.map +0 -1
- package/dist/_chunks/Relations-CtELXYIK.js.map +0 -1
- package/dist/_chunks/index-OerGjbAN.js.map +0 -1
- package/dist/_chunks/index-c_5DdJi-.mjs.map +0 -1
- package/dist/_chunks/layout-Ci7qHlFb.js.map +0 -1
- package/dist/_chunks/layout-oPBiO7RY.mjs.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
package/dist/server/index.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,
|
@@ -357,7 +367,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
357
367
|
if (userToPopulate == null) {
|
358
368
|
return null;
|
359
369
|
}
|
360
|
-
return strapi2.query("admin::user").findOne({
|
370
|
+
return strapi2.query("admin::user").findOne({
|
371
|
+
where: {
|
372
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
373
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
374
|
+
}
|
375
|
+
});
|
361
376
|
})
|
362
377
|
);
|
363
378
|
return {
|
@@ -468,6 +483,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
468
483
|
}
|
469
484
|
};
|
470
485
|
};
|
486
|
+
const shouldCreateHistoryVersion = (context) => {
|
487
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
488
|
+
return false;
|
489
|
+
}
|
490
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
491
|
+
return false;
|
492
|
+
}
|
493
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
494
|
+
return false;
|
495
|
+
}
|
496
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
497
|
+
return false;
|
498
|
+
}
|
499
|
+
return true;
|
500
|
+
};
|
501
|
+
const getSchemas = (uid2) => {
|
502
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
503
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
504
|
+
(currentComponentSchemas, key) => {
|
505
|
+
const fieldSchema = attributesSchema[key];
|
506
|
+
if (fieldSchema.type === "component") {
|
507
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
508
|
+
return {
|
509
|
+
...currentComponentSchemas,
|
510
|
+
[fieldSchema.component]: componentSchema
|
511
|
+
};
|
512
|
+
}
|
513
|
+
return currentComponentSchemas;
|
514
|
+
},
|
515
|
+
{}
|
516
|
+
);
|
517
|
+
return {
|
518
|
+
schema: omit(FIELDS_TO_IGNORE, attributesSchema),
|
519
|
+
componentsSchemas
|
520
|
+
};
|
521
|
+
};
|
471
522
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
472
523
|
const state = {
|
473
524
|
deleteExpiredJob: null,
|
@@ -480,63 +531,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
480
531
|
return;
|
481
532
|
}
|
482
533
|
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
534
|
const result = await next();
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
535
|
+
if (!shouldCreateHistoryVersion(context)) {
|
536
|
+
return result;
|
537
|
+
}
|
538
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
501
539
|
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();
|
540
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
541
|
+
if (!locales.length) {
|
542
|
+
return result;
|
508
543
|
}
|
509
|
-
const
|
510
|
-
|
511
|
-
|
512
|
-
|
544
|
+
const uid2 = context.contentType.uid;
|
545
|
+
const schemas = getSchemas(uid2);
|
546
|
+
const model = strapi2.getModel(uid2);
|
547
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
548
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
549
|
+
where: {
|
550
|
+
documentId,
|
551
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
552
|
+
...contentTypes$1.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
553
|
+
},
|
554
|
+
populate: serviceUtils.getDeepPopulate(
|
555
|
+
uid2,
|
556
|
+
true
|
557
|
+
/* use database syntax */
|
558
|
+
)
|
513
559
|
});
|
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
560
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
530
|
-
onCommit(() => {
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
561
|
+
onCommit(async () => {
|
562
|
+
for (const entry of localeEntries) {
|
563
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
564
|
+
await getService(strapi2, "history").createVersion({
|
565
|
+
contentType: uid2,
|
566
|
+
data: omit(FIELDS_TO_IGNORE, entry),
|
567
|
+
relatedDocumentId: documentId,
|
568
|
+
locale: entry.locale,
|
569
|
+
status,
|
570
|
+
...schemas
|
571
|
+
});
|
572
|
+
}
|
540
573
|
});
|
541
574
|
});
|
542
575
|
return result;
|
@@ -1176,6 +1209,11 @@ const { createPolicy } = policy;
|
|
1176
1209
|
const hasPermissions = createPolicy({
|
1177
1210
|
name: "plugin::content-manager.hasPermissions",
|
1178
1211
|
validator: validateHasPermissionsInput,
|
1212
|
+
/**
|
1213
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1214
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1215
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1216
|
+
*/
|
1179
1217
|
handler(ctx, config = {}) {
|
1180
1218
|
const { actions = [], hasAtLeastOne = false } = config;
|
1181
1219
|
const { userAbility } = ctx.state;
|
@@ -1656,7 +1694,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1656
1694
|
throw new errors.ForbiddenError();
|
1657
1695
|
}
|
1658
1696
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1659
|
-
const setCreator = setCreatorFields({ user, isEdition: true });
|
1697
|
+
const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
|
1660
1698
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1661
1699
|
const sanitizedBody = await sanitizeFn(body);
|
1662
1700
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1728,7 +1766,7 @@ const collectionTypes = {
|
|
1728
1766
|
permissionChecker2,
|
1729
1767
|
model,
|
1730
1768
|
// @ts-expect-error TODO: fix
|
1731
|
-
{ id, locale, publishedAt: null },
|
1769
|
+
{ documentId: id, locale, publishedAt: null },
|
1732
1770
|
{ availableLocales: true, availableStatus: false }
|
1733
1771
|
);
|
1734
1772
|
ctx.body = { data: {}, meta };
|
@@ -1854,11 +1892,34 @@ const collectionTypes = {
|
|
1854
1892
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1855
1893
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1856
1894
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1857
|
-
|
1895
|
+
let document;
|
1896
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1897
|
+
const isCreate = isNil$1(id);
|
1898
|
+
if (isCreate) {
|
1899
|
+
if (permissionChecker2.cannot.create()) {
|
1900
|
+
throw new errors.ForbiddenError();
|
1901
|
+
}
|
1902
|
+
document = await createDocument(ctx, { populate });
|
1903
|
+
}
|
1904
|
+
const isUpdate = !isCreate;
|
1905
|
+
if (isUpdate) {
|
1906
|
+
const documentExists = documentManager2.exists(model, id);
|
1907
|
+
if (!documentExists) {
|
1908
|
+
throw new errors.NotFoundError("Document not found");
|
1909
|
+
}
|
1910
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1911
|
+
if (!document) {
|
1912
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
1913
|
+
throw new errors.ForbiddenError();
|
1914
|
+
}
|
1915
|
+
document = await updateDocument(ctx);
|
1916
|
+
} else if (permissionChecker2.can.update(document)) {
|
1917
|
+
await updateDocument(ctx);
|
1918
|
+
}
|
1919
|
+
}
|
1858
1920
|
if (permissionChecker2.cannot.publish(document)) {
|
1859
1921
|
throw new errors.ForbiddenError();
|
1860
1922
|
}
|
1861
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1862
1923
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1863
1924
|
locale
|
1864
1925
|
// TODO: Allow setting creator fields on publish
|
@@ -1914,7 +1975,9 @@ const collectionTypes = {
|
|
1914
1975
|
if (permissionChecker2.cannot.unpublish()) {
|
1915
1976
|
return ctx.forbidden();
|
1916
1977
|
}
|
1917
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
1978
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1979
|
+
allowMultipleLocales: true
|
1980
|
+
});
|
1918
1981
|
const entityPromises = documentIds.map(
|
1919
1982
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1920
1983
|
);
|
@@ -2265,20 +2328,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2265
2328
|
userAbility,
|
2266
2329
|
model: model.uid
|
2267
2330
|
});
|
2268
|
-
|
2331
|
+
const isMainFieldListable = isListable(model, mainField);
|
2332
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2333
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2269
2334
|
return "id";
|
2270
2335
|
}
|
2271
|
-
if (
|
2272
|
-
|
2273
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2274
|
-
userAbility,
|
2275
|
-
model: "plugin::users-permissions.user"
|
2276
|
-
});
|
2277
|
-
if (userPermissionChecker.can.read()) {
|
2278
|
-
return "name";
|
2279
|
-
}
|
2280
|
-
}
|
2281
|
-
return "id";
|
2336
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2337
|
+
return "name";
|
2282
2338
|
}
|
2283
2339
|
return mainField;
|
2284
2340
|
};
|
@@ -2311,11 +2367,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2311
2367
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2312
2368
|
const isSourceLocalized = isLocalized(sourceModel);
|
2313
2369
|
const isTargetLocalized = isLocalized(targetModel);
|
2314
|
-
let validatedLocale = locale;
|
2315
|
-
if (!targetModel || !isTargetLocalized)
|
2316
|
-
validatedLocale = void 0;
|
2317
2370
|
return {
|
2318
|
-
locale
|
2371
|
+
locale,
|
2319
2372
|
isSourceLocalized,
|
2320
2373
|
isTargetLocalized
|
2321
2374
|
};
|
@@ -2418,7 +2471,7 @@ const relations = {
|
|
2418
2471
|
attribute,
|
2419
2472
|
fieldsToSelect,
|
2420
2473
|
mainField,
|
2421
|
-
source: { schema: sourceSchema },
|
2474
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2422
2475
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2423
2476
|
sourceSchema,
|
2424
2477
|
targetSchema,
|
@@ -2440,7 +2493,8 @@ const relations = {
|
|
2440
2493
|
fieldsToSelect,
|
2441
2494
|
mainField,
|
2442
2495
|
source: {
|
2443
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2496
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2497
|
+
isLocalized: isSourceLocalized
|
2444
2498
|
},
|
2445
2499
|
target: {
|
2446
2500
|
schema: { uid: targetUid },
|
@@ -2478,12 +2532,16 @@ const relations = {
|
|
2478
2532
|
} else {
|
2479
2533
|
where.id = id;
|
2480
2534
|
}
|
2481
|
-
|
2482
|
-
|
2535
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2536
|
+
if (!isEmpty(publishedAt)) {
|
2537
|
+
where[`${alias}.published_at`] = publishedAt;
|
2483
2538
|
}
|
2484
|
-
if (
|
2539
|
+
if (isTargetLocalized && locale) {
|
2485
2540
|
where[`${alias}.locale`] = locale;
|
2486
2541
|
}
|
2542
|
+
if (isSourceLocalized && locale) {
|
2543
|
+
where.locale = locale;
|
2544
|
+
}
|
2487
2545
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2488
2546
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2489
2547
|
}
|
@@ -2501,7 +2559,8 @@ const relations = {
|
|
2501
2559
|
id: { $notIn: uniq(idsToOmit) }
|
2502
2560
|
});
|
2503
2561
|
}
|
2504
|
-
const
|
2562
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2563
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2505
2564
|
ctx.body = {
|
2506
2565
|
...res,
|
2507
2566
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2536,9 +2595,7 @@ const relations = {
|
|
2536
2595
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2537
2596
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2538
2597
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2539
|
-
ordering: "desc"
|
2540
|
-
page: ctx.request.query.page,
|
2541
|
-
pageSize: ctx.request.query.pageSize
|
2598
|
+
ordering: "desc"
|
2542
2599
|
});
|
2543
2600
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2544
2601
|
ctx.body = {
|
@@ -2625,7 +2682,7 @@ const singleTypes = {
|
|
2625
2682
|
permissionChecker2,
|
2626
2683
|
model,
|
2627
2684
|
// @ts-expect-error - fix types
|
2628
|
-
{
|
2685
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2629
2686
|
{ availableLocales: true, availableStatus: false }
|
2630
2687
|
);
|
2631
2688
|
ctx.body = { data: {}, meta };
|
@@ -3444,12 +3501,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3444
3501
|
ability: userAbility,
|
3445
3502
|
model
|
3446
3503
|
});
|
3447
|
-
const
|
3504
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3505
|
+
const toSubject = (entity) => {
|
3506
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3507
|
+
};
|
3448
3508
|
const can = (action, entity, field) => {
|
3449
|
-
|
3509
|
+
const subject = toSubject(entity);
|
3510
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3511
|
+
return (
|
3512
|
+
// Test the original action to see if it passes
|
3513
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3514
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3515
|
+
);
|
3450
3516
|
};
|
3451
3517
|
const cannot = (action, entity, field) => {
|
3452
|
-
|
3518
|
+
const subject = toSubject(entity);
|
3519
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3520
|
+
return (
|
3521
|
+
// Test both the original action
|
3522
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3523
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3524
|
+
);
|
3453
3525
|
};
|
3454
3526
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3455
3527
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -4107,7 +4179,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4107
4179
|
*/
|
4108
4180
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4109
4181
|
if (!document) {
|
4110
|
-
return
|
4182
|
+
return {
|
4183
|
+
data: document,
|
4184
|
+
meta: {
|
4185
|
+
availableLocales: [],
|
4186
|
+
availableStatus: []
|
4187
|
+
}
|
4188
|
+
};
|
4111
4189
|
}
|
4112
4190
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4113
4191
|
if (!hasDraftAndPublish) {
|