Browse Source

Merge branch 'dev' of https://github.com/abpframework/abp into dev

pull/4201/head
Halil İbrahim Kalkan 6 years ago
parent
commit
73f4d0629d
  1. 19
      docs/en/Tutorials/Part-1.md
  2. 11
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IOrganizationUnitRepository.cs
  3. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs
  4. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs
  5. 29
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  6. 34
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs
  7. 29
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs
  8. 24
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/OrganizationUnitRepository_Tests.cs
  9. 4
      npm/ng-packs/packages/core/src/lib/states/config.state.ts

19
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" }

11
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<int> GetMembersCountAsync(
OrganizationUnit organizationUnit,
CancellationToken cancellationToken = default
);
Task RemoveAllRolesAsync(
OrganizationUnit organizationUnit,
CancellationToken cancellationToken = default
);
Task RemoveAllMembersAsync(
OrganizationUnit organizationUnit,
CancellationToken cancellationToken = default
);
}
}

4
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<bool> 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<List<OrganizationUnit>> GetOrganizationUnitsAsync(IdentityUser user)
public virtual async Task<List<OrganizationUnit>> 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
);
}

4
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);
}

29
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<OrganizationUnitRole>().Where(q => userOrganizationsQuery.Select(t => t.Id).Contains(q.OrganizationUnitId))
var orgUserRoleQuery = DbContext.Set<OrganizationUnitRole>()
.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<long> 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<List<IdentityUser>> GetUsersInOrganizationsListAsync(
List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default
)
{
//var userIds = DbContext.Set<IdentityUserOrganizationUnit>()
// .Where(q => organizationUnitIds.Contains(q.OrganizationUnitId))
// .Select(u => u.UserId);
//var query = DbContext.Users.Where(u => userIds.Contains(u.Id));
}
public async Task<List<IdentityUser>> GetUsersInOrganizationsListAsync(
List<Guid> organizationUnitIds,
CancellationToken cancellationToken = default
)
{
var query = from userOu in DbContext.Set<IdentityUserOrganizationUnit>()
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<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync(
@ -235,6 +232,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
public override IQueryable<IdentityUser> WithDetails()
{
return GetQueryable().IncludeDetails();
}
}
}
}

34
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<int> GetRolesCountAsync(
OrganizationUnit organizationUnit,
CancellationToken cancellationToken = default)
{
{
var query = from organizationRole in DbContext.Set<OrganizationUnitRole>()
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<OrganizationUnitRole>()
.Where(q => q.OrganizationUnitId == organizationUnit.Id);
DbContext.Set<OrganizationUnitRole>().RemoveRange(ouRolesQuery);
return Task.FromResult(0);
//Can be long running process that could be made available for cancellation perhaps
//return Task.Run(() =>
// DbContext.Set<OrganizationUnitRole>().RemoveRange(ouRolesQuery),
// GetCancellationToken(cancellationToken)
//);
}
public virtual Task RemoveAllMembersAsync(
OrganizationUnit organizationUnit,
CancellationToken cancellationToken = default)
{
var ouMembersQuery = DbContext.Set<IdentityUserOrganizationUnit>()
.Where(q => q.OrganizationUnitId == organizationUnit.Id);
DbContext.Set<IdentityUserOrganizationUnit>().RemoveRange(ouMembersQuery);
return Task.FromResult(0);
//Can be long running process that could be made available for cancellation perhaps
//return Task.Run(() =>
// DbContext.Set<IdentityUserOrganizationUnit>().RemoveRange(ouMembersQuery),
// GetCancellationToken(cancellationToken)
//);
}
}
}

29
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<IAbpIdentityMongoDbContext, OrganizationUnit, Guid>, IOrganizationUnitRepository
public class MongoOrganizationUnitRepository
: MongoDbRepository<IAbpIdentityMongoDbContext, OrganizationUnit, Guid>,
IOrganizationUnitRepository
{
public MongoOrganizationUnitRepository(
IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
@ -134,5 +139,25 @@ namespace Volo.Abp.Identity.MongoDB
.As<IMongoQueryable<IdentityUser>>()
.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<IMongoQueryable<IdentityUser>>()
.ToListAsync(GetCancellationToken(cancellationToken));
foreach (var user in users)
{
user.RemoveOrganizationUnit(organizationUnit.Id);
DbContext.Users.ReplaceOne(u => u.Id == user.Id, user);
}
}
}
}

24
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);
}
}
}

4
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);
}),
);

Loading…
Cancel
Save