Browse Source

IdentityUserOrganizationUnit and OrganizationUnitRole do not need a primary key

pull/2563/head
Mehmet Perk 7 years ago
parent
commit
876f441cce
  1. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs
  2. 7
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserOrganizationUnit.cs
  3. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/OrganizationUnitManager.cs
  4. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/Organizations/OrganizationUnitRole.cs
  5. 18
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs
  6. 2
      modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/OrganizationUnitManager_Tests.cs

2
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserManager.cs

@ -117,7 +117,7 @@ namespace Volo.Abp.Identity
var currentOus = user.OrganizationUnits;
if (currentOus.Any(cou => cou.Id == ou.Id))
if (currentOus.Any(cou => cou.OrganizationUnitId == ou.Id && cou.UserId == user.Id))
{
return;
}

7
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUserOrganizationUnit.cs

@ -7,7 +7,7 @@ namespace Volo.Abp.Identity
/// <summary>
/// Represents membership of a User to an OU.
/// </summary>
public class IdentityUserOrganizationUnit : CreationAuditedEntity<Guid>, IMultiTenant, ISoftDelete
public class IdentityUserOrganizationUnit : CreationAuditedEntity, IMultiTenant, ISoftDelete
{
/// <summary>
@ -50,5 +50,10 @@ namespace Volo.Abp.Identity
UserId = userId;
OrganizationUnitId = organizationUnitId;
}
public override object[] GetKeys()
{
return new object[] { UserId, OrganizationUnitId };
}
}
}

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

@ -160,7 +160,7 @@ namespace Volo.Abp.Identity.Organizations
{
var currentRoles = ou.Roles;
if (currentRoles.Any(r => r.Id == role.Id))
if (currentRoles.Any(r => r.OrganizationUnitId == ou.Id && r.RoleId == role.Id))
{
return Task.FromResult(0);
}

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

@ -7,7 +7,7 @@ namespace Volo.Abp.Identity.Organizations
/// <summary>
/// Represents membership of a User to an OU.
/// </summary>
public class OrganizationUnitRole : CreationAuditedEntity<Guid>, IMultiTenant, ISoftDelete
public class OrganizationUnitRole : CreationAuditedEntity, IMultiTenant, ISoftDelete
{
/// <summary>
/// TenantId of this entity.
@ -50,5 +50,9 @@ namespace Volo.Abp.Identity.Organizations
OrganizationUnitId = organizationUnitId;
}
public override object[] GetKeys()
{
return new object[] { OrganizationUnitId, RoleId };
}
}
}

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

@ -52,7 +52,7 @@ namespace Volo.Abp.Identity.MongoDB
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));
var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId));
return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)).ConfigureAwait(false);
}
@ -164,17 +164,11 @@ namespace Volo.Abp.Identity.MongoDB
Guid organizationUnitId,
CancellationToken cancellationToken = default)
{
var organizationUnitUserIds = await DbContext.Users.AsQueryable()
.SelectMany(u => u.OrganizationUnits)
.Where(ou => ou.OrganizationUnitId == organizationUnitId)
.Select(ouu => ouu.Id)
.ToListAsync(GetCancellationToken(cancellationToken))
.ConfigureAwait(false);
return await GetMongoQueryable()
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitUserIds.Contains(uou.Id)))
.ToListAsync(GetCancellationToken(cancellationToken))
.ConfigureAwait(false);
var result = await GetMongoQueryable()
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId))
.ToListAsync(GetCancellationToken(cancellationToken))
.ConfigureAwait(false);
return result;
}
public async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync(

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

@ -93,7 +93,7 @@ namespace Volo.Abp.Identity
//TODO: This method has a bug: add role not work
ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true).ConfigureAwait(false);
ou.Roles.FirstOrDefault().Id.ShouldBe(adminRole.Id);
ou.Roles.FirstOrDefault().RoleId.ShouldBe(adminRole.Id);
}
[Fact]

Loading…
Cancel
Save