/// <summary> /// 获取相应层级子级 /// </summary> /// <param name="level">当前层级向下层级</param> /// <returns></returns> public SysAuth[] GetSubs(int level) { int currLevel = this.PathLevel.GetValueOrDefault(); int maxLevel = this.PathLevel.GetValueOrDefault() + level; return(SysAuth.FindAll("PathLevel > ? AND PathLevel <= ?", currLevel, maxLevel)); }
private void SetDataByModule(SysModule mdl) { SysAuth[] pAuths; SysAuth pAuth = null; // 获取父权限(与系统模块对应) if (!String.IsNullOrEmpty(mdl.ParentID)) { pAuths = SysAuth.FindAllByProperties("ModuleID", mdl.ParentID); } else { pAuths = SysAuth.FindAllByProperties("Data", mdl.ApplicationID); } if (pAuths.Length > 0) { pAuth = pAuths[0]; this.ParentID = pAuth.AuthID; this.Path = String.Format("{0}.{1}", pAuth.Path, pAuth.AuthID); this.PathLevel = (pAuth.PathLevel == null ? 0 : (pAuth.PathLevel + 1)); } this.Name = mdl.Name; this.Code = String.Format("AUTH_MDL_{0}", mdl.Code); this.Type = 1; // 1为系统入口权限 this.SortIndex = mdl.SortIndex; this.ModuleID = mdl.ModuleID; this.Description = String.Format("模块 {0} 访问权限", mdl.Name); }
/// <summary> /// 修改应用(同时修改类型为1,对应权限的名称) /// </summary> public void DoUpdate() { this.DoValidate(); SysAuth[] auths = this.GetRelatedAuth(); using (TransactionScope trans = new TransactionScope()) { try { this.UpdateAndFlush(); if (auths.Length > 0) { foreach (SysAuth auth in auths) { auth.UpdateByApplication(this); } } else { SysAuth auth = new SysAuth(); auth.CreateByApplication(this); } trans.VoteCommit(); } catch (Exception ex) { trans.VoteRollBack(); throw ex; } } }
/// <summary> /// 添加兄弟模块 /// </summary> /// <param name="module"></param> public void CreateAsSib(SysAuth sib) { this.ParentID = sib.ParentID; this.Path = sib.Path; this.PathLevel = sib.PathLevel; this.DoCreate(); }
/// <summary> /// 添加子模块 /// </summary> /// <param name="module"></param> public void CreateAsSub(SysAuth parent) { this.ParentID = parent.AuthID; this.Path = String.Format("{0}.{1}", (parent.Path == null ? String.Empty : parent.Path), parent.AuthID); this.PathLevel = parent.PathLevel + 1; this.DoCreate(); }
/// <summary> /// 获取应用权限类型的应用 /// </summary> /// <returns></returns> public static IList <SysApplication> GetApplications() { // Type为1,ID为Data的权限 DetachedCriteria crits = DetachedCriteria.For <SysAuth>(); crits.Add(Expression.IsNotNull("Data")); crits.Add(Expression.IsNull("ModuleID")); crits.Add(Expression.Eq("Type", 1)); crits.SetResultTransformer(new DistinctRootEntityResultTransformer()); IList <SysAuth> auths = SysAuth.FindAll(crits); return(SysAuthRule.RetrieveAllApplicationFromAuthList(auths)); }
/// <summary> /// 由ID集合获取权限集合 /// </summary> /// <param name="authIDs"></param> /// <returns></returns> public static ICollection <SysAuth> GetAuthByIDs(ICollection authIDs) { ICollection myAuthIDs = null; if (authIDs is JArray) { JArray arrAuths = authIDs as JArray; myAuthIDs = new List <string>(arrAuths.Values <string>()); } else { myAuthIDs = authIDs; } SysAuth[] tAuths = SysAuth.FindAll(Expression.In("AuthID", myAuthIDs)); return(tAuths); }
/// <summary> /// 创建应用(将同时生成一条Type为1的权限信息) /// </summary> public void DoCreate() { this.DoValidate(); using (TransactionScope trans = new TransactionScope()) { try { // 事务开始 this.CreateAndFlush(); SysAuth auth = new SysAuth(); auth.CreateByApplication(this); trans.VoteCommit(); } catch (Exception ex) { trans.VoteRollBack(); throw ex; } } }
/// <summary> /// 是否拥有某权限 /// </summary> /// <param name="role"></param> /// <returns></returns> public bool HasPermission(SysAuth auth) { return(this.Auth.Contains(auth)); }
/// <summary> /// 获取可访问的应用 /// </summary> /// <returns></returns> public IList <SysApplication> GetAccessibleApplications() { return(SysAuth.GetApplicationsByAuths(this.AllAuth)); }
/// <summary> /// 获取可访问呢模块 /// </summary> /// <returns></returns> public IList <SysModule> GetAccessibleModules() { return(SysAuth.GetModulesByAuths(this.AllAuth)); }
/// <summary> /// 添加子模块 /// </summary> /// <param name="module"></param> public void CreateAsSub(string parentID) { SysAuth parent = SysAuth.Find(parentID); CreateAsSub(parent); }
/// <summary> /// 添加兄弟模块 /// </summary> /// <param name="module"></param> public void CreateAsSibs(string sibID) { SysAuth sib = SysAuth.Find(sibID); CreateAsSib(sib); }
/// <summary> /// 查询所有 /// </summary> /// <returns></returns> new public static SysAuth[] FindAll() { return(SysAuth.FindAll("FROM SysAuth auth WHERE auth.AuthID <> ?", '0')); }
/// <summary> /// 获取相应层级子级 /// </summary> /// <returns></returns> public SysAuth[] GetSubs() { int currLevel = this.PathLevel.GetValueOrDefault(); return(SysAuth.FindAll("PathLevel > ?", currLevel)); }
/// <summary> /// 获取相关权限 /// </summary> /// <returns></returns> public SysAuth[] GetRelatedAuth() { // Type为1 代表应用权限 SysAuth[] auths = SysAuth.FindAllByProperties("Type", 1, "ModuleID", this.ModuleID); return(auths); }
/// <summary> /// 获取相关权限 /// </summary> /// <returns></returns> public SysAuth[] GetRelatedAuth() { // Type为1 代表应用权限 SysAuth[] auths = SysAuth.FindAllByProperties("Type", 1, "Data", this.ApplicationID); return(auths); }