diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index 3814ab96e3..5675bf1fd4 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -56,6 +56,8 @@ namespace Volo.Abp.Identity int skipCount = 0, string filter = null, bool includeDetails = false, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default ); @@ -86,6 +88,8 @@ namespace Volo.Abp.Identity Task GetCountAsync( string filter = null, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default ); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs index c0fb15d80c..40b4575afe 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs @@ -71,7 +71,7 @@ namespace Volo.Abp.Identity string filter = null, CancellationToken cancellationToken = new CancellationToken()) { - return await UserRepository.GetCountAsync(filter, cancellationToken); + return await UserRepository.GetCountAsync(filter, cancellationToken: cancellationToken); } } } 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 dfed75c804..2ab2fb8263 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 @@ -136,8 +136,15 @@ namespace Volo.Abp.Identity.EntityFrameworkCore int skipCount = 0, string filter = null, bool includeDetails = false, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default) { + if(roleId.HasValue || organizationUnitId.HasValue) + { + includeDetails = true; + } + return await (await GetDbSetAsync()) .IncludeDetails(includeDetails) .WhereIf( @@ -149,6 +156,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore (u.Surname != null && u.Surname.Contains(filter)) || (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) + .WhereIf(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value)) + .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.UserName) : sorting) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -186,6 +195,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore public virtual async Task GetCountAsync( string filter = null, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default) { return await (await GetDbSetAsync()) @@ -198,6 +209,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore (u.Surname != null && u.Surname.Contains(filter)) || (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) + .WhereIf(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value)) + .WhereIf(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .LongCountAsync(GetCancellationToken(cancellationToken)); } 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 82db48b3ed..df0fe15672 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 @@ -138,8 +138,15 @@ namespace Volo.Abp.Identity.MongoDB int skipCount = 0, string filter = null, bool includeDetails = false, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default) { + if(roleId.HasValue || organizationUnitId.HasValue) + { + includeDetails = true; + } + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), @@ -150,6 +157,8 @@ namespace Volo.Abp.Identity.MongoDB (u.Surname != null && u.Surname.Contains(filter)) || (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) + .WhereIf>(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value)) + .WhereIf>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.UserName) : sorting) .As>() .PageBy>(skipCount, maxResultCount) @@ -195,6 +204,8 @@ namespace Volo.Abp.Identity.MongoDB public virtual async Task GetCountAsync( string filter = null, + Guid? roleId = null, + Guid? organizationUnitId = null, CancellationToken cancellationToken = default) { return await (await GetMongoQueryableAsync(cancellationToken)) @@ -207,6 +218,8 @@ namespace Volo.Abp.Identity.MongoDB (u.Surname != null && u.Surname.Contains(filter)) || (u.PhoneNumber != null && u.PhoneNumber.Contains(filter)) ) + .WhereIf>(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value)) + .WhereIf>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value)) .LongCountAsync(GetCancellationToken(cancellationToken)); }