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, int skipCount = 0,
string filter = null, string filter = null,
bool includeDetails = false, bool includeDetails = false,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
@ -86,6 +88,8 @@ namespace Volo.Abp.Identity
Task<long> GetCountAsync( Task<long> GetCountAsync(
string filter = null, string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default 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, string filter = null,
CancellationToken cancellationToken = new CancellationToken()) 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, int skipCount = 0,
string filter = null, string filter = null,
bool includeDetails = false, bool includeDetails = false,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if(roleId.HasValue || organizationUnitId.HasValue)
{
includeDetails = true;
}
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.WhereIf( .WhereIf(
@ -149,6 +156,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.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) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.UserName) : sorting)
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
@ -186,6 +195,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public virtual async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
string filter = null, string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()) return await (await GetDbSetAsync())
@ -198,6 +209,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.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)); .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, int skipCount = 0,
string filter = null, string filter = null,
bool includeDetails = false, bool includeDetails = false,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if(roleId.HasValue || organizationUnitId.HasValue)
{
includeDetails = true;
}
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>( .WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
@ -150,6 +157,8 @@ namespace Volo.Abp.Identity.MongoDB
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.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) .OrderBy(sorting.IsNullOrWhiteSpace() ? nameof(IdentityUser.UserName) : sorting)
.As<IMongoQueryable<IdentityUser>>() .As<IMongoQueryable<IdentityUser>>()
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount) .PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
@ -195,6 +204,8 @@ namespace Volo.Abp.Identity.MongoDB
public virtual async Task<long> GetCountAsync( public virtual async Task<long> GetCountAsync(
string filter = null, string filter = null,
Guid? roleId = null,
Guid? organizationUnitId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
@ -207,6 +218,8 @@ namespace Volo.Abp.Identity.MongoDB
(u.Surname != null && u.Surname.Contains(filter)) || (u.Surname != null && u.Surname.Contains(filter)) ||
(u.PhoneNumber != null && u.PhoneNumber.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)); .LongCountAsync(GetCancellationToken(cancellationToken));
} }

Loading…
Cancel
Save