@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.
Files changed (32) hide show
  1. package/README.md +46 -1
  2. package/dist/admin/{SettingTitle-DXGCUfum.js → ContentBox-D4PGQ8eh.js} +1 -5
  3. package/dist/admin/{SettingTitle-C1_2epDJ.mjs → ContentBox-KyQN2KGV.mjs} +2 -6
  4. package/dist/admin/{RoutePicker-C6LpgVMi.mjs → RoutePicker-CgndSXoF.mjs} +1 -1
  5. package/dist/admin/{RoutePicker-DvzQH2CX.js → RoutePicker-CwoMMhf_.js} +1 -1
  6. package/dist/admin/WarningBox-AyYq0Onj.mjs +18 -0
  7. package/dist/admin/{WarningBox-BHlYlKQ8.js → WarningBox-FF1yYDXP.js} +0 -24
  8. package/dist/admin/{de-BWUGdpM0.js → de-Cl0vM1wA.js} +51 -4
  9. package/dist/admin/{de-Dnk_hvMW.mjs → de-DWs5ckOd.mjs} +51 -4
  10. package/dist/admin/{en-D5EqZSGy.mjs → en-CyhISGZi.mjs} +51 -4
  11. package/dist/admin/{en-DOk8P6X5.js → en-DSmtmPYk.js} +51 -4
  12. package/dist/admin/{index-CVrufPeL.mjs → index-BKhrfzjO.mjs} +65 -26
  13. package/dist/admin/{index-DuSnxRbO.mjs → index-Bv5Ri-ri.mjs} +44 -12
  14. package/dist/admin/{index-D7zg69uM.js → index-BxGPKxr_.js} +50 -18
  15. package/dist/admin/index-Ctm4TBT5.mjs +5308 -0
  16. package/dist/admin/{index-Y4uwBSjP.mjs → index-D2O7sLKs.mjs} +1 -1
  17. package/dist/admin/{index-DHNPW0YT.js → index-DTrsl_uN.js} +65 -26
  18. package/dist/admin/index-FvaXwOH0.mjs +174 -0
  19. package/dist/admin/index-JBUU7dE6.js +5308 -0
  20. package/dist/admin/{index-Dp_eCRFS.js → index-jOCO4_-k.js} +1 -1
  21. package/dist/admin/index-uOC1Clyv.js +174 -0
  22. package/dist/admin/index.js +1 -1
  23. package/dist/admin/index.mjs +1 -1
  24. package/dist/server/index.js +314 -51
  25. package/dist/server/index.mjs +315 -52
  26. package/dist/server/src/index.d.ts +16 -3
  27. package/package.json +1 -1
  28. package/dist/admin/WarningBox-CfIVF0O-.mjs +0 -42
  29. package/dist/admin/index-DC-2-FsX.mjs +0 -9622
  30. package/dist/admin/index-Dx4gvFWK.mjs +0 -147
  31. package/dist/admin/index-FuvoHpAT.js +0 -147
  32. package/dist/admin/index-RmZ3LQPu.js +0 -9622
@@ -38,6 +38,7 @@ const PLUGIN_ID = pluginPkg.strapi.name.replace(/^(@[^-,.][\w,-]+\/|strapi-)plug
38
38
  const waNavigation = `plugin::${PLUGIN_ID}.navigation`;
39
39
  const waNavItem = `plugin::${PLUGIN_ID}.navitem`;
40
40
  const waRoute = `plugin::${PLUGIN_ID}.route`;
41
+ const DEFAULT_NAVIGATION_MAX_DEPTH = 1;
41
42
  async function checkPathExists(path, excludeDocumentId) {
42
43
  const filters = {
43
44
  $or: [{ path }, { uidPath: path }, { canonicalPath: path }]
@@ -4440,6 +4441,14 @@ async function buildNavigationPath({
4440
4441
  const validatedPath = await duplicateCheck(newPath, routeDocumentId);
4441
4442
  return validatedPath;
4442
4443
  }
4444
+ async function buildItemPath({
4445
+ slug,
4446
+ routeDocumentId,
4447
+ calculatedParent
4448
+ }) {
4449
+ const path = await buildNavigationPath({ slug, routeDocumentId, calculatedParent });
4450
+ return { path, slug: path.split("/").pop() ?? slug };
4451
+ }
4443
4452
  async function handleItemDeletion(navigationItems) {
4444
4453
  const errors = [];
4445
4454
  let items = [...navigationItems];
@@ -4525,15 +4534,15 @@ async function handleItemUpdate({
4525
4534
  });
4526
4535
  if (!route2)
4527
4536
  throw new Error(`Related route not found for new navigation item '${item.route.title}'`);
4528
- const path = await buildNavigationPath({
4529
- slug: item.route.slug,
4537
+ const { path, slug } = await buildItemPath({
4538
+ slug: transformToUrl(item.route.slug),
4530
4539
  routeDocumentId: route2.documentId,
4531
4540
  calculatedParent
4532
4541
  });
4533
4542
  assertPathAllowed(path, await getRouteBlacklist());
4534
4543
  await updateRoute(route2.documentId, {
4535
4544
  title: item.route.title,
4536
- slug: item.route.slug,
4545
+ slug,
4537
4546
  path,
4538
4547
  isOverride: path !== route2.canonicalPath
4539
4548
  });
@@ -4561,12 +4570,13 @@ async function handleItemUpdate({
4561
4570
  });
4562
4571
  if (!route2)
4563
4572
  throw new Error(`Related route not found for navigation item '${item.route.title}'`);
4564
- const slug = item.clientModifications?.slug || item.route.slug;
4565
- const path = isInternal ? await buildNavigationPath({
4566
- slug,
4573
+ const changedSlug = item.clientModifications?.slug;
4574
+ const requestedSlug = changedSlug ? isInternal ? transformToUrl(changedSlug) : changedSlug : item.route.slug;
4575
+ const { path, slug } = isInternal ? await buildItemPath({
4576
+ slug: requestedSlug,
4567
4577
  routeDocumentId: route2.documentId,
4568
4578
  calculatedParent
4569
- }) : slug;
4579
+ }) : { path: requestedSlug, slug: requestedSlug };
4570
4580
  const isOverride = path !== route2.canonicalPath;
4571
4581
  if (needsRouteUpdate) {
4572
4582
  if (isInternal) assertPathAllowed(path, await getRouteBlacklist());
@@ -4984,6 +4994,38 @@ async function getPublishedDocumentIds(routes2) {
4984
4994
  }
4985
4995
  return publishedDocumentIds;
4986
4996
  }
4997
+ async function getDocumentStatuses(routes2) {
4998
+ const documentIdsByUid = /* @__PURE__ */ new Map();
4999
+ for (const route2 of routes2) {
5000
+ if (!route2?.relatedContentType || !route2.relatedDocumentId) continue;
5001
+ const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
5002
+ documentIds.push(route2.relatedDocumentId);
5003
+ documentIdsByUid.set(route2.relatedContentType, documentIds);
5004
+ }
5005
+ const statuses = /* @__PURE__ */ new Map();
5006
+ for (const [uid, documentIds] of documentIdsByUid) {
5007
+ const contentType = strapi.contentTypes[uid];
5008
+ if (!contentType || !utils.contentTypes.hasDraftAndPublish(contentType)) continue;
5009
+ const query = {
5010
+ filters: { documentId: { $in: documentIds } },
5011
+ fields: ["documentId", "updatedAt"]
5012
+ };
5013
+ const [drafts, published] = await Promise.all([
5014
+ strapi.documents(uid).findMany({ ...query, status: "draft" }),
5015
+ strapi.documents(uid).findMany({ ...query, status: "published" })
5016
+ ]);
5017
+ const publishedUpdatedAt = new Map(
5018
+ published.map((entry) => [entry.documentId, new Date(entry.updatedAt).getTime()])
5019
+ );
5020
+ drafts.forEach((draft) => {
5021
+ const publishedAt = publishedUpdatedAt.get(draft.documentId);
5022
+ if (publishedAt === void 0) return statuses.set(draft.documentId, "draft");
5023
+ const isModified = new Date(draft.updatedAt).getTime() > publishedAt;
5024
+ statuses.set(draft.documentId, isModified ? "modified" : "published");
5025
+ });
5026
+ }
5027
+ return statuses;
5028
+ }
4987
5029
  const migration_001_canonical_path = {
4988
5030
  version: "001",
4989
5031
  description: "Migrate title field to canonicalPath using transformToUrl",
@@ -5134,10 +5176,25 @@ const migration_003_route_source_field = {
5134
5176
  );
5135
5177
  }
5136
5178
  };
5179
+ const migration_004_navigation_max_depth = {
5180
+ version: "004",
5181
+ description: "Move the global navigation max depth of the config to every navigation",
5182
+ async up(strapi2) {
5183
+ const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
5184
+ const config2 = await pluginStore.get({ key: "config" });
5185
+ const maxDepth = config2?.navigation?.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
5186
+ const { count } = await strapi2.db.query(waNavigation).updateMany({
5187
+ where: { maxDepth: { $null: true } },
5188
+ data: { maxDepth }
5189
+ });
5190
+ strapi2.log.info(`[webatlas] Set the max depth ${maxDepth} for ${count} navigation(s)`);
5191
+ }
5192
+ };
5137
5193
  const migrations = [
5138
5194
  migration_001_canonical_path,
5139
5195
  migration_002_webatlas_json_field,
5140
- migration_003_route_source_field
5196
+ migration_003_route_source_field,
5197
+ migration_004_navigation_max_depth
5141
5198
  ];
5142
5199
  const runMigrations = async (strapi2) => {
5143
5200
  const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
@@ -5175,9 +5232,37 @@ function registerPermissions(strapi2) {
5175
5232
  const actions = [
5176
5233
  {
5177
5234
  section: "plugins",
5178
- displayName: "Navigation page",
5179
- uid: "page.navigation",
5180
- subCategory: "Pages",
5235
+ displayName: "Read navigations",
5236
+ uid: "navigation.read",
5237
+ subCategory: "Navigation",
5238
+ pluginName: PLUGIN_ID
5239
+ },
5240
+ {
5241
+ section: "plugins",
5242
+ displayName: "Create navigations",
5243
+ uid: "navigation.create",
5244
+ subCategory: "Navigation",
5245
+ pluginName: PLUGIN_ID
5246
+ },
5247
+ {
5248
+ section: "plugins",
5249
+ displayName: "Edit navigations",
5250
+ uid: "navigation.update",
5251
+ subCategory: "Navigation",
5252
+ pluginName: PLUGIN_ID
5253
+ },
5254
+ {
5255
+ section: "plugins",
5256
+ displayName: "Delete navigations",
5257
+ uid: "navigation.delete",
5258
+ subCategory: "Navigation",
5259
+ pluginName: PLUGIN_ID
5260
+ },
5261
+ {
5262
+ section: "plugins",
5263
+ displayName: "Edit navigation items",
5264
+ uid: "navigation.edit-items",
5265
+ subCategory: "Navigation",
5181
5266
  pluginName: PLUGIN_ID
5182
5267
  },
5183
5268
  {
@@ -5189,15 +5274,29 @@ function registerPermissions(strapi2) {
5189
5274
  },
5190
5275
  {
5191
5276
  section: "plugins",
5192
- displayName: "General page",
5193
- uid: "settings.general",
5277
+ displayName: "Read general settings",
5278
+ uid: "settings.general.read",
5194
5279
  subCategory: "Settings",
5195
5280
  pluginName: PLUGIN_ID
5196
5281
  },
5197
5282
  {
5198
5283
  section: "plugins",
5199
- displayName: "Navigation page",
5200
- uid: "settings.navigation",
5284
+ displayName: "Update general settings",
5285
+ uid: "settings.general.update",
5286
+ subCategory: "Settings",
5287
+ pluginName: PLUGIN_ID
5288
+ },
5289
+ {
5290
+ section: "plugins",
5291
+ displayName: "Read navigation settings",
5292
+ uid: "settings.navigation.read",
5293
+ subCategory: "Settings",
5294
+ pluginName: PLUGIN_ID
5295
+ },
5296
+ {
5297
+ section: "plugins",
5298
+ displayName: "Update navigation settings",
5299
+ uid: "settings.navigation.update",
5201
5300
  subCategory: "Settings",
5202
5301
  pluginName: PLUGIN_ID
5203
5302
  },
@@ -5207,6 +5306,13 @@ function registerPermissions(strapi2) {
5207
5306
  uid: "cm.aside",
5208
5307
  subCategory: "Content Manager",
5209
5308
  pluginName: PLUGIN_ID
5309
+ },
5310
+ {
5311
+ section: "plugins",
5312
+ displayName: "Edit path (parent route and override)",
5313
+ uid: "cm.edit-path",
5314
+ subCategory: "Content Manager",
5315
+ pluginName: PLUGIN_ID
5210
5316
  }
5211
5317
  ];
5212
5318
  strapi2.admin.services.permission.actionProvider.registerMany(actions);
@@ -5216,13 +5322,10 @@ async function syncConfig(strapi2, enabledContentTypes) {
5216
5322
  const config2 = await pluginStore.get({
5217
5323
  key: "config"
5218
5324
  });
5325
+ const { navigation: _legacyNavigation, ...currentConfig } = config2 ?? {};
5219
5326
  let newConfig = {
5220
- ...config2,
5327
+ ...currentConfig,
5221
5328
  selectedContentTypes: [],
5222
- navigation: {
5223
- maxDepth: config2?.navigation?.maxDepth || 1,
5224
- ...config2?.navigation
5225
- },
5226
5329
  migrationVersion: config2?.migrationVersion || "0"
5227
5330
  };
5228
5331
  enabledContentTypes.forEach((type) => {
@@ -5239,6 +5342,21 @@ async function syncConfig(strapi2, enabledContentTypes) {
5239
5342
  }
5240
5343
  return newConfig;
5241
5344
  }
5345
+ async function getDefaultRouteData(strapi2, uid, data) {
5346
+ const pluginStore = strapi2.store({ type: "plugin", name: PLUGIN_ID });
5347
+ const currentConfig = await pluginStore.get({ key: "config" });
5348
+ const ctSettings = currentConfig?.selectedContentTypes.find((ct) => ct.uid === uid);
5349
+ const sourceValue = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
5350
+ if (typeof sourceValue !== "string" || !sourceValue.trim()) return void 0;
5351
+ const defaultParent = ctSettings.defaultParentRoute ? await strapi2.documents(waRoute).findFirst({
5352
+ filters: { relatedDocumentId: ctSettings.defaultParentRoute }
5353
+ }) : null;
5354
+ return {
5355
+ slug: transformToUrl(sourceValue),
5356
+ parentDocumentId: defaultParent?.documentId ?? null,
5357
+ isOverride: false
5358
+ };
5359
+ }
5242
5360
  function documentMiddleware(strapi2, enabledContentTypes, config2) {
5243
5361
  const actions = ["create", "update", "delete"];
5244
5362
  strapi2.documents.use(async (context, next) => {
@@ -5248,12 +5366,15 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5248
5366
  const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
5249
5367
  const requestContext = strapi2.requestContext.get();
5250
5368
  const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
5251
- if ((context.action === "create" || context.action === "update") && !isRouteDataAllowed) {
5369
+ const userAbility = requestContext?.state?.userAbility;
5370
+ const canUseAside = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.aside`);
5371
+ const canEditPath = !userAbility || userAbility.can(`plugin::${PLUGIN_ID}.cm.edit-path`);
5372
+ if ((context.action === "create" || context.action === "update") && (!isRouteDataAllowed || !canUseAside)) {
5252
5373
  delete context.params.data?.webatlas;
5253
5374
  }
5254
5375
  if (context.action === "create") {
5255
5376
  const data = context.params.data;
5256
- const { webatlas } = data;
5377
+ const webatlas = data.webatlas && canEditPath ? data.webatlas : await getDefaultRouteData(strapi2, context.uid, data);
5257
5378
  const { slug, parentDocumentId, isOverride } = webatlas || {};
5258
5379
  const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
5259
5380
  if (!transformedSlug) return next();
@@ -5309,17 +5430,28 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
5309
5430
  if (context.action === "update") {
5310
5431
  const data = context.params.data;
5311
5432
  const { documentId } = context.params;
5312
- const { webatlas } = data;
5433
+ const relatedRoute = await strapi2.documents(waRoute).findFirst({
5434
+ filters: {
5435
+ relatedDocumentId: documentId
5436
+ },
5437
+ populate: ["parent"]
5438
+ });
5439
+ let webatlas = data.webatlas;
5440
+ if (!relatedRoute && (!webatlas || !canEditPath)) {
5441
+ webatlas = await getDefaultRouteData(strapi2, context.uid, data);
5442
+ } else if (relatedRoute && webatlas && !canEditPath) {
5443
+ const sourceValue2 = ctSettings?.routeSourceField ? data[ctSettings.routeSourceField] : void 0;
5444
+ webatlas = !relatedRoute.isOverride && typeof sourceValue2 === "string" && sourceValue2.trim() ? {
5445
+ slug: transformToUrl(sourceValue2),
5446
+ parentDocumentId: relatedRoute.parent?.documentId ?? null,
5447
+ isOverride: false
5448
+ } : void 0;
5449
+ }
5313
5450
  const { slug, parentDocumentId, isOverride } = webatlas || {};
5314
5451
  if (!slug) {
5315
5452
  const result3 = await next();
5316
5453
  return result3;
5317
5454
  }
5318
- const relatedRoute = await strapi2.documents(waRoute).findFirst({
5319
- filters: {
5320
- relatedDocumentId: documentId
5321
- }
5322
- });
5323
5455
  let parent = null;
5324
5456
  let isValid = false;
5325
5457
  if (parentDocumentId) {
@@ -5521,9 +5653,6 @@ const register = ({ strapi: strapi2 }) => {
5521
5653
  const config = {
5522
5654
  default: {
5523
5655
  selectedContentTypes: [],
5524
- navigation: {
5525
- maxDepth: 1
5526
- },
5527
5656
  routeBlacklist: []
5528
5657
  },
5529
5658
  validator() {
@@ -5668,6 +5797,13 @@ const schema$1 = {
5668
5797
  default: false,
5669
5798
  configurable: false
5670
5799
  },
5800
+ // Depth index of the deepest allowed level, 0 = root only. Only changed in the plugin settings
5801
+ maxDepth: {
5802
+ type: "integer",
5803
+ default: DEFAULT_NAVIGATION_MAX_DEPTH,
5804
+ min: 0,
5805
+ configurable: false
5806
+ },
5671
5807
  items: {
5672
5808
  type: "relation",
5673
5809
  configurable: false,
@@ -5757,6 +5893,21 @@ const admin$2 = () => ({
5757
5893
  if (!documentId) throw new utils.errors.ValidationError("Route documentId is required");
5758
5894
  return await getAdminService().getRelatedRoute(documentId);
5759
5895
  },
5896
+ async getRelatedRoutes(ctx) {
5897
+ const documentIds = String(ctx.query.documentIds || "").split(",").filter(Boolean);
5898
+ if (documentIds.length === 0) throw new utils.errors.ValidationError("documentIds are required");
5899
+ if (documentIds.length > 100)
5900
+ throw new utils.errors.ValidationError("At most 100 documentIds are allowed");
5901
+ return await getAdminService().getRelatedRoutes(documentIds);
5902
+ },
5903
+ async getNavigationDepths(ctx) {
5904
+ return await getAdminService().getNavigationDepths();
5905
+ },
5906
+ async updateNavigationDepths(ctx) {
5907
+ const { data } = ctx.request.body;
5908
+ if (!Array.isArray(data)) throw new utils.errors.ValidationError("Navigation depths are required");
5909
+ return await getAdminService().updateNavigationDepths(data);
5910
+ },
5760
5911
  async getProhibitedRouteIds(ctx) {
5761
5912
  const { documentId } = ctx.params;
5762
5913
  return await getAdminService().getProhibitedRouteIds(documentId);
@@ -5872,9 +6023,9 @@ const admin$1 = {
5872
6023
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5873
6024
  config: {
5874
6025
  actions: [
5875
- `plugin::${PLUGIN_ID}.settings.general`,
5876
- `plugin::${PLUGIN_ID}.settings.navigation`,
5877
- `plugin::${PLUGIN_ID}.page.navigation`,
6026
+ `plugin::${PLUGIN_ID}.settings.general.read`,
6027
+ `plugin::${PLUGIN_ID}.settings.navigation.read`,
6028
+ `plugin::${PLUGIN_ID}.navigation.read`,
5878
6029
  `plugin::${PLUGIN_ID}.cm.aside`
5879
6030
  ]
5880
6031
  }
@@ -5892,10 +6043,7 @@ const admin$1 = {
5892
6043
  {
5893
6044
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5894
6045
  config: {
5895
- actions: [
5896
- `plugin::${PLUGIN_ID}.settings.general`,
5897
- `plugin::${PLUGIN_ID}.settings.navigation`
5898
- ]
6046
+ actions: [`plugin::${PLUGIN_ID}.settings.general.update`]
5899
6047
  }
5900
6048
  }
5901
6049
  ]
@@ -5928,7 +6076,56 @@ const admin$1 = {
5928
6076
  {
5929
6077
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5930
6078
  config: {
5931
- actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.page.navigation`]
6079
+ actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
6080
+ }
6081
+ }
6082
+ ]
6083
+ }
6084
+ },
6085
+ // The max depth is a structural setting, so it is only changed in the plugin settings
6086
+ {
6087
+ method: "GET",
6088
+ path: "/settings/navigation-depths",
6089
+ handler: "admin.getNavigationDepths",
6090
+ config: {
6091
+ policies: [
6092
+ "admin::isAuthenticatedAdmin",
6093
+ {
6094
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6095
+ config: {
6096
+ actions: [`plugin::${PLUGIN_ID}.settings.navigation.read`]
6097
+ }
6098
+ }
6099
+ ]
6100
+ }
6101
+ },
6102
+ {
6103
+ method: "PUT",
6104
+ path: "/settings/navigation-depths",
6105
+ handler: "admin.updateNavigationDepths",
6106
+ config: {
6107
+ policies: [
6108
+ "admin::isAuthenticatedAdmin",
6109
+ {
6110
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6111
+ config: {
6112
+ actions: [`plugin::${PLUGIN_ID}.settings.navigation.update`]
6113
+ }
6114
+ }
6115
+ ]
6116
+ }
6117
+ },
6118
+ {
6119
+ method: "GET",
6120
+ path: "/route/related/batch",
6121
+ handler: "admin.getRelatedRoutes",
6122
+ config: {
6123
+ policies: [
6124
+ "admin::isAuthenticatedAdmin",
6125
+ {
6126
+ name: `plugin::${PLUGIN_ID}.has-permissions`,
6127
+ config: {
6128
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5932
6129
  }
5933
6130
  }
5934
6131
  ]
@@ -5960,7 +6157,7 @@ const admin$1 = {
5960
6157
  {
5961
6158
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5962
6159
  config: {
5963
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6160
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5964
6161
  }
5965
6162
  }
5966
6163
  ]
@@ -5977,7 +6174,7 @@ const admin$1 = {
5977
6174
  {
5978
6175
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5979
6176
  config: {
5980
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6177
+ actions: [`plugin::${PLUGIN_ID}.navigation.read`]
5981
6178
  }
5982
6179
  }
5983
6180
  ]
@@ -5993,7 +6190,7 @@ const admin$1 = {
5993
6190
  {
5994
6191
  name: `plugin::${PLUGIN_ID}.has-permissions`,
5995
6192
  config: {
5996
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6193
+ actions: [`plugin::${PLUGIN_ID}.navigation.create`]
5997
6194
  }
5998
6195
  }
5999
6196
  ]
@@ -6009,7 +6206,7 @@ const admin$1 = {
6009
6206
  {
6010
6207
  name: `plugin::${PLUGIN_ID}.has-permissions`,
6011
6208
  config: {
6012
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6209
+ actions: [`plugin::${PLUGIN_ID}.navigation.update`]
6013
6210
  }
6014
6211
  }
6015
6212
  ]
@@ -6025,7 +6222,7 @@ const admin$1 = {
6025
6222
  {
6026
6223
  name: `plugin::${PLUGIN_ID}.has-permissions`,
6027
6224
  config: {
6028
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6225
+ actions: [`plugin::${PLUGIN_ID}.navigation.edit-items`]
6029
6226
  }
6030
6227
  }
6031
6228
  ]
@@ -6041,7 +6238,7 @@ const admin$1 = {
6041
6238
  {
6042
6239
  name: `plugin::${PLUGIN_ID}.has-permissions`,
6043
6240
  config: {
6044
- actions: [`plugin::${PLUGIN_ID}.page.navigation`]
6241
+ actions: [`plugin::${PLUGIN_ID}.navigation.delete`]
6045
6242
  }
6046
6243
  }
6047
6244
  ]
@@ -6058,7 +6255,7 @@ const admin$1 = {
6058
6255
  {
6059
6256
  name: `plugin::${PLUGIN_ID}.has-permissions`,
6060
6257
  config: {
6061
- actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.page.navigation`]
6258
+ actions: [`plugin::${PLUGIN_ID}.cm.aside`, `plugin::${PLUGIN_ID}.navigation.read`]
6062
6259
  }
6063
6260
  }
6064
6261
  ]
@@ -6091,6 +6288,36 @@ const routes = {
6091
6288
  admin: admin$1,
6092
6289
  "content-api": client$1
6093
6290
  };
6291
+ async function getNavigationDepths() {
6292
+ const navigations = await strapi.documents(waNavigation).findMany({
6293
+ populate: ["items", "items.parent"]
6294
+ });
6295
+ return navigations.map((navigation2) => {
6296
+ const { items } = buildStructuredNavigation(navigation2, "flat");
6297
+ return {
6298
+ documentId: navigation2.documentId,
6299
+ name: navigation2.name,
6300
+ maxDepth: navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH,
6301
+ deepestDepth: Math.max(-1, ...(items ?? []).map((item) => item.depth ?? 0))
6302
+ };
6303
+ });
6304
+ }
6305
+ async function assertItemDepths(navigationId, navigationItems) {
6306
+ const navigation2 = await strapi.documents(waNavigation).findOne({
6307
+ documentId: navigationId,
6308
+ fields: ["maxDepth"]
6309
+ });
6310
+ if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
6311
+ const maxDepth = navigation2.maxDepth ?? DEFAULT_NAVIGATION_MAX_DEPTH;
6312
+ const tooDeepItem = navigationItems.find(
6313
+ (item) => item.clientModifications?.type !== "delete" && (item.depth ?? 0) > maxDepth
6314
+ );
6315
+ if (tooDeepItem) {
6316
+ throw new utils.errors.ValidationError(
6317
+ `'${tooDeepItem.clientModifications?.title || tooDeepItem.route?.title}' is deeper than the ${maxDepth + 1} level(s) allowed in this navigation`
6318
+ );
6319
+ }
6320
+ }
6094
6321
  const admin = ({ strapi: strapi2 }) => ({
6095
6322
  async updateConfig(newConfig) {
6096
6323
  if (!newConfig) return;
@@ -6113,11 +6340,7 @@ const admin = ({ strapi: strapi2 }) => ({
6113
6340
  const defaultConfig = strapi2.config.get(`plugin::${PLUGIN_ID}`);
6114
6341
  config2 = {
6115
6342
  ...defaultConfig,
6116
- ...config2,
6117
- navigation: {
6118
- ...defaultConfig.navigation,
6119
- ...config2?.navigation
6120
- }
6343
+ ...config2
6121
6344
  };
6122
6345
  return config2;
6123
6346
  },
@@ -6137,6 +6360,13 @@ const admin = ({ strapi: strapi2 }) => ({
6137
6360
  populate: ["parent"]
6138
6361
  });
6139
6362
  },
6363
+ // Path of the routes linked to the given entries, with one query
6364
+ async getRelatedRoutes(documentIds) {
6365
+ return await strapi2.db?.query(waRoute).findMany({
6366
+ where: { relatedDocumentId: { $in: documentIds } },
6367
+ select: ["relatedDocumentId", "path"]
6368
+ });
6369
+ },
6140
6370
  async getProhibitedRouteIds(documentId) {
6141
6371
  let route2 = null;
6142
6372
  if (documentId) {
@@ -6181,6 +6411,16 @@ const admin = ({ strapi: strapi2 }) => ({
6181
6411
  );
6182
6412
  }
6183
6413
  }
6414
+ const navigations = Array.isArray(navigation2) ? navigation2 : [navigation2];
6415
+ const statuses = await getDocumentStatuses(
6416
+ navigations.flatMap((nav) => (nav.items ?? []).map((item) => item.route))
6417
+ );
6418
+ navigations.forEach(
6419
+ (nav) => nav.items?.forEach((item) => {
6420
+ const status = statuses.get(item.route?.relatedDocumentId);
6421
+ if (status) item.status = status;
6422
+ })
6423
+ );
6184
6424
  return navigation2;
6185
6425
  },
6186
6426
  async createNavigation(name, visible) {
@@ -6201,6 +6441,28 @@ const admin = ({ strapi: strapi2 }) => ({
6201
6441
  }
6202
6442
  });
6203
6443
  },
6444
+ async getNavigationDepths() {
6445
+ return await getNavigationDepths();
6446
+ },
6447
+ async updateNavigationDepths(depths) {
6448
+ const currentDepths = await getNavigationDepths();
6449
+ for (const { documentId, maxDepth } of depths) {
6450
+ const current = currentDepths.find((navigation2) => navigation2.documentId === documentId);
6451
+ if (!current) throw new utils.errors.NotFoundError("Navigation not found");
6452
+ if (!Number.isInteger(maxDepth) || maxDepth < 0) {
6453
+ throw new utils.errors.ValidationError(`Invalid max depth for the navigation '${current.name}'`);
6454
+ }
6455
+ if (maxDepth < current.deepestDepth) {
6456
+ throw new utils.errors.ValidationError(
6457
+ `The navigation '${current.name}' already has items on level ${current.deepestDepth + 1}`
6458
+ );
6459
+ }
6460
+ }
6461
+ for (const { documentId, maxDepth } of depths) {
6462
+ await strapi2.documents(waNavigation).update({ documentId, data: { maxDepth } });
6463
+ }
6464
+ return await getNavigationDepths();
6465
+ },
6204
6466
  async deleteNavigation(documentId) {
6205
6467
  const navigation2 = await strapi2.documents(waNavigation).findOne({
6206
6468
  documentId,
@@ -6218,6 +6480,7 @@ const admin = ({ strapi: strapi2 }) => ({
6218
6480
  },
6219
6481
  async updateNavigationItemStructure(navigationId, navigationItems) {
6220
6482
  if (!navigationId || !navigationItems) return;
6483
+ await assertItemDepths(navigationId, navigationItems);
6221
6484
  const errors2 = [];
6222
6485
  let newNavItemsMap = /* @__PURE__ */ new Map();
6223
6486
  const deletionResult = await handleItemDeletion(navigationItems);