@strapi/content-manager 0.0.0-experimental.dd3311938ac827f1fa8560c8840a9a394f5896c0 → 0.0.0-experimental.e14656d3b8681880212c13260b9a2b340c182f2d
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-y_7iLdmB.js → ComponentConfigurationPage-D_M8iBw5.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js.map → ComponentConfigurationPage-D_M8iBw5.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs → ComponentConfigurationPage-qemkOlnj.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs.map → ComponentConfigurationPage-qemkOlnj.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js → EditConfigurationPage-BePwPuHy.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js.map → EditConfigurationPage-BePwPuHy.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs → EditConfigurationPage-CjUrEewK.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs.map → EditConfigurationPage-CjUrEewK.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CTTDHKkQ.js → EditViewPage-B-RJeiJD.js} +57 -46
- package/dist/_chunks/EditViewPage-B-RJeiJD.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DWb0DE7R.mjs → EditViewPage-De8GyU8P.mjs} +58 -47
- package/dist/_chunks/EditViewPage-De8GyU8P.mjs.map +1 -0
- package/dist/_chunks/{Field-C5Z1Ivdv.js → Field-dq8Tg1M_.js} +514 -168
- package/dist/_chunks/Field-dq8Tg1M_.js.map +1 -0
- package/dist/_chunks/{Field-DnStdvQw.mjs → Field-pb2o8uBe.mjs} +516 -170
- package/dist/_chunks/Field-pb2o8uBe.mjs.map +1 -0
- package/dist/_chunks/{Form-B81OtW-k.js → Form-DGIf4jQU.js} +38 -28
- package/dist/_chunks/Form-DGIf4jQU.js.map +1 -0
- package/dist/_chunks/{Form-DqGgE55Q.mjs → Form-DJn0Dxha.mjs} +40 -30
- package/dist/_chunks/Form-DJn0Dxha.mjs.map +1 -0
- package/dist/_chunks/{History-DS6-HCYX.mjs → History-BowL3JKP.mjs} +52 -29
- package/dist/_chunks/History-BowL3JKP.mjs.map +1 -0
- package/dist/_chunks/{History-4NbOq2dX.js → History-Dh2NEHnR.js} +51 -28
- package/dist/_chunks/History-Dh2NEHnR.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DQJJltko.mjs → ListConfigurationPage-BpVOB-hn.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-BpVOB-hn.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CpfstlYY.js → ListConfigurationPage-BxYCWz9e.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-BxYCWz9e.js.map +1 -0
- package/dist/_chunks/{ListViewPage-CA3I75m5.js → ListViewPage-4XsciqHZ.js} +65 -68
- package/dist/_chunks/ListViewPage-4XsciqHZ.js.map +1 -0
- package/dist/_chunks/{ListViewPage-nQrOQuVo.mjs → ListViewPage-CXFUjZQC.mjs} +67 -70
- package/dist/_chunks/ListViewPage-CXFUjZQC.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js → NoContentTypePage-C8OpoHeU.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js.map → NoContentTypePage-C8OpoHeU.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs → NoContentTypePage-DuhOTp3x.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs.map → NoContentTypePage-DuhOTp3x.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs → NoPermissionsPage-DVz3mzDz.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs.map → NoPermissionsPage-DVz3mzDz.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CO2MK200.js → NoPermissionsPage-y_r7DVA2.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CO2MK200.js.map → NoPermissionsPage-y_r7DVA2.js.map} +1 -1
- package/dist/_chunks/{Relations-BDRl99Ux.mjs → Relations-CVNLrn1Y.mjs} +4 -4
- package/dist/_chunks/Relations-CVNLrn1Y.mjs.map +1 -0
- package/dist/_chunks/{Relations-DG2jnOcr.js → Relations-DPFCAa7b.js} +4 -4
- package/dist/_chunks/Relations-DPFCAa7b.js.map +1 -0
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-BrCTWlZv.mjs} +5 -4
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
- package/dist/_chunks/{en-fbKQxLGn.js → en-uOUIxfcQ.js} +5 -4
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-uOUIxfcQ.js.map} +1 -1
- package/dist/_chunks/{index-BZoNZMXL.js → index-C3fJE-1-.js} +465 -422
- package/dist/_chunks/index-C3fJE-1-.js.map +1 -0
- package/dist/_chunks/{index-Drt2DN7v.mjs → index-DiMrfcfy.mjs} +472 -429
- package/dist/_chunks/index-DiMrfcfy.mjs.map +1 -0
- package/dist/_chunks/{layout-DEYBqgF1.js → layout-C788OmNr.js} +23 -11
- package/dist/_chunks/layout-C788OmNr.js.map +1 -0
- package/dist/_chunks/{layout-BzAbmoO6.mjs → layout-ls3gxfpH.mjs} +25 -13
- package/dist/_chunks/layout-ls3gxfpH.mjs.map +1 -0
- package/dist/_chunks/{relations-D26zVRdi.mjs → relations-CLcOmGO0.mjs} +2 -2
- package/dist/_chunks/{relations-D26zVRdi.mjs.map → relations-CLcOmGO0.mjs.map} +1 -1
- package/dist/_chunks/{relations-D0eZ4VWw.js → relations-DYeotliT.js} +2 -2
- package/dist/_chunks/{relations-D0eZ4VWw.js.map → relations-DYeotliT.js.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 +8 -3
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +4 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations.d.ts +20 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +12 -32
- package/dist/admin/src/pages/ListView/components/BulkActions/Actions.d.ts +3 -30
- package/dist/admin/src/pages/ListView/components/BulkActions/ConfirmBulkActionDialog.d.ts +2 -2
- package/dist/admin/src/services/api.d.ts +1 -1
- package/dist/admin/src/services/components.d.ts +2 -2
- package/dist/admin/src/services/contentTypes.d.ts +3 -3
- package/dist/admin/src/services/documents.d.ts +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 +166 -108
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +167 -109
- 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/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +1 -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-CTTDHKkQ.js.map +0 -1
- package/dist/_chunks/EditViewPage-DWb0DE7R.mjs.map +0 -1
- package/dist/_chunks/Field-C5Z1Ivdv.js.map +0 -1
- package/dist/_chunks/Field-DnStdvQw.mjs.map +0 -1
- package/dist/_chunks/Form-B81OtW-k.js.map +0 -1
- package/dist/_chunks/Form-DqGgE55Q.mjs.map +0 -1
- package/dist/_chunks/History-4NbOq2dX.js.map +0 -1
- package/dist/_chunks/History-DS6-HCYX.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-CpfstlYY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DQJJltko.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-CA3I75m5.js.map +0 -1
- package/dist/_chunks/ListViewPage-nQrOQuVo.mjs.map +0 -1
- package/dist/_chunks/Relations-BDRl99Ux.mjs.map +0 -1
- package/dist/_chunks/Relations-DG2jnOcr.js.map +0 -1
- package/dist/_chunks/index-BZoNZMXL.js.map +0 -1
- package/dist/_chunks/index-Drt2DN7v.mjs.map +0 -1
- package/dist/_chunks/layout-BzAbmoO6.mjs.map +0 -1
- package/dist/_chunks/layout-DEYBqgF1.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";
|
@@ -200,20 +200,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
200
200
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
201
201
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
202
202
|
};
|
203
|
-
const getDeepPopulate2 = (uid2) => {
|
203
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
204
204
|
const model = strapi2.getModel(uid2);
|
205
205
|
const attributes = Object.entries(model.attributes);
|
206
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
206
207
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
207
208
|
switch (attribute.type) {
|
208
209
|
case "relation": {
|
210
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
211
|
+
if (isMorphRelation) {
|
212
|
+
break;
|
213
|
+
}
|
209
214
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
210
215
|
if (isVisible2) {
|
211
|
-
acc[attributeName] = {
|
216
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
212
217
|
}
|
213
218
|
break;
|
214
219
|
}
|
215
220
|
case "media": {
|
216
|
-
acc[attributeName] = {
|
221
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
217
222
|
break;
|
218
223
|
}
|
219
224
|
case "component": {
|
@@ -464,13 +469,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
464
469
|
}
|
465
470
|
};
|
466
471
|
};
|
472
|
+
const shouldCreateHistoryVersion = (context) => {
|
473
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
474
|
+
return false;
|
475
|
+
}
|
476
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
477
|
+
return false;
|
478
|
+
}
|
479
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
480
|
+
return false;
|
481
|
+
}
|
482
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
483
|
+
return false;
|
484
|
+
}
|
485
|
+
return true;
|
486
|
+
};
|
487
|
+
const getSchemas = (uid2) => {
|
488
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
489
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
490
|
+
(currentComponentSchemas, key) => {
|
491
|
+
const fieldSchema = attributesSchema[key];
|
492
|
+
if (fieldSchema.type === "component") {
|
493
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
494
|
+
return {
|
495
|
+
...currentComponentSchemas,
|
496
|
+
[fieldSchema.component]: componentSchema
|
497
|
+
};
|
498
|
+
}
|
499
|
+
return currentComponentSchemas;
|
500
|
+
},
|
501
|
+
{}
|
502
|
+
);
|
503
|
+
return {
|
504
|
+
schema: omit(FIELDS_TO_IGNORE, attributesSchema),
|
505
|
+
componentsSchemas
|
506
|
+
};
|
507
|
+
};
|
467
508
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
468
509
|
const state = {
|
469
510
|
deleteExpiredJob: null,
|
470
511
|
isInitialized: false
|
471
512
|
};
|
472
|
-
const query = strapi2.db.query(HISTORY_VERSION_UID);
|
473
|
-
const historyService = getService(strapi2, "history");
|
474
513
|
const serviceUtils = createServiceUtils({ strapi: strapi2 });
|
475
514
|
return {
|
476
515
|
async bootstrap() {
|
@@ -478,63 +517,43 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
478
517
|
return;
|
479
518
|
}
|
480
519
|
strapi2.documents.use(async (context, next) => {
|
481
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
482
|
-
return next();
|
483
|
-
}
|
484
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
485
|
-
return next();
|
486
|
-
}
|
487
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
488
|
-
return next();
|
489
|
-
}
|
490
|
-
const contentTypeUid = context.contentType.uid;
|
491
|
-
if (!contentTypeUid.startsWith("api::")) {
|
492
|
-
return next();
|
493
|
-
}
|
494
520
|
const result = await next();
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
499
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
500
|
-
const
|
501
|
-
if (
|
502
|
-
|
503
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
504
|
-
);
|
505
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
506
529
|
}
|
507
|
-
const
|
508
|
-
|
509
|
-
|
510
|
-
|
530
|
+
const uid2 = context.contentType.uid;
|
531
|
+
const schemas = getSchemas(uid2);
|
532
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
533
|
+
where: {
|
534
|
+
documentId,
|
535
|
+
locale: { $in: locales },
|
536
|
+
publishedAt: null
|
537
|
+
},
|
538
|
+
populate: serviceUtils.getDeepPopulate(
|
539
|
+
uid2,
|
540
|
+
true
|
541
|
+
/* use database syntax */
|
542
|
+
)
|
511
543
|
});
|
512
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
513
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
514
|
-
const componentsSchemas = Object.keys(
|
515
|
-
attributesSchema
|
516
|
-
).reduce((currentComponentSchemas, key) => {
|
517
|
-
const fieldSchema = attributesSchema[key];
|
518
|
-
if (fieldSchema.type === "component") {
|
519
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
520
|
-
return {
|
521
|
-
...currentComponentSchemas,
|
522
|
-
[fieldSchema.component]: componentSchema
|
523
|
-
};
|
524
|
-
}
|
525
|
-
return currentComponentSchemas;
|
526
|
-
}, {});
|
527
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
528
|
-
onCommit(() => {
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
545
|
+
onCommit(async () => {
|
546
|
+
for (const entry of localeEntries) {
|
547
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
548
|
+
await getService(strapi2, "history").createVersion({
|
549
|
+
contentType: uid2,
|
550
|
+
data: omit(FIELDS_TO_IGNORE, entry),
|
551
|
+
relatedDocumentId: documentId,
|
552
|
+
locale: entry.locale,
|
553
|
+
status,
|
554
|
+
...schemas
|
555
|
+
});
|
556
|
+
}
|
538
557
|
});
|
539
558
|
});
|
540
559
|
return result;
|
@@ -542,7 +561,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
542
561
|
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
543
562
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
544
563
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
545
|
-
query.deleteMany({
|
564
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
546
565
|
where: {
|
547
566
|
created_at: {
|
548
567
|
$lt: expirationDate.toISOString()
|
@@ -1174,6 +1193,11 @@ const { createPolicy } = policy;
|
|
1174
1193
|
const hasPermissions = createPolicy({
|
1175
1194
|
name: "plugin::content-manager.hasPermissions",
|
1176
1195
|
validator: validateHasPermissionsInput,
|
1196
|
+
/**
|
1197
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1198
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1199
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1200
|
+
*/
|
1177
1201
|
handler(ctx, config = {}) {
|
1178
1202
|
const { actions = [], hasAtLeastOne = false } = config;
|
1179
1203
|
const { userAbility } = ctx.state;
|
@@ -1567,9 +1591,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1567
1591
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1568
1592
|
);
|
1569
1593
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1570
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1594
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1571
1595
|
const { allowMultipleLocales } = opts;
|
1572
|
-
const { locale, status, ...rest } = request || {};
|
1596
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1597
|
+
const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1598
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1573
1599
|
const schema = yup$1.object().shape({
|
1574
1600
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1575
1601
|
status: statusSchema
|
@@ -1617,7 +1643,7 @@ const createDocument = async (ctx, opts) => {
|
|
1617
1643
|
const setCreator = setCreatorFields({ user });
|
1618
1644
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1619
1645
|
const sanitizedBody = await sanitizeFn(body);
|
1620
|
-
const { locale, status
|
1646
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1621
1647
|
return documentManager2.create(model, {
|
1622
1648
|
data: sanitizedBody,
|
1623
1649
|
locale,
|
@@ -1636,7 +1662,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1636
1662
|
}
|
1637
1663
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1638
1664
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1639
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1665
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1640
1666
|
const [documentVersion, documentExists] = await Promise.all([
|
1641
1667
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1642
1668
|
documentManager2.exists(model, id)
|
@@ -1674,7 +1700,7 @@ const collectionTypes = {
|
|
1674
1700
|
}
|
1675
1701
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1676
1702
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1677
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1703
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1678
1704
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1679
1705
|
{ ...permissionQuery, populate, locale, status },
|
1680
1706
|
model
|
@@ -1709,7 +1735,7 @@ const collectionTypes = {
|
|
1709
1735
|
}
|
1710
1736
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1711
1737
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1712
|
-
const { locale, status
|
1738
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1713
1739
|
const version = await documentManager2.findOne(id, model, {
|
1714
1740
|
populate,
|
1715
1741
|
locale,
|
@@ -1776,7 +1802,7 @@ const collectionTypes = {
|
|
1776
1802
|
}
|
1777
1803
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1778
1804
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1779
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1805
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1780
1806
|
const document = await documentManager2.findOne(id, model, {
|
1781
1807
|
populate,
|
1782
1808
|
locale,
|
@@ -1821,7 +1847,7 @@ const collectionTypes = {
|
|
1821
1847
|
}
|
1822
1848
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1823
1849
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1824
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1850
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1825
1851
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1826
1852
|
if (documentLocales.length === 0) {
|
1827
1853
|
return ctx.notFound();
|
@@ -1850,11 +1876,28 @@ const collectionTypes = {
|
|
1850
1876
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1851
1877
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1852
1878
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1853
|
-
|
1879
|
+
let document;
|
1880
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1881
|
+
const isCreate = isNil$1(id);
|
1882
|
+
if (isCreate) {
|
1883
|
+
if (permissionChecker2.cannot.create()) {
|
1884
|
+
throw new errors.ForbiddenError();
|
1885
|
+
}
|
1886
|
+
document = await createDocument(ctx, { populate });
|
1887
|
+
}
|
1888
|
+
const isUpdate = !isCreate;
|
1889
|
+
if (isUpdate) {
|
1890
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1891
|
+
if (!document) {
|
1892
|
+
throw new errors.NotFoundError("Document not found");
|
1893
|
+
}
|
1894
|
+
if (permissionChecker2.can.update(document)) {
|
1895
|
+
await updateDocument(ctx);
|
1896
|
+
}
|
1897
|
+
}
|
1854
1898
|
if (permissionChecker2.cannot.publish(document)) {
|
1855
1899
|
throw new errors.ForbiddenError();
|
1856
1900
|
}
|
1857
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1858
1901
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1859
1902
|
locale
|
1860
1903
|
// TODO: Allow setting creator fields on publish
|
@@ -1881,7 +1924,9 @@ const collectionTypes = {
|
|
1881
1924
|
}
|
1882
1925
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1883
1926
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1884
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1927
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1928
|
+
allowMultipleLocales: true
|
1929
|
+
});
|
1885
1930
|
const entityPromises = documentIds.map(
|
1886
1931
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1887
1932
|
);
|
@@ -1908,7 +1953,7 @@ const collectionTypes = {
|
|
1908
1953
|
if (permissionChecker2.cannot.unpublish()) {
|
1909
1954
|
return ctx.forbidden();
|
1910
1955
|
}
|
1911
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1956
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1912
1957
|
const entityPromises = documentIds.map(
|
1913
1958
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1914
1959
|
);
|
@@ -1941,7 +1986,7 @@ const collectionTypes = {
|
|
1941
1986
|
}
|
1942
1987
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1943
1988
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1944
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1989
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1945
1990
|
const document = await documentManager2.findOne(id, model, {
|
1946
1991
|
populate,
|
1947
1992
|
locale,
|
@@ -1978,7 +2023,7 @@ const collectionTypes = {
|
|
1978
2023
|
}
|
1979
2024
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1980
2025
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1981
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2026
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1982
2027
|
const document = await documentManager2.findOne(id, model, {
|
1983
2028
|
populate,
|
1984
2029
|
locale,
|
@@ -2009,7 +2054,7 @@ const collectionTypes = {
|
|
2009
2054
|
}
|
2010
2055
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2011
2056
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2012
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2057
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2013
2058
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2014
2059
|
populate,
|
2015
2060
|
locale
|
@@ -2036,7 +2081,7 @@ const collectionTypes = {
|
|
2036
2081
|
}
|
2037
2082
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2038
2083
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2039
|
-
const { locale, status
|
2084
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2040
2085
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2041
2086
|
if (!entity) {
|
2042
2087
|
return ctx.notFound();
|
@@ -2059,7 +2104,7 @@ const collectionTypes = {
|
|
2059
2104
|
if (permissionChecker2.cannot.read()) {
|
2060
2105
|
return ctx.forbidden();
|
2061
2106
|
}
|
2062
|
-
const
|
2107
|
+
const documents = await documentManager2.findMany(
|
2063
2108
|
{
|
2064
2109
|
filters: {
|
2065
2110
|
documentId: ids
|
@@ -2068,7 +2113,7 @@ const collectionTypes = {
|
|
2068
2113
|
},
|
2069
2114
|
model
|
2070
2115
|
);
|
2071
|
-
if (!
|
2116
|
+
if (!documents) {
|
2072
2117
|
return ctx.notFound();
|
2073
2118
|
}
|
2074
2119
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2259,20 +2304,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2259
2304
|
userAbility,
|
2260
2305
|
model: model.uid
|
2261
2306
|
});
|
2262
|
-
|
2307
|
+
const isMainFieldListable = isListable(model, mainField);
|
2308
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2309
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2263
2310
|
return "id";
|
2264
2311
|
}
|
2265
|
-
if (
|
2266
|
-
|
2267
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2268
|
-
userAbility,
|
2269
|
-
model: "plugin::users-permissions.user"
|
2270
|
-
});
|
2271
|
-
if (userPermissionChecker.can.read()) {
|
2272
|
-
return "name";
|
2273
|
-
}
|
2274
|
-
}
|
2275
|
-
return "id";
|
2312
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2313
|
+
return "name";
|
2276
2314
|
}
|
2277
2315
|
return mainField;
|
2278
2316
|
};
|
@@ -2530,9 +2568,7 @@ const relations = {
|
|
2530
2568
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2531
2569
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2532
2570
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2533
|
-
ordering: "desc"
|
2534
|
-
page: ctx.request.query.page,
|
2535
|
-
pageSize: ctx.request.query.pageSize
|
2571
|
+
ordering: "desc"
|
2536
2572
|
});
|
2537
2573
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2538
2574
|
ctx.body = {
|
@@ -2564,7 +2600,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2564
2600
|
throw new errors.ForbiddenError();
|
2565
2601
|
}
|
2566
2602
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2567
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2603
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2568
2604
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2569
2605
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2570
2606
|
// Find the first document to check if it exists
|
@@ -2605,7 +2641,7 @@ const singleTypes = {
|
|
2605
2641
|
return ctx.forbidden();
|
2606
2642
|
}
|
2607
2643
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2608
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2644
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2609
2645
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2610
2646
|
if (!version) {
|
2611
2647
|
if (permissionChecker2.cannot.create()) {
|
@@ -2650,7 +2686,7 @@ const singleTypes = {
|
|
2650
2686
|
}
|
2651
2687
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2652
2688
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2653
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2689
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2654
2690
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2655
2691
|
populate,
|
2656
2692
|
locale
|
@@ -2687,7 +2723,7 @@ const singleTypes = {
|
|
2687
2723
|
if (permissionChecker2.cannot.publish(document)) {
|
2688
2724
|
throw new errors.ForbiddenError();
|
2689
2725
|
}
|
2690
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2726
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2691
2727
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2692
2728
|
return publishResult.at(0);
|
2693
2729
|
});
|
@@ -2710,7 +2746,7 @@ const singleTypes = {
|
|
2710
2746
|
return ctx.forbidden();
|
2711
2747
|
}
|
2712
2748
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2713
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2749
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2714
2750
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2715
2751
|
if (!document) {
|
2716
2752
|
return ctx.notFound();
|
@@ -2742,7 +2778,7 @@ const singleTypes = {
|
|
2742
2778
|
return ctx.forbidden();
|
2743
2779
|
}
|
2744
2780
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2745
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2781
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2746
2782
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2747
2783
|
if (!document) {
|
2748
2784
|
return ctx.notFound();
|
@@ -2762,7 +2798,7 @@ const singleTypes = {
|
|
2762
2798
|
const { query } = ctx.request;
|
2763
2799
|
const documentManager2 = getService$1("document-manager");
|
2764
2800
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2765
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2801
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2766
2802
|
if (permissionChecker2.cannot.read()) {
|
2767
2803
|
return ctx.forbidden();
|
2768
2804
|
}
|
@@ -2783,7 +2819,7 @@ const uid$1 = {
|
|
2783
2819
|
async generateUID(ctx) {
|
2784
2820
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2785
2821
|
const { query = {} } = ctx.request;
|
2786
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2822
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2787
2823
|
await validateUIDField(contentTypeUID, field);
|
2788
2824
|
const uidService = getService$1("uid");
|
2789
2825
|
ctx.body = {
|
@@ -2795,7 +2831,7 @@ const uid$1 = {
|
|
2795
2831
|
ctx.request.body
|
2796
2832
|
);
|
2797
2833
|
const { query = {} } = ctx.request;
|
2798
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2834
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2799
2835
|
await validateUIDField(contentTypeUID, field);
|
2800
2836
|
const uidService = getService$1("uid");
|
2801
2837
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3438,12 +3474,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3438
3474
|
ability: userAbility,
|
3439
3475
|
model
|
3440
3476
|
});
|
3441
|
-
const
|
3477
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3478
|
+
const toSubject = (entity) => {
|
3479
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3480
|
+
};
|
3442
3481
|
const can = (action, entity, field) => {
|
3443
|
-
|
3482
|
+
const subject = toSubject(entity);
|
3483
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3484
|
+
return (
|
3485
|
+
// Test the original action to see if it passes
|
3486
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3487
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3488
|
+
);
|
3444
3489
|
};
|
3445
3490
|
const cannot = (action, entity, field) => {
|
3446
|
-
|
3491
|
+
const subject = toSubject(entity);
|
3492
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3493
|
+
return (
|
3494
|
+
// Test both the original action
|
3495
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3496
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3497
|
+
);
|
3447
3498
|
};
|
3448
3499
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3449
3500
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3720,6 +3771,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3720
3771
|
const attribute = model.attributes[attributeName];
|
3721
3772
|
switch (attribute.type) {
|
3722
3773
|
case "relation": {
|
3774
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3775
|
+
if (isMorphRelation) {
|
3776
|
+
break;
|
3777
|
+
}
|
3723
3778
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3724
3779
|
populateAcc[attributeName] = {
|
3725
3780
|
count: true,
|
@@ -4097,7 +4152,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4097
4152
|
*/
|
4098
4153
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4099
4154
|
if (!document) {
|
4100
|
-
return
|
4155
|
+
return {
|
4156
|
+
data: document,
|
4157
|
+
meta: {
|
4158
|
+
availableLocales: [],
|
4159
|
+
availableStatus: []
|
4160
|
+
}
|
4161
|
+
};
|
4101
4162
|
}
|
4102
4163
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4103
4164
|
if (!hasDraftAndPublish) {
|
@@ -4205,10 +4266,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4205
4266
|
async clone(id, body, uid2) {
|
4206
4267
|
const populate = await buildDeepPopulate(uid2);
|
4207
4268
|
const params = {
|
4208
|
-
data:
|
4209
|
-
...omitIdField(body),
|
4210
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4211
|
-
},
|
4269
|
+
data: omitIdField(body),
|
4212
4270
|
populate
|
4213
4271
|
};
|
4214
4272
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|