Example #1
0
        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));
        }
Example #2
0
        public JsonResult FunctionDelete(string id)
        {
            SysPower.Delete("where function_id in (@0)", id.ToIntList());
            SysFunction.Delete("where id in (@0)", id.ToIntList());

            return(Json(ArtDialogResponseResult.SuccessResult));
        }
Example #3
0
        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));
        }
Example #4
0
        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));
        }
        /// <summary>
        /// 是否有权限
        /// </summary>
        /// <param name="Ctrl">控制器</param>
        /// <param name="Power">权限</param>
        /// <returns></returns>
        public bool checkPower(string Ctrl, string Power)
        {
            bool             Ret          = false;
            IList <SysPower> SysPowerList = ViewBag.SysPowerList_;
            SysPower         SysPower     = SysPowerList.FirstOrDefault(n => n.Ctrl == Ctrl && n.Method == Power);

            if (SysPower != null)
            { //权限存在
                string PId = string.Format(",{0},", SysPower.Id);
                if (AdminUser.PowerID.IndexOf(PId) != -1)
                {
                    Ret = true;
                }
            }
            return(Ret);
        }
Example #6
0
        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
                {
                }
            }
        }
        public IList <SysMenu> GetBaseMenu(SysAdmin User)
        {
            IList <SysMenu> Temp = GetMenuList();

            User = User == null ? new SysAdmin() : User;
            IList <SysMenu>  List         = new List <SysMenu>();
            IList <SysPower> SysPowerList = GetSysPowerList();

            string[]   Sub = User.PowerID.Split(',');
            List <int> ID  = new List <int>();

            foreach (var s in Sub)
            {
                if (!s.IsNullOrEmpty())
                {
                    ID.Add(Int32.Parse(s));
                }
            }
            IList <SysPower> SysPowerAdminList = Entity.SysPower.Where(n => n.State == 1 && n.PType == 1 && ID.Contains(n.Id)).ToList();

            foreach (var p in Temp)
            {
                string Url = p.Url;
                if (!Url.IsNullOrEmpty())
                {
                    if (p.PId == 0)
                    {
                        int      PowerId = Int32.Parse(p.Url);//当顶级菜单 Url存放权限表对应Id
                        SysPower P0List  = SysPowerAdminList.FirstOrDefault(n => n.Id == PowerId);
                        if (P0List != null)
                        {
                            List.Add(p);
                        }
                    }
                    else
                    {
                        string[] Arr = Url.Split('?');
                        Url = Arr[0];
                        Url = Url.Replace(".html", "").Replace("/Manage/", "");
                        Arr = Url.Split('/');
                        string Ctrl = "", Method = "";
                        if (Arr.Length == 2)
                        {
                            Ctrl   = Arr[0];
                            Method = Arr[1];
                        }
                        else if (Arr.Length == 1)
                        {
                            Ctrl   = Arr[0];
                            Method = "index";
                        }
                        //使用严格验证,不存在权限的不能访问
                        SysPower SysPowerAdmin = SysPowerAdminList.FirstOrDefault(n => n.Ctrl == Ctrl && n.Method == Method);
                        if (SysPowerAdmin != null)
                        {
                            List.Add(p);
                        }
                    }
                }
            }
            //处理二级菜单
            foreach (var p in Temp.Where(n => n.Url == "###"))
            {
                if (List.Count(n => n.PId == p.Id) > 0)
                {
                    List.Add(p);
                }
            }
            return(List);
        }
        public IList <SysMenu> GetBaseMenu(SysAdmin User)
        {
            IList <SysMenu> Temp = GetMenuList();

            User = User == null ? new SysAdmin() : User;
            //if (AdminUser.UserName == "admin")
            //{
            //    return Temp;
            //}
            IList <SysMenu>  List = new List <SysMenu>();
            IList <SysPower> SysPowerAdminList = GetSysPowerList();

            foreach (var p in Temp)
            {
                string Url = p.Url;
                if (!Url.IsNullOrEmpty())
                {
                    if (p.PId == 0)
                    {
                        int      PowerId = Int32.Parse(p.Url);//当顶级菜单 Url存放权限表对应Id
                        SysPower P0List  = SysPowerAdminList.FirstOrDefault(n => n.Id == PowerId);
                        if (P0List != null || PowerId == 0)
                        {
                            List.Add(p);
                        }
                    }
                    else if (p.Sort > 10000)
                    {
                        List.Add(p);
                    }
                    else
                    {
                        string[] Arr = Url.Split('?');
                        Url = Arr[0];
                        Url = Url.Replace(".html", "").Replace("/Agent/", "");
                        Arr = Url.Split('/');
                        string Ctrl = "", Method = "";
                        if (Arr.Length == 2)
                        {
                            Ctrl   = Arr[0];
                            Method = Arr[1];
                        }
                        else if (Arr.Length == 1)
                        {
                            Ctrl   = Arr[0];
                            Method = "index";
                        }
                        //使用严格验证,不存在权限的不能访问
                        SysPower SysPowerAdmin = SysPowerAdminList.FirstOrDefault(n => n.Ctrl == Ctrl && n.Method == Method);
                        if (SysPowerAdmin != null)
                        {
                            List.Add(p);
                        }
                    }
                }
            }
            //处理二级菜单
            foreach (var p in Temp.Where(n => n.Url == "###"))
            {
                if (List.Count(n => n.PId == p.Id) > 0)
                {
                    List.Add(p);
                }
            }
            return(List);
        }