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 0a69e90eae..bf39874e00 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 @@ -28,11 +28,9 @@ namespace Volo.Abp.Identity ); Task> GetListAsync( - Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, - string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default ); @@ -114,10 +112,5 @@ namespace Volo.Abp.Identity OrganizationUnit organizationUnit, CancellationToken cancellationToken = default ); - - Task GetLongCountAsync( - Guid? parentId, - string filter = null, - CancellationToken cancellationToken = default); } } 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 5b5ad8a6cf..59fbd9518e 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 @@ -1,7 +1,6 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; -using System.IO; using System.Linq.Dynamic.Core; using System.Linq; using System.Threading; @@ -45,20 +44,14 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } public virtual async Task> GetListAsync( - Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, - string filter = null, bool includeDetails = true, CancellationToken cancellationToken = default) { return await DbSet .IncludeDetails(includeDetails) - .Where(ou=>ou.ParentId==parentId) - .WhereIf(!filter.IsNullOrWhiteSpace(), - ou => ou.DisplayName.Contains(filter) || - ou.Code.Contains(filter)) .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); @@ -97,9 +90,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore CancellationToken cancellationToken = default) { var query = from organizationRole in DbContext.Set() - join role in DbContext.Roles.IncludeDetails(includeDetails) on organizationRole.RoleId equals role.Id - where organizationRole.OrganizationUnitId == organizationUnit.Id - select role; + join role in DbContext.Roles.IncludeDetails(includeDetails) on organizationRole.RoleId equals role.Id + where organizationRole.OrganizationUnitId == organizationUnit.Id + select role; query = query .OrderBy(sorting ?? nameof(IdentityRole.Name)) .PageBy(skipCount, maxResultCount); @@ -112,9 +105,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore CancellationToken cancellationToken = default) { var query = from organizationRole in DbContext.Set() - join role in DbContext.Roles on organizationRole.RoleId equals role.Id - where organizationRole.OrganizationUnitId == organizationUnit.Id - select role; + join role in DbContext.Roles on organizationRole.RoleId equals role.Id + where organizationRole.OrganizationUnitId == organizationUnit.Id + select role; return await query.CountAsync(GetCancellationToken(cancellationToken)); } @@ -164,8 +157,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore var query = CreateGetMembersFilteredQuery(organizationUnit, filter); return await query.IncludeDetails(includeDetails).OrderBy(sorting ?? nameof(IdentityUser.UserName)) - .PageBy(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + .PageBy(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetMembersCountAsync( @@ -252,19 +245,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore DbContext.Set().RemoveRange(ouMembersQuery); } - public virtual async Task GetLongCountAsync(Guid? parentId, string filter = null, - CancellationToken cancellationToken = default) - { - return await DbSet - .Where(ou=>ou.ParentId==parentId) - .WhereIf(!filter.IsNullOrWhiteSpace(), ou => - ou.DisplayName.Contains(filter) || - ou.Code.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } - - protected virtual IQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, - string filter = null) + protected virtual IQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, string filter = null) { var query = from userOu in DbContext.Set() join user in DbContext.Users on userOu.UserId equals user.Id @@ -283,4 +264,4 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return query; } } -} \ 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 f6ae630eda..10ae4cd038 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 @@ -16,7 +16,7 @@ namespace Volo.Abp.Identity.MongoDB { public class MongoOrganizationUnitRepository : MongoDbRepository, - IOrganizationUnitRepository + IOrganizationUnitRepository { public MongoOrganizationUnitRepository( IMongoDbContextProvider dbContextProvider) @@ -41,8 +41,8 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value) - .ToListAsync(GetCancellationToken(cancellationToken)); + .Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListAsync( @@ -51,28 +51,22 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .Where(t => ids.Contains(t.Id)) - .ToListAsync(GetCancellationToken(cancellationToken)); + .Where(t => ids.Contains(t.Id)) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetListAsync( - Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, - string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .Where(ou=>ou.ParentId==parentId) - .WhereIf(!filter.IsNullOrWhiteSpace(), - ou => ou.DisplayName.Contains(filter) || - ou.Code.Contains(filter)) - .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetAsync( @@ -172,6 +166,7 @@ namespace Volo.Abp.Identity.MongoDB return await query.CountAsync(GetCancellationToken(cancellationToken)); } + public async Task> GetUnaddedUsersAsync( OrganizationUnit organizationUnit, string sorting = null, @@ -218,8 +213,7 @@ namespace Volo.Abp.Identity.MongoDB return Task.FromResult(0); } - public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, - CancellationToken cancellationToken = default) + public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) { var users = await DbContext.Users.AsQueryable() .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) @@ -233,19 +227,7 @@ namespace Volo.Abp.Identity.MongoDB } } - public virtual async Task GetLongCountAsync(Guid? parentId, string filter = null, - CancellationToken cancellationToken = default) - { - return await GetMongoQueryable() - .Where(ou=>ou.ParentId==parentId) - .WhereIf>(!filter.IsNullOrWhiteSpace(), ou => - ou.DisplayName.Contains(filter) || - ou.Code.Contains(filter)) - .LongCountAsync(GetCancellationToken(cancellationToken)); - } - - protected virtual IMongoQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, - string filter = null) + protected virtual IMongoQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, string filter = null) { return DbContext.Users.AsQueryable() .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) @@ -258,4 +240,4 @@ namespace Volo.Abp.Identity.MongoDB ); } } -} \ No newline at end of file +} diff --git a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs index b32c830002..5d64bb6c78 100644 --- a/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs +++ b/modules/identity/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs @@ -11,14 +11,11 @@ namespace Volo.Abp.Identity { private readonly IIdentityRoleAppService _roleAppService; private readonly IIdentityRoleRepository _roleRepository; - private readonly IOrganizationUnitRepository _organizationUnitRepository; - private readonly OrganizationUnitManager _organization; + public IdentityRoleAppService_Tests() { _roleAppService = GetRequiredService(); _roleRepository = GetRequiredService(); - _organization = GetRequiredService(); - _organizationUnitRepository=GetRequiredService(); } [Fact] @@ -84,31 +81,6 @@ namespace Volo.Abp.Identity role.Name.ShouldBe(input.Name); } - [Fact] - public async Task CreateWithDetailsAsync() - { - //Arrange - var input = new IdentityRoleCreateDto - { - Name = Guid.NewGuid().ToString("N").Left(8) - }; - - var orgInput=new OrganizationUnit( - _organization.GuidGenerator.Create(), - Guid.NewGuid().ToString("N").Left(8) - ); - - //Act - var result = await _roleAppService.CreateAsync(input); - - await _organization.CreateAsync(orgInput); - - var role = await _roleRepository.GetAsync(result.Id); - await _organization.AddRoleToOrganizationUnitAsync(role,orgInput); - //Assert - orgInput.Roles.Count.ShouldBeGreaterThan(0); - } - [Fact] public async Task UpdateAsync() { 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 d63daf1646..a671ba3284 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 @@ -59,22 +59,6 @@ namespace Volo.Abp.Identity var ous = await _organizationUnitRepository.GetListAsync(ouIds); ous.Count.ShouldBe(2); ous.ShouldContain(ou => ou.Id == ouIds.First()); - - var ou11 = await _organizationUnitRepository.GetAsync("OU11"); - ou11.ShouldNotBeNull(); - var ou11Children = await _organizationUnitRepository.GetListAsync(ou11.Id, includeDetails: true); - ou11Children.Count.ShouldBe(2); - } - - [Fact] - public async Task GetLongCountAsync() - { - (await _organizationUnitRepository.GetLongCountAsync(_guidGenerator.Create(), filter: "11")).ShouldBe(0); - var countRoot = await _organizationUnitRepository.GetLongCountAsync(null, filter: "1"); - countRoot.ShouldBe(1); - var ou11 = await _organizationUnitRepository.GetAsync("OU11"); - ou11.ShouldNotBeNull(); - (await _organizationUnitRepository.GetLongCountAsync(ou11.Id, "2")).ShouldBe(1); } [Fact] @@ -208,7 +192,7 @@ namespace Volo.Abp.Identity { 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 users = await _identityUserRepository.GetUsersInOrganizationsListAsync(new List {ou1.Id, ou2.Id}); users.Count.ShouldBeGreaterThan(0); }