From 58888316e770acadecd9340adc41e3961d33cf3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Fri, 4 Sep 2020 16:00:55 +0800 Subject: [PATCH 01/11] add OrganizaitonUnit GetListAsync filter paramter --- .../Identity/IOrganizationUnitRepository.cs | 1 + .../EfCoreOrganizationUnitRepository.cs | 31 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) 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 6650f62c82..e12d5a5f6d 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 @@ -31,6 +31,7 @@ namespace Volo.Abp.Identity string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, + string filter = null, bool includeDetails = false, 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 7bdb7d6837..26dcc27426 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,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.IO; using System.Linq.Dynamic.Core; using System.Linq; using System.Threading; @@ -12,7 +13,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { public class EfCoreOrganizationUnitRepository : EfCoreRepository, - IOrganizationUnitRepository + IOrganizationUnitRepository { public EfCoreOrganizationUnitRepository( IDbContextProvider dbContextProvider) @@ -47,15 +48,20 @@ namespace Volo.Abp.Identity.EntityFrameworkCore string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, + string filter = null, bool includeDetails = true, CancellationToken cancellationToken = default) { return await DbSet .IncludeDetails(includeDetails) + .WhereIf(!filter.IsNullOrWhiteSpace(), + ou => ou.DisplayName.Contains(filter) || + ou.Code.Contains(filter)) .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) .PageBy(skipCount, maxResultCount) .ToListAsync(GetCancellationToken(cancellationToken)); } + public virtual async Task> GetListAsync( IEnumerable ids, bool includeDetails = false, @@ -89,9 +95,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); @@ -104,9 +110,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)); } @@ -119,13 +125,13 @@ namespace Volo.Abp.Identity.EntityFrameworkCore string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default - ) + ) { 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( @@ -162,7 +168,8 @@ namespace Volo.Abp.Identity.EntityFrameworkCore DbContext.Set().RemoveRange(ouMembersQuery); } - 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 @@ -181,4 +188,4 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return query; } } -} +} \ No newline at end of file From c428ac27a608bb2586747f8f54b354d2b36798b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Fri, 4 Sep 2020 16:55:00 +0800 Subject: [PATCH 02/11] add filter paremeter and getCount api --- .../Identity/IOrganizationUnitRepository.cs | 5 +++ .../EfCoreOrganizationUnitRepository.cs | 10 +++++ .../MongoOrganizationUnitRepository.cs | 43 +++++++++++++------ 3 files changed, 45 insertions(+), 13 deletions(-) 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 e12d5a5f6d..561abd893f 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 @@ -81,5 +81,10 @@ 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 26dcc27426..311bb1a3dc 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 @@ -168,6 +168,16 @@ 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 + .WhereIf(!filter.IsNullOrWhiteSpace(), ou => + ou.DisplayName.Contains(filter) || + ou.Code.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + protected virtual IQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, string filter = null) { 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 8c163d4126..a31acf13ad 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,22 +51,26 @@ 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( string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, + string filter = null, bool includeDetails = false, CancellationToken cancellationToken = default) { return await GetMongoQueryable() - .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) - .As>() - .PageBy>(skipCount, maxResultCount) - .ToListAsync(GetCancellationToken(cancellationToken)); + .WhereIf(!filter.IsNullOrWhiteSpace(), + ou => ou.DisplayName.Contains(filter) || + ou.Code.Contains(filter)) + .OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName)) + .As>() + .PageBy>(skipCount, maxResultCount) + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetAsync( @@ -135,13 +139,15 @@ namespace Volo.Abp.Identity.MongoDB return await query.CountAsync(GetCancellationToken(cancellationToken)); } - public virtual Task RemoveAllRolesAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) + public virtual Task RemoveAllRolesAsync(OrganizationUnit organizationUnit, + CancellationToken cancellationToken = default) { organizationUnit.Roles.Clear(); 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)) @@ -155,7 +161,18 @@ namespace Volo.Abp.Identity.MongoDB } } - protected virtual IMongoQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, string filter = null) + public virtual async Task GetLongCountAsync(Guid? parentId, string filter = null, + CancellationToken cancellationToken = default) + { + return await GetMongoQueryable() + .WhereIf>(!filter.IsNullOrWhiteSpace(), ou => + ou.DisplayName.Contains(filter) || + ou.Code.Contains(filter)) + .LongCountAsync(GetCancellationToken(cancellationToken)); + } + + protected virtual IMongoQueryable CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, + string filter = null) { return DbContext.Users.AsQueryable() .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) @@ -168,4 +185,4 @@ namespace Volo.Abp.Identity.MongoDB ); } } -} +} \ No newline at end of file From 62277ec59e5d78e31ca7ad9b205ecb54d66fa030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Sun, 6 Sep 2020 15:35:05 +0800 Subject: [PATCH 03/11] add create role with org details unit test --- .../Identity/IdentityRoleAppService_Tests.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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 5d64bb6c78..0126758eb8 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,11 +11,14 @@ 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] @@ -81,6 +84,32 @@ 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); + + await _organization.AddRoleToOrganizationUnitAsync(result.Id,orgInput.Id); + + var orgRolesCount=await _organizationUnitRepository.GetRolesCountAsync(orgInput); + //Assert + orgRolesCount.ShouldBeGreaterThan(0); + } + [Fact] public async Task UpdateAsync() { From c02fdae537d43da1f33d8c42c2342944e9be8bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Sun, 6 Sep 2020 16:27:15 +0800 Subject: [PATCH 04/11] fixed CreateWithDetails unit test --- .../Volo/Abp/Identity/IdentityRoleAppService_Tests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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 0126758eb8..b32c830002 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 @@ -102,12 +102,11 @@ namespace Volo.Abp.Identity var result = await _roleAppService.CreateAsync(input); await _organization.CreateAsync(orgInput); - - await _organization.AddRoleToOrganizationUnitAsync(result.Id,orgInput.Id); - - var orgRolesCount=await _organizationUnitRepository.GetRolesCountAsync(orgInput); + + var role = await _roleRepository.GetAsync(result.Id); + await _organization.AddRoleToOrganizationUnitAsync(role,orgInput); //Assert - orgRolesCount.ShouldBeGreaterThan(0); + orgInput.Roles.Count.ShouldBeGreaterThan(0); } [Fact] From a6d7ff959499b96e09c9715392531287ad5a73b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=B4=AA=E6=9E=97?= Date: Wed, 9 Sep 2020 21:07:58 +0800 Subject: [PATCH 05/11] fixed parentId parameter and tested complete --- .../Identity/IOrganizationUnitRepository.cs | 1 + .../EfCoreOrganizationUnitRepository.cs | 3 +++ .../MongoDB/MongoOrganizationUnitRepository.cs | 3 +++ .../OrganizationUnitRepository_Tests.cs | 18 +++++++++++++++++- 4 files changed, 24 insertions(+), 1 deletion(-) 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 561abd893f..0e6272064d 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,6 +28,7 @@ namespace Volo.Abp.Identity ); Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, 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 311bb1a3dc..7dd1901fbc 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 @@ -45,6 +45,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore } public virtual async Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -54,6 +55,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { return await DbSet .IncludeDetails(includeDetails) + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) @@ -172,6 +174,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore CancellationToken cancellationToken = default) { return await DbSet + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) 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 a31acf13ad..73397636f5 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 @@ -56,6 +56,7 @@ namespace Volo.Abp.Identity.MongoDB } public virtual async Task> GetListAsync( + Guid? parentId, string sorting = null, int maxResultCount = int.MaxValue, int skipCount = 0, @@ -64,6 +65,7 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() + .Where(ou=>ou.ParentId==parentId) .WhereIf(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) @@ -165,6 +167,7 @@ namespace Volo.Abp.Identity.MongoDB CancellationToken cancellationToken = default) { return await GetMongoQueryable() + .Where(ou=>ou.ParentId==parentId) .WhereIf>(!filter.IsNullOrWhiteSpace(), ou => ou.DisplayName.Contains(filter) || ou.Code.Contains(filter)) 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 bb8300d449..2725441719 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,6 +59,22 @@ 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] @@ -192,7 +208,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); } From 79f1369a0c7410781bb968821d32c0511884036b Mon Sep 17 00:00:00 2001 From: jonny-xhl Date: Wed, 9 Sep 2020 21:31:42 +0800 Subject: [PATCH 06/11] resolved conflicts --- .../Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs | 6 ++++++ 1 file changed, 6 insertions(+) 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 62c26d236d..f6ae630eda 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 @@ -212,6 +212,12 @@ namespace Volo.Abp.Identity.MongoDB .CountAsync(GetCancellationToken(cancellationToken)); } + public virtual Task RemoveAllRolesAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) + { + organizationUnit.Roles.Clear(); + return Task.FromResult(0); + } + public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default) { From 7a9a9efeac453f369f71ed827fd0f021f0bcd52e Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Sun, 13 Sep 2020 19:12:56 +0300 Subject: [PATCH 07/11] feat: add custom node template for tree component --- .../tree/src/lib/components/tree.component.html | 9 ++++++++- .../components/tree/src/lib/components/tree.component.ts | 2 ++ .../src/lib/templates/tree-node-template.directive.ts | 8 ++++++++ .../packages/components/tree/src/lib/tree.module.ts | 9 ++++++--- npm/ng-packs/packages/components/tree/src/public-api.ts | 1 + 5 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 npm/ng-packs/packages/components/tree/src/lib/templates/tree-node-template.directive.ts diff --git a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html index b7c777a449..f575a5f44b 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html +++ b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html @@ -18,7 +18,14 @@ [title]="node.title" (click)="onSelectedNodeChange(node)" > - {{ node.title }} + + + + + {{ node.title }} +
diff --git a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts index ac7a709048..baf919c39b 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts +++ b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts @@ -9,6 +9,7 @@ import { } from '@angular/core'; import { NzFormatEmitEvent, NzFormatBeforeDropEvent } from 'ng-zorro-antd/tree'; import { of } from 'rxjs'; +import { TreeNodeTemplateDirective } from '../templates/tree-node-template.directive'; export type DropEvent = NzFormatEmitEvent & { pos: number }; @@ -25,6 +26,7 @@ export class TreeComponent { dropPosition: number; @ContentChild('menu') menu: TemplateRef; + @ContentChild(TreeNodeTemplateDirective) customNodeTemplate: TreeNodeTemplateDirective; @Output() readonly checkedKeysChange = new EventEmitter(); @Output() readonly expandedKeysChange = new EventEmitter(); @Output() readonly selectedNodeChange = new EventEmitter(); diff --git a/npm/ng-packs/packages/components/tree/src/lib/templates/tree-node-template.directive.ts b/npm/ng-packs/packages/components/tree/src/lib/templates/tree-node-template.directive.ts new file mode 100644 index 0000000000..56c66af04b --- /dev/null +++ b/npm/ng-packs/packages/components/tree/src/lib/templates/tree-node-template.directive.ts @@ -0,0 +1,8 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[abpTreeNodeTemplate],[abp-tree-node-template]', +}) +export class TreeNodeTemplateDirective { + constructor(public template: TemplateRef) {} +} diff --git a/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts b/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts index f16ed0dd55..feb806f7b3 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts +++ b/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts @@ -1,12 +1,15 @@ +import { CommonModule } from '@angular/common'; import { NgModule } from '@angular/core'; import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NzTreeModule } from 'ng-zorro-antd/tree'; import { TreeComponent } from './components/tree.component'; -import { CommonModule } from '@angular/common'; +import { TreeNodeTemplateDirective } from './templates/tree-node-template.directive'; + +const exported = [TreeNodeTemplateDirective, TreeComponent]; @NgModule({ imports: [CommonModule, NzTreeModule, NgbDropdownModule], - exports: [TreeComponent], - declarations: [TreeComponent], + exports: [...exported], + declarations: [...exported], }) export class TreeModule {} diff --git a/npm/ng-packs/packages/components/tree/src/public-api.ts b/npm/ng-packs/packages/components/tree/src/public-api.ts index df82ac0f93..09f2f16d0e 100644 --- a/npm/ng-packs/packages/components/tree/src/public-api.ts +++ b/npm/ng-packs/packages/components/tree/src/public-api.ts @@ -1,3 +1,4 @@ export * from './lib/tree.module'; export * from './lib/components/tree.component'; export * from './lib/utils/nz-tree-adapter'; +export * from './lib/templates/tree-node-template.directive'; From e6bce37fb054d987ed70de81ded907113a23c820 Mon Sep 17 00:00:00 2001 From: bnymncoskuner Date: Mon, 14 Sep 2020 10:03:45 +0300 Subject: [PATCH 08/11] feat: add icon template to tree component --- .../tree/src/lib/components/tree.component.html | 13 ++++++++----- .../tree/src/lib/components/tree.component.ts | 2 ++ .../templates/expanded-icon-template.directive.ts | 8 ++++++++ .../packages/components/tree/src/lib/tree.module.ts | 5 ++++- .../packages/components/tree/src/public-api.ts | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 npm/ng-packs/packages/components/tree/src/lib/templates/expanded-icon-template.directive.ts diff --git a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html index f575a5f44b..b98aa7e4ff 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html +++ b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.html @@ -7,6 +7,7 @@ [nzData]="nodes" [nzTreeTemplate]="treeTemplate" [nzExpandedKeys]="expandedKeys" + [nzExpandedIcon]="expandedIconTemplate?.template" (nzExpandChange)="onExpandedKeysChange($event)" (nzCheckBoxChange)="onCheckboxChange($event)" (nzOnDrop)="onDrop($event)" @@ -18,11 +19,13 @@ [title]="node.title" (click)="onSelectedNodeChange(node)" > - - - + + {{ node.title }} diff --git a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts index baf919c39b..7ba6280c0b 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts +++ b/npm/ng-packs/packages/components/tree/src/lib/components/tree.component.ts @@ -10,6 +10,7 @@ import { import { NzFormatEmitEvent, NzFormatBeforeDropEvent } from 'ng-zorro-antd/tree'; import { of } from 'rxjs'; import { TreeNodeTemplateDirective } from '../templates/tree-node-template.directive'; +import { ExpandedIconTemplateDirective } from '../templates/expanded-icon-template.directive'; export type DropEvent = NzFormatEmitEvent & { pos: number }; @@ -27,6 +28,7 @@ export class TreeComponent { @ContentChild('menu') menu: TemplateRef; @ContentChild(TreeNodeTemplateDirective) customNodeTemplate: TreeNodeTemplateDirective; + @ContentChild(ExpandedIconTemplateDirective) expandedIconTemplate: ExpandedIconTemplateDirective; @Output() readonly checkedKeysChange = new EventEmitter(); @Output() readonly expandedKeysChange = new EventEmitter(); @Output() readonly selectedNodeChange = new EventEmitter(); diff --git a/npm/ng-packs/packages/components/tree/src/lib/templates/expanded-icon-template.directive.ts b/npm/ng-packs/packages/components/tree/src/lib/templates/expanded-icon-template.directive.ts new file mode 100644 index 0000000000..35706bd25f --- /dev/null +++ b/npm/ng-packs/packages/components/tree/src/lib/templates/expanded-icon-template.directive.ts @@ -0,0 +1,8 @@ +import { Directive, TemplateRef } from '@angular/core'; + +@Directive({ + selector: '[abpTreeExpandedIconTemplate],[abp-tree-expanded-icon-template]', +}) +export class ExpandedIconTemplateDirective { + constructor(public template: TemplateRef) {} +} diff --git a/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts b/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts index feb806f7b3..b645a69925 100644 --- a/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts +++ b/npm/ng-packs/packages/components/tree/src/lib/tree.module.ts @@ -4,8 +4,11 @@ import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; import { NzTreeModule } from 'ng-zorro-antd/tree'; import { TreeComponent } from './components/tree.component'; import { TreeNodeTemplateDirective } from './templates/tree-node-template.directive'; +import { ExpandedIconTemplateDirective } from './templates/expanded-icon-template.directive'; -const exported = [TreeNodeTemplateDirective, TreeComponent]; +const templates = [TreeNodeTemplateDirective, ExpandedIconTemplateDirective]; + +const exported = [...templates, TreeComponent]; @NgModule({ imports: [CommonModule, NzTreeModule, NgbDropdownModule], diff --git a/npm/ng-packs/packages/components/tree/src/public-api.ts b/npm/ng-packs/packages/components/tree/src/public-api.ts index 09f2f16d0e..1f3dd48e00 100644 --- a/npm/ng-packs/packages/components/tree/src/public-api.ts +++ b/npm/ng-packs/packages/components/tree/src/public-api.ts @@ -2,3 +2,4 @@ export * from './lib/tree.module'; export * from './lib/components/tree.component'; export * from './lib/utils/nz-tree-adapter'; export * from './lib/templates/tree-node-template.directive'; +export * from './lib/templates/expanded-icon-template.directive'; From d2eb8a5fcb1d5b890e503992f19002157af9e894 Mon Sep 17 00:00:00 2001 From: mehmet-erim Date: Mon, 14 Sep 2020 14:35:21 +0300 Subject: [PATCH 09/11] chore: change imports --- .../feature-management/feature-management.component.ts | 3 ++- .../src/lib/services/feature-management-state.service.ts | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts b/npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts index 4e1df0b294..98d5e4cbbc 100644 --- a/npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts +++ b/npm/ng-packs/packages/feature-management/src/lib/components/feature-management/feature-management.component.ts @@ -3,7 +3,8 @@ import { LocaleDirection } from '@abp/ng.theme.shared'; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { finalize } from 'rxjs/operators'; import { FeatureManagement } from '../../models/feature-management'; -import { FeatureDto, FeaturesService, UpdateFeatureDto } from '../../proxy/feature-management'; +import { FeaturesService } from '../../proxy/feature-management/features.service'; +import { FeatureDto, UpdateFeatureDto } from '../../proxy/feature-management/models'; enum ValueTypes { ToggleStringValueType = 'ToggleStringValueType', diff --git a/npm/ng-packs/packages/feature-management/src/lib/services/feature-management-state.service.ts b/npm/ng-packs/packages/feature-management/src/lib/services/feature-management-state.service.ts index 79d7fbef34..20c76c41ae 100644 --- a/npm/ng-packs/packages/feature-management/src/lib/services/feature-management-state.service.ts +++ b/npm/ng-packs/packages/feature-management/src/lib/services/feature-management-state.service.ts @@ -1,8 +1,7 @@ import { Injectable } from '@angular/core'; import { Store } from '@ngxs/store'; -import { FeatureManagementState } from '../states'; -import { FeatureManagement } from '../models'; -import { GetFeatures, UpdateFeatures } from '../actions'; +import { GetFeatures, UpdateFeatures } from '../actions/feature-management.actions'; +import { FeatureManagementState } from '../states/feature-management.state'; @Injectable({ providedIn: 'root', From aa43c41289ff5d8f9621f71312b66c64b9ee5784 Mon Sep 17 00:00:00 2001 From: maliming <6908465+maliming@users.noreply.github.com> Date: Tue, 15 Sep 2020 10:20:26 +0800 Subject: [PATCH 10/11] Add security log document. Resolve #4794 --- docs/en/Modules/Identity.md | 23 +++++++++++++++++++++++ docs/zh-Hans/Modules/Identity.md | 25 ++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/docs/en/Modules/Identity.md b/docs/en/Modules/Identity.md index b950658505..b1e8e0efcc 100644 --- a/docs/en/Modules/Identity.md +++ b/docs/en/Modules/Identity.md @@ -4,3 +4,26 @@ Identity module is used to manage [organization units](Organization-Units.md), r See [the source code](https://github.com/abpframework/abp/tree/dev/modules/identity). Documentation will come soon... + +## Identity Security Log + +The security log can record some important operations or changes about your account. You can save the security log if needed. + +You can inject and use `IdentitySecurityLogManager` or `ISecurityLogManager` to write security logs. It will create a log object by default and fill in some common values, such as `CreationTime`, `ClientIpAddress`, `BrowserInfo`, `current user/tenant`, etc. Of course, you can override them. + +```cs +await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() +{ + Identity = "IdentityServer"; + Action = "ChangePassword"; +}); +``` + +Configure `AbpSecurityLogOptions `to provide the application name for the log or disable this feature. **enabed** by default. + +```cs +Configure(options => +{ + options.ApplicationName = "AbpSecurityTest"; +}); +``` diff --git a/docs/zh-Hans/Modules/Identity.md b/docs/zh-Hans/Modules/Identity.md index f396de00c1..4332e3b807 100644 --- a/docs/zh-Hans/Modules/Identity.md +++ b/docs/zh-Hans/Modules/Identity.md @@ -2,4 +2,27 @@ 身份模块基于Microsoft Identity 库用于管理[组织单元](Organization-Units.md), 角色, 用户和他们的权限. -参阅 [源码](https://github.com/abpframework/abp/tree/dev/modules/identity). 文档很快会被完善. \ No newline at end of file +参阅 [源码](https://github.com/abpframework/abp/tree/dev/modules/identity). 文档很快会被完善. + +## Identity安全日志 + +安全日志可以记录账户的一些重要的操作或者改动, 你可以在在一些功能中保存安全日志. + +你可以注入和使用 `IdentitySecurityLogManager` 或`ISecurityLogManager` 来保存安全日志. 默认它会创建一个安全日志对象并填充常用的值. 如 `CreationTime`, `ClientIpAddress`, `BrowserInfo`, `current user/tenant`等等. 当然你可以自定义这些值. + +```cs +await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() +{ + Identity = "IdentityServer"; + Action = "ChangePassword"; +}); +``` + +通过配置 `AbpSecurityLogOptions `来提供应用程序的名称或者禁用安全日志功能. 默认是启用状态. + +```cs +Configure(options => +{ + options.ApplicationName = "AbpSecurityTest"; +}); +``` From 6f2f19a32c5917dc5721e3109e6629b21c32a3af Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 15 Sep 2020 10:30:04 +0800 Subject: [PATCH 11/11] format security log document --- docs/en/Modules/Identity.md | 2 +- docs/zh-Hans/Modules/Identity.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/en/Modules/Identity.md b/docs/en/Modules/Identity.md index b1e8e0efcc..ac86b13564 100644 --- a/docs/en/Modules/Identity.md +++ b/docs/en/Modules/Identity.md @@ -19,7 +19,7 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() }); ``` -Configure `AbpSecurityLogOptions `to provide the application name for the log or disable this feature. **enabed** by default. +Configure `AbpSecurityLogOptions` to provide the application name for the log or disable this feature. **Enabled** by default. ```cs Configure(options => diff --git a/docs/zh-Hans/Modules/Identity.md b/docs/zh-Hans/Modules/Identity.md index 4332e3b807..5589fb367e 100644 --- a/docs/zh-Hans/Modules/Identity.md +++ b/docs/zh-Hans/Modules/Identity.md @@ -1,6 +1,6 @@ # 身份管理模块 -身份模块基于Microsoft Identity 库用于管理[组织单元](Organization-Units.md), 角色, 用户和他们的权限. +身份模块基于Microsoft Identity库用于管理[组织单元](Organization-Units.md), 角色, 用户和他们的权限. 参阅 [源码](https://github.com/abpframework/abp/tree/dev/modules/identity). 文档很快会被完善. @@ -8,7 +8,7 @@ 安全日志可以记录账户的一些重要的操作或者改动, 你可以在在一些功能中保存安全日志. -你可以注入和使用 `IdentitySecurityLogManager` 或`ISecurityLogManager` 来保存安全日志. 默认它会创建一个安全日志对象并填充常用的值. 如 `CreationTime`, `ClientIpAddress`, `BrowserInfo`, `current user/tenant`等等. 当然你可以自定义这些值. +你可以注入和使用 `IdentitySecurityLogManager` 或 `ISecurityLogManager` 来保存安全日志. 默认它会创建一个安全日志对象并填充常用的值. 如 `CreationTime`, `ClientIpAddress`, `BrowserInfo`, `current user/tenant`等等. 当然你可以自定义这些值. ```cs await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() @@ -18,7 +18,7 @@ await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() }); ``` -通过配置 `AbpSecurityLogOptions `来提供应用程序的名称或者禁用安全日志功能. 默认是启用状态. +通过配置 `AbpSecurityLogOptions` 来提供应用程序的名称或者禁用安全日志功能. 默认是**启用**状态. ```cs Configure(options =>