public static IEnumerable <MenuTree> GetCurrUserMenuTrees() { if (!SysHelper.IsLogined()) { return(new List <MenuTree>()); } var currUser = SysHelper.GetCurrUser(); if (currUser.IsSuperUser) { return(listMenuTrees); } var funcIds = SysPower.Fetch("where master_id=@0 and master_type=@1", currUser.ID, MasterType.User.ToString()).Select(power => power.FunctionID); var funcs = listFunctions.Where(func => funcIds.Contains(func.ID)); List <MenuTree> result = new List <MenuTree>(); result.AddRange(listMenuTrees.Where(tree => funcs.Any(func => func.MenuID == tree.ID))); foreach (var item in listMenuTrees.Where(tree => funcs.Any(func => func.MenuID == tree.ID))) { var parent = listMenuTrees.SingleOrDefault(tree => tree.ID == item.ParentID); if (parent != null && !result.Any(tree => tree.ID == parent.ID)) { result.Add(parent); } } return(result.Where(tree => tree.IsVisible).OrderBy(tree => tree.Sort)); }
public ActionResult Authorize(int id) { RoleAuthorizeModel model = new RoleAuthorizeModel { Role = SysRole.SingleOrDefault(id), Funcs = SysFunction.Fetch(Sql.Builder), Trees = MenuTree.Fetch(Sql.Builder), SelectedFuncIds = SysPower.Fetch("where master_id=@0 and master_type=@1", id, MasterType.Role.ToString()).Select(power => power.FunctionID) }; return(View(model)); }
public JsonResult Authorize(string functionIds, int id) { var role = SysRole.SingleOrDefault(id); // 删除权限 SysPower.Delete("where master_id in (@0) and master_type=@1", role.ID, MasterType.Role.ToString()); // 角色授权 if (string.IsNullOrEmpty(functionIds) == false) { var funcs = SysFunction.Fetch("where id in (@0)", functionIds.ToIntList()); foreach (var func in funcs) { SysPower power = new SysPower { FunctionID = func.ID, MasterID = role.ID, MasterType = MasterType.Role.ToString() }; power.Insert(); } } // 刷新用户权限 var users = SysUser.Fetch("where role_id=@0", role.ID); foreach (var user in users) { SysPower.Delete("where master_id in (@0) and master_type=@1", user.ID, MasterType.User.ToString()); var powers = SysPower.Fetch("where master_id=@0 and master_type=@1", user.RoleID, MasterType.Role.ToString()); foreach (var power in powers) { try { SysPower newPower = new SysPower { FunctionID = power.FunctionID, MasterID = user.ID, MasterType = MasterType.User.ToString() }; newPower.Insert(); } catch { } } } return(Json(ArtDialogResponseResult.SuccessResult)); }
private static void ResetUserPower(SysUser user) { // 重新赋权 List <SysPower> powers = SysPower.Fetch("where master_id=@0 and master_type=@1", user.RoleID, MasterType.Role.ToString()); foreach (var item in powers) { try { SysPower power = new SysPower { FunctionID = item.FunctionID, MasterID = user.ID, MasterType = MasterType.User.ToString() }; power.Insert(); } catch { } } }