Skip to content

Commit

Permalink
Added /Admin relative URL for admin menu nodes (OrchardCMS#12807)
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-Thierry Kéchichian <[email protected]>
  • Loading branch information
vengi83644 and jtkech authored Nov 26, 2022
1 parent fb9246a commit b9c2d51
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/OrchardCore/OrchardCore.Navigation.Core/NavigationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Environment.Shell;

namespace OrchardCore.Navigation
Expand All @@ -19,6 +21,7 @@ public class NavigationManager : INavigationManager
protected readonly ShellSettings _shellSettings;
private readonly IUrlHelperFactory _urlHelperFactory;
private readonly IAuthorizationService _authorizationService;
private readonly AdminOptions _adminOptions;

private IUrlHelper _urlHelper;

Expand All @@ -27,14 +30,16 @@ public NavigationManager(
ILogger<NavigationManager> logger,
ShellSettings shellSettings,
IUrlHelperFactory urlHelperFactory,
IAuthorizationService authorizationService
IAuthorizationService authorizationService,
IOptions<AdminOptions> adminOptions
)
{
_navigationProviders = navigationProviders;
_logger = logger;
_shellSettings = shellSettings;
_urlHelperFactory = urlHelperFactory;
_authorizationService = authorizationService;
_adminOptions = adminOptions.Value;
}

public async Task<IEnumerable<MenuItem>> BuildMenuAsync(string name, ActionContext actionContext)
Expand Down Expand Up @@ -203,8 +208,13 @@ private string GetUrl(string menuItemUrl, RouteValueDictionary routeValueDiction
menuItemUrl = menuItemUrl.Substring(2);
}

if (menuItemUrl.StartsWith($"{_adminOptions.AdminUrlPrefix}/", StringComparison.OrdinalIgnoreCase))
{
return actionContext.HttpContext.Request.PathBase.Add($"/{menuItemUrl}").Value;
}

// Use the unescaped 'Value' to not encode some possible reserved delimiters.
return actionContext.HttpContext.Request.PathBase.Add('/' + menuItemUrl).Value;
return actionContext.HttpContext.Request.PathBase.Add($"/{_adminOptions.AdminUrlPrefix}/{menuItemUrl}").Value;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\OrchardCore.Admin.Abstractions\OrchardCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\OrchardCore.Infrastructure.Abstractions\OrchardCore.Infrastructure.Abstractions.csproj" />
</ItemGroup>

Expand Down

0 comments on commit b9c2d51

Please sign in to comment.