Browse Source

Add role and organization unit filter to IdentityUserRepository

pull/9523/head
Engincan VESKE 5 years ago
parent
commit
8a0c51aaba
  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. 13
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  4. 13
      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);
}
}
}

13
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<long> 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));
}

13
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<IdentityUser, IMongoQueryable<IdentityUser>>(
!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<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 +204,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 +218,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