Browse Source

Lookup parent organization unit under the target tenant

pull/25357/head
maliming 3 months ago
parent
commit
1e9a3fcc34
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 9
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs
  2. 24
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs

9
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/OrganizationUnitManager.cs

@ -159,8 +159,13 @@ public class OrganizationUnitManager : DomainService
return;
}
var parent = await OrganizationUnitRepository.FindAsync(parentId.Value);
if (parent == null || parent.TenantId != tenantId)
OrganizationUnit parent;
using (CurrentTenant.Change(tenantId))
{
parent = await OrganizationUnitRepository.FindAsync(parentId.Value);
}
if (parent == null)
{
throw new BusinessException(IdentityErrorCodes.OrganizationUnitParentTenantMismatch)
.WithData("ParentId", parentId);

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

@ -169,4 +169,28 @@ public class OrganizationUnitManager_Tests : AbpIdentityDomainTestBase
ex.Code.ShouldBe(IdentityErrorCodes.OrganizationUnitParentTenantMismatch);
}
[Fact]
public async Task Should_Allow_Host_To_Create_Tenant_Organization_Unit_Under_Same_Tenant_Parent()
{
var tenantId = Guid.NewGuid();
OrganizationUnit tenantRoot;
using (_currentTenant.Change(tenantId))
{
tenantRoot = new OrganizationUnit(_guidGenerator.Create(), "TenantRoot", null, tenantId);
await _organizationUnitManager.CreateAsync(tenantRoot);
}
var child = new OrganizationUnit(_guidGenerator.Create(), "TenantChild", tenantRoot.Id, tenantId);
await _organizationUnitManager.CreateAsync(child);
using (_currentTenant.Change(tenantId))
{
var loaded = await _organizationUnitRepository.FindAsync(child.Id);
loaded.ShouldNotBeNull();
loaded.ParentId.ShouldBe(tenantRoot.Id);
loaded.TenantId.ShouldBe(tenantId);
}
}
}

Loading…
Cancel
Save