From daeec843ef06eed666a14231007265383d641265 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Tue, 30 Jan 2024 09:09:16 -0800 Subject: [PATCH] Cleanup Admin Menu (#15199) --- .../OrchardCore.Admin/AdminMenu.cs | 17 +++- .../OrchardCore.Admin/AdminMenuFilter.cs | 3 +- .../OrchardCore.AdminMenu/AdminMenu.cs | 15 +-- ...AdminMenuNavigationProvidersCoordinator.cs | 6 +- .../OrchardCore.Apis.GraphQL/AdminMenu.cs | 7 +- .../Navigation/AuditTrailAdminMenu.cs | 18 +++- .../Navigation/AuditTrailSettingsAdminMenu.cs | 22 +++-- .../OrchardCore.BackgroundTasks/AdminMenu.cs | 5 +- .../AdminMenu.cs | 30 ++++-- .../OrchardCore.ContentTypes/AdminMenu.cs | 33 ++++--- .../OrchardCore.Contents/AdminMenu.cs | 32 ++++--- ...xportContentToDeploymentTargetAdminMenu.cs | 14 ++- ...ToDeploymentTargetSettingsDisplayDriver.cs | 6 +- .../OrchardCore.Cors/AdminMenu.cs | 15 +-- .../OrchardCore.CustomSettings/AdminMenu.cs | 29 ++++-- .../OrchardCore.Demo/AdminMenu.cs | 21 ++-- .../AdminMenu.cs | 7 +- .../OrchardCore.Deployment/AdminMenu.cs | 9 +- .../OrchardCore.Email/AdminMenu.cs | 20 +++- .../OrchardCore.Facebook/AdminMenu.cs | 36 +++++-- .../OrchardCore.Features/AdminMenu.cs | 14 ++- .../AdminMenuGitHubLogin.cs | 31 ++++-- .../GoogleAuthenticationAdminMenu.cs | 96 +++++++++++++------ .../OrchardCore.Https/AdminMenu.cs | 18 +++- .../Drivers/HttpsSettingsDisplayDriver.cs | 6 +- .../OrchardCore.Layers/AdminMenu.cs | 20 ++-- .../OrchardCore.Localization/AdminMenu.cs | 40 +++++--- .../OrchardCore.Media.AmazonS3/AdminMenu.cs | 11 ++- .../OrchardCore.Media.Azure/AdminMenu.cs | 11 ++- .../OrchardCore.Media/AdminMenu.cs | 28 +++--- .../OrchardCore.Menu/AdminMenu.cs | 27 +++--- .../AdminMenuMicrosoftAccount.cs | 60 ++++++++---- .../OrchardCore.OpenId/AdminMenu.cs | 12 ++- .../OrchardCore.Placements/AdminMenu.cs | 5 +- .../OrchardCore.Queries/AdminMenu.cs | 16 ++-- .../OrchardCore.Queries/Sql/AdminMenu.cs | 10 +- .../OrchardCore.ReCaptcha/AdminMenu.cs | 18 +++- .../OrchardCore.Recipes/AdminMenu.cs | 16 ++-- .../OrchardCore.ReverseProxy/AdminMenu.cs | 36 ++++--- .../ReverseProxySettingsDisplayDriver.cs | 7 +- .../OrchardCore.Roles/AdminMenu.cs | 19 ++-- .../OrchardCore.Search.AzureAI/AdminMenu.cs | 2 +- .../AdminMenu.cs | 13 ++- .../OrchardCore.Search.Lucene/AdminMenu.cs | 13 ++- .../OrchardCore.Search/AdminMenu.cs | 16 +++- .../OrchardCore.Security/AdminMenu.cs | 32 +++++-- .../OrchardCore.Seo/AdminMenu.cs | 18 ++-- .../OrchardCore.Settings/AdminMenu.cs | 29 +++--- .../OrchardCore.Shortcodes/AdminMenu.cs | 5 +- .../OrchardCore.Sitemaps/AdminMenu.cs | 19 ++-- .../OrchardCore.Sms/AdminMenu.cs | 14 ++- .../OrchardCore.Taxonomies/AdminMenu.cs | 30 ++++-- .../OrchardCore.Templates/AdminMenu.cs | 5 +- .../AdminTemplatesAdminMenu.cs | 5 +- .../OrchardCore.Tenants/AdminMenu.cs | 5 +- .../FeatureProfilesAdminMenu.cs | 5 +- .../OrchardCore.Themes/AdminMenu.cs | 7 +- .../OrchardCore.Twitter/AdminMenuSignin.cs | 60 ++++++++---- .../OrchardCore.Users/AdminMenu.cs | 89 +++++++++++------ .../OrchardCore.Workflows/AdminMenu.cs | 13 ++- .../TheAdmin/Views/Navigation-admin.cshtml | 3 +- .../NavigationConstants.cs | 23 ++--- .../NavigationHelper.cs | 9 +- src/docs/releases/1.9.0.md | 48 +++++++++- 64 files changed, 850 insertions(+), 459 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs index 52eb6040747..dea3065f327 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Admin.Drivers; using OrchardCore.Navigation; @@ -8,6 +8,12 @@ namespace OrchardCore.Admin { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", AdminSiteSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,7 +23,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -26,12 +32,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings .Add(S["Admin"], S["Admin"].PrefixPosition(), admin => admin - .AddClass("admin").Id("admin") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = AdminSiteSettingsDisplayDriver.GroupId }) + .AddClass("admin").Id("admin") + .Action("Index", "Admin", _routeValues) .Permission(PermissionsAdminSettings.ManageAdminSettings) .LocalNav() ) - )); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs index 6ac854384bd..462f2338179 100644 --- a/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Admin/AdminMenuFilter.cs @@ -3,6 +3,7 @@ using OrchardCore.DisplayManagement; using OrchardCore.DisplayManagement.Layout; using OrchardCore.DisplayManagement.Shapes; +using OrchardCore.Navigation; namespace OrchardCore.Admin { @@ -57,7 +58,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext filterContext, R var menuShape = await _shapeFactory.CreateAsync("Navigation", Arguments.From(new { - MenuName = "admin", + MenuName = NavigationConstants.AdminId, filterContext.RouteData, })); diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs index a24415a7b16..84e2721d894 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.AdminMenu.Services; @@ -20,21 +19,23 @@ public AdminMenu(AdminMenuNavigationProvidersCoordinator adminMenuNavigationProv public async Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return; } // Configuration and settings menus for the AdminMenu module - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), admt => admt + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Admin Menus"], S["Admin Menus"].PrefixPosition(), adminMenu => adminMenu .Permission(Permissions.ManageAdminMenu) - .Action("List", "Menu", new { area = "OrchardCore.AdminMenu" }) + .Action("List", "Menu", "OrchardCore.AdminMenu") .LocalNav() - )); + ) + ); // This is the entry point for the adminMenu: dynamically generated custom admin menus - await _adminMenuNavigationProvider.BuildNavigationAsync("adminMenu", builder); + await _adminMenuNavigationProvider.BuildNavigationAsync(NavigationConstants.AdminMenuId, builder); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Services/AdminMenuNavigationProvidersCoordinator.cs b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Services/AdminMenuNavigationProvidersCoordinator.cs index 4f9e2448515..72dcdd35f0a 100644 --- a/src/OrchardCore.Modules/OrchardCore.AdminMenu/Services/AdminMenuNavigationProvidersCoordinator.cs +++ b/src/OrchardCore.Modules/OrchardCore.AdminMenu/Services/AdminMenuNavigationProvidersCoordinator.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -39,12 +38,13 @@ public AdminMenuNavigationProvidersCoordinator( // todo: use a public constant for the string public async Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "adminMenu", StringComparison.OrdinalIgnoreCase)) + if (!string.Equals(NavigationConstants.AdminMenuId, name)) { return; } - var trees = (await _adminMenuService.GetAdminMenuListAsync()).AdminMenu.Where(m => m.Enabled && m.MenuItems.Count > 0); + var trees = (await _adminMenuService.GetAdminMenuListAsync()) + .AdminMenu.Where(m => m.Enabled && m.MenuItems.Count > 0); foreach (var tree in trees) { diff --git a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs index bcc0c6cc80d..bb84d4f87e4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Apis.GraphQL/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,15 +15,15 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } builder .Add(S["Configuration"], configuration => configuration - .Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), deployment => deployment - .Action("Index", "Admin", new { area = "OrchardCore.Apis.GraphQL" }) + .Add(S["GraphiQL"], S["GraphiQL"].PrefixPosition(), graphiQL => graphiQL + .Action("Index", "Admin", "OrchardCore.Apis.GraphQL") .Permission(Permissions.ExecuteGraphQL) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailAdminMenu.cs index 8df6344cd12..b56cd76f432 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailAdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.AuditTrail.Controllers; using OrchardCore.Navigation; @@ -8,6 +8,12 @@ namespace OrchardCore.AuditTrail.Navigation { public class AuditTrailAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.AuditTrail" }, + { "correlationId", string.Empty }, + }; + protected readonly IStringLocalizer S; public AuditTrailAdminMenu(IStringLocalizer stringLocalizer) @@ -17,17 +23,19 @@ public AuditTrailAdminMenu(IStringLocalizer stringLocalizer public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } builder .Add(S["Audit Trail"], NavigationConstants.AdminMenuAuditTrailPosition, configuration => configuration - .AddClass("audittrail").Id("audittrail") - .Action(nameof(AdminController.Index), "Admin", new { area = "OrchardCore.AuditTrail", correlationId = "" }) + .AddClass("audittrail") + .Id("audittrail") + .Action(nameof(AdminController.Index), "Admin", _routeValues) .Permission(AuditTrailPermissions.ViewAuditTrail) - .LocalNav()); + .LocalNav() + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailSettingsAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailSettingsAdminMenu.cs index 1ffa49a4c44..570e337e0f9 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailSettingsAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Navigation/AuditTrailSettingsAdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.AuditTrail.Settings; using OrchardCore.Navigation; @@ -8,6 +8,12 @@ namespace OrchardCore.AuditTrail.Navigation { public class AuditTrailSettingsAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", AuditTrailSettingsGroup.Id }, + }; + protected readonly IStringLocalizer S; public AuditTrailSettingsAdminMenu(IStringLocalizer stringLocalizer) @@ -17,7 +23,7 @@ public AuditTrailSettingsAdminMenu(IStringLocalizer public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,11 +31,15 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings - .Add(S["Audit Trail"], S["Audit Trail"].PrefixPosition(), settings => settings - .AddClass("audittrail").Id("audittrailSettings") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = AuditTrailSettingsGroup.Id }) + .Add(S["Audit Trail"], S["Audit Trail"].PrefixPosition(), auditTrail => auditTrail + .AddClass("audittrail") + .Id("audittrailSettings") + .Action("Index", "Admin", _routeValues) .Permission(AuditTrailPermissions.ManageAuditTrailSettings) - .LocalNav()))); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/AdminMenu.cs index b09d182d14c..d2b4569ef92 100644 --- a/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.BackgroundTasks/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -13,7 +12,7 @@ public class AdminMenu : INavigationProvider public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -22,7 +21,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Tasks"], S["Tasks"].PrefixPosition(), tasks => tasks .Add(S["Background Tasks"], S["Background Tasks"].PrefixPosition(), backgroundTasks => backgroundTasks - .Action("Index", "BackgroundTask", new { area = "OrchardCore.BackgroundTasks" }) + .Action("Index", "BackgroundTask", "OrchardCore.BackgroundTasks") .Permission(Permissions.ManageBackgroundTasks) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/AdminMenu.cs index 3eaef3f0b8f..0b8726ff7db 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.ContentLocalization.Drivers; using OrchardCore.Modules; @@ -10,6 +10,18 @@ namespace OrchardCore.ContentLocalization [Feature("OrchardCore.ContentLocalization.ContentCulturePicker")] public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _providersRouteValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ContentRequestCultureProviderSettingsDriver.GroupId }, + }; + + private static readonly RouteValueDictionary _pickerRouteValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ContentCulturePickerSettingsDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -19,7 +31,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -28,15 +40,17 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings .Add(S["Localization"], localization => localization - .Add(S["Content Request Culture Provider"], S["Content Request Culture Provider"].PrefixPosition(), registration => registration - .AddClass("contentrequestcultureprovider").Id("contentrequestcultureprovider") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ContentRequestCultureProviderSettingsDriver.GroupId }) + .Add(S["Content Request Culture Provider"], S["Content Request Culture Provider"].PrefixPosition(), provider => provider + .AddClass("contentrequestcultureprovider") + .Id("contentrequestcultureprovider") + .Action("Index", "Admin", _providersRouteValues) .Permission(Permissions.ManageContentCulturePicker) .LocalNav() ) - .Add(S["Content Culture Picker"], S["Content Culture Picker"].PrefixPosition(), registration => registration - .AddClass("contentculturepicker").Id("contentculturepicker") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ContentCulturePickerSettingsDriver.GroupId }) + .Add(S["Content Culture Picker"], S["Content Culture Picker"].PrefixPosition(), picker => picker + .AddClass("contentculturepicker") + .Id("contentculturepicker") + .Action("Index", "Admin", _pickerRouteValues) .Permission(Permissions.ManageContentCulturePicker) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs index 4a054e7a533..f6bc91032ad 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.ContentTypes.Controllers; @@ -9,6 +8,8 @@ namespace OrchardCore.ContentTypes { public class AdminMenu : INavigationProvider { + private static readonly string _adminControllerName = typeof(AdminController).ControllerName(); + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -18,24 +19,26 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - var adminControllerName = typeof(AdminController).ControllerName(); - - builder.Add(S["Content"], content => content - .Add(S["Content Definition"], S["Content Definition"].PrefixPosition("9"), contentDefinition => contentDefinition - .Add(S["Content Types"], S["Content Types"].PrefixPosition("1"), contentTypes => contentTypes - .Action(nameof(AdminController.List), adminControllerName, new { area = "OrchardCore.ContentTypes" }) - .Permission(Permissions.ViewContentTypes) - .LocalNav()) - .Add(S["Content Parts"], S["Content Parts"].PrefixPosition("2"), contentParts => contentParts - .Action(nameof(AdminController.ListParts), adminControllerName, new { area = "OrchardCore.ContentTypes" }) - .Permission(Permissions.ViewContentTypes) - .LocalNav()) - )); + builder + .Add(S["Content"], content => content + .Add(S["Content Definition"], S["Content Definition"].PrefixPosition("9"), contentDefinition => contentDefinition + .Add(S["Content Types"], S["Content Types"].PrefixPosition("1"), contentTypes => contentTypes + .Action(nameof(AdminController.List), _adminControllerName, "OrchardCore.ContentTypes") + .Permission(Permissions.ViewContentTypes) + .LocalNav() + ) + .Add(S["Content Parts"], S["Content Parts"].PrefixPosition("2"), contentParts => contentParts + .Action(nameof(AdminController.ListParts), _adminControllerName, "OrchardCore.ContentTypes") + .Permission(Permissions.ViewContentTypes) + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs index 35681e1a269..6d96db5449b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; @@ -11,7 +10,6 @@ using OrchardCore.ContentManagement.Metadata.Models; using OrchardCore.Contents.Controllers; using OrchardCore.Contents.Security; -using OrchardCore.Entities; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Navigation; using OrchardCore.Settings; @@ -20,6 +18,19 @@ namespace OrchardCore.Contents { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Contents" }, + { "contentTypeId", string.Empty }, + }; + + private static readonly RouteValueDictionary _adminListRouteValues = new() + { + { "area", "OrchardCore.Contents" }, + { "controller", "Admin" }, + { "Action", "List" }, + }; + private readonly IContentDefinitionManager _contentDefinitionManager; private readonly IContentManager _contentManager; private readonly IHttpContextAccessor _httpContextAccessor; @@ -48,13 +59,13 @@ public AdminMenu( public async Task BuildNavigationAsync(string name, NavigationBuilder builder) { - var context = _httpContextAccessor.HttpContext; - - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return; } + var context = _httpContextAccessor.HttpContext; + var contentTypeDefinitions = (await _contentDefinitionManager.ListTypeDefinitionsAsync()).OrderBy(d => d.Name); var contentTypes = contentTypeDefinitions.Where(ctd => ctd.IsCreatable()).OrderBy(ctd => ctd.DisplayName); await builder.AddAsync(S["Content"], NavigationConstants.AdminMenuContentPosition, async content => @@ -67,7 +78,7 @@ await content.AddAsync(S["Content Items"], S["Content Items"].PrefixPosition(), contentItems.Permission(Permissions.ListContent); } - contentItems.Action(nameof(AdminController.List), typeof(AdminController).ControllerName(), new { area = "OrchardCore.Contents", contentTypeId = "" }); + contentItems.Action(nameof(AdminController.List), typeof(AdminController).ControllerName(), _routeValues); contentItems.LocalNav(); }); }); @@ -84,14 +95,9 @@ await builder.AddAsync(S["New"], "-1", async newMenu => var ci = await _contentManager.NewAsync(contentTypeDefinition.Name); var cim = await _contentManager.PopulateAspectAsync(ci); var createRouteValues = cim.CreateRouteValues; - createRouteValues.Add("returnUrl", _linkGenerator.GetPathByRouteValues(context, "", new - { - area = "OrchardCore.Contents", - controller = "Admin", - action = "List" - })); + createRouteValues.Add("returnUrl", _linkGenerator.GetPathByRouteValues(context, string.Empty, _adminListRouteValues)); - if (createRouteValues.Any()) + if (createRouteValues.Count > 0) { newMenu.Add(new LocalizedString(contentTypeDefinition.DisplayName, contentTypeDefinition.DisplayName), "5", item => item .Action(cim.CreateRouteValues["Action"] as string, cim.CreateRouteValues["Controller"] as string, cim.CreateRouteValues) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetAdminMenu.cs index 6ed5023654f..fd2ddc2d675 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetAdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,6 +7,12 @@ namespace OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget { public class ExportContentToDeploymentTargetAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ExportContentToDeploymentTargetSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public ExportContentToDeploymentTargetAdminMenu(IStringLocalizer localizer) @@ -16,7 +22,7 @@ public ExportContentToDeploymentTargetAdminMenu(IStringLocalizer loca public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,8 +31,8 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Import/Export"], S["Import/Export"].PrefixPosition(), import => import .Add(S["Settings"], settings => settings - .Add(S["Export Target Settings"], S["Export Target Settings"].PrefixPosition(), deployment => deployment - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "ExportContentToDeploymentTarget" }) + .Add(S["Export Target Settings"], S["Export Target Settings"].PrefixPosition(), targetSettings => targetSettings + .Action("Index", "Admin", _routeValues) .Permission(OrchardCore.Deployment.CommonPermissions.ManageDeploymentPlan) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetSettingsDisplayDriver.cs index e3885b41ae8..a6eb5199659 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetSettingsDisplayDriver.cs @@ -10,7 +10,7 @@ namespace OrchardCore.Contents.Deployment.ExportContentToDeploymentTarget { public class ExportContentToDeploymentTargetSettingsDisplayDriver : SectionDisplayDriver { - private const string SettingsGroupId = "ExportContentToDeploymentTarget"; + public const string GroupId = "ExportContentToDeploymentTarget"; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IAuthorizationService _authorizationService; @@ -34,12 +34,12 @@ public override async Task EditAsync(ExportContentToDeploymentTa return Initialize("ExportContentToDeploymentTargetSettings_Edit", model => { model.ExportContentToDeploymentTargetPlanId = settings.ExportContentToDeploymentTargetPlanId; - }).Location("Content:2").OnGroup(SettingsGroupId); + }).Location("Content:2").OnGroup(GroupId); } public override async Task UpdateAsync(ExportContentToDeploymentTargetSettings settings, BuildEditorContext context) { - if (context.GroupId == SettingsGroupId) + if (context.GroupId == GroupId) { var model = new ExportContentToDeploymentTargetSettingsViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Cors/AdminMenu.cs index f1397485da7..42c87f5c944 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,16 +6,16 @@ namespace OrchardCore.Cors { public class AdminMenu : INavigationProvider { + protected readonly IStringLocalizer S; + public AdminMenu(IStringLocalizer localizer) { S = localizer; } - public IStringLocalizer S { get; set; } - public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,11 +24,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings .Add(S["CORS"], S["CORS"].PrefixPosition(), entry => entry - .AddClass("cors").Id("cors") - .Action("Index", "Admin", new { area = "OrchardCore.Cors" }) + .AddClass("cors") + .Id("cors") + .Action("Index", "Admin", "OrchardCore.Cors") .Permission(Permissions.ManageCorsSettings) .LocalNav() - )) + ) + ) ); return Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs index 204b67e4032..beff6af04e2 100644 --- a/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.CustomSettings/AdminMenu.cs @@ -1,5 +1,6 @@ -using System; +using System.Collections.Concurrent; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.CustomSettings.Services; using OrchardCore.Mvc.Utilities; @@ -11,6 +12,7 @@ public class AdminMenu : INavigationProvider { private readonly CustomSettingsService _customSettingsService; protected readonly IStringLocalizer S; + private static readonly ConcurrentDictionary _routeValues = []; public AdminMenu( IStringLocalizer localizer, @@ -22,24 +24,39 @@ public AdminMenu( public async Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return; } foreach (var type in await _customSettingsService.GetAllSettingsTypesAsync()) { + if (!_routeValues.TryGetValue(type.Name, out var routeValues)) + { + routeValues = new RouteValueDictionary() + { + { "area", "OrchardCore.Settings" }, + { "groupId", type.Name }, + }; + + _routeValues[type.Name] = routeValues; + } + + var htmlName = type.Name.HtmlClassify(); + builder .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings .Add(new LocalizedString(type.DisplayName, type.DisplayName), type.DisplayName.PrefixPosition(), layers => layers - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = type.Name }) - .AddClass(type.Name.HtmlClassify()) - .Id(type.Name.HtmlClassify()) + .Action("Index", "Admin", routeValues) + .AddClass(htmlName) + .Id(htmlName) .Permission(Permissions.CreatePermissionForType(type)) .Resource(type.Name) .LocalNav() - ))); + ) + ) + ); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Demo/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Demo/AdminMenu.cs index 923b6e03631..993f99fe401 100644 --- a/src/OrchardCore.Modules/OrchardCore.Demo/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Demo/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -26,29 +25,29 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .AddClass("demo").Id("demo") .Add(S["This Menu Item 1"], "0", item => item .Add(S["This is Menu Item 1.1"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) .Add(S["This is Menu Item 1.2"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) .Add(S["This is Menu Item 1.2"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) ) .Add(S["This Menu Item 2"], "0", item => item .Add(S["This is Menu Item 2.1"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) .Add(S["This is Menu Item 2.2"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) .Add(S["This is Menu Item 3.2"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) ) .Add(S["This Menu Item 3"], "0", item => item .Add(S["This is Menu Item 3.1"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) .Add(S["This is Menu Item 3.2"], subItem => subItem - .Action("Index", "Admin", new { area = "OrchardCore.Demo" })) + .Action("Index", "Admin", "OrchardCore.Demo")) ) .Add(S["Todo (Liquid - Frontend)"], "0", item => item - .Action("Index", "Todo", new { area = "OrchardCore.Demo" }) + .Action("Index", "Todo", "OrchardCore.Demo") ) ); diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/AdminMenu.cs index 11e3e3639bd..2d2b9cce254 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment.Remote/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,12 +24,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Import/Export"], import => import .Add(S["Remote Instances"], S["Remote Instances"].PrefixPosition(), remote => remote - .Action("Index", "RemoteInstance", new { area = "OrchardCore.Deployment.Remote" }) + .Action("Index", "RemoteInstance", "OrchardCore.Deployment.Remote") .Permission(Permissions.ManageRemoteInstances) .LocalNav() ) .Add(S["Remote Clients"], S["Remote Clients"].PrefixPosition(), remote => remote - .Action("Index", "RemoteClient", new { area = "OrchardCore.Deployment.Remote" }) + .Action("Index", "RemoteClient", "OrchardCore.Deployment.Remote") .Permission(Permissions.ManageRemoteClients) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Deployment/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Deployment/AdminMenu.cs index 9630bb5924c..0fec8dc7bf5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Deployment/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Deployment/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,17 +24,17 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Configuration"], configuration => configuration .Add(S["Import/Export"], S["Import/Export"].PrefixPosition(), import => import .Add(S["Deployment Plans"], S["Deployment Plans"].PrefixPosition(), deployment => deployment - .Action("Index", "DeploymentPlan", new { area = "OrchardCore.Deployment" }) + .Action("Index", "DeploymentPlan", "OrchardCore.Deployment") .Permission(Permissions.Export) .LocalNav() ) .Add(S["Package Import"], S["Package Import"].PrefixPosition(), deployment => deployment - .Action("Index", "Import", new { area = "OrchardCore.Deployment" }) + .Action("Index", "Import", "OrchardCore.Deployment") .Permission(Permissions.Import) .LocalNav() ) .Add(S["JSON Import"], S["JSON Import"].PrefixPosition(), deployment => deployment - .Action("Json", "Import", new { area = "OrchardCore.Deployment" }) + .Action("Json", "Import", "OrchardCore.Deployment") .Permission(Permissions.Import) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Email/AdminMenu.cs index 60052f7a79e..f4db7cac39a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Email.Drivers; using OrchardCore.Navigation; @@ -8,6 +8,12 @@ namespace OrchardCore.Email { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", SmtpSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,18 +23,22 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) + { return Task.CompletedTask; + } builder .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings .Add(S["Email"], S["Email"].PrefixPosition(), entry => entry - .AddClass("email").Id("email") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SmtpSettingsDisplayDriver.GroupId }) + .AddClass("email").Id("email") + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageEmailSettings) .LocalNav() - ))); + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/AdminMenu.cs index cbf9083e13d..c149d0cf2e1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,6 +7,12 @@ namespace OrchardCore.Facebook; public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", FacebookConstants.Features.Core }, + }; + protected readonly IStringLocalizer S; public AdminMenu( @@ -17,7 +23,7 @@ public AdminMenu( public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,10 +31,10 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Configuration"], configuration => configuration .Add(S["Settings"], settings => settings - .Add(S["Meta App"], S["Meta App"].PrefixPosition(), facebook => facebook + .Add(S["Meta App"], S["Meta App"].PrefixPosition(), metaApp => metaApp .AddClass("facebookApp") .Id("facebookApp") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = FacebookConstants.Features.Core }) + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageFacebookApp) .LocalNav() ) @@ -41,6 +47,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) public class AdminMenuLogin : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", FacebookConstants.Features.Login }, + }; + protected readonly IStringLocalizer S; public AdminMenuLogin( @@ -51,7 +63,7 @@ public AdminMenuLogin( public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -59,10 +71,10 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Security"], security => security .Add(S["Authentication"], authentication => authentication - .Add(S["Meta"], S["Meta"].PrefixPosition(), settings => settings + .Add(S["Meta"], S["Meta"].PrefixPosition(), meta => meta .AddClass("facebook") .Id("facebook") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = FacebookConstants.Features.Login }) + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageFacebookApp) .LocalNav() ) @@ -75,6 +87,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) public class AdminMenuPixel : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", FacebookConstants.PixelSettingsGroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenuPixel( @@ -85,7 +103,7 @@ public AdminMenuPixel( public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -96,7 +114,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Meta Pixel"], S["Meta Pixel"].PrefixPosition(), pixel => pixel .AddClass("facebookPixel") .Id("facebookPixel") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = FacebookConstants.PixelSettingsGroupId }) + .Action("Index", "Admin", _routeValues) .Permission(FacebookConstants.ManageFacebookPixelPermission) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Features/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Features/AdminMenu.cs index 980f5d73619..c7bd974eef4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Features/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Features/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,6 +7,13 @@ namespace OrchardCore.Features { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", FeaturesConstants.FeatureId }, + // Since features admin accepts tenant, always pass empty string to create valid link for current tenant. + { "tenant", string.Empty }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -16,7 +23,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,8 +31,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Configuration"], configuration => configuration .Add(S["Features"], S["Features"].PrefixPosition(), deployment => deployment - // Since features admin accepts tenant, always pass empty string to create valid link for current tenant. - .Action("Features", "Admin", new { area = FeaturesConstants.FeatureId, tenant = string.Empty }) + .Action("Features", "Admin", _routeValues) .Permission(Permissions.ManageFeatures) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/AdminMenuGitHubLogin.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/AdminMenuGitHubLogin.cs index f7669b986d4..3bf0dbd3176 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/AdminMenuGitHubLogin.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/AdminMenuGitHubLogin.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Modules; using OrchardCore.Navigation; @@ -9,6 +9,12 @@ namespace OrchardCore.GitHub [Feature(GitHubConstants.Features.GitHubAuthentication)] public class AdminMenuGitHubLogin : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", GitHubConstants.Features.GitHubAuthentication }, + }; + protected readonly IStringLocalizer S; public AdminMenuGitHubLogin(IStringLocalizer localizer) @@ -18,17 +24,24 @@ public AdminMenuGitHubLogin(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Security"], security => security - .Add(S["Authentication"], authentication => authentication + return Task.CompletedTask; + } + + builder + .Add(S["Security"], security => security + .Add(S["Authentication"], authentication => authentication .Add(S["GitHub"], S["GitHub"].PrefixPosition(), settings => settings - .AddClass("github").Id("github") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = GitHubConstants.Features.GitHubAuthentication }) + .AddClass("github") + .Id("github") + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageGitHubAuthentication) - .LocalNav()) - )); - } + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Google/GoogleAuthenticationAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Google/GoogleAuthenticationAdminMenu.cs index d3e986ade47..425dfc883e9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/GoogleAuthenticationAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/GoogleAuthenticationAdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Modules; using OrchardCore.Navigation; @@ -9,6 +9,12 @@ namespace OrchardCore.Google [Feature(GoogleConstants.Features.GoogleAuthentication)] public class GoogleAuthenticationAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", GoogleConstants.Features.GoogleAuthentication }, + }; + protected readonly IStringLocalizer S; public GoogleAuthenticationAdminMenu(IStringLocalizer localizer) @@ -18,17 +24,24 @@ public GoogleAuthenticationAdminMenu(IStringLocalizer security - .Add(S["Authentication"], authentication => authentication - .Add(S["Google"], S["Google"].PrefixPosition(), settings => settings - .AddClass("google").Id("google") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = GoogleConstants.Features.GoogleAuthentication }) - .Permission(Permissions.ManageGoogleAuthentication) - .LocalNav()) - )); + return Task.CompletedTask; } + + builder + .Add(S["Security"], security => security + .Add(S["Authentication"], authentication => authentication + .Add(S["Google"], S["Google"].PrefixPosition(), google => google + .AddClass("google") + .Id("google") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageGoogleAuthentication) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } @@ -36,6 +49,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature(GoogleConstants.Features.GoogleAnalytics)] public class GoogleAnalyticsAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", GoogleConstants.Features.GoogleAnalytics }, + }; + protected readonly IStringLocalizer S; public GoogleAnalyticsAdminMenu(IStringLocalizer localizer) @@ -45,18 +64,23 @@ public GoogleAnalyticsAdminMenu(IStringLocalizer local public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], settings => settings - .Add(S["Google Analytics"], S["Google Analytics"].PrefixPosition(), settings => settings - .AddClass("googleAnalytics").Id("googleAnalytics") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = GoogleConstants.Features.GoogleAnalytics }) - .Permission(Permissions.ManageGoogleAnalytics) - .LocalNav()) - ) - ); + return Task.CompletedTask; } + + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Google Analytics"], S["Google Analytics"].PrefixPosition(), google => google + .AddClass("googleAnalytics").Id("googleAnalytics") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageGoogleAnalytics) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } @@ -64,6 +88,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature(GoogleConstants.Features.GoogleTagManager)] public class GoogleTagManagerAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", GoogleConstants.Features.GoogleTagManager }, + }; + protected readonly IStringLocalizer S; public GoogleTagManagerAdminMenu(IStringLocalizer localizer) @@ -73,18 +103,24 @@ public GoogleTagManagerAdminMenu(IStringLocalizer loc public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], settings => settings - .Add(S["Google Tag Manager"], S["Google Tag Manager"].PrefixPosition(), settings => settings - .AddClass("googleTagManager").Id("googleTagManager") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = GoogleConstants.Features.GoogleTagManager }) - .Permission(Permissions.ManageGoogleTagManager) - .LocalNav()) - ) - ); + return Task.CompletedTask; } + + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Google Tag Manager"], S["Google Tag Manager"].PrefixPosition(), google => google + .AddClass("googleTagManager") + .Id("googleTagManager") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageGoogleTagManager) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Https/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Https/AdminMenu.cs index 551e02a74f0..4ddb15109ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Https/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Https/AdminMenu.cs @@ -1,12 +1,19 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; +using OrchardCore.Https.Drivers; using OrchardCore.Navigation; namespace OrchardCore.Https { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", HttpsSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -16,7 +23,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,11 +31,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Security"], security => security .Add(S["Settings"], settings => settings - .Add(S["HTTPS"], S["HTTPS"].PrefixPosition(), entry => entry - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "Https" }) + .Add(S["HTTPS"], S["HTTPS"].PrefixPosition(), https => https + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageHttps) .LocalNav() - )) + ) + ) ); return Task.CompletedTask; diff --git a/src/OrchardCore.Modules/OrchardCore.Https/Drivers/HttpsSettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Https/Drivers/HttpsSettingsDisplayDriver.cs index 262b0537344..f9d84ae91bb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Https/Drivers/HttpsSettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Https/Drivers/HttpsSettingsDisplayDriver.cs @@ -15,7 +15,7 @@ namespace OrchardCore.Https.Drivers { public class HttpsSettingsDisplayDriver : SectionDisplayDriver { - private const string SettingsGroupId = "Https"; + public const string GroupId = "Https"; private readonly IHttpContextAccessor _httpContextAccessor; private readonly IAuthorizationService _authorizationService; @@ -62,12 +62,12 @@ public override async Task EditAsync(HttpsSettings settings, Bui (isHttpsRequest && !settings.RequireHttps ? _httpContextAccessor.HttpContext.Request.Host.Port : null); - }).Location("Content:2").OnGroup(SettingsGroupId); + }).Location("Content:2").OnGroup(GroupId); } public override async Task UpdateAsync(HttpsSettings settings, BuildEditorContext context) { - if (context.GroupId == SettingsGroupId) + if (context.GroupId == GroupId) { var user = _httpContextAccessor.HttpContext?.User; if (!await _authorizationService.AuthorizeAsync(user, Permissions.ManageHttps)) diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Layers/AdminMenu.cs index f11f3776f9c..3d89f76db7e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Layers.Drivers; using OrchardCore.Navigation; @@ -8,6 +8,12 @@ namespace OrchardCore.Layers { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", LayerSiteSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,7 +23,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -26,15 +32,17 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Design"], design => design .Add(S["Settings"], settings => settings .Add(S["Zones"], S["Zones"].PrefixPosition(), zones => zones - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = LayerSiteSettingsDisplayDriver.GroupId }) + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageLayers) .LocalNav() - )) + ) + ) .Add(S["Widgets"], S["Widgets"].PrefixPosition(), widgets => widgets .Permission(Permissions.ManageLayers) - .Action("Index", "Admin", new { area = "OrchardCore.Layers" }) + .Action("Index", "Admin", "OrchardCore.Layers") .LocalNav() - )); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Localization/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Localization/AdminMenu.cs index 6037ac1cb48..9833e105353 100644 --- a/src/OrchardCore.Modules/OrchardCore.Localization/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Localization/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Localization.Drivers; using OrchardCore.Navigation; @@ -11,6 +11,12 @@ namespace OrchardCore.Localization /// public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", LocalizationSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; /// @@ -25,23 +31,27 @@ public AdminMenu(IStringLocalizer localizer) /// public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder - .Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], settings => settings - .Add(S["Localization"], localization => localization - .AddClass("localization").Id("localization") - .Add(S["Cultures"], S["Cultures"].PrefixPosition(), entry => entry - .AddClass("cultures").Id("cultures") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = LocalizationSettingsDisplayDriver.GroupId }) - .Permission(Permissions.ManageCultures) - .LocalNav() - ) + return Task.CompletedTask; + } + + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Localization"], localization => localization + .AddClass("localization") + .Id("localization") + .Add(S["Cultures"], S["Cultures"].PrefixPosition(), cultures => cultures + .AddClass("cultures") + .Id("cultures") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageCultures) + .LocalNav() ) ) - ); - } + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AdminMenu.cs index d837e44d4ee..c0d1515c551 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.AmazonS3/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,10 +23,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder.Add(S["Configuration"], configuration => configuration .Add(S["Media"], S["Media"].PrefixPosition(), media => media .Add(S["Amazon S3 Options"], S["Amazon S3 Options"].PrefixPosition(), options => options - .Action("Options", "Admin", new { area = "OrchardCore.Media.AmazonS3" }) + .Action("Options", "Admin", "OrchardCore.Media.AmazonS3") .Permission(Permissions.ViewAmazonS3MediaOptions) - .LocalNav()) - )); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Media.Azure/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Media.Azure/AdminMenu.cs index 884aee78f11..0a1cb02248f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.Azure/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.Azure/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,10 +23,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder.Add(S["Configuration"], configuration => configuration .Add(S["Media"], S["Media"].PrefixPosition(), media => media .Add(S["Azure Blob Options"], S["Azure Blob Options"].PrefixPosition(), options => options - .Action("Options", "Admin", new { area = "OrchardCore.Media.Azure" }) + .Action("Options", "Admin", "OrchardCore.Media.Azure") .Permission(Permissions.ViewAzureMediaOptions) - .LocalNav()) - )); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Media/AdminMenu.cs index 9b35f1faac0..1ccb1514413 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,31 +15,36 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } builder .Add(S["Content"], content => content - .AddClass("media").Id("media") + .AddClass("media") + .Id("media") .Add(S["Media Library"], S["Media Library"].PrefixPosition(), media => media .Permission(Permissions.ManageMedia) - .Action("Index", "Admin", new { area = "OrchardCore.Media" }) + .Action("Index", "Admin", "OrchardCore.Media") .LocalNav() - )); + ) + ); builder.Add(S["Configuration"], configuration => configuration .Add(S["Media"], S["Media"].PrefixPosition(), media => media .Add(S["Media Options"], S["Media Options"].PrefixPosition(), options => options - .Action("Options", "Admin", new { area = "OrchardCore.Media" }) + .Action("Options", "Admin", "OrchardCore.Media") .Permission(Permissions.ViewMediaOptions) - .LocalNav()) + .LocalNav() + ) .Add(S["Media Profiles"], S["Media Profiles"].PrefixPosition(), mediaProfiles => mediaProfiles - .Action("Index", "MediaProfiles", new { area = "OrchardCore.Media" }) + .Action("Index", "MediaProfiles", "OrchardCore.Media") .Permission(Permissions.ManageMediaProfiles) - .LocalNav()) - )); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } @@ -57,7 +61,7 @@ public MediaCacheAdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -65,7 +69,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder.Add(S["Configuration"], configuration => configuration .Add(S["Media"], S["Media"].PrefixPosition(), media => media .Add(S["Media Cache"], S["Media Cache"].PrefixPosition(), cache => cache - .Action("Index", "MediaCache", new { area = "OrchardCore.Media" }) + .Action("Index", "MediaCache", "OrchardCore.Media") .Permission(MediaCachePermissions.ManageAssetCache) .LocalNav()) )); diff --git a/src/OrchardCore.Modules/OrchardCore.Menu/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Menu/AdminMenu.cs index 0fcc3eb9722..d1626a1000d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Menu/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Menu/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; @@ -8,6 +7,14 @@ namespace OrchardCore.Menu { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "contentTypeId", "Menu" }, + { "Area", "OrchardCore.Contents" }, + { "Options.SelectedContentType", "Menu" }, + { "Options.CanCreateSelectedContentType", true } + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,25 +24,19 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - var rvd = new RouteValueDictionary - { - { "contentTypeId", "Menu" }, - { "Area", "OrchardCore.Contents" }, - { "Options.SelectedContentType", "Menu" }, - { "Options.CanCreateSelectedContentType", true } - }; - - builder.Add(S["Content"], design => design + builder + .Add(S["Content"], design => design .Add(S["Menus"], S["Menus"].PrefixPosition(), menus => menus .Permission(Permissions.ManageMenu) - .Action("List", "Admin", rvd) + .Action("List", "Admin", _routeValues) .LocalNav() - )); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/AdminMenuMicrosoftAccount.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/AdminMenuMicrosoftAccount.cs index 0a14773b492..3fcd818deb8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/AdminMenuMicrosoftAccount.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/AdminMenuMicrosoftAccount.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Modules; using OrchardCore.Navigation; @@ -9,6 +9,12 @@ namespace OrchardCore.Microsoft.Authentication [Feature(MicrosoftAuthenticationConstants.Features.MicrosoftAccount)] public class AdminMenuMicrosoftAccount : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", MicrosoftAuthenticationConstants.Features.MicrosoftAccount }, + }; + protected readonly IStringLocalizer S; public AdminMenuMicrosoftAccount(IStringLocalizer localizer) @@ -18,17 +24,24 @@ public AdminMenuMicrosoftAccount(IStringLocalizer loc public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Security"], security => security - .Add(S["Authentication"], authentication => authentication - .Add(S["Microsoft"], S["Microsoft"].PrefixPosition(), client => client - .AddClass("microsoft").Id("microsoft") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = MicrosoftAuthenticationConstants.Features.MicrosoftAccount }) - .Permission(Permissions.ManageMicrosoftAuthentication) - .LocalNav()) - )); + return Task.CompletedTask; } + + builder + .Add(S["Security"], security => security + .Add(S["Authentication"], authentication => authentication + .Add(S["Microsoft"], S["Microsoft"].PrefixPosition(), microsoft => microsoft + .AddClass("microsoft") + .Id("microsoft") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageMicrosoftAuthentication) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } @@ -36,24 +49,33 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature(MicrosoftAuthenticationConstants.Features.AAD)] public class AdminMenuAAD : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", MicrosoftAuthenticationConstants.Features.AAD }, + }; + protected readonly IStringLocalizer S; public AdminMenuAAD(IStringLocalizer localizer) => S = localizer; public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Security"], security => security - .Add(S["Authentication"], authentication => authentication - .Add(S["Microsoft Entra ID"], S["Microsoft Entra ID"].PrefixPosition(), client => client - .AddClass("microsoft-entra-id").Id("microsoft-entra-id") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = MicrosoftAuthenticationConstants.Features.AAD }) - .Permission(Permissions.ManageMicrosoftAuthentication) - .LocalNav()) - )); + return Task.CompletedTask; } + builder + .Add(S["Security"], security => security + .Add(S["Authentication"], authentication => authentication + .Add(S["Microsoft Entra ID"], S["Microsoft Entra ID"].PrefixPosition(), client => client + .AddClass("microsoft-entra-id").Id("microsoft-entra-id") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageMicrosoftAuthentication) + .LocalNav()) + )); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/AdminMenu.cs index 631b98b6abf..05fa6b6972c 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/AdminMenu.cs @@ -1,7 +1,7 @@ -using System; using System.Collections.Immutable; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Environment.Shell.Descriptor.Models; using OrchardCore.Navigation; @@ -10,6 +10,12 @@ namespace OrchardCore.OpenId { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _clientRouteValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", "OrchardCore.OpenId.Client" }, + }; + private readonly ShellDescriptor _shellDescriptor; protected readonly IStringLocalizer S; @@ -23,7 +29,7 @@ public AdminMenu( public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -43,7 +49,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) if (features.Contains(OpenIdConstants.Features.Client)) { settings.Add(S["Authentication client"], "1", client => client - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "OrchardCore.OpenId.Client" }) + .Action("Index", "Admin", _clientRouteValues) .Permission(Permissions.ManageClientSettings) .LocalNav()); } diff --git a/src/OrchardCore.Modules/OrchardCore.Placements/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Placements/AdminMenu.cs index fd40c58e46f..09f8f615551 100644 --- a/src/OrchardCore.Modules/OrchardCore.Placements/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Placements/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,7 +23,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Design"], design => design .Add(S["Placements"], S["Placements"].PrefixPosition(), import => import - .Action("Index", "Admin", new { area = "OrchardCore.Placements" }) + .Action("Index", "Admin", "OrchardCore.Placements") .Permission(Permissions.ManagePlacements) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Queries/AdminMenu.cs index ec2e861933c..0bfe9c5a9da 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,19 +15,22 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search + builder + .Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search .AddClass("search").Id("search") .Add(S["Queries"], S["Queries"].PrefixPosition(), contentItems => contentItems - .Add(S["All queries"], "1", queries => queries - .Action("Index", "Admin", new { area = "OrchardCore.Queries" }) + .Add(S["All queries"], "1", queries => queries + .Action("Index", "Admin", "OrchardCore.Queries") .Permission(Permissions.ManageQueries) - .LocalNav()) - )); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/AdminMenu.cs index 4fd44f1c6aa..c8b70beb92f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Queries/Sql/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Queries/Sql/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,9 +24,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Search"], search => search .Add(S["Queries"], S["Queries"].PrefixPosition(), queries => queries .Add(S["Run SQL Query"], S["Run SQL Query"].PrefixPosition(), sql => sql - .Action("Query", "Admin", new { area = "OrchardCore.Queries" }) + .Action("Query", "Admin", "OrchardCore.Queries") .Permission(Permissions.ManageSqlQueries) - .LocalNav()))); + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/AdminMenu.cs index a534fdbfd95..10c8a6e3239 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; using OrchardCore.ReCaptcha.Drivers; @@ -8,6 +8,12 @@ namespace OrchardCore.ReCaptcha { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ReCaptchaSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,7 +23,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,11 +31,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Security"], security => security .Add(S["Settings"], settings => settings - .Add(S["reCaptcha"], S["reCaptcha"].PrefixPosition(), registration => registration + .Add(S["reCaptcha"], S["reCaptcha"].PrefixPosition(), reCaptcha => reCaptcha .Permission(Permissions.ManageReCaptchaSettings) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ReCaptchaSettingsDisplayDriver.GroupId }) + .Action("Index", "Admin", _routeValues) .LocalNav() - ))); + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Recipes/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Recipes/AdminMenu.cs index 4d45133120d..5fa3e8f23a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Recipes/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Recipes/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -17,17 +16,18 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Recipes"], S["Recipes"].PrefixPosition(), recipes => recipes - .AddClass("recipes").Id("recipes") - .Permission(StandardPermissions.SiteOwner) - .Action("Index", "Admin", new { area = "OrchardCore.Recipes" }) - .LocalNav() + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Recipes"], S["Recipes"].PrefixPosition(), recipes => recipes + .AddClass("recipes").Id("recipes") + .Permission(StandardPermissions.SiteOwner) + .Action("Index", "Admin", "OrchardCore.Recipes") + .LocalNav() ) ); diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/AdminMenu.cs index 8d3c8316b14..4231c4812d7 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/AdminMenu.cs @@ -1,12 +1,19 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; +using OrchardCore.ReverseProxy.Drivers; namespace OrchardCore.ReverseProxy { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ReverseProxySettingsDisplayDriver.GroupId}, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -16,21 +23,24 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder - .Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], settings => settings - .Add(S["Reverse Proxy"], S["Reverse Proxy"].PrefixPosition(), entry => entry - .AddClass("reverseproxy").Id("reverseproxy") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = "ReverseProxy" }) - .Permission(Permissions.ManageReverseProxySettings) - .LocalNav() - ) - ) - ); + return Task.CompletedTask; } + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Reverse Proxy"], S["Reverse Proxy"].PrefixPosition(), entry => entry + .AddClass("reverseproxy") + .Id("reverseproxy") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageReverseProxySettings) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Drivers/ReverseProxySettingsDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Drivers/ReverseProxySettingsDisplayDriver.cs index 5cf66a7f1cf..ee440e581c3 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Drivers/ReverseProxySettingsDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Drivers/ReverseProxySettingsDisplayDriver.cs @@ -14,7 +14,8 @@ namespace OrchardCore.ReverseProxy.Drivers { public class ReverseProxySettingsDisplayDriver : SectionDisplayDriver { - private const string SettingsGroupId = "ReverseProxy"; + public const string GroupId = "ReverseProxy"; + private readonly IShellHost _shellHost; private readonly ShellSettings _shellSettings; private readonly IHttpContextAccessor _httpContextAccessor; @@ -46,7 +47,7 @@ public override async Task EditAsync(ReverseProxySettings settin model.EnableXForwardedFor = settings.ForwardedHeaders.HasFlag(ForwardedHeaders.XForwardedFor); model.EnableXForwardedHost = settings.ForwardedHeaders.HasFlag(ForwardedHeaders.XForwardedHost); model.EnableXForwardedProto = settings.ForwardedHeaders.HasFlag(ForwardedHeaders.XForwardedProto); - }).Location("Content:2").OnGroup(SettingsGroupId); + }).Location("Content:2").OnGroup(GroupId); } public override async Task UpdateAsync(ReverseProxySettings section, BuildEditorContext context) @@ -58,7 +59,7 @@ public override async Task UpdateAsync(ReverseProxySettings sect return null; } - if (context.GroupId == SettingsGroupId) + if (context.GroupId == GroupId) { var model = new ReverseProxySettingsViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Roles/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Roles/AdminMenu.cs index 62fabd6f469..3d86d657a5c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Roles/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Roles/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,18 +15,20 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Security"], security => security - .Add(S["Roles"], S["Roles"].PrefixPosition(), roles => roles - .AddClass("roles").Id("roles") - .Action("Index", "Admin", "OrchardCore.Roles") - .Permission(Permissions.ManageRoles) - .LocalNav() - )); + builder + .Add(S["Security"], security => security + .Add(S["Roles"], S["Roles"].PrefixPosition(), roles => roles + .AddClass("roles").Id("roles") + .Action("Index", "Admin", "OrchardCore.Roles") + .Permission(Permissions.ManageRoles) + .LocalNav() + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/AdminMenu.cs index 0bea453cd11..6dc478b9795 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.AzureAI/AdminMenu.cs @@ -28,7 +28,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Id("azureaiservice") .Add(S["Indexing"], S["Indexing"].PrefixPosition(), indexing => indexing .Add(S["Azure AI Indices"], S["Azure AI Indices"].PrefixPosition(), indexes => indexes - .Action("Index", "Admin", new { area = "OrchardCore.Search.AzureAI" }) + .Action("Index", "Admin", "OrchardCore.Search.AzureAI") .Permission(AzureAISearchIndexPermissionHelper.ManageAzureAISearchIndexes) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/AdminMenu.cs index b30226ed9b2..c626b4f60f5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -11,7 +10,7 @@ public class AdminMenu(IStringLocalizer localizer) : INavigationProvi public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -21,19 +20,19 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .AddClass("elasticsearch").Id("Elasticsearch") .Add(S["Indexing"], S["Indexing"].PrefixPosition(), import => import .Add(S["Elasticsearch Indices"], S["Elasticsearch Indices"].PrefixPosition(), indexes => indexes - .Action("Index", "Admin", new { area = "OrchardCore.Search.Elasticsearch" }) + .Action("Index", "Admin", "OrchardCore.Search.Elasticsearch") .Permission(Permissions.ManageElasticIndexes) .LocalNav() - ) ) + ) .Add(S["Queries"], S["Queries"].PrefixPosition(), import => import .Add(S["Run Elasticsearch Query"], S["Run Elasticsearch Query"].PrefixPosition(), queries => queries - .Action("Query", "Admin", new { area = "OrchardCore.Search.Elasticsearch" }) + .Action("Query", "Admin", "OrchardCore.Search.Elasticsearch") .Permission(Permissions.ManageElasticIndexes) .LocalNav() - ) ) - ); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/AdminMenu.cs index acac7e5b1f7..b76a984dcfc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -11,7 +10,7 @@ public class AdminMenu(IStringLocalizer localizer) : INavigationProvi public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -21,19 +20,19 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .AddClass("search").Id("search") .Add(S["Indexing"], S["Indexing"].PrefixPosition(), import => import .Add(S["Lucene Indices"], S["Lucene Indices"].PrefixPosition(), indexes => indexes - .Action("Index", "Admin", new { area = "OrchardCore.Search.Lucene" }) + .Action("Index", "Admin", "OrchardCore.Search.Lucene") .Permission(Permissions.ManageLuceneIndexes) .LocalNav() ) ) - .Add(S["Queries"], S["Queries"].PrefixPosition(), import => import + .Add(S["Queries"], S["Queries"].PrefixPosition(), import => import .Add(S["Run Lucene Query"], S["Run Lucene Query"].PrefixPosition(), queries => queries - .Action("Query", "Admin", new { area = "OrchardCore.Search.Lucene" }) + .Action("Query", "Admin", "OrchardCore.Search.Lucene") .Permission(Permissions.ManageLuceneIndexes) .LocalNav() - ) ) - ); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Search/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Search/AdminMenu.cs index cabc55e26ae..3787a1c1604 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,6 +7,12 @@ namespace OrchardCore.Search { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", SearchConstants.SearchSettingsGroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -16,7 +22,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -25,11 +31,11 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Search"], NavigationConstants.AdminMenuSearchPosition, search => search .AddClass("search").Id("search") .Add(S["Settings"], S["Settings"].PrefixPosition(), settings => settings - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SearchConstants.SearchSettingsGroupId }) + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageSearchSettings) .LocalNav() - ) - ); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Security/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Security/AdminMenu.cs index 59e81be62b0..86b14eccc1a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Security/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Security/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; using OrchardCore.Security.Drivers; @@ -8,6 +8,13 @@ namespace OrchardCore.Security { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", SecuritySettingsDisplayDriver.SettingsGroupId }, + + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,17 +24,24 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Security"], NavigationConstants.AdminMenuSecurityPosition, security => security - .AddClass("security").Id("security") - .Add(S["Settings"], settings => settings - .Add(S["Security Headers"], S["Security Headers"].PrefixPosition(), headers => headers - .Permission(SecurityPermissions.ManageSecurityHeadersSettings) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SecuritySettingsDisplayDriver.SettingsGroupId }) - .LocalNav()))); + return Task.CompletedTask; } + builder + .Add(S["Security"], NavigationConstants.AdminMenuSecurityPosition, security => security + .AddClass("security") + .Id("security") + .Add(S["Settings"], settings => settings + .Add(S["Security Headers"], S["Security Headers"].PrefixPosition(), headers => headers + .Permission(SecurityPermissions.ManageSecurityHeadersSettings) + .Action("Index", "Admin", _routeValues) + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Seo/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Seo/AdminMenu.cs index 910fce477d5..451f62e55f8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Seo/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Seo/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -7,6 +7,12 @@ namespace OrchardCore.Seo; public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", SeoConstants.RobotsSettingsGroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -16,7 +22,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -27,12 +33,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["SEO"], S["SEO"].PrefixPosition(), seo => seo .AddClass("seo") .Id("seo") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SeoConstants.RobotsSettingsGroupId }) + .Action("Index", "Admin", _routeValues) .Permission(SeoConstants.ManageSeoSettings) .LocalNav() - ) - ) - ); + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Settings/AdminMenu.cs index 301e0a0e6f8..7c891fc4635 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; using OrchardCore.Settings.Drivers; @@ -8,6 +8,12 @@ namespace OrchardCore.Settings { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", DefaultSiteSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,24 +23,25 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } builder .Add(S["Configuration"], NavigationConstants.AdminMenuConfigurationPosition, configuration => configuration - .AddClass("menu-configuration") - .Id("configuration") + .AddClass("menu-configuration") + .Id("configuration") .Add(S["Settings"], "1", settings => settings - .Add(S["General"], "1", entry => entry - .AddClass("general").Id("general") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = DefaultSiteSettingsDisplayDriver.GroupId }) - .Permission(Permissions.ManageGroupSettings) - .LocalNav() - ), + .Add(S["General"], "1", entry => entry + .AddClass("general") + .Id("general") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageGroupSettings) + .LocalNav() + ), priority: 1) - ); + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Shortcodes/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Shortcodes/AdminMenu.cs index 14d5e48d758..9ed3af46b59 100644 --- a/src/OrchardCore.Modules/OrchardCore.Shortcodes/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Shortcodes/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,7 +23,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Design"], design => design .Add(S["Shortcodes"], S["Shortcodes"].PrefixPosition(), import => import - .Action("Index", "Admin", new { area = "OrchardCore.Shortcodes" }) + .Action("Index", "Admin", "OrchardCore.Shortcodes") .Permission(Permissions.ManageShortcodeTemplates) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Sitemaps/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Sitemaps/AdminMenu.cs index 63440975bff..d3a9d2b4890 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sitemaps/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sitemaps/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,27 +15,29 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Configuration"], configuration => configuration + builder + .Add(S["Configuration"], configuration => configuration .Add(S["SEO"], S["SEO"].PrefixPosition(), seo => seo .Permission(Permissions.ManageSitemaps) .Add(S["Sitemaps"], S["Sitemaps"].PrefixPosition("1"), sitemaps => sitemaps - .Action("List", "Admin", new { area = "OrchardCore.Sitemaps" }) + .Action("List", "Admin", "OrchardCore.Sitemaps") .LocalNav() ) - .Add(S["Sitemap Indexes"], S["Sitemap Indexes"].PrefixPosition("2"), sitemaps => sitemaps - .Action("List", "SitemapIndex", new { area = "OrchardCore.Sitemaps" }) + .Add(S["Sitemap Indexes"], S["Sitemap Indexes"].PrefixPosition("2"), indexes => indexes + .Action("List", "SitemapIndex", "OrchardCore.Sitemaps") .LocalNav() ) - .Add(S["Sitemaps Cache"], S["Sitemaps Cache"].PrefixPosition("3"), sitemaps => sitemaps - .Action("List", "SitemapCache", new { area = "OrchardCore.Sitemaps" }) + .Add(S["Sitemaps Cache"], S["Sitemaps Cache"].PrefixPosition("3"), cache => cache + .Action("List", "SitemapCache", "OrchardCore.Sitemaps") .LocalNav() ) - )); + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Sms/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Sms/AdminMenu.cs index 8e11efe61e3..b0c79db75f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Sms/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Sms/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Mvc.Core.Utilities; using OrchardCore.Navigation; @@ -9,6 +9,12 @@ namespace OrchardCore.Sms; public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", SmsSettings.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer stringLocalizer) @@ -18,7 +24,7 @@ public AdminMenu(IStringLocalizer stringLocalizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -29,14 +35,14 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["SMS"], S["SMS"].PrefixPosition(), sms => sms .AddClass("sms") .Id("sms") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = SmsSettings.GroupId }) + .Action("Index", "Admin", _routeValues) .Permission(SmsPermissions.ManageSmsSettings) .LocalNav() ) .Add(S["SMS Test"], S["SMS Test"].PrefixPosition(), sms => sms .AddClass("smstest") .Id("smstest") - .Action(nameof(AdminController.Test), typeof(AdminController).ControllerName(), new { area = "OrchardCore.Sms" }) + .Action(nameof(AdminController.Test), typeof(AdminController).ControllerName(), "OrchardCore.Sms") .Permission(SmsPermissions.ManageSmsSettings) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/AdminMenu.cs index 1e8fe028b50..9f556d2a5d7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; using OrchardCore.Taxonomies.Settings; @@ -8,6 +8,12 @@ namespace OrchardCore.Taxonomies { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", TaxonomyContentsAdminListSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -17,19 +23,23 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], "1", settings => settings - .Add(S["Taxonomy Filters"], S["Taxonomy Filters"].PrefixPosition(), admt => admt - .AddClass("taxonomyfilters").Id("taxonomyfilters") - .Permission(Permissions.ManageTaxonomies) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = TaxonomyContentsAdminListSettingsDisplayDriver.GroupId }) - .LocalNav() - ))); + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], "1", settings => settings + .Add(S["Taxonomy Filters"], S["Taxonomy Filters"].PrefixPosition(), filters => filters + .AddClass("taxonomyfilters") + .Id("taxonomyfilters") + .Permission(Permissions.ManageTaxonomies) + .Action("Index", "Admin", _routeValues) + .LocalNav() + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Templates/AdminMenu.cs index 0c50ab2508a..bcaef4ac4bb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,7 +23,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Design"], design => design .Add(S["Templates"], S["Templates"].PrefixPosition(), import => import - .Action("Index", "Template", new { area = "OrchardCore.Templates" }) + .Action("Index", "Template", "OrchardCore.Templates") .Permission(Permissions.ManageTemplates) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Templates/AdminTemplatesAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Templates/AdminTemplatesAdminMenu.cs index 50a745f1557..a502dec5a8a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Templates/AdminTemplatesAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Templates/AdminTemplatesAdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminTemplatesAdminMenu(IStringLocalizer localiz public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,7 +23,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Design"], design => design .Add(S["Admin Templates"], S["Admin Templates"].PrefixPosition(), import => import - .Action("Admin", "Template", new { area = "OrchardCore.Templates" }) + .Action("Admin", "Template", "OrchardCore.Templates") .Permission(AdminTemplatesPermissions.ManageAdminTemplates) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/AdminMenu.cs index e81bf23d7aa..3f43ce9d27c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Environment.Shell; @@ -19,7 +18,7 @@ public AdminMenu(IStringLocalizer localizer, ShellSettings shellSetti public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -35,7 +34,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .AddClass("menu-multitenancy") .Id("multitenancy") .Add(S["Tenants"], S["Tenants"].PrefixPosition(), tenant => tenant - .Action("Index", "Admin", new { area = "OrchardCore.Tenants" }) + .Action("Index", "Admin", "OrchardCore.Tenants") .Permission(Permissions.ManageTenants) .LocalNav() ), diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/FeatureProfilesAdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/FeatureProfilesAdminMenu.cs index 0ab6c1714c8..68287494e2b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/FeatureProfilesAdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/FeatureProfilesAdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Environment.Shell; @@ -19,7 +18,7 @@ public FeatureProfilesAdminMenu(IStringLocalizer local public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -34,7 +33,7 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Multi-Tenancy"], tenancy => tenancy .AddClass("menu-multitenancy") .Add(S["Feature Profiles"], S["Feature Profiles"].PrefixPosition(), featureProfiles => featureProfiles - .Action("Index", "FeatureProfiles", new { area = "OrchardCore.Tenants" }) + .Action("Index", "FeatureProfiles", "OrchardCore.Tenants") .Permission(Permissions.ManageTenantFeatureProfiles) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Themes/AdminMenu.cs index 7d8804c7c70..eae2d8f1754 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,7 +15,7 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -24,8 +23,8 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Design"], NavigationConstants.AdminMenuDesignPosition, design => design .AddClass("themes").Id("themes") - .Add(S["Themes"], S["Themes"].PrefixPosition(), installed => installed - .Action("Index", "Admin", new { area = "OrchardCore.Themes" }) + .Add(S["Themes"], S["Themes"].PrefixPosition(), themes => themes + .Action("Index", "Admin", "OrchardCore.Themes") .Permission(Permissions.ApplyTheme) .LocalNav() ) diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/AdminMenuSignin.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/AdminMenuSignin.cs index 2df4151f274..abc62fd55fe 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/AdminMenuSignin.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/AdminMenuSignin.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Modules; using OrchardCore.Navigation; @@ -9,6 +9,12 @@ namespace OrchardCore.Twitter [Feature(TwitterConstants.Features.Signin)] public class AdminMenuSignin : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", TwitterConstants.Features.Signin }, + }; + protected readonly IStringLocalizer S; public AdminMenuSignin(IStringLocalizer localizer) @@ -18,17 +24,23 @@ public AdminMenuSignin(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Security"], security => security - .Add(S["Authentication"], authentication => authentication - .Add(S["Sign in with Twitter"], S["Sign in with Twitter"].PrefixPosition(), settings => settings - .AddClass("twitter").Id("twitter") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = TwitterConstants.Features.Signin }) - .Permission(Permissions.ManageTwitterSignin) - .LocalNav()) - )); + return Task.CompletedTask; } + + builder + .Add(S["Security"], security => security + .Add(S["Authentication"], authentication => authentication + .Add(S["Sign in with Twitter"], S["Sign in with Twitter"].PrefixPosition(), twitter => twitter + .AddClass("twitter") + .Id("twitter") + .Action("Index", "Admin", _routeValues) + .Permission(Permissions.ManageTwitterSignin) + .LocalNav()) + ) + ); + return Task.CompletedTask; } } @@ -36,6 +48,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature(TwitterConstants.Features.Twitter)] public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", TwitterConstants.Features.Twitter }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -45,17 +63,23 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { - builder.Add(S["Configuration"], configuration => configuration - .Add(S["Settings"], settings => settings - .Add(S["Twitter"], S["Twitter"].PrefixPosition(), settings => settings + return Task.CompletedTask; + } + + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Twitter"], S["Twitter"].PrefixPosition(), twitter => twitter .AddClass("twitter").Id("twitter") - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = TwitterConstants.Features.Twitter }) + .Action("Index", "Admin", _routeValues) .Permission(Permissions.ManageTwitter) - .LocalNav()) - )); - } + .LocalNav() + ) + ) + ); + return Task.CompletedTask; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Users/AdminMenu.cs index 1a6444a097a..0737ea30d32 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/AdminMenu.cs @@ -1,5 +1,5 @@ -using System; using System.Threading.Tasks; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Localization; using OrchardCore.Modules; using OrchardCore.Navigation; @@ -10,6 +10,12 @@ namespace OrchardCore.Users { public class AdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", LoginSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public AdminMenu(IStringLocalizer localizer) @@ -19,28 +25,31 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Security"], NavigationConstants.AdminMenuSecurityPosition, security => security - .AddClass("security").Id("security") - .Add(S["Users"], S["Users"].PrefixPosition(), users => users - .AddClass("users").Id("users") - .Action("Index", "Admin", "OrchardCore.Users") - .Permission(CommonPermissions.ListUsers) - .Resource(new User()) + builder + .Add(S["Security"], NavigationConstants.AdminMenuSecurityPosition, security => security + .AddClass("security") + .Id("security") + .Add(S["Users"], S["Users"].PrefixPosition(), users => users + .AddClass("users") + .Id("users") + .Action("Index", "Admin", "OrchardCore.Users") + .Permission(CommonPermissions.ListUsers) + .Resource(new User()) + .LocalNav() + ) + .Add(S["Settings"], settings => settings + .Add(S["User Login"], S["User Login"].PrefixPosition(), login => login + .Permission(CommonPermissions.ManageUsers) + .Action("Index", "Admin", _routeValues) .LocalNav() - ) - .Add(S["Settings"], settings => settings - .Add(S["User Login"], S["User Login"].PrefixPosition(), login => login - .Permission(CommonPermissions.ManageUsers) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = LoginSettingsDisplayDriver.GroupId }) - .LocalNav() - ) - ) - ); + ) + ) + ); return Task.CompletedTask; } @@ -49,6 +58,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature("OrchardCore.Users.ChangeEmail")] public class ChangeEmailAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ChangeEmailSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public ChangeEmailAdminMenu(IStringLocalizer localizer) @@ -58,7 +73,7 @@ public ChangeEmailAdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -66,11 +81,13 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) builder .Add(S["Security"], security => security .Add(S["Settings"], settings => settings - .Add(S["User Change email"], S["User Change email"].PrefixPosition(), registration => registration + .Add(S["User Change email"], S["User Change email"].PrefixPosition(), email => email .Permission(CommonPermissions.ManageUsers) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ChangeEmailSettingsDisplayDriver.GroupId }) + .Action("Index", "Admin", _routeValues) .LocalNav() - ))); + ) + ) + ); return Task.CompletedTask; } @@ -79,6 +96,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature("OrchardCore.Users.Registration")] public class RegistrationAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", RegistrationSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public RegistrationAdminMenu(IStringLocalizer localizer) @@ -88,7 +111,7 @@ public RegistrationAdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -98,9 +121,11 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Settings"], settings => settings .Add(S["User Registration"], S["User Registration"].PrefixPosition(), registration => registration .Permission(CommonPermissions.ManageUsers) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = RegistrationSettingsDisplayDriver.GroupId }) + .Action("Index", "Admin", _routeValues) .LocalNav() - ))); + ) + ) + ); return Task.CompletedTask; } @@ -109,6 +134,12 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) [Feature("OrchardCore.Users.ResetPassword")] public class ResetPasswordAdminMenu : INavigationProvider { + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", ResetPasswordSettingsDisplayDriver.GroupId }, + }; + protected readonly IStringLocalizer S; public ResetPasswordAdminMenu(IStringLocalizer localizer) @@ -118,7 +149,7 @@ public ResetPasswordAdminMenu(IStringLocalizer localizer public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } @@ -128,9 +159,11 @@ public Task BuildNavigationAsync(string name, NavigationBuilder builder) .Add(S["Settings"], settings => settings .Add(S["User Reset password"], S["User Reset password"].PrefixPosition(), password => password .Permission(CommonPermissions.ManageUsers) - .Action("Index", "Admin", new { area = "OrchardCore.Settings", groupId = ResetPasswordSettingsDisplayDriver.GroupId }) + .Action("Index", "Admin", _routeValues) .LocalNav() - ))); + ) + ) + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Modules/OrchardCore.Workflows/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Workflows/AdminMenu.cs index ee6da25ddc6..3d9534cbf08 100644 --- a/src/OrchardCore.Modules/OrchardCore.Workflows/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Workflows/AdminMenu.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Navigation; @@ -16,15 +15,19 @@ public AdminMenu(IStringLocalizer localizer) public Task BuildNavigationAsync(string name, NavigationBuilder builder) { - if (!string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)) + if (!NavigationHelper.IsAdminMenu(name)) { return Task.CompletedTask; } - builder.Add(S["Workflows"], NavigationConstants.AdminMenuWorkflowsPosition, workflow => workflow - .AddClass("workflows").Id("workflows").Action("Index", "WorkflowType", new { area = "OrchardCore.Workflows" }) + builder + .Add(S["Workflows"], NavigationConstants.AdminMenuWorkflowsPosition, workflow => workflow + .AddClass("workflows") + .Id("workflows") + .Action("Index", "WorkflowType", "OrchardCore.Workflows") .Permission(Permissions.ManageWorkflows) - .LocalNav()); + .LocalNav() + ); return Task.CompletedTask; } diff --git a/src/OrchardCore.Themes/TheAdmin/Views/Navigation-admin.cshtml b/src/OrchardCore.Themes/TheAdmin/Views/Navigation-admin.cshtml index 6325f9a170c..2b2ecf54a4d 100644 --- a/src/OrchardCore.Themes/TheAdmin/Views/Navigation-admin.cshtml +++ b/src/OrchardCore.Themes/TheAdmin/Views/Navigation-admin.cshtml @@ -1,10 +1,11 @@ @inject OrchardCore.Settings.ISiteService siteService @using OrchardCore.Entities @using OrchardCore.Admin.Models +@using OrchardCore.Navigation @{ var adminSettings = (await siteService.GetSiteSettingsAsync()).As(); TagBuilder tag = Tag(Model, "ul"); - tag.Attributes["Id"] = "adminMenu"; + tag.Attributes["Id"] = NavigationConstants.AdminMenuId; foreach (var item in Model) { diff --git a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationConstants.cs b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationConstants.cs index 034f06d180e..7e5c586dafd 100644 --- a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationConstants.cs +++ b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationConstants.cs @@ -1,13 +1,14 @@ -namespace OrchardCore.Navigation +namespace OrchardCore.Navigation; + +public static class NavigationConstants { - public static class NavigationConstants - { - public const string AdminMenuContentPosition = "1"; - public const string AdminMenuDesignPosition = "2"; - public const string AdminMenuSearchPosition = "6"; - public const string AdminMenuSecurityPosition = "7"; - public const string AdminMenuAuditTrailPosition = "7.5"; - public const string AdminMenuWorkflowsPosition = "8"; - public const string AdminMenuConfigurationPosition = "100"; - } + public const string AdminMenuContentPosition = "1"; + public const string AdminMenuDesignPosition = "2"; + public const string AdminMenuSearchPosition = "6"; + public const string AdminMenuSecurityPosition = "7"; + public const string AdminMenuAuditTrailPosition = "7.5"; + public const string AdminMenuWorkflowsPosition = "8"; + public const string AdminMenuConfigurationPosition = "100"; + public const string AdminId = "admin"; + public const string AdminMenuId = "adminMenu"; } diff --git a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationHelper.cs b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationHelper.cs index a11bf08d0f0..f94188d2a63 100644 --- a/src/OrchardCore/OrchardCore.Navigation.Core/NavigationHelper.cs +++ b/src/OrchardCore/OrchardCore.Navigation.Core/NavigationHelper.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -11,6 +10,14 @@ namespace OrchardCore.Navigation { public class NavigationHelper { + /// + /// Checks if the given name matches the value . + /// + /// + /// boolean. + public static bool IsAdminMenu(string name) + => NavigationConstants.AdminId == name; + /// /// Populates the menu shapes. /// diff --git a/src/docs/releases/1.9.0.md b/src/docs/releases/1.9.0.md index 88c274d9513..789bafa5977 100644 --- a/src/docs/releases/1.9.0.md +++ b/src/docs/releases/1.9.0.md @@ -36,11 +36,55 @@ Added new extensions to make registering custom deployment step easier When identifying content types for GraphQL exposure, we identify those without a stereotype to provide you with control over the behavior of stereotyped content types. A new option, `DiscoverableSterotypes`, has been introduced in `GraphQLContentOptions`. This allows you to specify stereotypes that should be discoverable by default. -For instance, if you have several content types sterotyped as `ExampleStereotype`, you can make them discoverable by incorporating the following code into the startup class: +For instance, if you have several content types stereotyped as `ExampleStereotype`, you can make them discoverable by incorporating the following code into the startup class: ```csharp services.Configure(options => { options.DiscoverableSterotypes.Add("ExampleStereotype"); }); -``` \ No newline at end of file +``` + +### Admin + +The admin menu has undergone performance enhancements, and new helpers have been added. When incorporating `INavigationProvider` in your project, you can now utilize `NavigationHelper.IsAdminMenu(name)` instead of the previous approach using `string.Equals(name, "admin", StringComparison.OrdinalIgnoreCase)`. Moreover, when passing route values to an action, it is advised to store them in a constant variable. An illustrative example is provided below. +``` +public class AdminMenu : INavigationProvider +{ + private static readonly RouteValueDictionary _routeValues = new() + { + { "area", "OrchardCore.Settings" }, + { "groupId", AdminSiteSettingsDisplayDriver.GroupId }, + }; + + protected readonly IStringLocalizer S; + + public AdminMenu(IStringLocalizer stringLocalizer) + { + S = stringLocalizer; + } + + public Task BuildNavigationAsync(string name, NavigationBuilder builder) + { + if (!NavigationHelper.IsAdminMenu(name)) + { + return Task.CompletedTask; + } + + builder + .Add(S["Configuration"], configuration => configuration + .Add(S["Settings"], settings => settings + .Add(S["Admin"], S["Admin"].PrefixPosition(), admin => admin + .AddClass("admin") + .Id("admin") + .Action("Index", "Admin", _routeValues) + .Permission(PermissionsAdminSettings.ManageAdminSettings) + .LocalNav() + ) + ) + ); + + return Task.CompletedTask; + } +} +```