feat: 添加代码块是否授权方法

This commit is contained in:
zhangpeihang 2022-01-19 15:06:57 +08:00
parent 05f0d1d344
commit 267d0e68bd
2 changed files with 28 additions and 1 deletions

View File

@ -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<string> 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));
}
}

View File

@ -27,4 +27,13 @@ public interface INavigation
/// <param name="menuIds"></param>
/// <returns></returns>
bool SaveMenusByRoleId(string? roleId, List<string> menuIds);
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <param name="url"></param>
/// <param name="authKey"></param>
/// <returns></returns>
bool AuthorizationBlock(string userName, string url, string authKey);
}