Ejemplo n.º 1
0
        /// <summary>
        /// 验证是否有权限(返回BOOL值)
        /// </summary>
        /// <param name="role"></param>
        public bool CheckAdminRightForRole(Role role)
        {
            if (role == null || role.SystemID <= 0)
            {
                return(false);
            }

            switch (LoginUser.AccountType)
            {
            case UserTypeOptions.SuperAdmin:
                break;

            case UserTypeOptions.Admin:
                //管理员不能操作系统角色
                if (role.RoleType != RoleTypeOptions.General)
                {
                    return(false);
                }
                //不可以修改自身拥有的角色的权限
                if (role.ID > 0 && GetMyRoleIds(role.SystemID).Exists(a => a == role.ID))
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }
            //不可以修改没有管理权限的系统的角色信息
            if (!AdminSystems.Exists(a => a.ID == role.SystemID))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 验证是否有权限(返回BOOL值)
        /// </summary>
        /// <param name="sysId"></param>
        /// <param name="user"></param>
        /// <param name="allowProductAdmin"></param>
        /// <returns></returns>
        public bool CheckAdminRightForUserGrant(int sysId, User user, bool allowProductAdmin)
        {
            if (user == null || user.ID <= 0)
            {
                return(false);
            }

            switch (LoginUser.AccountType)
            {
            case UserTypeOptions.SuperAdmin:
                if (user.AccountType == UserTypeOptions.SuperAdmin && user.ID != LoginUser.ID)
                {
                    return(false);
                }
                return(true);

            case UserTypeOptions.Admin:
                if (user.AccountType == UserTypeOptions.SuperAdmin || user.AccountType == UserTypeOptions.Admin)
                {
                    return(false);
                }
                break;

            case UserTypeOptions.ProductAdmin:
                if (!allowProductAdmin)
                {
                    throw new NotRightException();
                }
                if (user.AccountType == UserTypeOptions.SuperAdmin || user.AccountType == UserTypeOptions.Admin ||
                    user.AccountType == UserTypeOptions.ProductAdmin)
                {
                    return(false);
                }
                break;

            default:
                return(false);
            }
            //必须要有该系统的管理权限
            if (sysId > 0 && !AdminSystems.Exists(a => a.ID == sysId))
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 验证是否有管理员权限(没有权限抛出NotRightException异常)
        /// </summary>
        /// <param name="sysId"></param>
        /// <param name="allowProductAdmin"></param>
        internal void HaveAdminRight(int sysId, bool allowProductAdmin)
        {
            switch (LoginUser.AccountType)
            {
            case UserTypeOptions.SuperAdmin:
            case UserTypeOptions.Admin:
                break;

            case UserTypeOptions.ProductAdmin:
                if (!allowProductAdmin)
                {
                    throw new NotRightException();
                }
                break;

            default:
                throw new NotRightException();
            }
            if (sysId > 0 && !AdminSystems.Exists(a => a.ID == sysId))
            {
                throw new NotRightException();
            }
        }