From 3705c627b3b40c6b025dda51a0a0389aa87ce1fc Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Fri, 24 Apr 2020 03:44:29 +0300 Subject: [PATCH] refactored and renamed --- .../Abp/Identity/IIdentityRoleRepository.cs | 4 +++ .../Abp/Identity/IIdentityUserRepository.cs | 10 ++++-- .../Identity/IOrganizationUnitRepository.cs | 23 +++++++------ .../EfCoreIdentityRoleRepository.cs | 19 ++++++++--- .../EfCoreIdentityUserRepository.cs | 19 +++++++++-- .../EfCoreOrganizationUnitRepository.cs | 12 ++----- .../MongoDB/MongoIdentityRoleRepository.cs | 13 ++++++-- .../MongoDB/MongoIdentityUserRepository.cs | 31 ++++++++++++------ .../MongoOrganizationUnitRepository.cs | 6 ++-- .../Abp/Identity/IdentityUserManager_Tests.cs | 6 ++-- .../Identity/OrganizationUnitManager_Tests.cs | 32 +++++++++---------- .../Identity/AbpIdentityTestDataBuilder.cs | 1 + .../Identity/IdentityUserRepository_Tests.cs | 2 +- .../Volo/Abp/Identity/LazyLoading_Tests.cs | 2 +- .../OrganizationUnitRepository_Tests.cs | 22 ++++++++++--- 15 files changed, 133 insertions(+), 69 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 3a344b3140..9596d34cfb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -20,6 +20,10 @@ namespace Volo.Abp.Identity int skipCount = 0, bool includeDetails = false, CancellationToken cancellationToken = default + ); + Task> GetListAsync( + IEnumerable ids, + CancellationToken cancellationToken = default ); Task> GetDefaultOnesAsync( 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 652dfe23c6..3814ab96e3 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 @@ -33,19 +33,19 @@ namespace Volo.Abp.Identity ); Task FindByNormalizedEmailAsync( - [NotNull] string normalizedEmail, + [NotNull] string normalizedEmail, bool includeDetails = true, CancellationToken cancellationToken = default ); Task> GetListByClaimAsync( - Claim claim, + Claim claim, bool includeDetails = false, CancellationToken cancellationToken = default ); Task> GetListByNormalizedRoleNameAsync( - string normalizedRoleName, + string normalizedRoleName, bool includeDetails = false, CancellationToken cancellationToken = default ); @@ -73,6 +73,10 @@ namespace Volo.Abp.Identity Task> GetUsersInOrganizationUnitAsync( Guid organizationUnitId, CancellationToken cancellationToken = default + ); + Task> GetUsersInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default ); Task> GetUsersInOrganizationUnitWithChildrenAsync( diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs index 891f4a7519..a0ef631d2b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs @@ -20,25 +20,28 @@ namespace Volo.Abp.Identity bool includeDetails = false, CancellationToken cancellationToken = default ); - Task> GetListAsync( - IEnumerable ids, - bool includeDetails = false, + + Task GetAsync( + string displayName, + bool includeDetails = true, CancellationToken cancellationToken = default ); + Task> GetListAsync( string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, - bool includeDetails = true, - CancellationToken cancellationToken = default - ); - - Task GetOrganizationUnitAsync( - string displayName, bool includeDetails = false, CancellationToken cancellationToken = default + ); + + Task> GetListAsync( + IEnumerable ids, + bool includeDetails = false, + CancellationToken cancellationToken = default ); - Task> GetOrganizationUnitRoles( + + Task> GetRolesAsync( Guid organizationUnitId, bool includeDetails = false, CancellationToken cancellationToken = default diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs index dfaaf51d91..d2a83f276d 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } public virtual async Task FindByNormalizedNameAsync( - string normalizedRoleName, + string normalizedRoleName, bool includeDetails = true, CancellationToken cancellationToken = default) { @@ -29,9 +29,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } public virtual async Task> GetListAsync( - string sorting = null, - int maxResultCount = int.MaxValue, - int skipCount = 0, + string sorting = null, + int maxResultCount = int.MaxValue, + int skipCount = 0, bool includeDetails = true, CancellationToken cancellationToken = default) { @@ -40,6 +40,15 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .OrderBy(sorting ?? nameof(IdentityRole.Name)) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); + } + + public virtual async Task> GetListAsync( + IEnumerable ids, + CancellationToken cancellationToken = default) + { + return await DbSet + .Where(t => ids.Contains(t.Id)) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetDefaultOnesAsync( @@ -51,6 +60,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); - } + } } } \ No newline at end of file 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 e52ebf7b49..d2b0b73ce2 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 @@ -197,9 +197,24 @@ namespace Volo.Abp.Identity.EntityFrameworkCore where userOu.OrganizationUnitId == organizationUnitId select user; return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + + public async Task> GetUsersInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default + ) + { + //var userIds = DbContext.Set() + // .Where(q => organizationUnitIds.Contains(q.OrganizationUnitId)) + // .Select(u => u.UserId); + //var query = DbContext.Users.Where(u => userIds.Contains(u.Id)); + var query = from userOu in DbContext.Set() + join user in DbSet on userOu.UserId equals user.Id + where organizationUnitIds.Contains(userOu.OrganizationUnitId) + select user; + return await query.ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task> GetUsersInOrganizationUnitWithChildrenAsync( string code, CancellationToken cancellationToken = default @@ -216,6 +231,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore 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 4796e409f9..dbb0304438 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 @@ -67,9 +67,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetOrganizationUnitAsync( + public async Task GetAsync( string displayName, - bool includeDetails = false, + bool includeDetails = true, CancellationToken cancellationToken = default) { return await DbSet @@ -79,7 +79,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore GetCancellationToken(cancellationToken) ); } - public async Task> GetOrganizationUnitRoles( + public async Task> GetRolesAsync( Guid organizationUnitId, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -96,10 +96,4 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return GetQueryable().IncludeDetails(); } } - - public class OrganizationUnitRoleWithIdentityRole - { - public IdentityRole IdentityRole { get; set; } - public OrganizationUnitRole OrganizationUnitRole { get; set; } - } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index b38a3433d9..5311ffe094 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -26,7 +26,7 @@ namespace Volo.Abp.Identity.MongoDB return await GetMongoQueryable().FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); } - public async Task> GetListAsync( + public virtual async Task> GetListAsync( string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -40,10 +40,19 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetListAsync( + IEnumerable ids, + CancellationToken cancellationToken = default) + { + return await GetMongoQueryable() + .Where(t => ids.Contains(t.Id)) + .ToListAsync(GetCancellationToken(cancellationToken)); + } + public virtual async Task> GetDefaultOnesAsync( bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); - } + } } } \ No newline at end of file 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 e6469238ae..4b90caa9f5 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 @@ -23,7 +23,7 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task FindByNormalizedUserNameAsync( - string normalizedUserName, + string normalizedUserName, bool includeDetails = true, CancellationToken cancellationToken = default) { @@ -35,7 +35,7 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task> GetRoleNamesAsync( - Guid id, + Guid id, CancellationToken cancellationToken = default) { var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); @@ -60,13 +60,13 @@ namespace Volo.Abp.Identity.MongoDB var organizationUnitIds = user.OrganizationUnits .Select(r => r.OrganizationUnitId) - .ToArray(); - + .ToArray(); + var organizationUnits = DbContext.OrganizationUnits .AsQueryable() .Where(ou => organizationUnitIds.Contains(ou.Id)) - .ToArray(); - + .ToArray(); + var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); return await DbContext.Roles //TODO: Such usage suppress filters! @@ -77,8 +77,8 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task FindByLoginAsync( - string loginProvider, - string providerKey, + string loginProvider, + string providerKey, bool includeDetails = true, CancellationToken cancellationToken = default) { @@ -106,7 +106,7 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task> GetListByNormalizedRoleNameAsync( - string normalizedRoleName, + string normalizedRoleName, bool includeDetails = false, CancellationToken cancellationToken = default) { @@ -200,6 +200,17 @@ namespace Volo.Abp.Identity.MongoDB return result; } + public async Task> GetUsersInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default) + { + var result = await GetMongoQueryable() + .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) + .ToListAsync(GetCancellationToken(cancellationToken)) + ; + return result; + } + public async Task> GetUsersInOrganizationUnitWithChildrenAsync( string code, CancellationToken cancellationToken = default) @@ -214,6 +225,6 @@ namespace Volo.Abp.Identity.MongoDB .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .ToListAsync(GetCancellationToken(cancellationToken)) ; - } + } } } \ 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 ef689df45d..bc7cdcda91 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 @@ -64,9 +64,9 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task GetOrganizationUnitAsync( + public async Task GetAsync( string displayName, - bool includeDetails = false, + bool includeDetails = true, CancellationToken cancellationToken = default) { return await GetMongoQueryable() @@ -76,7 +76,7 @@ namespace Volo.Abp.Identity.MongoDB ); } - public async Task> GetOrganizationUnitRoles( + public async Task> GetRolesAsync( Guid organizationUnitId, bool includeDetails = false, CancellationToken cancellationToken = default) 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 d4bc45f2b6..04f08ed266 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")); user.ShouldNotBeNull(); - var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( + var ou = await _organizationUnitRepository.GetAsync( _lookupNormalizer.NormalizeName("OU11")); ou.ShouldNotBeNull(); @@ -150,7 +150,7 @@ namespace Volo.Abp.Identity { using (var uow = _unitOfWorkManager.Begin()) { - var ou = await _organizationUnitRepository.GetOrganizationUnitAsync( + var ou = await _organizationUnitRepository.GetAsync( _lookupNormalizer.NormalizeName("OU111")); ou.ShouldNotBeNull(); @@ -158,7 +158,7 @@ namespace Volo.Abp.Identity _lookupNormalizer.NormalizeName("john.nash")); user.ShouldNotBeNull(); - var ouNew = await _organizationUnitRepository.GetOrganizationUnitAsync( + var ouNew = await _organizationUnitRepository.GetAsync( _lookupNormalizer.NormalizeName("OU2")); 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 95bad2fd22..65c1068bb4 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 @@ -33,55 +33,55 @@ namespace Volo.Abp.Identity { await _organizationUnitManager.CreateAsync(new OrganizationUnit(_guidGenerator.Create(), "Root 1")); - var root1 = await _organizationUnitRepository.GetOrganizationUnitAsync("Root 1"); + var root1 = await _organizationUnitRepository.GetAsync("Root 1"); root1.ShouldNotBeNull(); } [Fact] public async Task UpdateAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); + var ou = await _organizationUnitRepository.GetAsync("OU111"); ou.Code = OrganizationUnit.CreateCode(123); await _organizationUnitManager.UpdateAsync(ou); - var ouAfterChange = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); + var ouAfterChange = await _organizationUnitRepository.GetAsync("OU111"); ouAfterChange.Code.ShouldContain("123"); } [Fact] public async Task DeleteAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11"); + var ou = await _organizationUnitRepository.GetAsync("OU11"); await _organizationUnitManager.DeleteAsync(ou.Id); - (await _organizationUnitRepository.GetOrganizationUnitAsync("OU11")).ShouldBeNull(); + (await _organizationUnitRepository.GetAsync("OU11")).ShouldBeNull(); } [Fact] public async Task MoveAsync() { - var ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1"); - var ou2 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU2"); + var ou1 = await _organizationUnitRepository.GetAsync("OU1"); + var ou2 = await _organizationUnitRepository.GetAsync("OU2"); await _organizationUnitManager.MoveAsync(ou1.Id, ou2.Id); - ou1 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1"); + ou1 = await _organizationUnitRepository.GetAsync("OU1"); ou1.ParentId.ShouldBe(ou2.Id); ou1.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2)); - var ou11 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU11"); + var ou11 = await _organizationUnitRepository.GetAsync("OU11"); ou11.ParentId.ShouldBe(ou1.Id); ou11.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1)); - var ou111 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); + var ou111 = await _organizationUnitRepository.GetAsync("OU111"); ou111.ParentId.ShouldBe(ou11.Id); ou111.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 1)); - var ou112 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU112"); + var ou112 = await _organizationUnitRepository.GetAsync("OU112"); ou112.ParentId.ShouldBe(ou11.Id); ou112.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 1, 2)); - var ou12 = await _organizationUnitRepository.GetOrganizationUnitAsync("OU12"); + var ou12 = await _organizationUnitRepository.GetAsync("OU12"); ou12.ParentId.ShouldBe(ou1.Id); ou12.Code.ShouldBe(OrganizationUnit.CreateCode(2, 2, 2)); } @@ -94,7 +94,7 @@ namespace Volo.Abp.Identity using (var uow = _unitOfWorkManager.Begin()) { - ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true); + ou = await _organizationUnitRepository.GetAsync("OU1", true); adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou); await _organizationUnitRepository.UpdateAsync(ou); @@ -102,19 +102,19 @@ namespace Volo.Abp.Identity await uow.CompleteAsync(); } - ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true); + ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails: true); ou.Roles.First().RoleId.ShouldBe(adminRole.Id); } [Fact] public async Task RemoveRoleFromOrganizationUnitAsync() { - var ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", true); + var ou = await _organizationUnitRepository.GetAsync("OU1", true); var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole.Id, ou.Id); await _organizationUnitManager.RemoveRoleFromOrganizationUnitAsync(adminRole.Id, ou.Id); - ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true); + ou = await _organizationUnitRepository.GetAsync("OU1", includeDetails: true); ou.Roles.FirstOrDefault(r => r.RoleId == adminRole.Id).ShouldBeNull(); } } diff --git a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs index c59d8eea0a..8999a9615a 100644 --- a/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs +++ b/modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/AbpIdentityTestDataBuilder.cs @@ -113,6 +113,7 @@ namespace Volo.Abp.Identity await _userRepository.InsertAsync(john); var david = new IdentityUser(_testData.UserDavidId, "david", "david@abp.io"); + david.AddOrganizationUnit(_ou112.Id); await _userRepository.InsertAsync(david); var neo = new IdentityUser(_testData.UserNeoId, "neo", "neo@abp.io"); 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 7aef8f6c87..1d6728c0ae 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 @@ -171,7 +171,7 @@ namespace Volo.Abp.Identity private async Task GetOU(string diplayName) { - var organizationUnit = await OrganizationUnitRepository.GetOrganizationUnitAsync(diplayName); + var organizationUnit = await OrganizationUnitRepository.GetAsync(diplayName); 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 e49655829a..eae5ee5c1d 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 @@ -69,7 +69,7 @@ namespace Volo.Abp.Identity { using (var uow = GetRequiredService().Begin()) { - var ou = await OrganizationUnitRepository.GetOrganizationUnitAsync(LookupNormalizer.NormalizeName("OU111"), includeDetails: false); + var ou = await OrganizationUnitRepository.GetAsync(LookupNormalizer.NormalizeName("OU111"), includeDetails: 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 4e35a606b3..fb06743500 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 @@ -1,6 +1,8 @@ using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.DependencyInjection; using Shouldly; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Volo.Abp.Guids; @@ -20,6 +22,7 @@ namespace Volo.Abp.Identity private readonly OrganizationUnitManager _organizationUnitManager; private readonly IIdentityRoleRepository _identityRoleRepository; private readonly IUnitOfWorkManager _unitOfWorkManager; + private readonly IIdentityUserRepository _identityUserRepository; public OrganizationUnitRepository_Tests() { @@ -29,7 +32,8 @@ namespace Volo.Abp.Identity _guidGenerator = GetRequiredService(); _organizationUnitManager = GetRequiredService(); _identityRoleRepository = GetRequiredService(); - _unitOfWorkManager = GetRequiredService(); + _unitOfWorkManager = GetRequiredService(); + _identityUserRepository = GetRequiredService(); } [Fact] @@ -57,7 +61,7 @@ namespace Volo.Abp.Identity [Fact] public async Task GetOrganizationUnitAsync() { - var organizationUnit = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111"); + var organizationUnit = await _organizationUnitRepository.GetAsync("OU111"); organizationUnit.ShouldNotBeNull(); } @@ -78,12 +82,22 @@ namespace Volo.Abp.Identity [Fact] public async Task GetOrganizationUnitRolesAsync() { - OrganizationUnit ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU111", true); + OrganizationUnit ou = await _organizationUnitRepository.GetAsync("OU111", true); - var ou111Roles = await _organizationUnitRepository.GetOrganizationUnitRoles(ou.Id, true); + var ou111Roles = await _organizationUnitRepository.GetRolesAsync(ou.Id, true); ou111Roles.Count.ShouldBe(2); ou111Roles.ShouldContain(n => n.Name == "manager"); ou111Roles.ShouldContain(n => n.Name == "moderator"); } + + [Fact] + public async Task GetUsersInOrganizationUnitListAsync() + { + OrganizationUnit ou1 = await _organizationUnitRepository.GetAsync("OU111", true); + OrganizationUnit ou2 = await _organizationUnitRepository.GetAsync("OU112", true); + var users = await _identityUserRepository.GetUsersInOrganizationsListAsync(new List { ou1.Id, ou2.Id }); + //var dodo = users.ToDictionary(u => u.Id, u => u); + users.Count.ShouldBeGreaterThan(0); + } } }