From 4db9a9a42ef73ac04aaf34670dad0ba6d2be25dd Mon Sep 17 00:00:00 2001 From: Mehmet Perk Date: Tue, 14 Jan 2020 23:12:55 +0300 Subject: [PATCH] get users by organization unit --- .../Abp/Identity/IIdentityUserRepository.cs | 10 +++++ .../Volo/Abp/Identity/IdentityUserManager.cs | 37 +++++++++++++----- .../IOrganizationUnitRepository.cs | 2 +- .../EfCoreIdentityUserRepository.cs | 26 +++++++++++++ .../EfCoreOrganizationUnitRepository.cs | 2 +- .../MongoDB/MongoIdentityUserRepository.cs | 38 ++++++++++++++++++- .../MongoOrganizationUnitRepository.cs | 2 +- .../Abp/Identity/IdentityUserManager_Tests.cs | 6 +-- .../Identity/OrganizationUnitManager_Tests.cs | 32 ++++++++-------- .../Identity/IdentityUserRepository_Tests.cs | 26 +++++++++++++ .../Volo/Abp/Identity/LazyLoading_Tests.cs | 2 +- .../OrganizationUnitRepository_Tests.cs | 4 +- 12 files changed, 151 insertions(+), 36 deletions(-) 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 04ff5c2e5f..ef03c86b7a 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 @@ -71,6 +71,16 @@ namespace Volo.Abp.Identity bool includeDetails = false, CancellationToken cancellationToken = default); + Task> GetUsersInOrganizationUnitAsync( + Guid organizationUnitId, + CancellationToken cancellationToken = default + ); + + Task> GetUsersInOrganizationUnitWithChildrenAsync( + string code, + CancellationToken cancellationToken = default + ); + Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs index 87faf866cb..644c21df5c 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs @@ -93,8 +93,8 @@ namespace Volo.Abp.Identity public virtual async Task IsInOrganizationUnitAsync(Guid userId, Guid ouId) { return await IsInOrganizationUnitAsync( - await GetByIdAsync(userId), - await _organizationUnitRepository.GetAsync(ouId) + await GetByIdAsync(userId).ConfigureAwait(false), + await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false) ); } @@ -106,8 +106,8 @@ namespace Volo.Abp.Identity public virtual async Task AddToOrganizationUnitAsync(Guid userId, Guid ouId) { await AddToOrganizationUnitAsync( - await _identityUserRepository.GetAsync(userId, true), - await _organizationUnitRepository.GetAsync(ouId) + await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false), + await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false) ); } @@ -130,8 +130,8 @@ namespace Volo.Abp.Identity public virtual async Task RemoveFromOrganizationUnitAsync(Guid userId, Guid ouId) { await RemoveFromOrganizationUnitAsync( - await _identityUserRepository.GetAsync(userId, true), - await _organizationUnitRepository.GetAsync(ouId) + await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false), + await _organizationUnitRepository.GetAsync(ouId).ConfigureAwait(false) ); } @@ -145,7 +145,7 @@ namespace Volo.Abp.Identity public virtual async Task SetOrganizationUnitsAsync(Guid userId, params Guid[] organizationUnitIds) { await SetOrganizationUnitsAsync( - await _identityUserRepository.GetAsync(userId, true), + await _identityUserRepository.GetAsync(userId, true).ConfigureAwait(false), organizationUnitIds ); } @@ -164,7 +164,7 @@ namespace Volo.Abp.Identity { if (!organizationUnitIds.Contains(currentOu.Id)) { - await RemoveFromOrganizationUnitAsync(user.Id, currentOu.Id); + await RemoveFromOrganizationUnitAsync(user.Id, currentOu.Id).ConfigureAwait(false); } } @@ -175,7 +175,7 @@ namespace Volo.Abp.Identity { await AddToOrganizationUnitAsync( user, - await _organizationUnitRepository.GetAsync(organizationUnitId) + await _organizationUnitRepository.GetAsync(organizationUnitId).ConfigureAwait(false) ); } } @@ -197,7 +197,24 @@ namespace Volo.Abp.Identity var ouOfUser = user.OrganizationUnits; - return await _organizationUnitRepository.GetListAsync(ouOfUser.Select(t => t.OrganizationUnitId)); + return await _organizationUnitRepository.GetListAsync(ouOfUser.Select(t => t.OrganizationUnitId)).ConfigureAwait(false); + } + + [UnitOfWork] + public virtual async Task> GetUsersInOrganizationUnitAsync(OrganizationUnit organizationUnit, bool includeChildren = false) + { + if (includeChildren) + { + return await _identityUserRepository + .GetUsersInOrganizationUnitWithChildrenAsync(organizationUnit.Code) + .ConfigureAwait(false); + } + else + { + return await _identityUserRepository + .GetUsersInOrganizationUnitAsync(organizationUnit.Id) + .ConfigureAwait(false); + } } } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs index 81bd90acea..4d90ba3a1d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs @@ -16,7 +16,7 @@ namespace Volo.Abp.Identity.Organizations Task> GetListAsync(bool includeDetails = true, CancellationToken cancellationToken = default); - Task GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default); + Task GetOrganizationUnitAsync(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default); } } 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 587c2043ac..0564668225 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 @@ -170,6 +170,32 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); } + public virtual async Task> GetUsersInOrganizationUnitAsync( + Guid organizationUnitId, + CancellationToken cancellationToken = default + ) + { + var query = from userOu in DbContext.Set() + join user in DbSet on userOu.UserId equals user.Id + where userOu.OrganizationUnitId == organizationUnitId + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); + } + + + public virtual async Task> GetUsersInOrganizationUnitWithChildrenAsync( + string code, + CancellationToken cancellationToken = default + ) + { + var query = from userOu in DbContext.Set() + join user in DbSet on userOu.UserId equals user.Id + join ou in DbContext.Set() on userOu.OrganizationUnitId equals ou.Id + where ou.Code.StartsWith(code) + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); + } + public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs index 7d4a8a1fa0..0c4a486481 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs @@ -42,7 +42,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); } - public async Task GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task GetOrganizationUnitAsync(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default) { return await DbSet .IncludeDetails(includeDetails) 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 f309cdcf7d..8da8bd9cf0 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 @@ -140,7 +140,10 @@ namespace Volo.Abp.Identity.MongoDB { var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false); var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId); - return await DbContext.OrganizationUnits.AsQueryable().Where(ou => organizationUnitIds.Contains(ou.Id)).ToListAsync().ConfigureAwait(false); + return await DbContext.OrganizationUnits.AsQueryable() + .Where(ou => organizationUnitIds.Contains(ou.Id)) + .ToListAsync(GetCancellationToken(cancellationToken)) + .ConfigureAwait(false); } public async Task GetCountAsync( @@ -156,5 +159,38 @@ namespace Volo.Abp.Identity.MongoDB ) .LongCountAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); } + + public async Task> GetUsersInOrganizationUnitAsync( + Guid organizationUnitId, + CancellationToken cancellationToken = default) + { + var organizationUnitUserIds = await DbContext.Users.AsQueryable() + .SelectMany(u => u.OrganizationUnits) + .Where(ou => ou.OrganizationUnitId == organizationUnitId) + .Select(ouu => ouu.Id) + .ToListAsync(GetCancellationToken(cancellationToken)) + .ConfigureAwait(false); + + return await GetMongoQueryable() + .Where(u => u.OrganizationUnits.Any(uou => organizationUnitUserIds.Contains(uou.Id))) + .ToListAsync(GetCancellationToken(cancellationToken)) + .ConfigureAwait(false); + } + + public async Task> GetUsersInOrganizationUnitWithChildrenAsync( + string code, + CancellationToken cancellationToken = default) + { + var organizationUnitIds = await DbContext.OrganizationUnits.AsQueryable() + .Where(ou => ou.Code.StartsWith(code)) + .Select(ou => ou.Id) + .ToListAsync(GetCancellationToken(cancellationToken)) + .ConfigureAwait(false); + + return await GetMongoQueryable() + .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) + .ToListAsync(GetCancellationToken(cancellationToken)) + .ConfigureAwait(false); + } } } \ No newline at end of file diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs index 483daf31a7..cede5e46de 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs @@ -44,7 +44,7 @@ namespace Volo.Abp.Identity.MongoDB .Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); } - public async Task GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task GetOrganizationUnitAsync(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default) { return await DbContext.OrganizationUnits.AsQueryable() .FirstOrDefaultAsync( diff --git a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs index b2749a2f4a..444e6e26e1 100644 --- a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityUserManager_Tests.cs @@ -97,7 +97,7 @@ namespace Volo.Abp.Identity _lookupNormalizer.NormalizeName("david")).ConfigureAwait(false); user.ShouldNotBeNull(); - var ou = await _organizationUnitRepository.GetOrganizationUnit( + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( _lookupNormalizer.NormalizeName("OU11")).ConfigureAwait(false); ou.ShouldNotBeNull(); @@ -120,7 +120,7 @@ namespace Volo.Abp.Identity { using (var uow = _unitOfWorkManager.Begin()) { - var ou = await _organizationUnitRepository.GetOrganizationUnit( + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( _lookupNormalizer.NormalizeName("OU111")).ConfigureAwait(false); ou.ShouldNotBeNull(); @@ -128,7 +128,7 @@ namespace Volo.Abp.Identity _lookupNormalizer.NormalizeName("john.nash")).ConfigureAwait(false); user.ShouldNotBeNull(); - var ouNew = await _organizationUnitRepository.GetOrganizationUnit( + var ouNew = await _organizationUnitRepository.GetOrganizationUnitAsync( _lookupNormalizer.NormalizeName("OU2")).ConfigureAwait(false); ouNew.ShouldNotBeNull(); diff --git a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs index 0ed3618318..539af5d1a1 100644 --- a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs @@ -31,55 +31,55 @@ namespace Volo.Abp.Identity { await _organizationUnitManager.CreateAsync(new OrganizationUnit(null, "Root 1")); - var root1 = await _organizationUnitRepository.GetOrganizationUnit("Root 1").ConfigureAwait(false); + var root1 = await _organizationUnitRepository.GetOrganizationUnitAsync("Root 1").ConfigureAwait(false); root1.ShouldNotBeNull(); } [Fact] public async Task UpdateAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnit("OU111").ConfigureAwait(false); + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111").ConfigureAwait(false); ou.Code = OrganizationUnit.CreateCode(123); await _organizationUnitManager.UpdateAsync(ou); - var ouAfterChange = await _organizationUnitRepository.GetOrganizationUnit("OU111").ConfigureAwait(false); + var ouAfterChange = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111").ConfigureAwait(false); ouAfterChange.Code.ShouldContain("123"); } [Fact] public async Task DeleteAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnit("OU11").ConfigureAwait(false); + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11").ConfigureAwait(false); await _organizationUnitManager.DeleteAsync(ou.Id); - (await _organizationUnitRepository.GetOrganizationUnit("OU11").ConfigureAwait(false)).ShouldBeNull(); + (await _organizationUnitRepository.GetOrganizationUnitAsync("OU11").ConfigureAwait(false)).ShouldBeNull(); } [Fact] public async Task MoveAsync() { - var ou1 = await _organizationUnitRepository.GetOrganizationUnit("OU1").ConfigureAwait(false); - var ou2 = await _organizationUnitRepository.GetOrganizationUnit("OU2").ConfigureAwait(false); + var ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1").ConfigureAwait(false); + var ou2 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU2").ConfigureAwait(false); await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id); - ou1 = await _organizationUnitRepository.GetOrganizationUnit("OU1").ConfigureAwait(false); + ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1").ConfigureAwait(false); ou1.ParentId.ShouldBe(ou2.Id); ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2)); - var ou11 = await _organizationUnitRepository.GetOrganizationUnit("OU11").ConfigureAwait(false); + var ou11 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11").ConfigureAwait(false); ou11.ParentId.ShouldBe(ou1.Id); ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1)); - var ou111 = await _organizationUnitRepository.GetOrganizationUnit("OU111").ConfigureAwait(false); + var ou111 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111").ConfigureAwait(false); ou111.ParentId.ShouldBe(ou11.Id); ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1)); - var ou112 = await _organizationUnitRepository.GetOrganizationUnit("OU112").ConfigureAwait(false); + var ou112 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU112").ConfigureAwait(false); ou112.ParentId.ShouldBe(ou11.Id); ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2)); - var ou12 = await _organizationUnitRepository.GetOrganizationUnit("OU12").ConfigureAwait(false); + var ou12 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU12").ConfigureAwait(false); ou12.ParentId.ShouldBe(ou1.Id); ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2)); } @@ -87,24 +87,24 @@ namespace Volo.Abp.Identity [Fact] public async Task AddRoleToOrganizationUnitAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", true).ConfigureAwait(false); + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true).ConfigureAwait(false); var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")).ConfigureAwait(false); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou); //TODO: This method has a bug: add role not work - ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", includeDetails: true).ConfigureAwait(false); + ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true).ConfigureAwait(false); ou.Roles.FirstOrDefault().Id.ShouldBe(adminRole.Id); } [Fact] public async Task RemoveRoleFromOrganizationUnitAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", true).ConfigureAwait(false); + var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true).ConfigureAwait(false); var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")).ConfigureAwait(false); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole.Id, ou.Id); await _organizationUnitManager.RemoveRoleFromOrganizationUnitAsync(adminRole.Id, ou.Id); - ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", includeDetails: true).ConfigureAwait(false); + ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true).ConfigureAwait(false); ou.Roles.FirstOrDefault(r => r.RoleId == adminRole.Id).ShouldBeNull(); } } diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs index f4719a63a7..7433e4c202 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityUserRepository_Tests.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Shouldly; +using Volo.Abp.Identity.Organizations; using Volo.Abp.Modularity; using Xunit; @@ -15,11 +16,13 @@ namespace Volo.Abp.Identity { protected IIdentityUserRepository UserRepository { get; } protected ILookupNormalizer LookupNormalizer { get; } + protected IOrganizationUnitRepository OrganizationUnitRepository { get; } protected IdentityUserRepository_Tests() { UserRepository = ServiceProvider.GetRequiredService(); LookupNormalizer = ServiceProvider.GetRequiredService(); + OrganizationUnitRepository = ServiceProvider.GetRequiredService(); } [Fact] @@ -128,6 +131,22 @@ namespace Volo.Abp.Identity (await UserRepository.GetCountAsync("undefined-username").ConfigureAwait(false)).ShouldBe(0); } + [Fact] + public async Task GetUsersInOrganizationUnitAsync() + { + var users = await UserRepository.GetUsersInOrganizationUnitAsync((await GetOU("OU111").ConfigureAwait(false)).Id).ConfigureAwait(false); + users.ShouldNotBeNull(); + users.Count.ShouldBeGreaterThan(0); + } + + [Fact] + public async Task GetUsersInOrganizationUnitWithChildrenAsync() + { + var users = await UserRepository.GetUsersInOrganizationUnitWithChildrenAsync((await GetOU("OU111").ConfigureAwait(false)).Code).ConfigureAwait(false); + users.ShouldNotBeNull(); + users.Count.ShouldBeGreaterThan(0); + } + [Fact] public async Task Should_Eager_Load_User_Collections() { @@ -148,5 +167,12 @@ namespace Volo.Abp.Identity john.OrganizationUnits.ShouldNotBeNull(); john.OrganizationUnits.Any().ShouldBeTrue(); } + + private async Task GetOU(string diplayName) + { + var organizationUnit = await OrganizationUnitRepository.GetOrganizationUnitAsync(diplayName).ConfigureAwait(false); + organizationUnit.ShouldNotBeNull(); + return organizationUnit; + } } } diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs index cd09c1209e..3db968232b 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/LazyLoading_Tests.cs @@ -70,7 +70,7 @@ namespace Volo.Abp.Identity { using (var uow = GetRequiredService().Begin()) { - var ou = await OrganizationUnitRepository.GetOrganizationUnit(LookupNormalizer.NormalizeName("OU111"), includeDetails: false).ConfigureAwait(false); + var ou = await OrganizationUnitRepository.GetOrganizationUnitAsync(LookupNormalizer.NormalizeName("OU111"), includeDetails: false).ConfigureAwait(false); ou.Roles.ShouldNotBeNull(); //? ou.Roles.Any().ShouldBeTrue(); diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs index 4d6e07f447..20452a90f5 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs @@ -52,9 +52,9 @@ namespace Volo.Abp.Identity } [Fact] - public async Task GetOrganizationUnit() + public async Task GetOrganizationUnitAsync() { - var organizationUnit = await OrganizationUnitRepository.GetOrganizationUnit("OU111").ConfigureAwait(false); + var organizationUnit = await OrganizationUnitRepository.GetOrganizationUnitAsync("OU111").ConfigureAwait(false); organizationUnit.ShouldNotBeNull(); }