@strapi/content-manager 0.0.0-experimental.7afdc9b682bc83a53ce599c4fb7c9e4506b31fff → 0.0.0-experimental.81dfdf02b1367004c7deed9e01afa9d3a15d0fa5
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-DJcn1DrO.js → ComponentConfigurationPage-D_M8iBw5.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-DJcn1DrO.js.map → ComponentConfigurationPage-D_M8iBw5.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs → ComponentConfigurationPage-qemkOlnj.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-CR5XdR33.mjs.map → ComponentConfigurationPage-qemkOlnj.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js → EditConfigurationPage-BePwPuHy.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-tDtWj7R2.js.map → EditConfigurationPage-BePwPuHy.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs → EditConfigurationPage-CjUrEewK.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-DmCIb4kD.mjs.map → EditConfigurationPage-CjUrEewK.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CoQEnFlC.js → EditViewPage-B-RJeiJD.js} +57 -46
- package/dist/_chunks/EditViewPage-B-RJeiJD.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DvaV7U9b.mjs → EditViewPage-De8GyU8P.mjs} +58 -47
- package/dist/_chunks/EditViewPage-De8GyU8P.mjs.map +1 -0
- package/dist/_chunks/{Field-ZdrmmQ4Y.js → Field-dq8Tg1M_.js} +514 -168
- package/dist/_chunks/Field-dq8Tg1M_.js.map +1 -0
- package/dist/_chunks/{Field-Cz_J9551.mjs → Field-pb2o8uBe.mjs} +516 -170
- package/dist/_chunks/Field-pb2o8uBe.mjs.map +1 -0
- package/dist/_chunks/{Form-Bpig5rch.js → Form-DGIf4jQU.js} +38 -28
- package/dist/_chunks/Form-DGIf4jQU.js.map +1 -0
- package/dist/_chunks/{Form-Dxmihyw8.mjs → Form-DJn0Dxha.mjs} +40 -30
- package/dist/_chunks/Form-DJn0Dxha.mjs.map +1 -0
- package/dist/_chunks/{History-BZP8n7KT.mjs → History-BowL3JKP.mjs} +141 -37
- package/dist/_chunks/History-BowL3JKP.mjs.map +1 -0
- package/dist/_chunks/{History-BfX6XmZK.js → History-Dh2NEHnR.js} +140 -36
- package/dist/_chunks/History-Dh2NEHnR.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DxKuVkKz.mjs → ListConfigurationPage-BpVOB-hn.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-BpVOB-hn.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-B3CXj8PY.js → ListConfigurationPage-BxYCWz9e.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-BxYCWz9e.js.map +1 -0
- package/dist/_chunks/{ListViewPage-Bk9VO__I.js → ListViewPage-4XsciqHZ.js} +65 -68
- package/dist/_chunks/ListViewPage-4XsciqHZ.js.map +1 -0
- package/dist/_chunks/{ListViewPage-D5D3tVPq.mjs → ListViewPage-CXFUjZQC.mjs} +67 -70
- package/dist/_chunks/ListViewPage-CXFUjZQC.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js → NoContentTypePage-C8OpoHeU.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-DsB2F7Z1.js.map → NoContentTypePage-C8OpoHeU.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs → NoContentTypePage-DuhOTp3x.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DnMeuQCj.mjs.map → NoContentTypePage-DuhOTp3x.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs → NoPermissionsPage-DVz3mzDz.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-OyoME_Tf.mjs.map → NoPermissionsPage-DVz3mzDz.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js → NoPermissionsPage-y_r7DVA2.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-BQDM64_b.js.map → NoPermissionsPage-y_r7DVA2.js.map} +1 -1
- package/dist/_chunks/{Relations-BOYZmuWy.mjs → Relations-CVNLrn1Y.mjs} +4 -4
- package/dist/_chunks/Relations-CVNLrn1Y.mjs.map +1 -0
- package/dist/_chunks/{Relations-B6B3A3mb.js → Relations-DPFCAa7b.js} +4 -4
- package/dist/_chunks/Relations-DPFCAa7b.js.map +1 -0
- package/dist/_chunks/{en-Dzv55oQw.mjs → en-BrCTWlZv.mjs} +8 -4
- package/dist/_chunks/{en-Dzv55oQw.mjs.map → en-BrCTWlZv.mjs.map} +1 -1
- package/dist/_chunks/{en-BN1bvFK7.js → en-uOUIxfcQ.js} +8 -4
- package/dist/_chunks/{en-BN1bvFK7.js.map → en-uOUIxfcQ.js.map} +1 -1
- package/dist/_chunks/{index-DzN3kBgx.js → index-C3fJE-1-.js} +491 -431
- package/dist/_chunks/index-C3fJE-1-.js.map +1 -0
- package/dist/_chunks/{index-VHviNMeW.mjs → index-DiMrfcfy.mjs} +511 -451
- package/dist/_chunks/index-DiMrfcfy.mjs.map +1 -0
- package/dist/_chunks/{layout-b91XRlD2.js → layout-C788OmNr.js} +37 -20
- package/dist/_chunks/layout-C788OmNr.js.map +1 -0
- package/dist/_chunks/{layout-CPn1PM6x.mjs → layout-ls3gxfpH.mjs} +39 -22
- package/dist/_chunks/layout-ls3gxfpH.mjs.map +1 -0
- package/dist/_chunks/{relations-BsqxS6tR.mjs → relations-CLcOmGO0.mjs} +2 -2
- package/dist/_chunks/{relations-BsqxS6tR.mjs.map → relations-CLcOmGO0.mjs.map} +1 -1
- package/dist/_chunks/{relations-CA7IYmcP.js → relations-DYeotliT.js} +2 -2
- package/dist/_chunks/{relations-CA7IYmcP.js.map → relations-DYeotliT.js.map} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +5 -5
- package/dist/admin/src/history/components/VersionInputRenderer.d.ts +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 +164 -103
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +165 -104
- 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-CoQEnFlC.js.map +0 -1
- package/dist/_chunks/EditViewPage-DvaV7U9b.mjs.map +0 -1
- package/dist/_chunks/Field-Cz_J9551.mjs.map +0 -1
- package/dist/_chunks/Field-ZdrmmQ4Y.js.map +0 -1
- package/dist/_chunks/Form-Bpig5rch.js.map +0 -1
- package/dist/_chunks/Form-Dxmihyw8.mjs.map +0 -1
- package/dist/_chunks/History-BZP8n7KT.mjs.map +0 -1
- package/dist/_chunks/History-BfX6XmZK.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-B3CXj8PY.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DxKuVkKz.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-Bk9VO__I.js.map +0 -1
- package/dist/_chunks/ListViewPage-D5D3tVPq.mjs.map +0 -1
- package/dist/_chunks/Relations-B6B3A3mb.js.map +0 -1
- package/dist/_chunks/Relations-BOYZmuWy.mjs.map +0 -1
- package/dist/_chunks/index-DzN3kBgx.js.map +0 -1
- package/dist/_chunks/index-VHviNMeW.mjs.map +0 -1
- package/dist/_chunks/layout-CPn1PM6x.mjs.map +0 -1
- package/dist/_chunks/layout-b91XRlD2.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,60 +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
|
-
const contentTypeUid = context.contentType.uid;
|
488
|
-
if (!contentTypeUid.startsWith("api::")) {
|
489
|
-
return next();
|
490
|
-
}
|
491
520
|
const result = await next();
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
521
|
+
if (!shouldCreateHistoryVersion(context)) {
|
522
|
+
return result;
|
523
|
+
}
|
524
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
496
525
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
497
|
-
const
|
498
|
-
if (
|
499
|
-
|
500
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
501
|
-
);
|
502
|
-
return next();
|
526
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
527
|
+
if (!locales.length) {
|
528
|
+
return result;
|
503
529
|
}
|
504
|
-
const
|
505
|
-
|
506
|
-
|
507
|
-
|
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
|
+
)
|
508
543
|
});
|
509
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
510
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
511
|
-
const componentsSchemas = Object.keys(
|
512
|
-
attributesSchema
|
513
|
-
).reduce((currentComponentSchemas, key) => {
|
514
|
-
const fieldSchema = attributesSchema[key];
|
515
|
-
if (fieldSchema.type === "component") {
|
516
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
517
|
-
return {
|
518
|
-
...currentComponentSchemas,
|
519
|
-
[fieldSchema.component]: componentSchema
|
520
|
-
};
|
521
|
-
}
|
522
|
-
return currentComponentSchemas;
|
523
|
-
}, {});
|
524
544
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
525
|
-
onCommit(() => {
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
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
|
+
}
|
535
557
|
});
|
536
558
|
});
|
537
559
|
return result;
|
@@ -539,7 +561,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
539
561
|
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
540
562
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
541
563
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
542
|
-
query.deleteMany({
|
564
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
543
565
|
where: {
|
544
566
|
created_at: {
|
545
567
|
$lt: expirationDate.toISOString()
|
@@ -1171,6 +1193,11 @@ const { createPolicy } = policy;
|
|
1171
1193
|
const hasPermissions = createPolicy({
|
1172
1194
|
name: "plugin::content-manager.hasPermissions",
|
1173
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
|
+
*/
|
1174
1201
|
handler(ctx, config = {}) {
|
1175
1202
|
const { actions = [], hasAtLeastOne = false } = config;
|
1176
1203
|
const { userAbility } = ctx.state;
|
@@ -1564,9 +1591,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1564
1591
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1565
1592
|
);
|
1566
1593
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1567
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1594
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1568
1595
|
const { allowMultipleLocales } = opts;
|
1569
|
-
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;
|
1570
1599
|
const schema = yup$1.object().shape({
|
1571
1600
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1572
1601
|
status: statusSchema
|
@@ -1614,7 +1643,7 @@ const createDocument = async (ctx, opts) => {
|
|
1614
1643
|
const setCreator = setCreatorFields({ user });
|
1615
1644
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1616
1645
|
const sanitizedBody = await sanitizeFn(body);
|
1617
|
-
const { locale, status
|
1646
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1618
1647
|
return documentManager2.create(model, {
|
1619
1648
|
data: sanitizedBody,
|
1620
1649
|
locale,
|
@@ -1633,7 +1662,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1633
1662
|
}
|
1634
1663
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1635
1664
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1636
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1665
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1637
1666
|
const [documentVersion, documentExists] = await Promise.all([
|
1638
1667
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1639
1668
|
documentManager2.exists(model, id)
|
@@ -1671,7 +1700,7 @@ const collectionTypes = {
|
|
1671
1700
|
}
|
1672
1701
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1673
1702
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(1).countRelations({ toOne: false, toMany: true }).build();
|
1674
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
1703
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1675
1704
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1676
1705
|
{ ...permissionQuery, populate, locale, status },
|
1677
1706
|
model
|
@@ -1706,7 +1735,7 @@ const collectionTypes = {
|
|
1706
1735
|
}
|
1707
1736
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1708
1737
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1709
|
-
const { locale, status
|
1738
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1710
1739
|
const version = await documentManager2.findOne(id, model, {
|
1711
1740
|
populate,
|
1712
1741
|
locale,
|
@@ -1773,7 +1802,7 @@ const collectionTypes = {
|
|
1773
1802
|
}
|
1774
1803
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1775
1804
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1776
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1805
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1777
1806
|
const document = await documentManager2.findOne(id, model, {
|
1778
1807
|
populate,
|
1779
1808
|
locale,
|
@@ -1818,7 +1847,7 @@ const collectionTypes = {
|
|
1818
1847
|
}
|
1819
1848
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1820
1849
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1821
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1850
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1822
1851
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1823
1852
|
if (documentLocales.length === 0) {
|
1824
1853
|
return ctx.notFound();
|
@@ -1847,11 +1876,28 @@ const collectionTypes = {
|
|
1847
1876
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1848
1877
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1849
1878
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1850
|
-
|
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
|
+
}
|
1851
1898
|
if (permissionChecker2.cannot.publish(document)) {
|
1852
1899
|
throw new errors.ForbiddenError();
|
1853
1900
|
}
|
1854
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1855
1901
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1856
1902
|
locale
|
1857
1903
|
// TODO: Allow setting creator fields on publish
|
@@ -1878,7 +1924,9 @@ const collectionTypes = {
|
|
1878
1924
|
}
|
1879
1925
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1880
1926
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1881
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1927
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1928
|
+
allowMultipleLocales: true
|
1929
|
+
});
|
1882
1930
|
const entityPromises = documentIds.map(
|
1883
1931
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1884
1932
|
);
|
@@ -1905,7 +1953,7 @@ const collectionTypes = {
|
|
1905
1953
|
if (permissionChecker2.cannot.unpublish()) {
|
1906
1954
|
return ctx.forbidden();
|
1907
1955
|
}
|
1908
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1956
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1909
1957
|
const entityPromises = documentIds.map(
|
1910
1958
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1911
1959
|
);
|
@@ -1938,7 +1986,7 @@ const collectionTypes = {
|
|
1938
1986
|
}
|
1939
1987
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1940
1988
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1941
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1989
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1942
1990
|
const document = await documentManager2.findOne(id, model, {
|
1943
1991
|
populate,
|
1944
1992
|
locale,
|
@@ -1975,7 +2023,7 @@ const collectionTypes = {
|
|
1975
2023
|
}
|
1976
2024
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1977
2025
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1978
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2026
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1979
2027
|
const document = await documentManager2.findOne(id, model, {
|
1980
2028
|
populate,
|
1981
2029
|
locale,
|
@@ -2006,7 +2054,7 @@ const collectionTypes = {
|
|
2006
2054
|
}
|
2007
2055
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2008
2056
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2009
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2057
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2010
2058
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2011
2059
|
populate,
|
2012
2060
|
locale
|
@@ -2033,7 +2081,7 @@ const collectionTypes = {
|
|
2033
2081
|
}
|
2034
2082
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2035
2083
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2036
|
-
const { locale, status
|
2084
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2037
2085
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2038
2086
|
if (!entity) {
|
2039
2087
|
return ctx.notFound();
|
@@ -2256,20 +2304,13 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2256
2304
|
userAbility,
|
2257
2305
|
model: model.uid
|
2258
2306
|
});
|
2259
|
-
|
2307
|
+
const isMainFieldListable = isListable(model, mainField);
|
2308
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2309
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2260
2310
|
return "id";
|
2261
2311
|
}
|
2262
|
-
if (
|
2263
|
-
|
2264
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2265
|
-
userAbility,
|
2266
|
-
model: "plugin::users-permissions.user"
|
2267
|
-
});
|
2268
|
-
if (userPermissionChecker.can.read()) {
|
2269
|
-
return "name";
|
2270
|
-
}
|
2271
|
-
}
|
2272
|
-
return "id";
|
2312
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2313
|
+
return "name";
|
2273
2314
|
}
|
2274
2315
|
return mainField;
|
2275
2316
|
};
|
@@ -2527,9 +2568,7 @@ const relations = {
|
|
2527
2568
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2528
2569
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2529
2570
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2530
|
-
ordering: "desc"
|
2531
|
-
page: ctx.request.query.page,
|
2532
|
-
pageSize: ctx.request.query.pageSize
|
2571
|
+
ordering: "desc"
|
2533
2572
|
});
|
2534
2573
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2535
2574
|
ctx.body = {
|
@@ -2561,7 +2600,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2561
2600
|
throw new errors.ForbiddenError();
|
2562
2601
|
}
|
2563
2602
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2564
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2603
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2565
2604
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2566
2605
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2567
2606
|
// Find the first document to check if it exists
|
@@ -2602,7 +2641,7 @@ const singleTypes = {
|
|
2602
2641
|
return ctx.forbidden();
|
2603
2642
|
}
|
2604
2643
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2605
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2644
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2606
2645
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2607
2646
|
if (!version) {
|
2608
2647
|
if (permissionChecker2.cannot.create()) {
|
@@ -2647,7 +2686,7 @@ const singleTypes = {
|
|
2647
2686
|
}
|
2648
2687
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2649
2688
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2650
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2689
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2651
2690
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2652
2691
|
populate,
|
2653
2692
|
locale
|
@@ -2684,7 +2723,7 @@ const singleTypes = {
|
|
2684
2723
|
if (permissionChecker2.cannot.publish(document)) {
|
2685
2724
|
throw new errors.ForbiddenError();
|
2686
2725
|
}
|
2687
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2726
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2688
2727
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2689
2728
|
return publishResult.at(0);
|
2690
2729
|
});
|
@@ -2707,7 +2746,7 @@ const singleTypes = {
|
|
2707
2746
|
return ctx.forbidden();
|
2708
2747
|
}
|
2709
2748
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2710
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2749
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2711
2750
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2712
2751
|
if (!document) {
|
2713
2752
|
return ctx.notFound();
|
@@ -2739,7 +2778,7 @@ const singleTypes = {
|
|
2739
2778
|
return ctx.forbidden();
|
2740
2779
|
}
|
2741
2780
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2742
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2781
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2743
2782
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2744
2783
|
if (!document) {
|
2745
2784
|
return ctx.notFound();
|
@@ -2759,7 +2798,7 @@ const singleTypes = {
|
|
2759
2798
|
const { query } = ctx.request;
|
2760
2799
|
const documentManager2 = getService$1("document-manager");
|
2761
2800
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2762
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2801
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2763
2802
|
if (permissionChecker2.cannot.read()) {
|
2764
2803
|
return ctx.forbidden();
|
2765
2804
|
}
|
@@ -2780,7 +2819,7 @@ const uid$1 = {
|
|
2780
2819
|
async generateUID(ctx) {
|
2781
2820
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2782
2821
|
const { query = {} } = ctx.request;
|
2783
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2822
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2784
2823
|
await validateUIDField(contentTypeUID, field);
|
2785
2824
|
const uidService = getService$1("uid");
|
2786
2825
|
ctx.body = {
|
@@ -2792,7 +2831,7 @@ const uid$1 = {
|
|
2792
2831
|
ctx.request.body
|
2793
2832
|
);
|
2794
2833
|
const { query = {} } = ctx.request;
|
2795
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2834
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2796
2835
|
await validateUIDField(contentTypeUID, field);
|
2797
2836
|
const uidService = getService$1("uid");
|
2798
2837
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3435,12 +3474,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3435
3474
|
ability: userAbility,
|
3436
3475
|
model
|
3437
3476
|
});
|
3438
|
-
const
|
3477
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3478
|
+
const toSubject = (entity) => {
|
3479
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3480
|
+
};
|
3439
3481
|
const can = (action, entity, field) => {
|
3440
|
-
|
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
|
+
);
|
3441
3489
|
};
|
3442
3490
|
const cannot = (action, entity, field) => {
|
3443
|
-
|
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
|
+
);
|
3444
3498
|
};
|
3445
3499
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3446
3500
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3717,6 +3771,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3717
3771
|
const attribute = model.attributes[attributeName];
|
3718
3772
|
switch (attribute.type) {
|
3719
3773
|
case "relation": {
|
3774
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3775
|
+
if (isMorphRelation) {
|
3776
|
+
break;
|
3777
|
+
}
|
3720
3778
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3721
3779
|
populateAcc[attributeName] = {
|
3722
3780
|
count: true,
|
@@ -4094,7 +4152,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4094
4152
|
*/
|
4095
4153
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4096
4154
|
if (!document) {
|
4097
|
-
return
|
4155
|
+
return {
|
4156
|
+
data: document,
|
4157
|
+
meta: {
|
4158
|
+
availableLocales: [],
|
4159
|
+
availableStatus: []
|
4160
|
+
}
|
4161
|
+
};
|
4098
4162
|
}
|
4099
4163
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4100
4164
|
if (!hasDraftAndPublish) {
|
@@ -4202,10 +4266,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4202
4266
|
async clone(id, body, uid2) {
|
4203
4267
|
const populate = await buildDeepPopulate(uid2);
|
4204
4268
|
const params = {
|
4205
|
-
data:
|
4206
|
-
...omitIdField(body),
|
4207
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4208
|
-
},
|
4269
|
+
data: omitIdField(body),
|
4209
4270
|
populate
|
4210
4271
|
};
|
4211
4272
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|