diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs index 820d1d17..967112a7 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs @@ -1,4 +1,5 @@ -using BootstrapAdmin.Caching; +using System; +using BootstrapAdmin.Caching; using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.Web.Core; using PetaPoco; @@ -66,4 +67,21 @@ class NavigationService : INavigation } return ret; } + + public bool AuthorizationBlock(string userName, string url, string authKey) + { + var menus = GetAllMenus(userName); + + var activeMeun = menus.FirstOrDefault(s => s.Url.Equals($"~/{url}", StringComparison.OrdinalIgnoreCase)); + if (activeMeun == null) + { + return false; + } + + IEnumerable authorKeys = from m in menus + where m.ParentId == activeMeun.Id && m.IsResource == EnumResource.Block + select m.Url; + + return authorKeys.Any(s => s.Equals(authKey, StringComparison.OrdinalIgnoreCase)); + } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs index b54e246f..4ed90074 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs @@ -27,4 +27,13 @@ public interface INavigation /// /// bool SaveMenusByRoleId(string? roleId, List menuIds); + + /// + /// + /// + /// + /// + /// + /// + bool AuthorizationBlock(string userName, string url, string authKey); }