示例#1
0
        private bool CanManage(Role role1, Role role2, PermissionLimit limit)
        {
            if ((role1.Type & RoleType.Manager) != RoleType.Manager)
            {
                return(false);                                                    //组1 不是管理员, 默认返回false
            }
            if ((role2.Type & RoleType.Manager) != RoleType.Manager)
            {
                return(true);                                                     //组2 不是管理员, 默认返回true
            }
            switch (limit.LimitType)
            {
            case PermissionLimitType.Unlimited:
                return(true);

            case PermissionLimitType.RoleLevelLowerMe:
                if (role1.Level > role2.Level)
                {
                    return(true);
                }
                break;

            case PermissionLimitType.RoleLevelLowerOrSameMe:
                if (role1.Level >= role2.Level)
                {
                    return(true);
                }
                break;

            case PermissionLimitType.ExcludeCustomRoles:
                if (limit.ExcludeRoles.ContainsKey(role1.RoleID))
                {
                    List <Guid> r = limit.ExcludeRoles[role1.RoleID];
                    return(r == null ? true : !r.Contains(role2.RoleID));
                }
                else
                {
                    return(true);
                }
            }
            return(false);
        }
示例#2
0
 private  bool CanManage(Role role1, Role role2, PermissionLimit limit)
 {
     if((role1.Type & RoleType.Manager)!= RoleType.Manager ) return false; //组1 不是管理员, 默认返回false
     if ((role2.Type & RoleType.Manager) != RoleType.Manager) return true; //组2 不是管理员, 默认返回true
     switch (limit.LimitType)
     {
         case PermissionLimitType.Unlimited:
             return true;
         case PermissionLimitType.RoleLevelLowerMe:
             if (role1.Level > role2.Level) 
                 return true;
             break;
         case PermissionLimitType.RoleLevelLowerOrSameMe:
             if (role1.Level >= role2.Level) 
                 return true;
             break;
         case PermissionLimitType.ExcludeCustomRoles:
             if (limit.ExcludeRoles.ContainsKey(role1.RoleID))
             {
                 List<Guid> r = limit.ExcludeRoles[role1.RoleID];
                 return r == null ? true : !r.Contains(role2.RoleID);
             }
             else
             {
                 return true;
             }
     }
     return false;
 }
示例#3
0
 public PermissionSettings()
 {
     UserPermissionLimit    = new PermissionLimit(PermissionLimitType.RoleLevelLowerMe);
     ContentPermissionLimit = new PermissionLimit(PermissionLimitType.RoleLevelLowerOrSameMe);
     MarkPermissionLimit    = new PermissionLimit(PermissionLimitType.RoleLevelLowerMe);
 }
示例#4
0
 public PermissionSettings()
 {
     UserPermissionLimit = new PermissionLimit(PermissionLimitType.RoleLevelLowerMe);
     ContentPermissionLimit = new PermissionLimit(PermissionLimitType.RoleLevelLowerOrSameMe);
     MarkPermissionLimit = new PermissionLimit(PermissionLimitType.RoleLevelLowerMe);
 }
        /// <summary>
        /// 如果LimitType == PermissionLimitType.ExcludeCustomRoles 的时候取得页面上返回的角色表 
        /// </summary>
        /// <param name="formKey"></param>
        /// <param name="limit"></param>
        private void GetLimitRoleList( string formKey, PermissionLimit limit)
        {
            limit.ExcludeRoles.Clear();
            foreach (Role r in this.RoleList)
            {

                limit.ExcludeRoles.Add(r.RoleID, new List<Guid>(RoleList.Count));
                foreach (Role r2 in this.RoleList)
                {
                    if (_Request.Get<bool>(string.Format(formKey, r.RoleID, r2.RoleID), Method.Post, false) == false)
                    {
                        limit.ExcludeRoles[r.RoleID].Add(r2.RoleID);
                    }
                }
            }
        }
示例#6
0
        /// <summary>
        /// role1是否可以管理role2的内容
        /// </summary>
        /// <param name="role1"></param>
        /// <param name="role2"></param>
        /// <returns></returns>
        public bool CanManageContent(Guid role1, Guid role2)
        {
            PermissionLimit limit = AllSettings.Current.PermissionSettings.ContentPermissionLimit;

            return(CanManage(GetRole(role1), GetRole(role2), limit));
        }