Browse Source

mongodb repo for organization units

pull/2563/head
Mehmet Perk 7 years ago
parent
commit
4e7e04a7fe
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  2. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs
  3. 12
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs
  4. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/OrganizationUnitManager.cs
  5. 13
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs
  6. 24
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs
  7. 3
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContext.cs
  8. 6
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContextExtensions.cs
  9. 2
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs
  10. 3
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/IAbpIdentityMongoDbContext.cs
  11. 40
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs
  12. 66
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs
  13. 4
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs
  14. 10
      modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/OrganizationUnitRepository_Tests.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -22,6 +22,10 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<string>> GetRoleNamesInOrganizationUnitAsync(
Guid id,
CancellationToken cancellationToken = default);
Task<IdentityUser> FindByLoginAsync( Task<IdentityUser> FindByLoginAsync(
[NotNull] string loginProvider, [NotNull] string loginProvider,
[NotNull] string providerKey, [NotNull] string providerKey,

6
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserStore.cs

@ -366,7 +366,11 @@ namespace Volo.Abp.Identity
Check.NotNull(user, nameof(user)); Check.NotNull(user, nameof(user));
return await _userRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken); var userRoles = await _userRepository.GetRoleNamesAsync(user.Id, cancellationToken: cancellationToken);
var userOrganizationUnitRoles = await _userRepository.GetRoleNamesInOrganizationUnitAsync(user.Id, cancellationToken: cancellationToken);
return userRoles.Union(userOrganizationUnitRoles).ToList();
} }
/// <summary> /// <summary>

12
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/IOrganizationUnitRepository.cs

@ -8,18 +8,18 @@ namespace Volo.Abp.Identity.Organizations
{ {
public interface IOrganizationUnitRepository : IBasicRepository<OrganizationUnit, Guid> public interface IOrganizationUnitRepository : IBasicRepository<OrganizationUnit, Guid>
{ {
Task<List<OrganizationUnit>> GetChildrenAsync(Guid? parentId); Task<List<OrganizationUnit>> GetChildrenAsync(Guid? parentId, CancellationToken cancellationToken = default);
Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId); Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId, CancellationToken cancellationToken = default);
Task<List<OrganizationUnit>> GetListAsync(IEnumerable<Guid> ids); Task<List<OrganizationUnit>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default);
Task<List<OrganizationUnit>> GetListAsync(bool includeDetails = true); Task<List<OrganizationUnit>> GetListAsync(bool includeDetails = true, CancellationToken cancellationToken = default);
Task<OrganizationUnit> GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default); Task<OrganizationUnit> GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default);
Task AddRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId); Task AddRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default);
Task RemoveRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId); Task RemoveRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default);
} }
} }

6
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/OrganizationUnitManager.cs

@ -151,8 +151,8 @@ namespace Volo.Abp.Identity.Organizations
public virtual async Task AddRoleToOrganizationUnitAsync(Guid roleId, Guid ouId) public virtual async Task AddRoleToOrganizationUnitAsync(Guid roleId, Guid ouId)
{ {
await AddRoleToOrganizationUnitAsync( await AddRoleToOrganizationUnitAsync(
await _identityRoleRepository.GetAsync(roleId), await _identityRoleRepository.GetAsync(roleId).ConfigureAwait(false),
await _organizationUnitRepository.GetAsync(ouId) await _organizationUnitRepository.GetAsync(ouId, true).ConfigureAwait(false)
); );
} }
@ -162,7 +162,7 @@ namespace Volo.Abp.Identity.Organizations
if (currentRoles.Any(r => r.Id == role.Id)) if (currentRoles.Any(r => r.Id == role.Id))
{ {
return; return ;
} }
ou.AddRole(role.Id); ou.AddRole(role.Id);
await _organizationUnitRepository.AddRole(ou, role, ou.TenantId); await _organizationUnitRepository.AddRole(ou, role, ou.TenantId);

13
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs

@ -44,6 +44,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public virtual async Task<List<string>> GetRoleNamesInOrganizationUnitAsync(
Guid id,
CancellationToken cancellationToken = default)
{
var query = from userOu in DbContext.Set<IdentityUserOrganizationUnit>()
join roleOu in DbContext.Set<OrganizationUnitRole>() on userOu.OrganizationUnitId equals roleOu.OrganizationUnitId
join userOuRoles in DbContext.Roles on roleOu.RoleId equals userOuRoles.Id
where userOu.UserId == id
select userOuRoles.Name;
return await query.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public virtual async Task<IdentityUser> FindByLoginAsync( public virtual async Task<IdentityUser> FindByLoginAsync(
string loginProvider, string loginProvider,
string providerKey, string providerKey,

24
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreOrganizationUnitRepository.cs

@ -18,28 +18,28 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{ {
} }
public async Task<List<OrganizationUnit>> GetChildrenAsync(Guid? parentId) public async Task<List<OrganizationUnit>> GetChildrenAsync(Guid? parentId, CancellationToken cancellationToken = default)
{ {
return await DbSet.Where(x => x.ParentId == parentId) return await DbSet.Where(x => x.ParentId == parentId)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId) public async Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId, CancellationToken cancellationToken = default)
{ {
return await DbSet.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value) return await DbSet.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<OrganizationUnit>> GetListAsync(IEnumerable<Guid> ids) public async Task<List<OrganizationUnit>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)
{ {
return await DbSet.Where(t => ids.Contains(t.Id)).ToListAsync(); return await DbSet.Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<OrganizationUnit>> GetListAsync(bool includeDetails = true) public override async Task<List<OrganizationUnit>> GetListAsync(bool includeDetails = true, CancellationToken cancellationToken = default)
{ {
return await DbSet return await DbSet
.IncludeDetails(includeDetails) .IncludeDetails(includeDetails)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<OrganizationUnit> GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default) public async Task<OrganizationUnit> GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default)
@ -52,14 +52,14 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
).ConfigureAwait(false); ).ConfigureAwait(false);
} }
public async Task AddRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId) public Task AddRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default)
{ {
var our = new OrganizationUnitRole(tenantId, role.Id, ou.Id); var our = new OrganizationUnitRole(tenantId, role.Id, ou.Id);
DbContext.Set<OrganizationUnitRole>().Add(our); DbContext.Set<OrganizationUnitRole>().Add(our);
await DbContext.SaveChangesAsync(); return Task.FromResult(0);
} }
public async Task RemoveRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId) public async Task RemoveRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default)
{ {
var context = DbContext.Set<OrganizationUnitRole>(); var context = DbContext.Set<OrganizationUnitRole>();
var our = await context.FirstOrDefaultAsync(our => var our = await context.FirstOrDefaultAsync(our =>
@ -68,12 +68,12 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
our.TenantId == tenantId our.TenantId == tenantId
); );
DbContext.Set<OrganizationUnitRole>().Remove(our); DbContext.Set<OrganizationUnitRole>().Remove(our);
await DbContext.SaveChangesAsync();
} }
public override IQueryable<OrganizationUnit> WithDetails() public override IQueryable<OrganizationUnit> WithDetails()
{ {
return GetQueryable().IncludeDetails(); return GetQueryable().IncludeDetails();
} }
} }
} }

3
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContext.cs

@ -1,5 +1,6 @@
using MongoDB.Driver; using MongoDB.Driver;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB namespace Volo.Abp.Identity.MongoDB
@ -13,6 +14,8 @@ namespace Volo.Abp.Identity.MongoDB
public IMongoCollection<IdentityClaimType> ClaimTypes => Collection<IdentityClaimType>(); public IMongoCollection<IdentityClaimType> ClaimTypes => Collection<IdentityClaimType>();
public IMongoCollection<OrganizationUnit> OrganizationUnits => Collection<OrganizationUnit>();
protected override void CreateModel(IMongoModelBuilder modelBuilder) protected override void CreateModel(IMongoModelBuilder modelBuilder)
{ {
base.CreateModel(modelBuilder); base.CreateModel(modelBuilder);

6
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbContextExtensions.cs

@ -1,4 +1,5 @@
using System; using System;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB namespace Volo.Abp.Identity.MongoDB
@ -31,6 +32,11 @@ namespace Volo.Abp.Identity.MongoDB
{ {
b.CollectionName = options.CollectionPrefix + "ClaimTypes"; b.CollectionName = options.CollectionPrefix + "ClaimTypes";
}); });
builder.Entity<OrganizationUnit>(b =>
{
b.CollectionName = options.CollectionPrefix + "OrganizationUnit";
});
} }
} }
} }

2
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/AbpIdentityMongoDbModule.cs

@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Users.MongoDB; using Volo.Abp.Users.MongoDB;
@ -17,6 +18,7 @@ namespace Volo.Abp.Identity.MongoDB
options.AddRepository<IdentityUser, MongoIdentityUserRepository>(); options.AddRepository<IdentityUser, MongoIdentityUserRepository>();
options.AddRepository<IdentityRole, MongoIdentityRoleRepository>(); options.AddRepository<IdentityRole, MongoIdentityRoleRepository>();
options.AddRepository<IdentityClaimType, MongoIdentityRoleRepository>(); options.AddRepository<IdentityClaimType, MongoIdentityRoleRepository>();
options.AddRepository<OrganizationUnit, MongoIdentityRoleRepository>();
}); });
} }
} }

3
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/IAbpIdentityMongoDbContext.cs

@ -1,5 +1,6 @@
using MongoDB.Driver; using MongoDB.Driver;
using Volo.Abp.Data; using Volo.Abp.Data;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB namespace Volo.Abp.Identity.MongoDB
@ -12,5 +13,7 @@ namespace Volo.Abp.Identity.MongoDB
IMongoCollection<IdentityRole> Roles { get; } IMongoCollection<IdentityRole> Roles { get; }
IMongoCollection<IdentityClaimType> ClaimTypes { get; } IMongoCollection<IdentityClaimType> ClaimTypes { get; }
IMongoCollection<OrganizationUnit> OrganizationUnits { get; }
} }
} }

40
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs

@ -9,6 +9,7 @@ using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.Guids; using Volo.Abp.Guids;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB namespace Volo.Abp.Identity.MongoDB
@ -17,14 +18,14 @@ namespace Volo.Abp.Identity.MongoDB
{ {
private readonly IGuidGenerator _guidGenerator; private readonly IGuidGenerator _guidGenerator;
public MongoIdentityUserRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IGuidGenerator guidGenerator) public MongoIdentityUserRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IGuidGenerator guidGenerator)
: base(dbContextProvider) : base(dbContextProvider)
{ {
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
} }
public async Task<IdentityUser> FindByNormalizedUserNameAsync( public async Task<IdentityUser> FindByNormalizedUserNameAsync(
string normalizedUserName, string normalizedUserName,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -36,7 +37,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
public async Task<List<string>> GetRoleNamesAsync( public async Task<List<string>> GetRoleNamesAsync(
Guid id, Guid id,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false); var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false);
@ -44,9 +45,20 @@ namespace Volo.Abp.Identity.MongoDB
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<string>> GetRoleNamesInOrganizationUnitAsync(
Guid id,
CancellationToken cancellationToken = default)
{
var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false);
var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId);
var organizationUnits = DbContext.OrganizationUnits.AsQueryable().Where(ou => organizationUnitIds.Contains(ou.Id));
var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.Id));
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<IdentityUser> FindByLoginAsync( public async Task<IdentityUser> FindByLoginAsync(
string loginProvider, string loginProvider,
string providerKey, string providerKey,
bool includeDetails = true, bool includeDetails = true,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -74,7 +86,7 @@ namespace Volo.Abp.Identity.MongoDB
} }
public async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync( public async Task<List<IdentityUser>> GetListByNormalizedRoleNameAsync(
string normalizedRoleName, string normalizedRoleName,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -92,9 +104,9 @@ namespace Volo.Abp.Identity.MongoDB
public async Task<List<IdentityUser>> GetListAsync( public async Task<List<IdentityUser>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string filter = null, string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
@ -121,6 +133,16 @@ namespace Volo.Abp.Identity.MongoDB
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false); return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
} }
public async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync(
Guid id,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false);
var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId);
return await DbContext.OrganizationUnits.AsQueryable().Where(ou => organizationUnitIds.Contains(ou.Id)).ToListAsync().ConfigureAwait(false);
}
public async Task<long> GetCountAsync( public async Task<long> GetCountAsync(
string filter = null, string filter = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)

66
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoOrganizationUnitRepository.cs

@ -0,0 +1,66 @@
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.Guids;
using Volo.Abp.Identity.Organizations;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public class MongoOrganizationUnitRepository : MongoDbRepository<IAbpIdentityMongoDbContext, OrganizationUnit, Guid>, IOrganizationUnitRepository
{
private readonly IGuidGenerator _guidGenerator;
public MongoOrganizationUnitRepository(
IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider,
IGuidGenerator guidGenerator)
: base(dbContextProvider)
{
_guidGenerator = guidGenerator;
}
public async Task<List<OrganizationUnit>> GetChildrenAsync(Guid? parentId, CancellationToken cancellationToken = default)
{
return await DbContext.OrganizationUnits.AsQueryable().Where(ou => ou.ParentId == parentId)
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<List<OrganizationUnit>> GetAllChildrenWithParentCodeAsync(string code, Guid? parentId, CancellationToken cancellationToken = default)
{
return await DbContext.OrganizationUnits.AsQueryable()
.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value)
.ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<List<OrganizationUnit>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)
{
return await DbContext.OrganizationUnits.AsQueryable()
.Where(t => ids.Contains(t.Id)).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
public async Task<OrganizationUnit> GetOrganizationUnit(string displayName, bool includeDetails = false, CancellationToken cancellationToken = default)
{
return await DbContext.OrganizationUnits.AsQueryable()
.FirstOrDefaultAsync(
ou => ou.DisplayName == displayName,
GetCancellationToken(cancellationToken)
).ConfigureAwait(false);
}
public Task AddRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task RemoveRole(OrganizationUnit ou, IdentityRole role, Guid? tenantId, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}
}

4
modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs

@ -89,9 +89,9 @@ namespace Volo.Abp.Identity
{ {
var ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", true).ConfigureAwait(false); var ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", true).ConfigureAwait(false);
var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")).ConfigureAwait(false); var adminRole = await _identityRoleRepository.FindByNormalizedNameAsync(_lookupNormalizer.NormalizeName("admin")).ConfigureAwait(false);
await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole.Id, ou.Id); await _organizationUnitManager.AddRoleToOrganizationUnitAsync(adminRole, ou);
//TODO: This method has a bug: includeDetails not work //TODO: This method has a bug: includeDetails not work or add role not work
ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", includeDetails: true).ConfigureAwait(false); ou = await _organizationUnitRepository.GetOrganizationUnit("OU1", includeDetails: true).ConfigureAwait(false);
ou.Roles.FirstOrDefault().Id.ShouldBe(adminRole.Id); ou.Roles.FirstOrDefault().Id.ShouldBe(adminRole.Id);
} }

10
modules/identity/test/Volo.Abp.Identity.MongoDB.Tests/Volo/Abp/Identity/MongoDB/OrganizationUnitRepository_Tests.cs

@ -0,0 +1,10 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Volo.Abp.Identity.MongoDB
{
public class OrganizationUnitRepository_Tests : OrganizationUnitRepository_Tests<AbpIdentityMongoDbTestModule>
{
}
}
Loading…
Cancel
Save