@mattisvensson/strapi-plugin-webatlas 0.12.2 → 0.13.0
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/README.md +46 -1
- package/dist/admin/{SettingTitle-DXGCUfum.js → ContentBox-D4PGQ8eh.js} +1 -5
- package/dist/admin/{SettingTitle-C1_2epDJ.mjs → ContentBox-KyQN2KGV.mjs} +2 -6
- package/dist/admin/{RoutePicker-C6LpgVMi.mjs → RoutePicker-CgndSXoF.mjs} +1 -1
- package/dist/admin/{RoutePicker-DvzQH2CX.js → RoutePicker-CwoMMhf_.js} +1 -1
- package/dist/admin/WarningBox-AyYq0Onj.mjs +18 -0
- package/dist/admin/{WarningBox-BHlYlKQ8.js → WarningBox-FF1yYDXP.js} +0 -24
- package/dist/admin/{de-BWUGdpM0.js → de-Cl0vM1wA.js} +51 -4
- package/dist/admin/{de-Dnk_hvMW.mjs → de-DWs5ckOd.mjs} +51 -4
- package/dist/admin/{en-D5EqZSGy.mjs → en-CyhISGZi.mjs} +51 -4
- package/dist/admin/{en-DOk8P6X5.js → en-DSmtmPYk.js} +51 -4
- package/dist/admin/{index-CVrufPeL.mjs → index-BKhrfzjO.mjs} +65 -26
- package/dist/admin/{index-DuSnxRbO.mjs → index-Bv5Ri-ri.mjs} +44 -12
- package/dist/admin/{index-D7zg69uM.js → index-BxGPKxr_.js} +50 -18
- package/dist/admin/index-Ctm4TBT5.mjs +5308 -0
- package/dist/admin/{index-Y4uwBSjP.mjs → index-D2O7sLKs.mjs} +1 -1
- package/dist/admin/{index-DHNPW0YT.js → index-DTrsl_uN.js} +65 -26
- package/dist/admin/index-FvaXwOH0.mjs +174 -0
- package/dist/admin/index-JBUU7dE6.js +5308 -0
- package/dist/admin/{index-Dp_eCRFS.js → index-jOCO4_-k.js} +1 -1
- package/dist/admin/index-uOC1Clyv.js +174 -0
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +314 -51
- package/dist/server/index.mjs +315 -52
- package/dist/server/src/index.d.ts +16 -3
- package/package.json +1 -1
- package/dist/admin/WarningBox-CfIVF0O-.mjs +0 -42
- package/dist/admin/index-DC-2-FsX.mjs +0 -9622
- package/dist/admin/index-Dx4gvFWK.mjs +0 -147
- package/dist/admin/index-FuvoHpAT.js +0 -147
- package/dist/admin/index-RmZ3LQPu.js +0 -9622
package/dist/server/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { errors } from "@strapi/utils";
|
|
1
|
+
import { errors, contentTypes as contentTypes$1 } from "@strapi/utils";
|
|
2
2
|
function transformToUrl(input, replaceSlash = true) {
|
|
3
3
|
const specialCharMap = {
|
|
4
4
|
ü: "ue",
|
|
@@ -36,6 +36,7 @@ const PLUGIN_ID = pluginPkg.strapi.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plug
|
|
|
36
36
|
const waNavigation = `plugin::${PLUGIN_ID}.navigation`;
|
|
37
37
|
const waNavItem = `plugin::${PLUGIN_ID}.navitem`;
|
|
38
38
|
const waRoute = `plugin::${PLUGIN_ID}.route`;
|
|
39
|
+
const DEFAULT_NAVIGATION_MAX_DEPTH = 1;
|
|
39
40
|
async function checkPathExists(path, excludeDocumentId) {
|
|
40
41
|
const filters = {
|
|
41
42
|
$or: [{ path }, { uidPath: path }, { canonicalPath: path }]
|
|
@@ -4438,6 +4439,14 @@ async function buildNavigationPath({
|
|
|
4438
4439
|
const validatedPath = await duplicateCheck(newPath, routeDocumentId);
|
|
4439
4440
|
return validatedPath;
|
|
4440
4441
|
}
|
|
4442
|
+
async function buildItemPath({
|
|
4443
|
+
slug,
|
|
4444
|
+
routeDocumentId,
|
|
4445
|
+
calculatedParent
|
|
4446
|
+
}) {
|
|
4447
|
+
const path = await buildNavigationPath({ slug, routeDocumentId, calculatedParent });
|
|
4448
|
+
return { path, slug: path.split("/").pop() ?? slug };
|
|
4449
|
+
}
|
|
4441
4450
|
async function handleItemDeletion(navigationItems) {
|
|
4442
4451
|
const errors2 = [];
|
|
4443
4452
|
let items = [...navigationItems];
|
|
@@ -4523,15 +4532,15 @@ async function handleItemUpdate({
|
|
|
4523
4532
|
});
|
|
4524
4533
|
if (!route2)
|
|
4525
4534
|
throw new Error(`Related route not found for new navigation item '${item.route.title}'`);
|
|
4526
|
-
const path = await
|
|
4527
|
-
slug: item.route.slug,
|
|
4535
|
+
const { path, slug } = await buildItemPath({
|
|
4536
|
+
slug: transformToUrl(item.route.slug),
|
|
4528
4537
|
routeDocumentId: route2.documentId,
|
|
4529
4538
|
calculatedParent
|
|
4530
4539
|
});
|
|
4531
4540
|
assertPathAllowed(path, await getRouteBlacklist());
|
|
4532
4541
|
await updateRoute(route2.documentId, {
|
|
4533
4542
|
title: item.route.title,
|
|
4534
|
-
slug
|
|
4543
|
+
slug,
|
|
4535
4544
|
path,
|
|
4536
4545
|
isOverride: path !== route2.canonicalPath
|
|
4537
4546
|
});
|
|
@@ -4559,12 +4568,13 @@ async function handleItemUpdate({
|
|
|
4559
4568
|
});
|
|
4560
4569
|
if (!route2)
|
|
4561
4570
|
throw new Error(`Related route not found for navigation item '${item.route.title}'`);
|
|
4562
|
-
const
|
|
4563
|
-
const
|
|
4564
|
-
|
|
4571
|
+
const changedSlug = item.clientModifications?.slug;
|
|
4572
|
+
const requestedSlug = changedSlug ? isInternal ? transformToUrl(changedSlug) : changedSlug : item.route.slug;
|
|
4573
|
+
const { path, slug } = isInternal ? await buildItemPath({
|
|
4574
|
+
slug: requestedSlug,
|
|
4565
4575
|
routeDocumentId: route2.documentId,
|
|
4566
4576
|
calculatedParent
|
|
4567
|
-
}) : slug;
|
|
4577
|
+
}) : { path: requestedSlug, slug: requestedSlug };
|
|
4568
4578
|
const isOverride = path !== route2.canonicalPath;
|
|
4569
4579
|
if (needsRouteUpdate) {
|
|
4570
4580
|
if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
|
|
@@ -4982,6 +4992,38 @@ async function getPublishedDocumentIds(routes2) {
|
|
|
4982
4992
|
}
|
|
4983
4993
|
return publishedDocumentIds;
|
|
4984
4994
|
}
|
|
4995
|
+
async function getDocumentStatuses(routes2) {
|
|
4996
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
4997
|
+
for (const route2 of routes2) {
|
|
4998
|
+
if (!route2?.relatedContentType || !route2.relatedDocumentId) continue;
|
|
4999
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
5000
|
+
documentIds.push(route2.relatedDocumentId);
|
|
5001
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
5002
|
+
}
|
|
5003
|
+
const statuses = /* @__PURE__ */ new Map();
|
|
5004
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
5005
|
+
const contentType = strapi.contentTypes[uid];
|
|
5006
|
+
if (!contentType || !contentTypes$1.hasDraftAndPublish(contentType)) continue;
|
|
5007
|
+
const query = {
|
|
5008
|
+
filters: { documentId: { $in: documentIds } },
|
|
5009
|
+
fields: ["documentId", "updatedAt"]
|
|
5010
|
+
};
|
|
5011
|
+
const [drafts, published] = await Promise.all([
|
|
5012
|
+
strapi.documents(uid).findMany({ ...query, status: "draft" }),
|
|
5013
|
+
strapi.documents(uid).findMany({ ...query, status: "published" })
|
|
5014
|
+
]);
|
|
5015
|
+
const publishedUpdatedAt = new Map(
|
|
5016
|
+
published.map((entry) => [entry.documentId, new Date(entry.updatedAt).getTime()])
|
|
5017
|
+
);
|
|
5018
|
+
drafts.forEach((draft) => {
|
|
5019
|
+
const publishedAt = publishedUpdatedAt.get(draft.documentId);
|
|
5020
|
+
if (publishedAt === void 0) return statuses.set(draft.documentId, "draft");
|
|
5021
|
+
const isModified = new Date(draft.updatedAt).getTime() > publishedAt;
|
|
5022
|
+
statuses.set(draft.documentId, isModified ? "modified" : "published");
|
|
5023
|
+
});
|
|
5024
|
+
}
|
|
5025
|
+
return statuses;
|
|
5026
|
+
}
|
|
4985
5027
|
const migration_001_canonical_path = {
|
|
4986
5028
|
version: "001",
|
|
4987
5029
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -5132,10 +5174,25 @@ const migration_003_route_source_field = {
|
|
|
5132
5174
|
);
|
|
5133
5175
|
}
|
|
5134
5176
|
};
|
|
5177
|
+
const migration_004_navigation_max_depth = {
|
|
5178
|
+
version: "004",
|
|
5179
|
+
description: "Move the global navigation max depth of the config to every navigation",
|
|
5180
|
+
async up(strapi2) {
|
|
5181
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5182
|
+
const config2 = await pluginStore.get({ key: "config" });
|
|
5183
|
+
const maxDepth = config2?.navigation?.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
5184
|
+
const { count } = await strapi2.db.query(waNavigation).updateMany({
|
|
5185
|
+
where: { maxDepth: { $null: true } },
|
|
5186
|
+
data: { maxDepth }
|
|
5187
|
+
});
|
|
5188
|
+
strapi2.log.info(`[webatlas] Set the max depth ${maxDepth} for ${count} navigation(s)`);
|
|
5189
|
+
}
|
|
5190
|
+
};
|
|
5135
5191
|
const migrations = [
|
|
5136
5192
|
migration_001_canonical_path,
|
|
5137
5193
|
migration_002_webatlas_json_field,
|
|
5138
|
-
migration_003_route_source_field
|
|
5194
|
+
migration_003_route_source_field,
|
|
5195
|
+
migration_004_navigation_max_depth
|
|
5139
5196
|
];
|
|
5140
5197
|
const runMigrations = async (strapi2) => {
|
|
5141
5198
|
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
@@ -5173,9 +5230,37 @@ function registerPermissions(strapi2) {
|
|
|
5173
5230
|
const actions = [
|
|
5174
5231
|
{
|
|
5175
5232
|
section: "plugins",
|
|
5176
|
-
displayName: "
|
|
5177
|
-
uid: "
|
|
5178
|
-
subCategory: "
|
|
5233
|
+
displayName: "Read navigations",
|
|
5234
|
+
uid: "navigation.read",
|
|
5235
|
+
subCategory: "Navigation",
|
|
5236
|
+
pluginName: PLUGIN_ID
|
|
5237
|
+
},
|
|
5238
|
+
{
|
|
5239
|
+
section: "plugins",
|
|
5240
|
+
displayName: "Create navigations",
|
|
5241
|
+
uid: "navigation.create",
|
|
5242
|
+
subCategory: "Navigation",
|
|
5243
|
+
pluginName: PLUGIN_ID
|
|
5244
|
+
},
|
|
5245
|
+
{
|
|
5246
|
+
section: "plugins",
|
|
5247
|
+
displayName: "Edit navigations",
|
|
5248
|
+
uid: "navigation.update",
|
|
5249
|
+
subCategory: "Navigation",
|
|
5250
|
+
pluginName: PLUGIN_ID
|
|
5251
|
+
},
|
|
5252
|
+
{
|
|
5253
|
+
section: "plugins",
|
|
5254
|
+
displayName: "Delete navigations",
|
|
5255
|
+
uid: "navigation.delete",
|
|
5256
|
+
subCategory: "Navigation",
|
|
5257
|
+
pluginName: PLUGIN_ID
|
|
5258
|
+
},
|
|
5259
|
+
{
|
|
5260
|
+
section: "plugins",
|
|
5261
|
+
displayName: "Edit navigation items",
|
|
5262
|
+
uid: "navigation.edit-items",
|
|
5263
|
+
subCategory: "Navigation",
|
|
5179
5264
|
pluginName: PLUGIN_ID
|
|
5180
5265
|
},
|
|
5181
5266
|
{
|
|
@@ -5187,15 +5272,29 @@ function registerPermissions(strapi2) {
|
|
|
5187
5272
|
},
|
|
5188
5273
|
{
|
|
5189
5274
|
section: "plugins",
|
|
5190
|
-
displayName: "
|
|
5191
|
-
uid: "settings.general",
|
|
5275
|
+
displayName: "Read general settings",
|
|
5276
|
+
uid: "settings.general.read",
|
|
5192
5277
|
subCategory: "Settings",
|
|
5193
5278
|
pluginName: PLUGIN_ID
|
|
5194
5279
|
},
|
|
5195
5280
|
{
|
|
5196
5281
|
section: "plugins",
|
|
5197
|
-
displayName: "
|
|
5198
|
-
uid: "settings.
|
|
5282
|
+
displayName: "Update general settings",
|
|
5283
|
+
uid: "settings.general.update",
|
|
5284
|
+
subCategory: "Settings",
|
|
5285
|
+
pluginName: PLUGIN_ID
|
|
5286
|
+
},
|
|
5287
|
+
{
|
|
5288
|
+
section: "plugins",
|
|
5289
|
+
displayName: "Read navigation settings",
|
|
5290
|
+
uid: "settings.navigation.read",
|
|
5291
|
+
subCategory: "Settings",
|
|
5292
|
+
pluginName: PLUGIN_ID
|
|
5293
|
+
},
|
|
5294
|
+
{
|
|
5295
|
+
section: "plugins",
|
|
5296
|
+
displayName: "Update navigation settings",
|
|
5297
|
+
uid: "settings.navigation.update",
|
|
5199
5298
|
subCategory: "Settings",
|
|
5200
5299
|
pluginName: PLUGIN_ID
|
|
5201
5300
|
},
|
|
@@ -5205,6 +5304,13 @@ function registerPermissions(strapi2) {
|
|
|
5205
5304
|
uid: "cm.aside",
|
|
5206
5305
|
subCategory: "Content Manager",
|
|
5207
5306
|
pluginName: PLUGIN_ID
|
|
5307
|
+
},
|
|
5308
|
+
{
|
|
5309
|
+
section: "plugins",
|
|
5310
|
+
displayName: "Edit path (parent route and override)",
|
|
5311
|
+
uid: "cm.edit-path",
|
|
5312
|
+
subCategory: "Content Manager",
|
|
5313
|
+
pluginName: PLUGIN_ID
|
|
5208
5314
|
}
|
|
5209
5315
|
];
|
|
5210
5316
|
strapi2.admin.services.permission.actionProvider.registerMany(actions);
|
|
@@ -5214,13 +5320,10 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5214
5320
|
const config2 = await pluginStore.get({
|
|
5215
5321
|
key: "config"
|
|
5216
5322
|
});
|
|
5323
|
+
const { navigation: _legacyNavigation, ...currentConfig } = config2 ?? {};
|
|
5217
5324
|
let newConfig = {
|
|
5218
|
-
...
|
|
5325
|
+
...currentConfig,
|
|
5219
5326
|
selectedContentTypes: [],
|
|
5220
|
-
navigation: {
|
|
5221
|
-
maxDepth: config2?.navigation?.maxDepth || 1,
|
|
5222
|
-
...config2?.navigation
|
|
5223
|
-
},
|
|
5224
5327
|
migrationVersion: config2?.migrationVersion || "0"
|
|
5225
5328
|
};
|
|
5226
5329
|
enabledContentTypes.forEach((type) => {
|
|
@@ -5237,6 +5340,21 @@ async function syncConfig(strapi2, enabledContentTypes) {
|
|
|
5237
5340
|
}
|
|
5238
5341
|
return newConfig;
|
|
5239
5342
|
}
|
|
5343
|
+
async function getDefaultRouteData(strapi2, uid, data) {
|
|
5344
|
+
const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
|
|
5345
|
+
const currentConfig = await pluginStore.get({ key: "config" });
|
|
5346
|
+
const ctSettings = currentConfig?.selectedContentTypes.find((ct) => ct.uid === uid);
|
|
5347
|
+
const sourceValue = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5348
|
+
if (typeof sourceValue !== "string" || !sourceValue.trim()) return void 0;
|
|
5349
|
+
const defaultParent = ctSettings.defaultParentRoute ? await strapi2.documents(waRoute).findFirst({
|
|
5350
|
+
filters: { relatedDocumentId: ctSettings.defaultParentRoute }
|
|
5351
|
+
}) : null;
|
|
5352
|
+
return {
|
|
5353
|
+
slug: transformToUrl(sourceValue),
|
|
5354
|
+
parentDocumentId: defaultParent?.documentId ?? null,
|
|
5355
|
+
isOverride: false
|
|
5356
|
+
};
|
|
5357
|
+
}
|
|
5240
5358
|
function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
5241
5359
|
const actions = ["create", "update", "delete"];
|
|
5242
5360
|
strapi2.documents.use(async (context, next) => {
|
|
@@ -5246,12 +5364,15 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5246
5364
|
const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
|
|
5247
5365
|
const requestContext = strapi2.requestContext.get();
|
|
5248
5366
|
const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
|
|
5249
|
-
|
|
5367
|
+
const userAbility = requestContext?.state?.userAbility;
|
|
5368
|
+
const canUseAside = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.aside`);
|
|
5369
|
+
const canEditPath = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.edit-path`);
|
|
5370
|
+
if ((context.action === "create" || context.action === "update") && (!isRouteDataAllowed || !canUseAside)) {
|
|
5250
5371
|
delete context.params.data?.webatlas;
|
|
5251
5372
|
}
|
|
5252
5373
|
if (context.action === "create") {
|
|
5253
5374
|
const data = context.params.data;
|
|
5254
|
-
const
|
|
5375
|
+
const webatlas = data.webatlas && canEditPath ? data.webatlas : await getDefaultRouteData(strapi2, context.uid, data);
|
|
5255
5376
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5256
5377
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5257
5378
|
if (!transformedSlug) return next();
|
|
@@ -5307,17 +5428,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5307
5428
|
if (context.action === "update") {
|
|
5308
5429
|
const data = context.params.data;
|
|
5309
5430
|
const { documentId } = context.params;
|
|
5310
|
-
const
|
|
5431
|
+
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5432
|
+
filters: {
|
|
5433
|
+
relatedDocumentId: documentId
|
|
5434
|
+
},
|
|
5435
|
+
populate: ["parent"]
|
|
5436
|
+
});
|
|
5437
|
+
let webatlas = data.webatlas;
|
|
5438
|
+
if (!relatedRoute && (!webatlas || !canEditPath)) {
|
|
5439
|
+
webatlas = await getDefaultRouteData(strapi2, context.uid, data);
|
|
5440
|
+
} else if (relatedRoute && webatlas && !canEditPath) {
|
|
5441
|
+
const sourceValue2 = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
|
|
5442
|
+
webatlas = !relatedRoute.isOverride && typeof sourceValue2 === "string" && sourceValue2.trim() ? {
|
|
5443
|
+
slug: transformToUrl(sourceValue2),
|
|
5444
|
+
parentDocumentId: relatedRoute.parent?.documentId ?? null,
|
|
5445
|
+
isOverride: false
|
|
5446
|
+
} : void 0;
|
|
5447
|
+
}
|
|
5311
5448
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5312
5449
|
if (!slug) {
|
|
5313
5450
|
const result3 = await next();
|
|
5314
5451
|
return result3;
|
|
5315
5452
|
}
|
|
5316
|
-
const relatedRoute = await strapi2.documents(waRoute).findFirst({
|
|
5317
|
-
filters: {
|
|
5318
|
-
relatedDocumentId: documentId
|
|
5319
|
-
}
|
|
5320
|
-
});
|
|
5321
5453
|
let parent = null;
|
|
5322
5454
|
let isValid = false;
|
|
5323
5455
|
if (parentDocumentId) {
|
|
@@ -5519,9 +5651,6 @@ const register = ({ strapi: strapi2 }) => {
|
|
|
5519
5651
|
const config = {
|
|
5520
5652
|
default: {
|
|
5521
5653
|
selectedContentTypes: [],
|
|
5522
|
-
navigation: {
|
|
5523
|
-
maxDepth: 1
|
|
5524
|
-
},
|
|
5525
5654
|
routeBlacklist: []
|
|
5526
5655
|
},
|
|
5527
5656
|
validator() {
|
|
@@ -5666,6 +5795,13 @@ const schema$1 = {
|
|
|
5666
5795
|
default: false,
|
|
5667
5796
|
configurable: false
|
|
5668
5797
|
},
|
|
5798
|
+
// Depth index of the deepest allowed level, 0 = root only. Only changed in the plugin settings
|
|
5799
|
+
maxDepth: {
|
|
5800
|
+
type: "integer",
|
|
5801
|
+
default: DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
5802
|
+
min: 0,
|
|
5803
|
+
configurable: false
|
|
5804
|
+
},
|
|
5669
5805
|
items: {
|
|
5670
5806
|
type: "relation",
|
|
5671
5807
|
configurable: false,
|
|
@@ -5755,6 +5891,21 @@ const admin$2 = () => ({
|
|
|
5755
5891
|
if (!documentId) throw new errors.ValidationError("Route documentId is required");
|
|
5756
5892
|
return await getAdminService().getRelatedRoute(documentId);
|
|
5757
5893
|
},
|
|
5894
|
+
async getRelatedRoutes(ctx) {
|
|
5895
|
+
const documentIds = String(ctx.query.documentIds || "").split(",").filter(Boolean);
|
|
5896
|
+
if (documentIds.length === 0) throw new errors.ValidationError("documentIds are required");
|
|
5897
|
+
if (documentIds.length > 100)
|
|
5898
|
+
throw new errors.ValidationError("At most 100 documentIds are allowed");
|
|
5899
|
+
return await getAdminService().getRelatedRoutes(documentIds);
|
|
5900
|
+
},
|
|
5901
|
+
async getNavigationDepths(ctx) {
|
|
5902
|
+
return await getAdminService().getNavigationDepths();
|
|
5903
|
+
},
|
|
5904
|
+
async updateNavigationDepths(ctx) {
|
|
5905
|
+
const { data } = ctx.request.body;
|
|
5906
|
+
if (!Array.isArray(data)) throw new errors.ValidationError("Navigation depths are required");
|
|
5907
|
+
return await getAdminService().updateNavigationDepths(data);
|
|
5908
|
+
},
|
|
5758
5909
|
async getProhibitedRouteIds(ctx) {
|
|
5759
5910
|
const { documentId } = ctx.params;
|
|
5760
5911
|
return await getAdminService().getProhibitedRouteIds(documentId);
|
|
@@ -5870,9 +6021,9 @@ const admin$1 = {
|
|
|
5870
6021
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5871
6022
|
config: {
|
|
5872
6023
|
actions: [
|
|
5873
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5874
|
-
`plugin::${PLUGIN_ID}.settings.navigation`,
|
|
5875
|
-
`plugin::${PLUGIN_ID}.
|
|
6024
|
+
`plugin::${PLUGIN_ID}.settings.general.read`,
|
|
6025
|
+
`plugin::${PLUGIN_ID}.settings.navigation.read`,
|
|
6026
|
+
`plugin::${PLUGIN_ID}.navigation.read`,
|
|
5876
6027
|
`plugin::${PLUGIN_ID}.cm.aside`
|
|
5877
6028
|
]
|
|
5878
6029
|
}
|
|
@@ -5890,10 +6041,7 @@ const admin$1 = {
|
|
|
5890
6041
|
{
|
|
5891
6042
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5892
6043
|
config: {
|
|
5893
|
-
actions: [
|
|
5894
|
-
`plugin::${PLUGIN_ID}.settings.general`,
|
|
5895
|
-
`plugin::${PLUGIN_ID}.settings.navigation`
|
|
5896
|
-
]
|
|
6044
|
+
actions: [`plugin::${PLUGIN_ID}.settings.general.update`]
|
|
5897
6045
|
}
|
|
5898
6046
|
}
|
|
5899
6047
|
]
|
|
@@ -5926,7 +6074,56 @@ const admin$1 = {
|
|
|
5926
6074
|
{
|
|
5927
6075
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5928
6076
|
config: {
|
|
5929
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6077
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6078
|
+
}
|
|
6079
|
+
}
|
|
6080
|
+
]
|
|
6081
|
+
}
|
|
6082
|
+
},
|
|
6083
|
+
// The max depth is a structural setting, so it is only changed in the plugin settings
|
|
6084
|
+
{
|
|
6085
|
+
method: "GET",
|
|
6086
|
+
path: "/settings/navigation-depths",
|
|
6087
|
+
handler: "admin.getNavigationDepths",
|
|
6088
|
+
config: {
|
|
6089
|
+
policies: [
|
|
6090
|
+
"admin::isAuthenticatedAdmin",
|
|
6091
|
+
{
|
|
6092
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6093
|
+
config: {
|
|
6094
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.read`]
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
6097
|
+
]
|
|
6098
|
+
}
|
|
6099
|
+
},
|
|
6100
|
+
{
|
|
6101
|
+
method: "PUT",
|
|
6102
|
+
path: "/settings/navigation-depths",
|
|
6103
|
+
handler: "admin.updateNavigationDepths",
|
|
6104
|
+
config: {
|
|
6105
|
+
policies: [
|
|
6106
|
+
"admin::isAuthenticatedAdmin",
|
|
6107
|
+
{
|
|
6108
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6109
|
+
config: {
|
|
6110
|
+
actions: [`plugin::${PLUGIN_ID}.settings.navigation.update`]
|
|
6111
|
+
}
|
|
6112
|
+
}
|
|
6113
|
+
]
|
|
6114
|
+
}
|
|
6115
|
+
},
|
|
6116
|
+
{
|
|
6117
|
+
method: "GET",
|
|
6118
|
+
path: "/route/related/batch",
|
|
6119
|
+
handler: "admin.getRelatedRoutes",
|
|
6120
|
+
config: {
|
|
6121
|
+
policies: [
|
|
6122
|
+
"admin::isAuthenticatedAdmin",
|
|
6123
|
+
{
|
|
6124
|
+
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6125
|
+
config: {
|
|
6126
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5930
6127
|
}
|
|
5931
6128
|
}
|
|
5932
6129
|
]
|
|
@@ -5958,7 +6155,7 @@ const admin$1 = {
|
|
|
5958
6155
|
{
|
|
5959
6156
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5960
6157
|
config: {
|
|
5961
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6158
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5962
6159
|
}
|
|
5963
6160
|
}
|
|
5964
6161
|
]
|
|
@@ -5975,7 +6172,7 @@ const admin$1 = {
|
|
|
5975
6172
|
{
|
|
5976
6173
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5977
6174
|
config: {
|
|
5978
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6175
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.read`]
|
|
5979
6176
|
}
|
|
5980
6177
|
}
|
|
5981
6178
|
]
|
|
@@ -5991,7 +6188,7 @@ const admin$1 = {
|
|
|
5991
6188
|
{
|
|
5992
6189
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
5993
6190
|
config: {
|
|
5994
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6191
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.create`]
|
|
5995
6192
|
}
|
|
5996
6193
|
}
|
|
5997
6194
|
]
|
|
@@ -6007,7 +6204,7 @@ const admin$1 = {
|
|
|
6007
6204
|
{
|
|
6008
6205
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6009
6206
|
config: {
|
|
6010
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6207
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.update`]
|
|
6011
6208
|
}
|
|
6012
6209
|
}
|
|
6013
6210
|
]
|
|
@@ -6023,7 +6220,7 @@ const admin$1 = {
|
|
|
6023
6220
|
{
|
|
6024
6221
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6025
6222
|
config: {
|
|
6026
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6223
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.edit-items`]
|
|
6027
6224
|
}
|
|
6028
6225
|
}
|
|
6029
6226
|
]
|
|
@@ -6039,7 +6236,7 @@ const admin$1 = {
|
|
|
6039
6236
|
{
|
|
6040
6237
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6041
6238
|
config: {
|
|
6042
|
-
actions: [`plugin::${PLUGIN_ID}.
|
|
6239
|
+
actions: [`plugin::${PLUGIN_ID}.navigation.delete`]
|
|
6043
6240
|
}
|
|
6044
6241
|
}
|
|
6045
6242
|
]
|
|
@@ -6056,7 +6253,7 @@ const admin$1 = {
|
|
|
6056
6253
|
{
|
|
6057
6254
|
name: `plugin::${PLUGIN_ID}.has-permissions`,
|
|
6058
6255
|
config: {
|
|
6059
|
-
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.
|
|
6256
|
+
actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
|
|
6060
6257
|
}
|
|
6061
6258
|
}
|
|
6062
6259
|
]
|
|
@@ -6089,6 +6286,36 @@ const routes = {
|
|
|
6089
6286
|
admin: admin$1,
|
|
6090
6287
|
"content-api": client$1
|
|
6091
6288
|
};
|
|
6289
|
+
async function getNavigationDepths() {
|
|
6290
|
+
const navigations = await strapi.documents(waNavigation).findMany({
|
|
6291
|
+
populate: ["items", "items.parent"]
|
|
6292
|
+
});
|
|
6293
|
+
return navigations.map((navigation2) => {
|
|
6294
|
+
const { items } = buildStructuredNavigation(navigation2, "flat");
|
|
6295
|
+
return {
|
|
6296
|
+
documentId: navigation2.documentId,
|
|
6297
|
+
name: navigation2.name,
|
|
6298
|
+
maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
|
|
6299
|
+
deepestDepth: Math.max(-1, ...(items ?? []).map((item) => item.depth ?? 0))
|
|
6300
|
+
};
|
|
6301
|
+
});
|
|
6302
|
+
}
|
|
6303
|
+
async function assertItemDepths(navigationId, navigationItems) {
|
|
6304
|
+
const navigation2 = await strapi.documents(waNavigation).findOne({
|
|
6305
|
+
documentId: navigationId,
|
|
6306
|
+
fields: ["maxDepth"]
|
|
6307
|
+
});
|
|
6308
|
+
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
6309
|
+
const maxDepth = navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
|
|
6310
|
+
const tooDeepItem = navigationItems.find(
|
|
6311
|
+
(item) => item.clientModifications?.type !== "delete" && (item.depth ?? 0) > maxDepth
|
|
6312
|
+
);
|
|
6313
|
+
if (tooDeepItem) {
|
|
6314
|
+
throw new errors.ValidationError(
|
|
6315
|
+
`'${tooDeepItem.clientModifications?.title || tooDeepItem.route?.title}' is deeper than the ${maxDepth + 1} level(s) allowed in this navigation`
|
|
6316
|
+
);
|
|
6317
|
+
}
|
|
6318
|
+
}
|
|
6092
6319
|
const admin = ({ strapi: strapi2 }) => ({
|
|
6093
6320
|
async updateConfig(newConfig) {
|
|
6094
6321
|
if (!newConfig) return;
|
|
@@ -6111,11 +6338,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6111
6338
|
const defaultConfig = strapi2.config.get(`plugin::${PLUGIN_ID}`);
|
|
6112
6339
|
config2 = {
|
|
6113
6340
|
...defaultConfig,
|
|
6114
|
-
...config2
|
|
6115
|
-
navigation: {
|
|
6116
|
-
...defaultConfig.navigation,
|
|
6117
|
-
...config2?.navigation
|
|
6118
|
-
}
|
|
6341
|
+
...config2
|
|
6119
6342
|
};
|
|
6120
6343
|
return config2;
|
|
6121
6344
|
},
|
|
@@ -6135,6 +6358,13 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6135
6358
|
populate: ["parent"]
|
|
6136
6359
|
});
|
|
6137
6360
|
},
|
|
6361
|
+
// Path of the routes linked to the given entries, with one query
|
|
6362
|
+
async getRelatedRoutes(documentIds) {
|
|
6363
|
+
return await strapi2.db?.query(waRoute).findMany({
|
|
6364
|
+
where: { relatedDocumentId: { $in: documentIds } },
|
|
6365
|
+
select: ["relatedDocumentId", "path"]
|
|
6366
|
+
});
|
|
6367
|
+
},
|
|
6138
6368
|
async getProhibitedRouteIds(documentId) {
|
|
6139
6369
|
let route2 = null;
|
|
6140
6370
|
if (documentId) {
|
|
@@ -6179,6 +6409,16 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6179
6409
|
);
|
|
6180
6410
|
}
|
|
6181
6411
|
}
|
|
6412
|
+
const navigations = Array.isArray(navigation2) ? navigation2 : [navigation2];
|
|
6413
|
+
const statuses = await getDocumentStatuses(
|
|
6414
|
+
navigations.flatMap((nav) => (nav.items ?? []).map((item) => item.route))
|
|
6415
|
+
);
|
|
6416
|
+
navigations.forEach(
|
|
6417
|
+
(nav) => nav.items?.forEach((item) => {
|
|
6418
|
+
const status = statuses.get(item.route?.relatedDocumentId);
|
|
6419
|
+
if (status) item.status = status;
|
|
6420
|
+
})
|
|
6421
|
+
);
|
|
6182
6422
|
return navigation2;
|
|
6183
6423
|
},
|
|
6184
6424
|
async createNavigation(name, visible) {
|
|
@@ -6199,6 +6439,28 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6199
6439
|
}
|
|
6200
6440
|
});
|
|
6201
6441
|
},
|
|
6442
|
+
async getNavigationDepths() {
|
|
6443
|
+
return await getNavigationDepths();
|
|
6444
|
+
},
|
|
6445
|
+
async updateNavigationDepths(depths) {
|
|
6446
|
+
const currentDepths = await getNavigationDepths();
|
|
6447
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6448
|
+
const current = currentDepths.find((navigation2) => navigation2.documentId === documentId);
|
|
6449
|
+
if (!current) throw new errors.NotFoundError("Navigation not found");
|
|
6450
|
+
if (!Number.isInteger(maxDepth) || maxDepth < 0) {
|
|
6451
|
+
throw new errors.ValidationError(`Invalid max depth for the navigation '${current.name}'`);
|
|
6452
|
+
}
|
|
6453
|
+
if (maxDepth < current.deepestDepth) {
|
|
6454
|
+
throw new errors.ValidationError(
|
|
6455
|
+
`The navigation '${current.name}' already has items on level ${current.deepestDepth + 1}`
|
|
6456
|
+
);
|
|
6457
|
+
}
|
|
6458
|
+
}
|
|
6459
|
+
for (const { documentId, maxDepth } of depths) {
|
|
6460
|
+
await strapi2.documents(waNavigation).update({ documentId, data: { maxDepth } });
|
|
6461
|
+
}
|
|
6462
|
+
return await getNavigationDepths();
|
|
6463
|
+
},
|
|
6202
6464
|
async deleteNavigation(documentId) {
|
|
6203
6465
|
const navigation2 = await strapi2.documents(waNavigation).findOne({
|
|
6204
6466
|
documentId,
|
|
@@ -6216,6 +6478,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6216
6478
|
},
|
|
6217
6479
|
async updateNavigationItemStructure(navigationId, navigationItems) {
|
|
6218
6480
|
if (!navigationId || !navigationItems) return;
|
|
6481
|
+
await assertItemDepths(navigationId, navigationItems);
|
|
6219
6482
|
const errors2 = [];
|
|
6220
6483
|
let newNavItemsMap = /* @__PURE__ */ new Map();
|
|
6221
6484
|
const deletionResult = await handleItemDeletion(navigationItems);
|
|
@@ -11,9 +11,6 @@ declare const _default: {
|
|
|
11
11
|
config: {
|
|
12
12
|
default: {
|
|
13
13
|
selectedContentTypes: any[];
|
|
14
|
-
navigation: {
|
|
15
|
-
maxDepth: number;
|
|
16
|
-
};
|
|
17
14
|
routeBlacklist: any[];
|
|
18
15
|
};
|
|
19
16
|
validator(): void;
|
|
@@ -25,6 +22,9 @@ declare const _default: {
|
|
|
25
22
|
getRoute(ctx: any): Promise<any>;
|
|
26
23
|
getAllRoutes(ctx: any): Promise<any>;
|
|
27
24
|
getRelatedRoute(ctx: any): Promise<any>;
|
|
25
|
+
getRelatedRoutes(ctx: any): Promise<any>;
|
|
26
|
+
getNavigationDepths(ctx: any): Promise<any>;
|
|
27
|
+
updateNavigationDepths(ctx: any): Promise<any>;
|
|
28
28
|
getProhibitedRouteIds(ctx: any): Promise<any>;
|
|
29
29
|
getNavigation(ctx: any): Promise<any>;
|
|
30
30
|
createNavigation(ctx: any): Promise<any>;
|
|
@@ -78,10 +78,16 @@ declare const _default: {
|
|
|
78
78
|
getRoute(documentId: string): Promise<any>;
|
|
79
79
|
getAllRoutes(): Promise<any>;
|
|
80
80
|
getRelatedRoute(documentId: string): Promise<any>;
|
|
81
|
+
getRelatedRoutes(documentIds: string[]): Promise<any>;
|
|
81
82
|
getProhibitedRouteIds(documentId: string): Promise<string[]>;
|
|
82
83
|
getNavigation(documentId?: string, variant?: import('../../types').StructuredNavigationVariant | "namesOnly"): Promise<any>;
|
|
83
84
|
createNavigation(name: string, visible: boolean): Promise<any>;
|
|
84
85
|
updateNavigation(documentId: string, data: import('../../types').NavigationInput): Promise<any>;
|
|
86
|
+
getNavigationDepths(): Promise<import('../../types').NavigationDepth[]>;
|
|
87
|
+
updateNavigationDepths(depths: {
|
|
88
|
+
documentId: string;
|
|
89
|
+
maxDepth: number;
|
|
90
|
+
}[]): Promise<import('../../types').NavigationDepth[]>;
|
|
85
91
|
deleteNavigation(documentId: string): Promise<any>;
|
|
86
92
|
updateNavigationItemStructure(navigationId: string, navigationItems: import('../../types').NestedNavItem[]): Promise<{
|
|
87
93
|
success: boolean;
|
|
@@ -130,6 +136,7 @@ declare const _default: {
|
|
|
130
136
|
name: string;
|
|
131
137
|
slug: string;
|
|
132
138
|
visible: boolean;
|
|
139
|
+
maxDepth?: number;
|
|
133
140
|
updatedAt: string;
|
|
134
141
|
createdAt: string;
|
|
135
142
|
}>;
|
|
@@ -275,6 +282,12 @@ declare const _default: {
|
|
|
275
282
|
default: boolean;
|
|
276
283
|
configurable: boolean;
|
|
277
284
|
};
|
|
285
|
+
maxDepth: {
|
|
286
|
+
type: string;
|
|
287
|
+
default: number;
|
|
288
|
+
min: number;
|
|
289
|
+
configurable: boolean;
|
|
290
|
+
};
|
|
278
291
|
items: {
|
|
279
292
|
type: string;
|
|
280
293
|
configurable: boolean;
|