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; 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; return;
} }

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

@ -7,7 +7,7 @@ namespace Volo.Abp.Identity
/// <summary> /// <summary>
/// Represents membership of a User to an OU. /// Represents membership of a User to an OU.
/// </summary> /// </summary>
public class IdentityUserOrganizationUnit : CreationAuditedEntity<Guid>, IMultiTenant, ISoftDelete public class IdentityUserOrganizationUnit : CreationAuditedEntity, IMultiTenant, ISoftDelete
{ {
/// <summary> /// <summary>
@ -50,5 +50,10 @@ namespace Volo.Abp.Identity
UserId = userId; UserId = userId;
OrganizationUnitId = organizationUnitId; 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; 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); 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> /// <summary>
/// Represents membership of a User to an OU. /// Represents membership of a User to an OU.
/// </summary> /// </summary>
public class OrganizationUnitRole : CreationAuditedEntity<Guid>, IMultiTenant, ISoftDelete public class OrganizationUnitRole : CreationAuditedEntity, IMultiTenant, ISoftDelete
{ {
/// <summary> /// <summary>
/// TenantId of this entity. /// TenantId of this entity.
@ -50,5 +50,9 @@ namespace Volo.Abp.Identity.Organizations
OrganizationUnitId = organizationUnitId; 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 user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)).ConfigureAwait(false);
var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId); var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId);
var organizationUnits = DbContext.OrganizationUnits.AsQueryable().Where(ou => organizationUnitIds.Contains(ou.Id)); 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); 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, Guid organizationUnitId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var organizationUnitUserIds = await DbContext.Users.AsQueryable() var result = await GetMongoQueryable()
.SelectMany(u => u.OrganizationUnits) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId))
.Where(ou => ou.OrganizationUnitId == organizationUnitId) .ToListAsync(GetCancellationToken(cancellationToken))
.Select(ouu => ouu.Id) .ConfigureAwait(false);
.ToListAsync(GetCancellationToken(cancellationToken)) return result;
.ConfigureAwait(false);
return await GetMongoQueryable()
.Where(u => u.OrganizationUnits.Any(uou => organizationUnitUserIds.Contains(uou.Id)))
.ToListAsync(GetCancellationToken(cancellationToken))
.ConfigureAwait(false);
} }
public async Task<List<IdentityUser>> GetUsersInOrganizationUnitWithChildrenAsync( 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 //TODO: This method has a bug: add role not work
ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true).ConfigureAwait(false); ou = await _organizationUnitRepository.GetOrganizationUnitAsync("OU1", includeDetails: true).ConfigureAwait(false);
ou.Roles.FirstOrDefault().Id.ShouldBe(adminRole.Id); ou.Roles.FirstOrDefault().RoleId.ShouldBe(adminRole.Id);
} }
[Fact] [Fact]

Loading…
Cancel
Save