后端角色权限新增加管理员判断

This commit is contained in:
不做码农 2021-12-17 21:59:15 +08:00
parent ae5e215b7b
commit 3b2c1577ff
2 changed files with 10 additions and 1 deletions

View File

@ -13,5 +13,9 @@ namespace Infrastructure
/// 管理员权限 /// 管理员权限
/// </summary> /// </summary>
public static string AdminPerm = "*:*:*"; public static string AdminPerm = "*:*:*";
/// <summary>
/// 管理员角色
/// </summary>
public static string AdminRole = "admin";
} }
} }

View File

@ -43,10 +43,15 @@ namespace ZR.Admin.WebApi.Filters
if (info != null && info?.UserId > 0) if (info != null && info?.UserId > 0)
{ {
List<string> perms = info.Permissions; List<string> perms = info.Permissions;
List<string> rolePerms = info.RoleIds;
if (perms.Exists(f => f.Equals(GlobalConstant.AdminPerm))) if (perms.Exists(f => f.Equals(GlobalConstant.AdminPerm)))
{ {
HasPermi = true; HasPermi = true;
} }
else if (rolePerms.Exists(f => f.Equals(GlobalConstant.AdminRole)))
{
HasPermi = true;
}
else if (!string.IsNullOrEmpty(Permission)) else if (!string.IsNullOrEmpty(Permission))
{ {
HasPermi = perms.Exists(f => f.ToLower() == Permission.ToLower()); HasPermi = perms.Exists(f => f.ToLower() == Permission.ToLower());