Exemple #1
0
        /// <summary>
        /// 用户授权筛选
        /// </summary>
        /// <param name="filter">筛选信息</param>
        /// <returns></returns>
        IQuery CreateAuthorityQueryObject(UserAuthorityFilterDto filter)
        {
            if (filter == null)
            {
                return(null);
            }
            IQuery query = CreateAuthorityQueryObject(filter, true) ?? QueryFactory.Create <AuthorityQuery>();

            #region 用户授权筛选

            if (filter.UserFilter != null)
            {
                IQuery userQuery = this.Instance <IUserBusiness>().CreateQueryObject(filter.UserFilter);
                if (userQuery != null)
                {
                    userQuery.AddQueryFields <UserQuery>(c => c.SysNo);

                    #region 用户或者角色绑定的授权

                    IQuery userOrRoleBindAuthQuery = QueryFactory.Create();

                    //用户授权
                    IQuery userAuthBindQuery = QueryFactory.Create <UserAuthorizeQuery>(c => c.Disable == false);
                    userAuthBindQuery.And <UserAuthorizeQuery>(c => c.User, CriteriaOperator.In, userQuery);
                    userAuthBindQuery.AddQueryFields <UserAuthorizeQuery>(c => c.Authority);
                    IQuery userAuthQuery = QueryFactory.Create <AuthorityQuery>();
                    userAuthQuery.And <AuthorityQuery>(c => c.Code, CriteriaOperator.In, userAuthBindQuery);
                    userOrRoleBindAuthQuery.And(userAuthQuery);
                    //角色授权
                    IQuery userRoleBindQuery = QueryFactory.Create <UserRoleQuery>();
                    userRoleBindQuery.And <UserRoleQuery>(c => c.UserSysNo, CriteriaOperator.In, userQuery);
                    userRoleBindQuery.AddQueryFields <UserRoleQuery>(c => c.RoleSysNo);
                    IQuery roleAuthBindQuery = QueryFactory.Create <RoleAuthorizeQuery>();
                    roleAuthBindQuery.And <RoleAuthorizeQuery>(c => c.Role, CriteriaOperator.In, userRoleBindQuery);
                    roleAuthBindQuery.AddQueryFields <RoleAuthorizeQuery>(c => c.Authority);
                    IQuery roleAuthQuery = QueryFactory.Create <AuthorityQuery>();
                    roleAuthQuery.And <AuthorityQuery>(c => c.Code, CriteriaOperator.In, roleAuthBindQuery);
                    userOrRoleBindAuthQuery.Or(roleAuthQuery);

                    query.And(userOrRoleBindAuthQuery);

                    #endregion

                    //排除用户禁用的授权
                    IQuery userDisableAuthQuery = QueryFactory.Create <UserAuthorizeQuery>(c => c.Disable == true);
                    userDisableAuthQuery.And <UserAuthorizeQuery>(c => c.User, CriteriaOperator.In, userQuery);
                    userDisableAuthQuery.AddQueryFields <UserAuthorizeQuery>(c => c.Authority);
                    query.And <AuthorityQuery>(c => c.Code, CriteriaOperator.NotIn, userDisableAuthQuery);
                }
            }

            #endregion

            return(query);
        }
Exemple #2
0
 public ActionResult SearchUserAuthority(UserAuthorityFilterDto filter)
 {
     return(SearchAuthority(filter));
 }
Exemple #3
0
        /// <summary>
        /// 用户授权筛选
        /// </summary>
        /// <param name="filter">筛选信息</param>
        /// <returns></returns>
        IQuery CreateUserAuthorityQueryObject(UserAuthorityFilterDto filter)
        {
            if (filter == null)
            {
                return(null);
            }
            IQuery query = CreateAuthorityQueryObject(filter, true) ?? QueryManager.Create <AuthorityQuery>();

            #region 用户授权筛选

            if (filter.UserFilter != null)
            {
                IQuery userQuery = this.Instance <IUserBusiness>().CreateQueryObject(filter.UserFilter);
                if (userQuery != null)
                {
                    userQuery.AddQueryFields <UserQuery>(c => c.SysNo);

                    IQuery userOrRoleBindAuthQuery = QueryManager.Create();//用户和角色授权权限

                    #region 用户授权

                    IQuery userBindAuthQuery = QueryManager.Create <UserAuthorizeQuery>(c => c.Disable == false);
                    userBindAuthQuery.In <UserAuthorizeQuery>(c => c.UserSysNo, userQuery);
                    userBindAuthQuery.AddQueryFields <UserAuthorizeQuery>(c => c.AuthoritySysNo);
                    IQuery userAuthQuery = QueryManager.Create <AuthorityQuery>();
                    userAuthQuery.In <AuthorityQuery>(c => c.SysNo, userBindAuthQuery);
                    userOrRoleBindAuthQuery.And(userAuthQuery);

                    #endregion

                    #region 角色授权

                    //用户绑定的角色
                    var userRoleBindQuery = QueryManager.Create <UserRoleQuery>();
                    userRoleBindQuery.In <UserRoleQuery>(c => c.UserSysNo, userQuery);
                    userRoleBindQuery.AddQueryFields <UserRoleQuery>(c => c.RoleSysNo);
                    //包括所有上级角色
                    var roleQuery = QueryManager.Create <RoleQuery>(r => r.Status == RoleStatus.正常);
                    roleQuery.In <RoleQuery>(r => r.SysNo, userRoleBindQuery);
                    roleQuery.SetRecurve <RoleQuery>(r => r.SysNo, r => r.Parent, RecurveDirection.Up);
                    roleQuery.AddQueryFields <RoleQuery>(r => r.SysNo);

                    //角色授权
                    var roleAuthBindQuery = QueryManager.Create <RoleAuthorizeQuery>();
                    roleAuthBindQuery.In <RoleAuthorizeQuery>(c => c.RoleSysNo, roleQuery);
                    roleAuthBindQuery.AddQueryFields <RoleAuthorizeQuery>(c => c.AuthoritySysNo);
                    var roleAuthQuery = QueryManager.Create <AuthorityQuery>();
                    roleAuthQuery.In <AuthorityQuery>(c => c.SysNo, roleAuthBindQuery);
                    userOrRoleBindAuthQuery.Or(roleAuthQuery);

                    #endregion

                    query.And(userOrRoleBindAuthQuery);

                    #region 用户禁用授权

                    IQuery userDisableAuthQuery = QueryManager.Create <UserAuthorizeQuery>(c => c.Disable == true);
                    userDisableAuthQuery.In <UserAuthorizeQuery>(c => c.UserSysNo, userQuery);
                    userDisableAuthQuery.AddQueryFields <UserAuthorizeQuery>(c => c.AuthoritySysNo);
                    query.NotIn <AuthorityQuery>(c => c.SysNo, userDisableAuthQuery);

                    #endregion
                }
            }

            #endregion

            return(query);
        }