Browse Source

Merge pull request #9523 from abpframework/EngincanV/identity-users-search

Identity: Add role and organization filters to GetListAsync
pull/9552/head
maliming 5 years ago
committed by GitHub
parent
commit
eaa807ee03
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserRepositoryExternalUserLookupServiceProvider.cs
  3. 8
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  4. 8
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

4
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<long> GetCountAsync(
string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default
);
}

2
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);
}
}
}

8
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -136,6 +136,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
int skipCount = 0,
string filter = null,
bool includeDetails = false,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
@ -149,6 +151,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 +190,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public virtual async Task<long> GetCountAsync(
string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
@ -198,6 +204,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));
}

8
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -138,6 +138,8 @@ namespace Volo.Abp.Identity.MongoDB
int skipCount = 0,
string filter = null,
bool includeDetails = false,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
@ -150,6 +152,8 @@ namespace Volo.Abp.Identity.MongoDB
(u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value))
.OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.UserName) : sorting)
.As<IMongoQueryable<IdentityUser>>()
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
@ -195,6 +199,8 @@ namespace Volo.Abp.Identity.MongoDB
public virtual async Task<long> GetCountAsync(
string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken))
@ -207,6 +213,8 @@ namespace Volo.Abp.Identity.MongoDB
(u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.Contains(filter))
)
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(roleId.HasValue, identityUser => identityUser.Roles.Any(x => x.RoleId == roleId.Value))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(organizationUnitId.HasValue, identityUser => identityUser.OrganizationUnits.Any(x => x.OrganizationUnitId == organizationUnitId.Value))
.LongCountAsync(GetCancellationToken(cancellationToken));
}

Loading…
Cancel
Save