diff --git a/docs/en/Tutorials/Part-1.md b/docs/en/Tutorials/Part-1.md index be812cc162..bd08cbdcd5 100644 --- a/docs/en/Tutorials/Part-1.md +++ b/docs/en/Tutorials/Part-1.md @@ -607,7 +607,7 @@ namespace Acme.BookStore.Web.Menus { //<-- added the below code context.Menu.AddItem( - new ApplicationMenuItem("BooksStore", l["Menu:BookStore"]) + new ApplicationMenuItem("BooksStore", l["Menu:BookStore"], icon: "fa fa-book") .AddItem( new ApplicationMenuItem("BooksStore.Books", l["Menu:Books"], url: "/Books") ) @@ -646,7 +646,16 @@ Open the `en.json` (*English translations*) file and add the below localization "Type": "Type", "Price": "Price", "CreationTime": "Creation time", - "AreYouSureToDelete": "Are you sure you want to delete this item?" + "AreYouSureToDelete": "Are you sure you want to delete this item?", + "Enum:BookType:0": "Undefined", + "Enum:BookType:1": "Adventure", + "Enum:BookType:2": "Biography", + "Enum:BookType:3": "Dystopia", + "Enum:BookType:4": "Fantastic", + "Enum:BookType:5": "Horror", + "Enum:BookType:6": "Science", + "Enum:BookType:7": "ScienceFiction", + "Enum:BookType:8": "Poetry" } } ```` @@ -716,7 +725,11 @@ $(function () { ajax: abp.libs.datatables.createAjax(acme.bookStore.book.getList), columnDefs: [ { data: "name" }, - { data: "type" }, + { data: "type", + render: function(data){ + return l('Enum:BookType:' + data); + } + }, { data: "publishDate" }, { data: "price" }, { data: "creationTime" } 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 def41cdc8a..bf698ca54f 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 @@ -64,9 +64,20 @@ namespace Volo.Abp.Identity bool includeDetails = false, CancellationToken cancellationToken = default ); + Task GetMembersCountAsync( OrganizationUnit organizationUnit, CancellationToken cancellationToken = default ); + + Task RemoveAllRolesAsync( + OrganizationUnit organizationUnit, + CancellationToken cancellationToken = default + ); + + Task RemoveAllMembersAsync( + OrganizationUnit organizationUnit, + 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 f90694349a..2400743ab3 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 @@ -96,7 +96,6 @@ namespace Volo.Abp.Identity return IdentityResult.Success; } - public virtual async Task IsInOrganizationUnitAsync(Guid userId, Guid ouId) { var user = await IdentityUserRepository.GetAsync(userId, cancellationToken: CancellationToken); @@ -191,12 +190,13 @@ namespace Volo.Abp.Identity } [UnitOfWork] - public virtual async Task> GetOrganizationUnitsAsync(IdentityUser user) + public virtual async Task> GetOrganizationUnitsAsync(IdentityUser user, bool includeDetails = false) { await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); return await OrganizationUnitRepository.GetListAsync( user.OrganizationUnits.Select(t => t.OrganizationUnitId), + includeDetails, cancellationToken: CancellationToken ); } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs index bfaa522dd0..fb5a5278f2 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs @@ -80,6 +80,10 @@ namespace Volo.Abp.Identity await OrganizationUnitRepository.DeleteAsync(child); } + var organizationUnit = await OrganizationUnitRepository.GetAsync(id); + + await OrganizationUnitRepository.RemoveAllMembersAsync(organizationUnit); + await OrganizationUnitRepository.RemoveAllRolesAsync(organizationUnit); await OrganizationUnitRepository.DeleteAsync(id); } 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 c1bee0449a..f2e82cfb77 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 @@ -152,15 +152,16 @@ namespace Volo.Abp.Identity.EntityFrameworkCore where userOrg.UserId == id select ou; - var orgUserRoleQuery = DbContext.Set().Where(q => userOrganizationsQuery.Select(t => t.Id).Contains(q.OrganizationUnitId)) + var orgUserRoleQuery = DbContext.Set() + .Where(q => userOrganizationsQuery + .Select(t => t.Id) + .Contains(q.OrganizationUnitId)) .Select(t => t.RoleId); var orgRoles = DbContext.Roles.Where(q => orgUserRoleQuery.Contains(q.Id)); var resultQuery = query.Union(orgRoles); return await resultQuery.ToListAsync(GetCancellationToken(cancellationToken)); - - //return await query.ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync( @@ -201,22 +202,18 @@ 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)); + } + + public async Task> GetUsersInOrganizationsListAsync( + List organizationUnitIds, + CancellationToken cancellationToken = default + ) + { 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)); + return await query.ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task> GetUsersInOrganizationUnitWithChildrenAsync( @@ -235,6 +232,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 350f64ffe7..812c655140 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 @@ -102,7 +102,7 @@ namespace Volo.Abp.Identity.EntityFrameworkCore public virtual async Task GetRolesCountAsync( OrganizationUnit organizationUnit, 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 @@ -156,5 +156,37 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { return GetQueryable().IncludeDetails(); } + + public virtual Task RemoveAllRolesAsync( + OrganizationUnit organizationUnit, + CancellationToken cancellationToken = default) + { + var ouRolesQuery = DbContext.Set() + .Where(q => q.OrganizationUnitId == organizationUnit.Id); + + DbContext.Set().RemoveRange(ouRolesQuery); + return Task.FromResult(0); + //Can be long running process that could be made available for cancellation perhaps + //return Task.Run(() => + // DbContext.Set().RemoveRange(ouRolesQuery), + // GetCancellationToken(cancellationToken) + //); + } + + public virtual Task RemoveAllMembersAsync( + OrganizationUnit organizationUnit, + CancellationToken cancellationToken = default) + { + var ouMembersQuery = DbContext.Set() + .Where(q => q.OrganizationUnitId == organizationUnit.Id); + + DbContext.Set().RemoveRange(ouMembersQuery); + return Task.FromResult(0); + //Can be long running process that could be made available for cancellation perhaps + //return Task.Run(() => + // DbContext.Set().RemoveRange(ouMembersQuery), + // GetCancellationToken(cancellationToken) + //); + } } } 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 ae735300fd..943d570153 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 @@ -1,17 +1,22 @@ -using MongoDB.Driver; +using MongoDB.Bson; +using MongoDB.Driver; using MongoDB.Driver.Linq; using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Linq.Dynamic.Core; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; +using Volo.Abp.Uow; namespace Volo.Abp.Identity.MongoDB { - public class MongoOrganizationUnitRepository : MongoDbRepository, IOrganizationUnitRepository + public class MongoOrganizationUnitRepository + : MongoDbRepository, + IOrganizationUnitRepository { public MongoOrganizationUnitRepository( IMongoDbContextProvider dbContextProvider) @@ -134,5 +139,25 @@ namespace Volo.Abp.Identity.MongoDB .As>() .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) + { + var users = await DbContext.Users.AsQueryable() + .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id)) + .As>() + .ToListAsync(GetCancellationToken(cancellationToken)); + + foreach (var user in users) + { + user.RemoveOrganizationUnit(organizationUnit.Id); + DbContext.Users.ReplaceOne(u => u.Id == user.Id, user); + } + } } } 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 6f6835396d..bbb7d649c9 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 @@ -151,5 +151,29 @@ namespace Volo.Abp.Identity rolesCount.ShouldBeGreaterThan(1); } + + [Fact] + public async Task RemoveAllMembersOfOrganizationUnit() + { + OrganizationUnit ou = await _organizationUnitRepository.GetAsync("OU111", true); + var membersCount = await _organizationUnitRepository.GetMembersCountAsync(ou); + membersCount.ShouldBeGreaterThan(1); + + await _organizationUnitRepository.RemoveAllMembersAsync(ou); + var newCount = await _organizationUnitRepository.GetMembersCountAsync(ou); + newCount.ShouldBe(0); + } + + [Fact] + public async Task RemoveAllRolesOfOrganizationUnit() + { + OrganizationUnit ou = await _organizationUnitRepository.GetAsync("OU111", true); + var rolesCount = await _organizationUnitRepository.GetRolesCountAsync(ou); + rolesCount.ShouldBeGreaterThan(1); + + await _organizationUnitRepository.RemoveAllRolesAsync(ou); + var newCount = await _organizationUnitRepository.GetRolesCountAsync(ou); + newCount.ShouldBe(0); + } } } diff --git a/npm/ng-packs/packages/core/src/lib/states/config.state.ts b/npm/ng-packs/packages/core/src/lib/states/config.state.ts index 5c5338a948..0618f127c5 100644 --- a/npm/ng-packs/packages/core/src/lib/states/config.state.ts +++ b/npm/ng-packs/packages/core/src/lib/states/config.state.ts @@ -239,8 +239,8 @@ export class ConfigState { ? of(null) : dispatch(new SetLanguage(defaultLang, false)); }), - catchError(err => { - dispatch(new RestOccurError(new HttpErrorResponse({ status: 0, error: err }))); + catchError((err: HttpErrorResponse) => { + dispatch(new RestOccurError(err)); return throwError(err); }), );