@strapi/content-manager 0.0.0-experimental.dd3311938ac827f1fa8560c8840a9a394f5896c0 → 0.0.0-experimental.de2b94258659463e5ddc5992e9a9490d66d950dd
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-CQDCxI8x.js} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-y_7iLdmB.js.map → ComponentConfigurationPage-CQDCxI8x.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs → ComponentConfigurationPage-jmWwucg_.mjs} +3 -3
- package/dist/_chunks/{ComponentConfigurationPage-BMajAl1u.mjs.map → ComponentConfigurationPage-jmWwucg_.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js → EditConfigurationPage-Ce4bIm4n.js} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CPVB8Uqc.js.map → EditConfigurationPage-Ce4bIm4n.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs → EditConfigurationPage-W07CEdm2.mjs} +3 -3
- package/dist/_chunks/{EditConfigurationPage-CcOoD26O.mjs.map → EditConfigurationPage-W07CEdm2.mjs.map} +1 -1
- package/dist/_chunks/{EditViewPage-CTTDHKkQ.js → EditViewPage-CqHMM0P0.js} +68 -47
- package/dist/_chunks/EditViewPage-CqHMM0P0.js.map +1 -0
- package/dist/_chunks/{EditViewPage-DWb0DE7R.mjs → EditViewPage-al5OO1NR.mjs} +69 -48
- package/dist/_chunks/EditViewPage-al5OO1NR.mjs.map +1 -0
- package/dist/_chunks/{Field-C5Z1Ivdv.js → Field-DSOUlTCm.js} +581 -229
- package/dist/_chunks/Field-DSOUlTCm.js.map +1 -0
- package/dist/_chunks/{Field-DnStdvQw.mjs → Field-EeG6NQ7x.mjs} +579 -227
- package/dist/_chunks/Field-EeG6NQ7x.mjs.map +1 -0
- package/dist/_chunks/{Form-DqGgE55Q.mjs → Form-BAo9ANb_.mjs} +54 -36
- package/dist/_chunks/Form-BAo9ANb_.mjs.map +1 -0
- package/dist/_chunks/{Form-B81OtW-k.js → Form-DAEfHKzm.js} +52 -34
- package/dist/_chunks/Form-DAEfHKzm.js.map +1 -0
- package/dist/_chunks/{History-DS6-HCYX.mjs → History-BpLIu67W.mjs} +69 -33
- package/dist/_chunks/History-BpLIu67W.mjs.map +1 -0
- package/dist/_chunks/{History-4NbOq2dX.js → History-CTFvy6XH.js} +68 -32
- package/dist/_chunks/History-CTFvy6XH.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CpfstlYY.js → ListConfigurationPage-CDzlMBz_.js} +57 -46
- package/dist/_chunks/ListConfigurationPage-CDzlMBz_.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DQJJltko.mjs → ListConfigurationPage-DOqj5f8Y.mjs} +58 -48
- package/dist/_chunks/ListConfigurationPage-DOqj5f8Y.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-nQrOQuVo.mjs → ListViewPage-BbXYNI0v.mjs} +103 -102
- package/dist/_chunks/ListViewPage-BbXYNI0v.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-CA3I75m5.js → ListViewPage-D0fpPYKp.js} +105 -104
- package/dist/_chunks/ListViewPage-D0fpPYKp.js.map +1 -0
- package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js → NoContentTypePage-DTzkSAV5.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-Dldu-_Mx.js.map → NoContentTypePage-DTzkSAV5.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs → NoContentTypePage-w2Q0VVOT.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DbnHE22g.mjs.map → NoContentTypePage-w2Q0VVOT.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-CO2MK200.js → NoPermissionsPage-BoI2rU68.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-CO2MK200.js.map → NoPermissionsPage-BoI2rU68.js.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs → NoPermissionsPage-Km0Vk5Wp.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-fOIkQM0v.mjs.map → NoPermissionsPage-Km0Vk5Wp.mjs.map} +1 -1
- package/dist/_chunks/{Relations-BDRl99Ux.mjs → Relations-C_bpmSuQ.mjs} +51 -29
- package/dist/_chunks/Relations-C_bpmSuQ.mjs.map +1 -0
- package/dist/_chunks/{Relations-DG2jnOcr.js → Relations-D6Nz5ksc.js} +51 -29
- package/dist/_chunks/Relations-D6Nz5ksc.js.map +1 -0
- package/dist/_chunks/{en-fbKQxLGn.js → en-Bm0D0IWz.js} +17 -15
- package/dist/_chunks/{en-fbKQxLGn.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-Ux26r5pl.mjs → en-DKV44jRb.mjs} +17 -15
- package/dist/_chunks/{en-Ux26r5pl.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-BZoNZMXL.js → index-BsMu2oVP.js} +1032 -865
- package/dist/_chunks/index-BsMu2oVP.js.map +1 -0
- package/dist/_chunks/{index-Drt2DN7v.mjs → index-DcQ6xogO.mjs} +1041 -875
- package/dist/_chunks/index-DcQ6xogO.mjs.map +1 -0
- package/dist/_chunks/{layout-DEYBqgF1.js → layout-B4aCAdTt.js} +25 -12
- package/dist/_chunks/layout-B4aCAdTt.js.map +1 -0
- package/dist/_chunks/{layout-BzAbmoO6.mjs → layout-BavJ6v4B.mjs} +27 -14
- package/dist/_chunks/layout-BavJ6v4B.mjs.map +1 -0
- package/dist/_chunks/{relations-D26zVRdi.mjs → relations-DMG453Od.mjs} +2 -2
- package/dist/_chunks/{relations-D26zVRdi.mjs.map → relations-DMG453Od.mjs.map} +1 -1
- package/dist/_chunks/{relations-D0eZ4VWw.js → relations-Lrm9nz_m.js} +2 -2
- package/dist/_chunks/{relations-D0eZ4VWw.js.map → relations-Lrm9nz_m.js.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 +3 -2
- package/dist/admin/src/exports.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/hooks/useDocument.d.ts +32 -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 +6 -58
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- 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 +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 +248 -137
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +249 -138
- 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/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts +4 -2
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +2 -1
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- 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 +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/permission-checker.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/services/utils/populate.d.ts.map +1 -1
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.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-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/_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,20 +202,25 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
200
202
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
201
203
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
202
204
|
};
|
203
|
-
const getDeepPopulate2 = (uid2) => {
|
205
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
204
206
|
const model = strapi2.getModel(uid2);
|
205
207
|
const attributes = Object.entries(model.attributes);
|
208
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
206
209
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
207
210
|
switch (attribute.type) {
|
208
211
|
case "relation": {
|
212
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
213
|
+
if (isMorphRelation) {
|
214
|
+
break;
|
215
|
+
}
|
209
216
|
const isVisible2 = contentTypes$1.isVisibleAttribute(model, attributeName);
|
210
217
|
if (isVisible2) {
|
211
|
-
acc[attributeName] = {
|
218
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
212
219
|
}
|
213
220
|
break;
|
214
221
|
}
|
215
222
|
case "media": {
|
216
|
-
acc[attributeName] = {
|
223
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
217
224
|
break;
|
218
225
|
}
|
219
226
|
case "component": {
|
@@ -286,6 +293,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
286
293
|
getRelationRestoreValue,
|
287
294
|
getMediaRestoreValue,
|
288
295
|
getDefaultLocale,
|
296
|
+
isLocalizedContentType,
|
289
297
|
getLocaleDictionary,
|
290
298
|
getRetentionDays,
|
291
299
|
getVersionStatus,
|
@@ -308,7 +316,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
308
316
|
});
|
309
317
|
},
|
310
318
|
async findVersionsPage(params) {
|
311
|
-
const
|
319
|
+
const model = strapi2.getModel(params.query.contentType);
|
320
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
321
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
322
|
+
let locale = null;
|
323
|
+
if (isLocalizedContentType) {
|
324
|
+
locale = params.query.locale || defaultLocale;
|
325
|
+
}
|
312
326
|
const [{ results, pagination: pagination2 }, localeDictionary] = await Promise.all([
|
313
327
|
query.findPage({
|
314
328
|
...params.query,
|
@@ -353,7 +367,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
353
367
|
if (userToPopulate == null) {
|
354
368
|
return null;
|
355
369
|
}
|
356
|
-
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
|
+
});
|
357
376
|
})
|
358
377
|
);
|
359
378
|
return {
|
@@ -464,13 +483,47 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
464
483
|
}
|
465
484
|
};
|
466
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
|
+
};
|
467
522
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
468
523
|
const state = {
|
469
524
|
deleteExpiredJob: null,
|
470
525
|
isInitialized: false
|
471
526
|
};
|
472
|
-
const query = strapi2.db.query(HISTORY_VERSION_UID);
|
473
|
-
const historyService = getService(strapi2, "history");
|
474
527
|
const serviceUtils = createServiceUtils({ strapi: strapi2 });
|
475
528
|
return {
|
476
529
|
async bootstrap() {
|
@@ -478,63 +531,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
478
531
|
return;
|
479
532
|
}
|
480
533
|
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
534
|
const result = await next();
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
535
|
+
if (!shouldCreateHistoryVersion(context)) {
|
536
|
+
return result;
|
537
|
+
}
|
538
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
499
539
|
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();
|
540
|
+
const locales = castArray(context.params?.locale || defaultLocale);
|
541
|
+
if (!locales.length) {
|
542
|
+
return result;
|
506
543
|
}
|
507
|
-
const
|
508
|
-
|
509
|
-
|
510
|
-
|
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
|
+
)
|
511
559
|
});
|
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
560
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
528
|
-
onCommit(() => {
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
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
|
+
}
|
538
573
|
});
|
539
574
|
});
|
540
575
|
return result;
|
@@ -542,7 +577,7 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
542
577
|
state.deleteExpiredJob = scheduleJob("0 0 * * *", () => {
|
543
578
|
const retentionDaysInMilliseconds = serviceUtils.getRetentionDays() * 24 * 60 * 60 * 1e3;
|
544
579
|
const expirationDate = new Date(Date.now() - retentionDaysInMilliseconds);
|
545
|
-
query.deleteMany({
|
580
|
+
strapi2.db.query(HISTORY_VERSION_UID).deleteMany({
|
546
581
|
where: {
|
547
582
|
created_at: {
|
548
583
|
$lt: expirationDate.toISOString()
|
@@ -1174,6 +1209,11 @@ const { createPolicy } = policy;
|
|
1174
1209
|
const hasPermissions = createPolicy({
|
1175
1210
|
name: "plugin::content-manager.hasPermissions",
|
1176
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
|
+
*/
|
1177
1217
|
handler(ctx, config = {}) {
|
1178
1218
|
const { actions = [], hasAtLeastOne = false } = config;
|
1179
1219
|
const { userAbility } = ctx.state;
|
@@ -1567,9 +1607,11 @@ const multipleLocaleSchema = yup$1.lazy(
|
|
1567
1607
|
(value) => Array.isArray(value) ? yup$1.array().of(singleLocaleSchema.required()) : singleLocaleSchema
|
1568
1608
|
);
|
1569
1609
|
const statusSchema = yup$1.mixed().oneOf(["draft", "published"], "Invalid status");
|
1570
|
-
const getDocumentLocaleAndStatus = async (request, opts = { allowMultipleLocales: false }) => {
|
1610
|
+
const getDocumentLocaleAndStatus = async (request, model, opts = { allowMultipleLocales: false }) => {
|
1571
1611
|
const { allowMultipleLocales } = opts;
|
1572
|
-
const { locale, status, ...rest } = request || {};
|
1612
|
+
const { locale, status: providedStatus, ...rest } = request || {};
|
1613
|
+
const defaultStatus = contentTypes$1.hasDraftAndPublish(strapi.getModel(model)) ? void 0 : "published";
|
1614
|
+
const status = providedStatus !== void 0 ? providedStatus : defaultStatus;
|
1573
1615
|
const schema = yup$1.object().shape({
|
1574
1616
|
locale: allowMultipleLocales ? multipleLocaleSchema : singleLocaleSchema,
|
1575
1617
|
status: statusSchema
|
@@ -1617,7 +1659,7 @@ const createDocument = async (ctx, opts) => {
|
|
1617
1659
|
const setCreator = setCreatorFields({ user });
|
1618
1660
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1619
1661
|
const sanitizedBody = await sanitizeFn(body);
|
1620
|
-
const { locale, status
|
1662
|
+
const { locale, status } = await getDocumentLocaleAndStatus(body, model);
|
1621
1663
|
return documentManager2.create(model, {
|
1622
1664
|
data: sanitizedBody,
|
1623
1665
|
locale,
|
@@ -1636,7 +1678,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1636
1678
|
}
|
1637
1679
|
const permissionQuery = await permissionChecker2.sanitizedQuery.update(ctx.query);
|
1638
1680
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1639
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1681
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1640
1682
|
const [documentVersion, documentExists] = await Promise.all([
|
1641
1683
|
documentManager2.findOne(id, model, { populate, locale, status: "draft" }),
|
1642
1684
|
documentManager2.exists(model, id)
|
@@ -1652,7 +1694,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1652
1694
|
throw new errors.ForbiddenError();
|
1653
1695
|
}
|
1654
1696
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1655
|
-
const setCreator = setCreatorFields({ user, isEdition: true });
|
1697
|
+
const setCreator = documentVersion ? setCreatorFields({ user, isEdition: true }) : setCreatorFields({ user });
|
1656
1698
|
const sanitizeFn = async.pipe(pickPermittedFields, setCreator);
|
1657
1699
|
const sanitizedBody = await sanitizeFn(body);
|
1658
1700
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1674,7 +1716,7 @@ const collectionTypes = {
|
|
1674
1716
|
}
|
1675
1717
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
1676
1718
|
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);
|
1719
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
1678
1720
|
const { results: documents, pagination: pagination2 } = await documentManager2.findPage(
|
1679
1721
|
{ ...permissionQuery, populate, locale, status },
|
1680
1722
|
model
|
@@ -1709,7 +1751,7 @@ const collectionTypes = {
|
|
1709
1751
|
}
|
1710
1752
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
1711
1753
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1712
|
-
const { locale, status
|
1754
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1713
1755
|
const version = await documentManager2.findOne(id, model, {
|
1714
1756
|
populate,
|
1715
1757
|
locale,
|
@@ -1724,7 +1766,7 @@ const collectionTypes = {
|
|
1724
1766
|
permissionChecker2,
|
1725
1767
|
model,
|
1726
1768
|
// @ts-expect-error TODO: fix
|
1727
|
-
{ id, locale, publishedAt: null },
|
1769
|
+
{ documentId: id, locale, publishedAt: null },
|
1728
1770
|
{ availableLocales: true, availableStatus: false }
|
1729
1771
|
);
|
1730
1772
|
ctx.body = { data: {}, meta };
|
@@ -1776,7 +1818,7 @@ const collectionTypes = {
|
|
1776
1818
|
}
|
1777
1819
|
const permissionQuery = await permissionChecker2.sanitizedQuery.create(ctx.query);
|
1778
1820
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1779
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1821
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1780
1822
|
const document = await documentManager2.findOne(id, model, {
|
1781
1823
|
populate,
|
1782
1824
|
locale,
|
@@ -1821,7 +1863,7 @@ const collectionTypes = {
|
|
1821
1863
|
}
|
1822
1864
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(ctx.query);
|
1823
1865
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1824
|
-
const { locale } = await getDocumentLocaleAndStatus(ctx.query);
|
1866
|
+
const { locale } = await getDocumentLocaleAndStatus(ctx.query, model);
|
1825
1867
|
const documentLocales = await documentManager2.findLocales(id, model, { populate, locale });
|
1826
1868
|
if (documentLocales.length === 0) {
|
1827
1869
|
return ctx.notFound();
|
@@ -1850,11 +1892,34 @@ const collectionTypes = {
|
|
1850
1892
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1851
1893
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1852
1894
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1853
|
-
|
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
|
+
}
|
1854
1920
|
if (permissionChecker2.cannot.publish(document)) {
|
1855
1921
|
throw new errors.ForbiddenError();
|
1856
1922
|
}
|
1857
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
1858
1923
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1859
1924
|
locale
|
1860
1925
|
// TODO: Allow setting creator fields on publish
|
@@ -1881,7 +1946,9 @@ const collectionTypes = {
|
|
1881
1946
|
}
|
1882
1947
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1883
1948
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1884
|
-
const { locale } = await getDocumentLocaleAndStatus(body, {
|
1949
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1950
|
+
allowMultipleLocales: true
|
1951
|
+
});
|
1885
1952
|
const entityPromises = documentIds.map(
|
1886
1953
|
(documentId) => documentManager2.findLocales(documentId, model, { populate, locale, isPublished: false })
|
1887
1954
|
);
|
@@ -1908,7 +1975,9 @@ const collectionTypes = {
|
|
1908
1975
|
if (permissionChecker2.cannot.unpublish()) {
|
1909
1976
|
return ctx.forbidden();
|
1910
1977
|
}
|
1911
|
-
const { locale } = await getDocumentLocaleAndStatus(body
|
1978
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
1979
|
+
allowMultipleLocales: true
|
1980
|
+
});
|
1912
1981
|
const entityPromises = documentIds.map(
|
1913
1982
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1914
1983
|
);
|
@@ -1941,7 +2010,7 @@ const collectionTypes = {
|
|
1941
2010
|
}
|
1942
2011
|
const permissionQuery = await permissionChecker2.sanitizedQuery.unpublish(ctx.query);
|
1943
2012
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1944
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2013
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1945
2014
|
const document = await documentManager2.findOne(id, model, {
|
1946
2015
|
populate,
|
1947
2016
|
locale,
|
@@ -1978,7 +2047,7 @@ const collectionTypes = {
|
|
1978
2047
|
}
|
1979
2048
|
const permissionQuery = await permissionChecker2.sanitizedQuery.discard(ctx.query);
|
1980
2049
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
1981
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2050
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1982
2051
|
const document = await documentManager2.findOne(id, model, {
|
1983
2052
|
populate,
|
1984
2053
|
locale,
|
@@ -2009,7 +2078,7 @@ const collectionTypes = {
|
|
2009
2078
|
}
|
2010
2079
|
const permissionQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2011
2080
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2012
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2081
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2013
2082
|
const documentLocales = await documentManager2.findLocales(documentIds, model, {
|
2014
2083
|
populate,
|
2015
2084
|
locale
|
@@ -2036,7 +2105,7 @@ const collectionTypes = {
|
|
2036
2105
|
}
|
2037
2106
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(ctx.query);
|
2038
2107
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).build();
|
2039
|
-
const { locale, status
|
2108
|
+
const { locale, status } = await getDocumentLocaleAndStatus(ctx.query, model);
|
2040
2109
|
const entity = await documentManager2.findOne(id, model, { populate, locale, status });
|
2041
2110
|
if (!entity) {
|
2042
2111
|
return ctx.notFound();
|
@@ -2059,7 +2128,7 @@ const collectionTypes = {
|
|
2059
2128
|
if (permissionChecker2.cannot.read()) {
|
2060
2129
|
return ctx.forbidden();
|
2061
2130
|
}
|
2062
|
-
const
|
2131
|
+
const documents = await documentManager2.findMany(
|
2063
2132
|
{
|
2064
2133
|
filters: {
|
2065
2134
|
documentId: ids
|
@@ -2068,7 +2137,7 @@ const collectionTypes = {
|
|
2068
2137
|
},
|
2069
2138
|
model
|
2070
2139
|
);
|
2071
|
-
if (!
|
2140
|
+
if (!documents) {
|
2072
2141
|
return ctx.notFound();
|
2073
2142
|
}
|
2074
2143
|
const number = await documentManager2.countManyEntriesDraftRelations(ids, model, locale);
|
@@ -2259,32 +2328,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2259
2328
|
userAbility,
|
2260
2329
|
model: model.uid
|
2261
2330
|
});
|
2262
|
-
|
2331
|
+
const isMainFieldListable = isListable(model, mainField);
|
2332
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2333
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2263
2334
|
return "id";
|
2264
2335
|
}
|
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";
|
2336
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2337
|
+
return "name";
|
2276
2338
|
}
|
2277
2339
|
return mainField;
|
2278
2340
|
};
|
2279
|
-
const addStatusToRelations = async (
|
2280
|
-
if (!contentTypes$1.hasDraftAndPublish(strapi.
|
2341
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2342
|
+
if (!contentTypes$1.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2281
2343
|
return relations2;
|
2282
2344
|
}
|
2283
2345
|
const documentMetadata2 = getService$1("document-metadata");
|
2284
|
-
|
2346
|
+
if (!relations2.length) {
|
2347
|
+
return relations2;
|
2348
|
+
}
|
2349
|
+
const firstRelation = relations2[0];
|
2350
|
+
const filters = {
|
2351
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2352
|
+
// NOTE: find the "opposite" status
|
2353
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2354
|
+
};
|
2355
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2356
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2357
|
+
filters
|
2358
|
+
});
|
2285
2359
|
return relations2.map((relation) => {
|
2286
|
-
const availableStatuses =
|
2287
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2360
|
+
const availableStatuses = availableStatus.filter(
|
2361
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2288
2362
|
);
|
2289
2363
|
return {
|
2290
2364
|
...relation,
|
@@ -2305,11 +2379,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2305
2379
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2306
2380
|
const isSourceLocalized = isLocalized(sourceModel);
|
2307
2381
|
const isTargetLocalized = isLocalized(targetModel);
|
2308
|
-
let validatedLocale = locale;
|
2309
|
-
if (!targetModel || !isTargetLocalized)
|
2310
|
-
validatedLocale = void 0;
|
2311
2382
|
return {
|
2312
|
-
locale
|
2383
|
+
locale,
|
2313
2384
|
isSourceLocalized,
|
2314
2385
|
isTargetLocalized
|
2315
2386
|
};
|
@@ -2412,7 +2483,7 @@ const relations = {
|
|
2412
2483
|
attribute,
|
2413
2484
|
fieldsToSelect,
|
2414
2485
|
mainField,
|
2415
|
-
source: { schema: sourceSchema },
|
2486
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2416
2487
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2417
2488
|
sourceSchema,
|
2418
2489
|
targetSchema,
|
@@ -2434,7 +2505,8 @@ const relations = {
|
|
2434
2505
|
fieldsToSelect,
|
2435
2506
|
mainField,
|
2436
2507
|
source: {
|
2437
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2508
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2509
|
+
isLocalized: isSourceLocalized
|
2438
2510
|
},
|
2439
2511
|
target: {
|
2440
2512
|
schema: { uid: targetUid },
|
@@ -2472,12 +2544,16 @@ const relations = {
|
|
2472
2544
|
} else {
|
2473
2545
|
where.id = id;
|
2474
2546
|
}
|
2475
|
-
|
2476
|
-
|
2547
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2548
|
+
if (!isEmpty(publishedAt)) {
|
2549
|
+
where[`${alias}.published_at`] = publishedAt;
|
2477
2550
|
}
|
2478
|
-
if (
|
2551
|
+
if (isTargetLocalized && locale) {
|
2479
2552
|
where[`${alias}.locale`] = locale;
|
2480
2553
|
}
|
2554
|
+
if (isSourceLocalized && locale) {
|
2555
|
+
where.locale = locale;
|
2556
|
+
}
|
2481
2557
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2482
2558
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2483
2559
|
}
|
@@ -2495,7 +2571,8 @@ const relations = {
|
|
2495
2571
|
id: { $notIn: uniq(idsToOmit) }
|
2496
2572
|
});
|
2497
2573
|
}
|
2498
|
-
const
|
2574
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2575
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2499
2576
|
ctx.body = {
|
2500
2577
|
...res,
|
2501
2578
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2510,29 +2587,39 @@ const relations = {
|
|
2510
2587
|
attribute,
|
2511
2588
|
targetField,
|
2512
2589
|
fieldsToSelect,
|
2513
|
-
|
2514
|
-
|
2515
|
-
}
|
2516
|
-
target: {
|
2517
|
-
schema: { uid: targetUid }
|
2518
|
-
}
|
2590
|
+
status,
|
2591
|
+
source: { schema: sourceSchema },
|
2592
|
+
target: { schema: targetSchema }
|
2519
2593
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2594
|
+
const { uid: sourceUid } = sourceSchema;
|
2595
|
+
const { uid: targetUid } = targetSchema;
|
2520
2596
|
const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2521
2597
|
const dbQuery = strapi.db.query(sourceUid);
|
2522
2598
|
const loadRelations = relations$1.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2599
|
+
const filters = {};
|
2600
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2601
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2602
|
+
if (status === "published") {
|
2603
|
+
filters.publishedAt = { $notNull: true };
|
2604
|
+
} else {
|
2605
|
+
filters.publishedAt = { $null: true };
|
2606
|
+
}
|
2607
|
+
}
|
2608
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2609
|
+
filters.publishedAt = { $null: true };
|
2610
|
+
}
|
2523
2611
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2524
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2612
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2525
2613
|
ordering: "desc",
|
2526
2614
|
page: ctx.request.query.page,
|
2527
|
-
pageSize: ctx.request.query.pageSize
|
2615
|
+
pageSize: ctx.request.query.pageSize,
|
2616
|
+
filters
|
2528
2617
|
});
|
2529
2618
|
const loadedIds = res.results.map((item) => item.id);
|
2530
2619
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2531
2620
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2532
2621
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2533
|
-
ordering: "desc"
|
2534
|
-
page: ctx.request.query.page,
|
2535
|
-
pageSize: ctx.request.query.pageSize
|
2622
|
+
ordering: "desc"
|
2536
2623
|
});
|
2537
2624
|
const relationsUnion = uniqBy("id", concat(sanitizedRes.results, res.results));
|
2538
2625
|
ctx.body = {
|
@@ -2564,7 +2651,7 @@ const createOrUpdateDocument = async (ctx, opts) => {
|
|
2564
2651
|
throw new errors.ForbiddenError();
|
2565
2652
|
}
|
2566
2653
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.update(query);
|
2567
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2654
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2568
2655
|
const [documentVersion, otherDocumentVersion] = await Promise.all([
|
2569
2656
|
findDocument(sanitizedQuery, model, { locale, status: "draft" }),
|
2570
2657
|
// Find the first document to check if it exists
|
@@ -2605,7 +2692,7 @@ const singleTypes = {
|
|
2605
2692
|
return ctx.forbidden();
|
2606
2693
|
}
|
2607
2694
|
const permissionQuery = await permissionChecker2.sanitizedQuery.read(query);
|
2608
|
-
const { locale, status } = await getDocumentLocaleAndStatus(query);
|
2695
|
+
const { locale, status } = await getDocumentLocaleAndStatus(query, model);
|
2609
2696
|
const version = await findDocument(permissionQuery, model, { locale, status });
|
2610
2697
|
if (!version) {
|
2611
2698
|
if (permissionChecker2.cannot.create()) {
|
@@ -2619,7 +2706,7 @@ const singleTypes = {
|
|
2619
2706
|
permissionChecker2,
|
2620
2707
|
model,
|
2621
2708
|
// @ts-expect-error - fix types
|
2622
|
-
{
|
2709
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2623
2710
|
{ availableLocales: true, availableStatus: false }
|
2624
2711
|
);
|
2625
2712
|
ctx.body = { data: {}, meta };
|
@@ -2650,7 +2737,7 @@ const singleTypes = {
|
|
2650
2737
|
}
|
2651
2738
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.delete(query);
|
2652
2739
|
const populate = await buildPopulateFromQuery(sanitizedQuery, model);
|
2653
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2740
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2654
2741
|
const documentLocales = await documentManager2.findLocales(void 0, model, {
|
2655
2742
|
populate,
|
2656
2743
|
locale
|
@@ -2687,7 +2774,7 @@ const singleTypes = {
|
|
2687
2774
|
if (permissionChecker2.cannot.publish(document)) {
|
2688
2775
|
throw new errors.ForbiddenError();
|
2689
2776
|
}
|
2690
|
-
const { locale } = await getDocumentLocaleAndStatus(document);
|
2777
|
+
const { locale } = await getDocumentLocaleAndStatus(document, model);
|
2691
2778
|
const publishResult = await documentManager2.publish(document.documentId, model, { locale });
|
2692
2779
|
return publishResult.at(0);
|
2693
2780
|
});
|
@@ -2710,7 +2797,7 @@ const singleTypes = {
|
|
2710
2797
|
return ctx.forbidden();
|
2711
2798
|
}
|
2712
2799
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.unpublish(query);
|
2713
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2800
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2714
2801
|
const document = await findDocument(sanitizedQuery, model, { locale });
|
2715
2802
|
if (!document) {
|
2716
2803
|
return ctx.notFound();
|
@@ -2742,7 +2829,7 @@ const singleTypes = {
|
|
2742
2829
|
return ctx.forbidden();
|
2743
2830
|
}
|
2744
2831
|
const sanitizedQuery = await permissionChecker2.sanitizedQuery.discard(query);
|
2745
|
-
const { locale } = await getDocumentLocaleAndStatus(body);
|
2832
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
2746
2833
|
const document = await findDocument(sanitizedQuery, model, { locale, status: "published" });
|
2747
2834
|
if (!document) {
|
2748
2835
|
return ctx.notFound();
|
@@ -2762,7 +2849,7 @@ const singleTypes = {
|
|
2762
2849
|
const { query } = ctx.request;
|
2763
2850
|
const documentManager2 = getService$1("document-manager");
|
2764
2851
|
const permissionChecker2 = getService$1("permission-checker").create({ userAbility, model });
|
2765
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2852
|
+
const { locale } = await getDocumentLocaleAndStatus(query, model);
|
2766
2853
|
if (permissionChecker2.cannot.read()) {
|
2767
2854
|
return ctx.forbidden();
|
2768
2855
|
}
|
@@ -2783,7 +2870,7 @@ const uid$1 = {
|
|
2783
2870
|
async generateUID(ctx) {
|
2784
2871
|
const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
|
2785
2872
|
const { query = {} } = ctx.request;
|
2786
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2873
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2787
2874
|
await validateUIDField(contentTypeUID, field);
|
2788
2875
|
const uidService = getService$1("uid");
|
2789
2876
|
ctx.body = {
|
@@ -2795,7 +2882,7 @@ const uid$1 = {
|
|
2795
2882
|
ctx.request.body
|
2796
2883
|
);
|
2797
2884
|
const { query = {} } = ctx.request;
|
2798
|
-
const { locale } = await getDocumentLocaleAndStatus(query);
|
2885
|
+
const { locale } = await getDocumentLocaleAndStatus(query, contentTypeUID);
|
2799
2886
|
await validateUIDField(contentTypeUID, field);
|
2800
2887
|
const uidService = getService$1("uid");
|
2801
2888
|
const isAvailable = await uidService.checkUIDAvailability({
|
@@ -3438,12 +3525,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3438
3525
|
ability: userAbility,
|
3439
3526
|
model
|
3440
3527
|
});
|
3441
|
-
const
|
3528
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3529
|
+
const toSubject = (entity) => {
|
3530
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3531
|
+
};
|
3442
3532
|
const can = (action, entity, field) => {
|
3443
|
-
|
3533
|
+
const subject = toSubject(entity);
|
3534
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3535
|
+
return (
|
3536
|
+
// Test the original action to see if it passes
|
3537
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3538
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3539
|
+
);
|
3444
3540
|
};
|
3445
3541
|
const cannot = (action, entity, field) => {
|
3446
|
-
|
3542
|
+
const subject = toSubject(entity);
|
3543
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3544
|
+
return (
|
3545
|
+
// Test both the original action
|
3546
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3547
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3548
|
+
);
|
3447
3549
|
};
|
3448
3550
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3449
3551
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -3720,6 +3822,10 @@ const getDeepPopulateDraftCount = (uid2) => {
|
|
3720
3822
|
const attribute = model.attributes[attributeName];
|
3721
3823
|
switch (attribute.type) {
|
3722
3824
|
case "relation": {
|
3825
|
+
const isMorphRelation = attribute.relation.toLowerCase().startsWith("morph");
|
3826
|
+
if (isMorphRelation) {
|
3827
|
+
break;
|
3828
|
+
}
|
3723
3829
|
if (isVisibleAttribute$1(model, attributeName)) {
|
3724
3830
|
populateAcc[attributeName] = {
|
3725
3831
|
count: true,
|
@@ -3971,7 +4077,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
3971
4077
|
*/
|
3972
4078
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
3973
4079
|
const versionsByLocale = groupBy("locale", allVersions);
|
3974
|
-
|
4080
|
+
if (version.locale) {
|
4081
|
+
delete versionsByLocale[version.locale];
|
4082
|
+
}
|
3975
4083
|
const model = strapi2.getModel(uid2);
|
3976
4084
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
3977
4085
|
const traversalFunction = async (localeVersion) => traverseEntity(
|
@@ -4097,7 +4205,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4097
4205
|
*/
|
4098
4206
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4099
4207
|
if (!document) {
|
4100
|
-
return
|
4208
|
+
return {
|
4209
|
+
data: document,
|
4210
|
+
meta: {
|
4211
|
+
availableLocales: [],
|
4212
|
+
availableStatus: []
|
4213
|
+
}
|
4214
|
+
};
|
4101
4215
|
}
|
4102
4216
|
const hasDraftAndPublish = contentTypes$1.hasDraftAndPublish(strapi2.getModel(uid2));
|
4103
4217
|
if (!hasDraftAndPublish) {
|
@@ -4205,10 +4319,7 @@ const documentManager = ({ strapi: strapi2 }) => {
|
|
4205
4319
|
async clone(id, body, uid2) {
|
4206
4320
|
const populate = await buildDeepPopulate(uid2);
|
4207
4321
|
const params = {
|
4208
|
-
data:
|
4209
|
-
...omitIdField(body),
|
4210
|
-
[PUBLISHED_AT_ATTRIBUTE]: null
|
4211
|
-
},
|
4322
|
+
data: omitIdField(body),
|
4212
4323
|
populate
|
4213
4324
|
};
|
4214
4325
|
return strapi2.documents(uid2).clone({ ...params, documentId: id }).then((result) => result?.entries.at(0));
|