@strapi/content-manager 0.0.0-experimental.1bca8e0e074de8b0775bcddc7656fbc9e9f1393b → 0.0.0-experimental.1fc4b627b49f713b07ed9f7f2b37741dcf8cf736
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs → ComponentConfigurationPage-CIjXcRAB.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-BAgyHiMm.mjs.map → ComponentConfigurationPage-CIjXcRAB.mjs.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js → ComponentConfigurationPage-gsCd80MU.js} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-5ukroXAh.js.map → ComponentConfigurationPage-gsCd80MU.js.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs → EditConfigurationPage-BglmD_BF.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-DmoXawIh.mjs.map → EditConfigurationPage-BglmD_BF.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js → EditConfigurationPage-DHDQKBzw.js} +4 -4
- package/dist/_chunks/{EditConfigurationPage-Xp7lun0f.js.map → EditConfigurationPage-DHDQKBzw.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-C-ukDOB7.js → EditViewPage-C4iTxUPU.js} +30 -9
- package/dist/_chunks/EditViewPage-C4iTxUPU.js.map +1 -0
- package/dist/_chunks/{EditViewPage-BLsjc5F-.mjs → EditViewPage-CiwVPMaK.mjs} +30 -9
- package/dist/_chunks/EditViewPage-CiwVPMaK.mjs.map +1 -0
- package/dist/_chunks/{Field-Cs7duwWd.mjs → Field-DIjL1b5d.mjs} +173 -101
- package/dist/_chunks/Field-DIjL1b5d.mjs.map +1 -0
- package/dist/_chunks/{Field-Bfph5SOd.js → Field-DhXEK8y1.js} +175 -103
- package/dist/_chunks/Field-DhXEK8y1.js.map +1 -0
- package/dist/_chunks/{Form-Dg_GS5TQ.mjs → Form-CmNesrvR.mjs} +36 -17
- package/dist/_chunks/Form-CmNesrvR.mjs.map +1 -0
- package/dist/_chunks/{Form-CPYqIWDG.js → Form-CwmJ4sWe.js} +36 -17
- package/dist/_chunks/Form-CwmJ4sWe.js.map +1 -0
- package/dist/_chunks/{History-DNQkXANT.js → History-BLCCNgCt.js} +24 -11
- package/dist/_chunks/History-BLCCNgCt.js.map +1 -0
- package/dist/_chunks/{History-wrnHqf09.mjs → History-D-99Wh30.mjs} +25 -12
- package/dist/_chunks/History-D-99Wh30.mjs.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-CUQxfpjT.js → ListConfigurationPage-DxWpeZrO.js} +15 -5
- package/dist/_chunks/ListConfigurationPage-DxWpeZrO.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-DScmJVkW.mjs → ListConfigurationPage-JPWZz7Kg.mjs} +15 -5
- package/dist/_chunks/ListConfigurationPage-JPWZz7Kg.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-BsLiH2-2.js → ListViewPage-CIQekSFz.js} +61 -41
- package/dist/_chunks/ListViewPage-CIQekSFz.js.map +1 -0
- package/dist/_chunks/{ListViewPage-C4IvrMgY.mjs → ListViewPage-DSK3f0ST.mjs} +59 -39
- package/dist/_chunks/ListViewPage-DSK3f0ST.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js → NoContentTypePage-C5cxKvC2.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-BZ-PnGAf.js.map → NoContentTypePage-C5cxKvC2.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs → NoContentTypePage-D99LU1YP.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-Djg8nPlj.mjs.map → NoContentTypePage-D99LU1YP.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs → NoPermissionsPage-DBrBw-0y.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DSP7R-hv.mjs.map → NoPermissionsPage-DBrBw-0y.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js → NoPermissionsPage-Oy4tmUrW.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-_lUqjGW3.js.map → NoPermissionsPage-Oy4tmUrW.js.map} +1 -1
- package/dist/_chunks/{Relations-BZr8tL0R.mjs → Relations-BBmhcWFV.mjs} +70 -37
- package/dist/_chunks/Relations-BBmhcWFV.mjs.map +1 -0
- package/dist/_chunks/{Relations-CtELXYIK.js → Relations-eG-9p_qS.js} +69 -36
- package/dist/_chunks/Relations-eG-9p_qS.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-Bm0D0IWz.js} +13 -12
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-Bm0D0IWz.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-DKV44jRb.mjs} +13 -12
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-DKV44jRb.mjs.map} +1 -1
- package/dist/_chunks/{index-OerGjbAN.js → index-BIWDoFLK.js} +1968 -1781
- package/dist/_chunks/index-BIWDoFLK.js.map +1 -0
- package/dist/_chunks/{index-c_5DdJi-.mjs → index-BrUzbQ30.mjs} +1987 -1801
- package/dist/_chunks/index-BrUzbQ30.mjs.map +1 -0
- package/dist/_chunks/{layout-oPBiO7RY.mjs → layout-_5-cXs34.mjs} +22 -9
- package/dist/_chunks/layout-_5-cXs34.mjs.map +1 -0
- package/dist/_chunks/{layout-Ci7qHlFb.js → layout-lMc9i1-Z.js} +21 -8
- package/dist/_chunks/layout-lMc9i1-Z.js.map +1 -0
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-COBpStiF.js → relations-BRHithi8.js} +3 -7
- package/dist/_chunks/relations-BRHithi8.js.map +1 -0
- package/dist/_chunks/{relations-BIdWFjdq.mjs → relations-B_VLk-DD.mjs} +3 -7
- package/dist/_chunks/relations-B_VLk-DD.mjs.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +5 -4
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/history/services/historyVersion.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/EditorLayout.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygFooter.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +4 -48
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/preview/constants.d.ts +1 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- 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 +284 -120
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +285 -121
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.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/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/preview/constants.d.ts +2 -0
- package/dist/server/src/preview/constants.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +9 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +4 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +6 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +7 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/routes/index.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/index.d.ts.map +1 -1
- 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/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-BLsjc5F-.mjs.map +0 -1
- package/dist/_chunks/EditViewPage-C-ukDOB7.js.map +0 -1
- package/dist/_chunks/Field-Bfph5SOd.js.map +0 -1
- package/dist/_chunks/Field-Cs7duwWd.mjs.map +0 -1
- package/dist/_chunks/Form-CPYqIWDG.js.map +0 -1
- package/dist/_chunks/Form-Dg_GS5TQ.mjs.map +0 -1
- package/dist/_chunks/History-DNQkXANT.js.map +0 -1
- package/dist/_chunks/History-wrnHqf09.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-CUQxfpjT.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-DScmJVkW.mjs.map +0 -1
- package/dist/_chunks/ListViewPage-BsLiH2-2.js.map +0 -1
- package/dist/_chunks/ListViewPage-C4IvrMgY.mjs.map +0 -1
- package/dist/_chunks/Relations-BZr8tL0R.mjs.map +0 -1
- package/dist/_chunks/Relations-CtELXYIK.js.map +0 -1
- package/dist/_chunks/index-OerGjbAN.js.map +0 -1
- package/dist/_chunks/index-c_5DdJi-.mjs.map +0 -1
- package/dist/_chunks/layout-Ci7qHlFb.js.map +0 -1
- package/dist/_chunks/layout-oPBiO7RY.mjs.map +0 -1
- package/dist/_chunks/relations-BIdWFjdq.mjs.map +0 -1
- package/dist/_chunks/relations-COBpStiF.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.js
CHANGED
@@ -121,7 +121,7 @@ const createHistoryVersionController = ({ strapi: strapi2 }) => {
|
|
121
121
|
}
|
122
122
|
};
|
123
123
|
};
|
124
|
-
const controllers$
|
124
|
+
const controllers$2 = {
|
125
125
|
"history-version": createHistoryVersionController
|
126
126
|
/**
|
127
127
|
* Casting is needed because the types aren't aware that Strapi supports
|
@@ -199,7 +199,9 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
199
199
|
return strapi2.db.query("plugin::upload.file").findOne({ where: { id: versionRelationData.id } });
|
200
200
|
};
|
201
201
|
const localesService = strapi2.plugin("i18n")?.service("locales");
|
202
|
+
const i18nContentTypeService = strapi2.plugin("i18n")?.service("content-types");
|
202
203
|
const getDefaultLocale = async () => localesService ? localesService.getDefaultLocale() : null;
|
204
|
+
const isLocalizedContentType = (model) => i18nContentTypeService ? i18nContentTypeService.isLocalizedContentType(model) : false;
|
203
205
|
const getLocaleDictionary = async () => {
|
204
206
|
if (!localesService)
|
205
207
|
return {};
|
@@ -226,9 +228,10 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
226
228
|
const meta = await documentMetadataService.getMetadata(contentTypeUid, document);
|
227
229
|
return documentMetadataService.getStatus(document, meta.availableStatus);
|
228
230
|
};
|
229
|
-
const getDeepPopulate2 = (uid2) => {
|
231
|
+
const getDeepPopulate2 = (uid2, useDatabaseSyntax = false) => {
|
230
232
|
const model = strapi2.getModel(uid2);
|
231
233
|
const attributes = Object.entries(model.attributes);
|
234
|
+
const fieldSelector = useDatabaseSyntax ? "select" : "fields";
|
232
235
|
return attributes.reduce((acc, [attributeName, attribute]) => {
|
233
236
|
switch (attribute.type) {
|
234
237
|
case "relation": {
|
@@ -238,12 +241,12 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
238
241
|
}
|
239
242
|
const isVisible2 = strapiUtils.contentTypes.isVisibleAttribute(model, attributeName);
|
240
243
|
if (isVisible2) {
|
241
|
-
acc[attributeName] = {
|
244
|
+
acc[attributeName] = { [fieldSelector]: ["documentId", "locale", "publishedAt"] };
|
242
245
|
}
|
243
246
|
break;
|
244
247
|
}
|
245
248
|
case "media": {
|
246
|
-
acc[attributeName] = {
|
249
|
+
acc[attributeName] = { [fieldSelector]: ["id"] };
|
247
250
|
break;
|
248
251
|
}
|
249
252
|
case "component": {
|
@@ -316,6 +319,7 @@ const createServiceUtils = ({ strapi: strapi2 }) => {
|
|
316
319
|
getRelationRestoreValue,
|
317
320
|
getMediaRestoreValue,
|
318
321
|
getDefaultLocale,
|
322
|
+
isLocalizedContentType,
|
319
323
|
getLocaleDictionary,
|
320
324
|
getRetentionDays,
|
321
325
|
getVersionStatus,
|
@@ -338,7 +342,13 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
338
342
|
});
|
339
343
|
},
|
340
344
|
async findVersionsPage(params) {
|
341
|
-
const
|
345
|
+
const model = strapi2.getModel(params.query.contentType);
|
346
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
347
|
+
const defaultLocale = await serviceUtils.getDefaultLocale();
|
348
|
+
let locale = null;
|
349
|
+
if (isLocalizedContentType) {
|
350
|
+
locale = params.query.locale || defaultLocale;
|
351
|
+
}
|
342
352
|
const [{ results, pagination }, localeDictionary] = await Promise.all([
|
343
353
|
query.findPage({
|
344
354
|
...params.query,
|
@@ -383,7 +393,12 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
383
393
|
if (userToPopulate == null) {
|
384
394
|
return null;
|
385
395
|
}
|
386
|
-
return strapi2.query("admin::user").findOne({
|
396
|
+
return strapi2.query("admin::user").findOne({
|
397
|
+
where: {
|
398
|
+
...userToPopulate.id ? { id: userToPopulate.id } : {},
|
399
|
+
...userToPopulate.documentId ? { documentId: userToPopulate.documentId } : {}
|
400
|
+
}
|
401
|
+
});
|
387
402
|
})
|
388
403
|
);
|
389
404
|
return {
|
@@ -494,6 +509,42 @@ const createHistoryService = ({ strapi: strapi2 }) => {
|
|
494
509
|
}
|
495
510
|
};
|
496
511
|
};
|
512
|
+
const shouldCreateHistoryVersion = (context) => {
|
513
|
+
if (!strapi.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
514
|
+
return false;
|
515
|
+
}
|
516
|
+
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
517
|
+
return false;
|
518
|
+
}
|
519
|
+
if (context.action === "update" && strapi.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
520
|
+
return false;
|
521
|
+
}
|
522
|
+
if (!context.contentType.uid.startsWith("api::")) {
|
523
|
+
return false;
|
524
|
+
}
|
525
|
+
return true;
|
526
|
+
};
|
527
|
+
const getSchemas = (uid2) => {
|
528
|
+
const attributesSchema = strapi.getModel(uid2).attributes;
|
529
|
+
const componentsSchemas = Object.keys(attributesSchema).reduce(
|
530
|
+
(currentComponentSchemas, key) => {
|
531
|
+
const fieldSchema = attributesSchema[key];
|
532
|
+
if (fieldSchema.type === "component") {
|
533
|
+
const componentSchema = strapi.getModel(fieldSchema.component).attributes;
|
534
|
+
return {
|
535
|
+
...currentComponentSchemas,
|
536
|
+
[fieldSchema.component]: componentSchema
|
537
|
+
};
|
538
|
+
}
|
539
|
+
return currentComponentSchemas;
|
540
|
+
},
|
541
|
+
{}
|
542
|
+
);
|
543
|
+
return {
|
544
|
+
schema: fp.omit(FIELDS_TO_IGNORE, attributesSchema),
|
545
|
+
componentsSchemas
|
546
|
+
};
|
547
|
+
};
|
497
548
|
const createLifecyclesService = ({ strapi: strapi2 }) => {
|
498
549
|
const state = {
|
499
550
|
deleteExpiredJob: null,
|
@@ -506,63 +557,45 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
506
557
|
return;
|
507
558
|
}
|
508
559
|
strapi2.documents.use(async (context, next) => {
|
509
|
-
if (!strapi2.requestContext.get()?.request.url.startsWith("/content-manager")) {
|
510
|
-
return next();
|
511
|
-
}
|
512
|
-
if (context.action !== "create" && context.action !== "update" && context.action !== "clone" && context.action !== "publish" && context.action !== "unpublish" && context.action !== "discardDraft") {
|
513
|
-
return next();
|
514
|
-
}
|
515
|
-
if (context.action === "update" && strapi2.requestContext.get()?.request.url.endsWith("/actions/publish")) {
|
516
|
-
return next();
|
517
|
-
}
|
518
|
-
const contentTypeUid = context.contentType.uid;
|
519
|
-
if (!contentTypeUid.startsWith("api::")) {
|
520
|
-
return next();
|
521
|
-
}
|
522
560
|
const result = await next();
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
561
|
+
if (!shouldCreateHistoryVersion(context)) {
|
562
|
+
return result;
|
563
|
+
}
|
564
|
+
const documentId = context.action === "create" || context.action === "clone" ? result.documentId : context.params.documentId;
|
527
565
|
const defaultLocale = await serviceUtils.getDefaultLocale();
|
528
|
-
const
|
529
|
-
if (
|
530
|
-
|
531
|
-
"[Content manager history middleware]: An array of locales was provided, but only a single locale is supported for the findOne operation."
|
532
|
-
);
|
533
|
-
return next();
|
566
|
+
const locales = fp.castArray(context.params?.locale || defaultLocale);
|
567
|
+
if (!locales.length) {
|
568
|
+
return result;
|
534
569
|
}
|
535
|
-
const
|
536
|
-
|
537
|
-
|
538
|
-
|
570
|
+
const uid2 = context.contentType.uid;
|
571
|
+
const schemas = getSchemas(uid2);
|
572
|
+
const model = strapi2.getModel(uid2);
|
573
|
+
const isLocalizedContentType = serviceUtils.isLocalizedContentType(model);
|
574
|
+
const localeEntries = await strapi2.db.query(uid2).findMany({
|
575
|
+
where: {
|
576
|
+
documentId,
|
577
|
+
...isLocalizedContentType ? { locale: { $in: locales } } : {},
|
578
|
+
...strapiUtils.contentTypes.hasDraftAndPublish(strapi2.contentTypes[uid2]) ? { publishedAt: null } : {}
|
579
|
+
},
|
580
|
+
populate: serviceUtils.getDeepPopulate(
|
581
|
+
uid2,
|
582
|
+
true
|
583
|
+
/* use database syntax */
|
584
|
+
)
|
539
585
|
});
|
540
|
-
const status = await serviceUtils.getVersionStatus(contentTypeUid, document);
|
541
|
-
const attributesSchema = strapi2.getModel(contentTypeUid).attributes;
|
542
|
-
const componentsSchemas = Object.keys(
|
543
|
-
attributesSchema
|
544
|
-
).reduce((currentComponentSchemas, key) => {
|
545
|
-
const fieldSchema = attributesSchema[key];
|
546
|
-
if (fieldSchema.type === "component") {
|
547
|
-
const componentSchema = strapi2.getModel(fieldSchema.component).attributes;
|
548
|
-
return {
|
549
|
-
...currentComponentSchemas,
|
550
|
-
[fieldSchema.component]: componentSchema
|
551
|
-
};
|
552
|
-
}
|
553
|
-
return currentComponentSchemas;
|
554
|
-
}, {});
|
555
586
|
await strapi2.db.transaction(async ({ onCommit }) => {
|
556
|
-
onCommit(() => {
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
587
|
+
onCommit(async () => {
|
588
|
+
for (const entry of localeEntries) {
|
589
|
+
const status = await serviceUtils.getVersionStatus(uid2, entry);
|
590
|
+
await getService(strapi2, "history").createVersion({
|
591
|
+
contentType: uid2,
|
592
|
+
data: fp.omit(FIELDS_TO_IGNORE, entry),
|
593
|
+
relatedDocumentId: documentId,
|
594
|
+
locale: entry.locale,
|
595
|
+
status,
|
596
|
+
...schemas
|
597
|
+
});
|
598
|
+
}
|
566
599
|
});
|
567
600
|
});
|
568
601
|
return result;
|
@@ -587,17 +620,17 @@ const createLifecyclesService = ({ strapi: strapi2 }) => {
|
|
587
620
|
}
|
588
621
|
};
|
589
622
|
};
|
590
|
-
const services$
|
623
|
+
const services$2 = {
|
591
624
|
history: createHistoryService,
|
592
625
|
lifecycles: createLifecyclesService
|
593
626
|
};
|
594
|
-
const info = { pluginName: "content-manager", type: "admin" };
|
627
|
+
const info$1 = { pluginName: "content-manager", type: "admin" };
|
595
628
|
const historyVersionRouter = {
|
596
629
|
type: "admin",
|
597
630
|
routes: [
|
598
631
|
{
|
599
632
|
method: "GET",
|
600
|
-
info,
|
633
|
+
info: info$1,
|
601
634
|
path: "/history-versions",
|
602
635
|
handler: "history-version.findMany",
|
603
636
|
config: {
|
@@ -606,7 +639,7 @@ const historyVersionRouter = {
|
|
606
639
|
},
|
607
640
|
{
|
608
641
|
method: "PUT",
|
609
|
-
info,
|
642
|
+
info: info$1,
|
610
643
|
path: "/history-versions/:versionId/restore",
|
611
644
|
handler: "history-version.restoreVersion",
|
612
645
|
config: {
|
@@ -615,7 +648,7 @@ const historyVersionRouter = {
|
|
615
648
|
}
|
616
649
|
]
|
617
650
|
};
|
618
|
-
const routes$
|
651
|
+
const routes$2 = {
|
619
652
|
"history-version": historyVersionRouter
|
620
653
|
};
|
621
654
|
const historyVersion = {
|
@@ -662,7 +695,7 @@ const historyVersion = {
|
|
662
695
|
}
|
663
696
|
}
|
664
697
|
};
|
665
|
-
const getFeature = () => {
|
698
|
+
const getFeature$1 = () => {
|
666
699
|
if (strapi.ee.features.isEnabled("cms-content-history")) {
|
667
700
|
return {
|
668
701
|
register({ strapi: strapi2 }) {
|
@@ -674,9 +707,9 @@ const getFeature = () => {
|
|
674
707
|
destroy({ strapi: strapi2 }) {
|
675
708
|
getService(strapi2, "lifecycles").destroy();
|
676
709
|
},
|
677
|
-
controllers: controllers$
|
678
|
-
services: services$
|
679
|
-
routes: routes$
|
710
|
+
controllers: controllers$2,
|
711
|
+
services: services$2,
|
712
|
+
routes: routes$2
|
680
713
|
};
|
681
714
|
}
|
682
715
|
return {
|
@@ -685,7 +718,7 @@ const getFeature = () => {
|
|
685
718
|
}
|
686
719
|
};
|
687
720
|
};
|
688
|
-
const history = getFeature();
|
721
|
+
const history = getFeature$1();
|
689
722
|
const register = async ({ strapi: strapi2 }) => {
|
690
723
|
await history.register?.({ strapi: strapi2 });
|
691
724
|
};
|
@@ -693,6 +726,62 @@ const ALLOWED_WEBHOOK_EVENTS = {
|
|
693
726
|
ENTRY_PUBLISH: "entry.publish",
|
694
727
|
ENTRY_UNPUBLISH: "entry.unpublish"
|
695
728
|
};
|
729
|
+
const FEATURE_ID = "preview";
|
730
|
+
const info = { pluginName: "content-manager", type: "admin" };
|
731
|
+
const previewRouter = {
|
732
|
+
type: "admin",
|
733
|
+
routes: [
|
734
|
+
{
|
735
|
+
method: "GET",
|
736
|
+
info,
|
737
|
+
path: "/preview/url/:contentType",
|
738
|
+
handler: "preview.getPreviewURL",
|
739
|
+
config: {
|
740
|
+
policies: ["admin::isAuthenticatedAdmin"]
|
741
|
+
}
|
742
|
+
}
|
743
|
+
]
|
744
|
+
};
|
745
|
+
const routes$1 = {
|
746
|
+
preview: previewRouter
|
747
|
+
};
|
748
|
+
const createPreviewController = () => {
|
749
|
+
return {
|
750
|
+
async getPreviewURL(ctx) {
|
751
|
+
ctx.request;
|
752
|
+
return {
|
753
|
+
data: { url: "" }
|
754
|
+
};
|
755
|
+
}
|
756
|
+
};
|
757
|
+
};
|
758
|
+
const controllers$1 = {
|
759
|
+
preview: createPreviewController
|
760
|
+
/**
|
761
|
+
* Casting is needed because the types aren't aware that Strapi supports
|
762
|
+
* passing a controller factory as the value, instead of a controller object directly
|
763
|
+
*/
|
764
|
+
};
|
765
|
+
const createPreviewService = () => {
|
766
|
+
};
|
767
|
+
const services$1 = {
|
768
|
+
preview: createPreviewService
|
769
|
+
};
|
770
|
+
const getFeature = () => {
|
771
|
+
if (!strapi.features.future.isEnabled(FEATURE_ID)) {
|
772
|
+
return {};
|
773
|
+
}
|
774
|
+
return {
|
775
|
+
bootstrap() {
|
776
|
+
console.log("Bootstrapping preview server");
|
777
|
+
strapi.config.get("admin.preview");
|
778
|
+
},
|
779
|
+
routes: routes$1,
|
780
|
+
controllers: controllers$1,
|
781
|
+
services: services$1
|
782
|
+
};
|
783
|
+
};
|
784
|
+
const preview = getFeature();
|
696
785
|
const bootstrap = async () => {
|
697
786
|
Object.entries(ALLOWED_WEBHOOK_EVENTS).forEach(([key, value]) => {
|
698
787
|
strapi.get("webhookStore").addAllowedEvent(key, value);
|
@@ -702,6 +791,7 @@ const bootstrap = async () => {
|
|
702
791
|
await getService$1("content-types").syncConfigurations();
|
703
792
|
await getService$1("permission").registerPermissions();
|
704
793
|
await history.bootstrap?.({ strapi });
|
794
|
+
await preview.bootstrap?.({ strapi });
|
705
795
|
};
|
706
796
|
const destroy = async ({ strapi: strapi2 }) => {
|
707
797
|
await history.destroy?.({ strapi: strapi2 });
|
@@ -1191,7 +1281,8 @@ const admin = {
|
|
1191
1281
|
};
|
1192
1282
|
const routes = {
|
1193
1283
|
admin,
|
1194
|
-
...history.routes ? history.routes : {}
|
1284
|
+
...history.routes ? history.routes : {},
|
1285
|
+
...preview.routes ? preview.routes : {}
|
1195
1286
|
};
|
1196
1287
|
const hasPermissionsSchema = strapiUtils.yup.object({
|
1197
1288
|
actions: strapiUtils.yup.array().of(strapiUtils.yup.string()),
|
@@ -1202,6 +1293,11 @@ const { createPolicy } = strapiUtils.policy;
|
|
1202
1293
|
const hasPermissions = createPolicy({
|
1203
1294
|
name: "plugin::content-manager.hasPermissions",
|
1204
1295
|
validator: validateHasPermissionsInput,
|
1296
|
+
/**
|
1297
|
+
* NOTE: Action aliases are currently not checked at this level (policy).
|
1298
|
+
* This is currently the intended behavior to avoid changing the behavior of API related permissions.
|
1299
|
+
* If you want to add support for it, please create a dedicated RFC with a list of potential side effect this could have.
|
1300
|
+
*/
|
1205
1301
|
handler(ctx, config = {}) {
|
1206
1302
|
const { actions = [], hasAtLeastOne = false } = config;
|
1207
1303
|
const { userAbility } = ctx.state;
|
@@ -1682,7 +1778,7 @@ const updateDocument = async (ctx, opts) => {
|
|
1682
1778
|
throw new strapiUtils.errors.ForbiddenError();
|
1683
1779
|
}
|
1684
1780
|
const pickPermittedFields = documentVersion ? permissionChecker2.sanitizeUpdateInput(documentVersion) : permissionChecker2.sanitizeCreateInput;
|
1685
|
-
const setCreator = strapiUtils.setCreatorFields({ user, isEdition: true });
|
1781
|
+
const setCreator = documentVersion ? strapiUtils.setCreatorFields({ user, isEdition: true }) : strapiUtils.setCreatorFields({ user });
|
1686
1782
|
const sanitizeFn = strapiUtils.async.pipe(pickPermittedFields, setCreator);
|
1687
1783
|
const sanitizedBody = await sanitizeFn(body);
|
1688
1784
|
return documentManager2.update(documentVersion?.documentId || id, model, {
|
@@ -1754,7 +1850,7 @@ const collectionTypes = {
|
|
1754
1850
|
permissionChecker2,
|
1755
1851
|
model,
|
1756
1852
|
// @ts-expect-error TODO: fix
|
1757
|
-
{ id, locale, publishedAt: null },
|
1853
|
+
{ documentId: id, locale, publishedAt: null },
|
1758
1854
|
{ availableLocales: true, availableStatus: false }
|
1759
1855
|
);
|
1760
1856
|
ctx.body = { data: {}, meta };
|
@@ -1880,11 +1976,34 @@ const collectionTypes = {
|
|
1880
1976
|
const publishedDocument = await strapi.db.transaction(async () => {
|
1881
1977
|
const permissionQuery = await permissionChecker2.sanitizedQuery.publish(ctx.query);
|
1882
1978
|
const populate = await getService$1("populate-builder")(model).populateFromQuery(permissionQuery).populateDeep(Infinity).countRelations().build();
|
1883
|
-
|
1979
|
+
let document;
|
1980
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1981
|
+
const isCreate = fp.isNil(id);
|
1982
|
+
if (isCreate) {
|
1983
|
+
if (permissionChecker2.cannot.create()) {
|
1984
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1985
|
+
}
|
1986
|
+
document = await createDocument(ctx, { populate });
|
1987
|
+
}
|
1988
|
+
const isUpdate = !isCreate;
|
1989
|
+
if (isUpdate) {
|
1990
|
+
const documentExists = documentManager2.exists(model, id);
|
1991
|
+
if (!documentExists) {
|
1992
|
+
throw new strapiUtils.errors.NotFoundError("Document not found");
|
1993
|
+
}
|
1994
|
+
document = await documentManager2.findOne(id, model, { populate, locale });
|
1995
|
+
if (!document) {
|
1996
|
+
if (permissionChecker2.cannot.create({ locale }) || permissionChecker2.cannot.publish({ locale })) {
|
1997
|
+
throw new strapiUtils.errors.ForbiddenError();
|
1998
|
+
}
|
1999
|
+
document = await updateDocument(ctx);
|
2000
|
+
} else if (permissionChecker2.can.update(document)) {
|
2001
|
+
await updateDocument(ctx);
|
2002
|
+
}
|
2003
|
+
}
|
1884
2004
|
if (permissionChecker2.cannot.publish(document)) {
|
1885
2005
|
throw new strapiUtils.errors.ForbiddenError();
|
1886
2006
|
}
|
1887
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model);
|
1888
2007
|
const publishResult = await documentManager2.publish(document.documentId, model, {
|
1889
2008
|
locale
|
1890
2009
|
// TODO: Allow setting creator fields on publish
|
@@ -1940,7 +2059,9 @@ const collectionTypes = {
|
|
1940
2059
|
if (permissionChecker2.cannot.unpublish()) {
|
1941
2060
|
return ctx.forbidden();
|
1942
2061
|
}
|
1943
|
-
const { locale } = await getDocumentLocaleAndStatus(body, model
|
2062
|
+
const { locale } = await getDocumentLocaleAndStatus(body, model, {
|
2063
|
+
allowMultipleLocales: true
|
2064
|
+
});
|
1944
2065
|
const entityPromises = documentIds.map(
|
1945
2066
|
(documentId) => documentManager2.findLocales(documentId, model, { locale, isPublished: true })
|
1946
2067
|
);
|
@@ -2291,32 +2412,37 @@ const sanitizeMainField = (model, mainField, userAbility) => {
|
|
2291
2412
|
userAbility,
|
2292
2413
|
model: model.uid
|
2293
2414
|
});
|
2294
|
-
|
2415
|
+
const isMainFieldListable = isListable(model, mainField);
|
2416
|
+
const canReadMainField = permissionChecker2.can.read(null, mainField);
|
2417
|
+
if (!isMainFieldListable || !canReadMainField) {
|
2295
2418
|
return "id";
|
2296
2419
|
}
|
2297
|
-
if (
|
2298
|
-
|
2299
|
-
const userPermissionChecker = getService$1("permission-checker").create({
|
2300
|
-
userAbility,
|
2301
|
-
model: "plugin::users-permissions.user"
|
2302
|
-
});
|
2303
|
-
if (userPermissionChecker.can.read()) {
|
2304
|
-
return "name";
|
2305
|
-
}
|
2306
|
-
}
|
2307
|
-
return "id";
|
2420
|
+
if (model.uid === "plugin::users-permissions.role") {
|
2421
|
+
return "name";
|
2308
2422
|
}
|
2309
2423
|
return mainField;
|
2310
2424
|
};
|
2311
|
-
const addStatusToRelations = async (
|
2312
|
-
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.
|
2425
|
+
const addStatusToRelations = async (targetUid, relations2) => {
|
2426
|
+
if (!strapiUtils.contentTypes.hasDraftAndPublish(strapi.getModel(targetUid))) {
|
2313
2427
|
return relations2;
|
2314
2428
|
}
|
2315
2429
|
const documentMetadata2 = getService$1("document-metadata");
|
2316
|
-
|
2430
|
+
if (!relations2.length) {
|
2431
|
+
return relations2;
|
2432
|
+
}
|
2433
|
+
const firstRelation = relations2[0];
|
2434
|
+
const filters = {
|
2435
|
+
documentId: { $in: relations2.map((r) => r.documentId) },
|
2436
|
+
// NOTE: find the "opposite" status
|
2437
|
+
publishedAt: firstRelation.publishedAt !== null ? { $null: true } : { $notNull: true }
|
2438
|
+
};
|
2439
|
+
const availableStatus = await strapi.query(targetUid).findMany({
|
2440
|
+
select: ["id", "documentId", "locale", "updatedAt", "createdAt", "publishedAt"],
|
2441
|
+
filters
|
2442
|
+
});
|
2317
2443
|
return relations2.map((relation) => {
|
2318
|
-
const availableStatuses =
|
2319
|
-
(availableDocument) => availableDocument.documentId === relation.documentId
|
2444
|
+
const availableStatuses = availableStatus.filter(
|
2445
|
+
(availableDocument) => availableDocument.documentId === relation.documentId && (relation.locale ? availableDocument.locale === relation.locale : true)
|
2320
2446
|
);
|
2321
2447
|
return {
|
2322
2448
|
...relation,
|
@@ -2337,11 +2463,8 @@ const validateLocale = (sourceUid, targetUid, locale) => {
|
|
2337
2463
|
const isLocalized = strapi.plugin("i18n").service("content-types").isLocalizedContentType;
|
2338
2464
|
const isSourceLocalized = isLocalized(sourceModel);
|
2339
2465
|
const isTargetLocalized = isLocalized(targetModel);
|
2340
|
-
let validatedLocale = locale;
|
2341
|
-
if (!targetModel || !isTargetLocalized)
|
2342
|
-
validatedLocale = void 0;
|
2343
2466
|
return {
|
2344
|
-
locale
|
2467
|
+
locale,
|
2345
2468
|
isSourceLocalized,
|
2346
2469
|
isTargetLocalized
|
2347
2470
|
};
|
@@ -2444,7 +2567,7 @@ const relations = {
|
|
2444
2567
|
attribute,
|
2445
2568
|
fieldsToSelect,
|
2446
2569
|
mainField,
|
2447
|
-
source: { schema: sourceSchema },
|
2570
|
+
source: { schema: sourceSchema, isLocalized: isSourceLocalized },
|
2448
2571
|
target: { schema: targetSchema, isLocalized: isTargetLocalized },
|
2449
2572
|
sourceSchema,
|
2450
2573
|
targetSchema,
|
@@ -2466,7 +2589,8 @@ const relations = {
|
|
2466
2589
|
fieldsToSelect,
|
2467
2590
|
mainField,
|
2468
2591
|
source: {
|
2469
|
-
schema: { uid: sourceUid, modelType: sourceModelType }
|
2592
|
+
schema: { uid: sourceUid, modelType: sourceModelType },
|
2593
|
+
isLocalized: isSourceLocalized
|
2470
2594
|
},
|
2471
2595
|
target: {
|
2472
2596
|
schema: { uid: targetUid },
|
@@ -2504,12 +2628,16 @@ const relations = {
|
|
2504
2628
|
} else {
|
2505
2629
|
where.id = id;
|
2506
2630
|
}
|
2507
|
-
|
2508
|
-
|
2631
|
+
const publishedAt = getPublishedAtClause(status, targetUid);
|
2632
|
+
if (!fp.isEmpty(publishedAt)) {
|
2633
|
+
where[`${alias}.published_at`] = publishedAt;
|
2509
2634
|
}
|
2510
|
-
if (
|
2635
|
+
if (isTargetLocalized && locale) {
|
2511
2636
|
where[`${alias}.locale`] = locale;
|
2512
2637
|
}
|
2638
|
+
if (isSourceLocalized && locale) {
|
2639
|
+
where.locale = locale;
|
2640
|
+
}
|
2513
2641
|
if ((idsToInclude?.length ?? 0) !== 0) {
|
2514
2642
|
where[`${alias}.id`].$notIn = idsToInclude;
|
2515
2643
|
}
|
@@ -2527,7 +2655,8 @@ const relations = {
|
|
2527
2655
|
id: { $notIn: fp.uniq(idsToOmit) }
|
2528
2656
|
});
|
2529
2657
|
}
|
2530
|
-
const
|
2658
|
+
const dbQuery = strapi.get("query-params").transform(targetUid, queryParams);
|
2659
|
+
const res = await strapi.db.query(targetUid).findPage(dbQuery);
|
2531
2660
|
ctx.body = {
|
2532
2661
|
...res,
|
2533
2662
|
results: await addStatusToRelations(targetUid, res.results)
|
@@ -2542,29 +2671,39 @@ const relations = {
|
|
2542
2671
|
attribute,
|
2543
2672
|
targetField,
|
2544
2673
|
fieldsToSelect,
|
2545
|
-
|
2546
|
-
|
2547
|
-
}
|
2548
|
-
target: {
|
2549
|
-
schema: { uid: targetUid }
|
2550
|
-
}
|
2674
|
+
status,
|
2675
|
+
source: { schema: sourceSchema },
|
2676
|
+
target: { schema: targetSchema }
|
2551
2677
|
} = await this.extractAndValidateRequestInfo(ctx, id);
|
2678
|
+
const { uid: sourceUid } = sourceSchema;
|
2679
|
+
const { uid: targetUid } = targetSchema;
|
2552
2680
|
const permissionQuery = await getService$1("permission-checker").create({ userAbility, model: targetUid }).sanitizedQuery.read({ fields: fieldsToSelect });
|
2553
2681
|
const dbQuery = strapi.db.query(sourceUid);
|
2554
2682
|
const loadRelations = strapiUtils.relations.isAnyToMany(attribute) ? (...args) => dbQuery.loadPages(...args) : (...args) => dbQuery.load(...args).then((res2) => ({ results: res2 ? [res2] : [] }));
|
2683
|
+
const filters = {};
|
2684
|
+
if (sourceSchema?.options?.draftAndPublish) {
|
2685
|
+
if (targetSchema?.options?.draftAndPublish) {
|
2686
|
+
if (status === "published") {
|
2687
|
+
filters.publishedAt = { $notNull: true };
|
2688
|
+
} else {
|
2689
|
+
filters.publishedAt = { $null: true };
|
2690
|
+
}
|
2691
|
+
}
|
2692
|
+
} else if (targetSchema?.options?.draftAndPublish) {
|
2693
|
+
filters.publishedAt = { $null: true };
|
2694
|
+
}
|
2555
2695
|
const res = await loadRelations({ id: entryId }, targetField, {
|
2556
|
-
select: ["id", "documentId", "locale", "publishedAt"],
|
2696
|
+
select: ["id", "documentId", "locale", "publishedAt", "updatedAt"],
|
2557
2697
|
ordering: "desc",
|
2558
2698
|
page: ctx.request.query.page,
|
2559
|
-
pageSize: ctx.request.query.pageSize
|
2699
|
+
pageSize: ctx.request.query.pageSize,
|
2700
|
+
filters
|
2560
2701
|
});
|
2561
2702
|
const loadedIds = res.results.map((item) => item.id);
|
2562
2703
|
addFiltersClause(permissionQuery, { id: { $in: loadedIds } });
|
2563
2704
|
const sanitizedRes = await loadRelations({ id: entryId }, targetField, {
|
2564
2705
|
...strapi.get("query-params").transform(targetUid, permissionQuery),
|
2565
|
-
ordering: "desc"
|
2566
|
-
page: ctx.request.query.page,
|
2567
|
-
pageSize: ctx.request.query.pageSize
|
2706
|
+
ordering: "desc"
|
2568
2707
|
});
|
2569
2708
|
const relationsUnion = fp.uniqBy("id", fp.concat(sanitizedRes.results, res.results));
|
2570
2709
|
ctx.body = {
|
@@ -2651,7 +2790,7 @@ const singleTypes = {
|
|
2651
2790
|
permissionChecker2,
|
2652
2791
|
model,
|
2653
2792
|
// @ts-expect-error - fix types
|
2654
|
-
{
|
2793
|
+
{ documentId: document.documentId, locale, publishedAt: null },
|
2655
2794
|
{ availableLocales: true, availableStatus: false }
|
2656
2795
|
);
|
2657
2796
|
ctx.body = { data: {}, meta };
|
@@ -2850,7 +2989,8 @@ const controllers = {
|
|
2850
2989
|
relations,
|
2851
2990
|
"single-types": singleTypes,
|
2852
2991
|
uid: uid$1,
|
2853
|
-
...history.controllers ? history.controllers : {}
|
2992
|
+
...history.controllers ? history.controllers : {},
|
2993
|
+
...preview.controllers ? preview.controllers : {}
|
2854
2994
|
};
|
2855
2995
|
const keys = {
|
2856
2996
|
CONFIGURATION: "configuration"
|
@@ -3470,12 +3610,27 @@ const createPermissionChecker = (strapi2) => ({ userAbility, model }) => {
|
|
3470
3610
|
ability: userAbility,
|
3471
3611
|
model
|
3472
3612
|
});
|
3473
|
-
const
|
3613
|
+
const { actionProvider } = strapi2.service("admin::permission");
|
3614
|
+
const toSubject = (entity) => {
|
3615
|
+
return entity ? permissionsManager.toSubject(entity, model) : model;
|
3616
|
+
};
|
3474
3617
|
const can = (action, entity, field) => {
|
3475
|
-
|
3618
|
+
const subject = toSubject(entity);
|
3619
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3620
|
+
return (
|
3621
|
+
// Test the original action to see if it passes
|
3622
|
+
userAbility.can(action, subject, field) || // Else try every known alias if at least one of them succeed, then the user "can"
|
3623
|
+
aliases.some((alias) => userAbility.can(alias, subject, field))
|
3624
|
+
);
|
3476
3625
|
};
|
3477
3626
|
const cannot = (action, entity, field) => {
|
3478
|
-
|
3627
|
+
const subject = toSubject(entity);
|
3628
|
+
const aliases = actionProvider.unstable_aliases(action, model);
|
3629
|
+
return (
|
3630
|
+
// Test both the original action
|
3631
|
+
userAbility.cannot(action, subject, field) && // and every known alias, if all of them fail (cannot), then the user truly "cannot"
|
3632
|
+
aliases.every((alias) => userAbility.cannot(alias, subject, field))
|
3633
|
+
);
|
3479
3634
|
};
|
3480
3635
|
const sanitizeOutput = (data, { action = ACTIONS.read } = {}) => {
|
3481
3636
|
return permissionsManager.sanitizeOutput(data, { subject: toSubject(data), action });
|
@@ -4007,7 +4162,9 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4007
4162
|
*/
|
4008
4163
|
async getAvailableLocales(uid2, version, allVersions, validatableFields = []) {
|
4009
4164
|
const versionsByLocale = fp.groupBy("locale", allVersions);
|
4010
|
-
|
4165
|
+
if (version.locale) {
|
4166
|
+
delete versionsByLocale[version.locale];
|
4167
|
+
}
|
4011
4168
|
const model = strapi2.getModel(uid2);
|
4012
4169
|
const keysToKeep = [...AVAILABLE_LOCALES_FIELDS, ...validatableFields];
|
4013
4170
|
const traversalFunction = async (localeVersion) => strapiUtils.traverseEntity(
|
@@ -4133,7 +4290,13 @@ const documentMetadata = ({ strapi: strapi2 }) => ({
|
|
4133
4290
|
*/
|
4134
4291
|
async formatDocumentWithMetadata(uid2, document, opts = {}) {
|
4135
4292
|
if (!document) {
|
4136
|
-
return
|
4293
|
+
return {
|
4294
|
+
data: document,
|
4295
|
+
meta: {
|
4296
|
+
availableLocales: [],
|
4297
|
+
availableStatus: []
|
4298
|
+
}
|
4299
|
+
};
|
4137
4300
|
}
|
4138
4301
|
const hasDraftAndPublish = strapiUtils.contentTypes.hasDraftAndPublish(strapi2.getModel(uid2));
|
4139
4302
|
if (!hasDraftAndPublish) {
|
@@ -4357,7 +4520,8 @@ const services = {
|
|
4357
4520
|
permission,
|
4358
4521
|
"populate-builder": populateBuilder$1,
|
4359
4522
|
uid,
|
4360
|
-
...history.services ? history.services : {}
|
4523
|
+
...history.services ? history.services : {},
|
4524
|
+
...preview.services ? preview.services : {}
|
4361
4525
|
};
|
4362
4526
|
const index = () => {
|
4363
4527
|
return {
|