From 2a730bea7306bcf33bfce27b7181faf6823371a8 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Thu, 21 Mar 2024 16:14:04 +0800 Subject: [PATCH] Fix user filter --- .../EfCoreIdentityUserRepository.cs | 12 ++++++++++-- .../MongoDB/MongoIdentityUserRepository.cs | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs index bbaa8087f4..8c905a3169 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs @@ -289,7 +289,16 @@ public class EfCoreIdentityUserRepository : EfCoreRepository().Where(q => q.RoleId == roleId.Value).Select(q => q.OrganizationUnitId).ToArrayAsync(cancellationToken: cancellationToken); + query = query.Where(identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value) || identityUser.OrganizationUnits.Any(x => organizationUnitIds.Contains(x.OrganizationUnitId))); + } + + return await query .WhereIf( !filter.IsNullOrWhiteSpace(), u => @@ -299,7 +308,6 @@ public class EfCoreIdentityUserRepository : EfCoreRepository identityUser.Roles.Any(x => x.RoleId == roleId.Value)) .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .WhereIf(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) .WhereIf(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber) diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs index aab3e3c63a..43a875f6f0 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs @@ -263,7 +263,19 @@ public class MongoIdentityUserRepository : MongoDbRepository(cancellationToken)) + .Where(ou => ou.Roles.Any(r => r.RoleId == roleId.Value)) + .Select(userOrganizationUnit => userOrganizationUnit.Id) + .ToArray(); + + query = query.Where(identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value) || identityUser.OrganizationUnits.Any(x => organizationUnitIds.Contains(x.OrganizationUnitId))); + } + + return await query .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -273,7 +285,6 @@ public class MongoIdentityUserRepository : MongoDbRepository>(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value)) .WhereIf>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .WhereIf>(!string.IsNullOrWhiteSpace(userName), x => x.UserName == userName) .WhereIf>(!string.IsNullOrWhiteSpace(phoneNumber), x => x.PhoneNumber == phoneNumber)