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

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());
@ -55,7 +60,7 @@ namespace ZR.Admin.WebApi.Filters
bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false); bool isDemoMode = ConfigUtils.Instance.GetAppConfig("DemoMode", false);
//演示公开环境屏蔽权限 //演示公开环境屏蔽权限
string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send" ,"export", "upload", "common"}; string[] denyPerms = new string[] { "update", "add", "remove", "add", "edit", "delete", "import", "run", "start", "stop", "clear", "send", "export", "upload", "common" };
if (isDemoMode && denyPerms.Any(f => Permission.ToLower().Contains(f))) if (isDemoMode && denyPerms.Any(f => Permission.ToLower().Contains(f)))
{ {
context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" }); context.Result = new JsonResult(new { code = ResultCode.FORBIDDEN, msg = "演示模式 , 不允许操作" });