|
|
|
@ -22,7 +22,6 @@ namespace Volo.Abp.Identity |
|
|
|
protected IIdentityRoleRepository RoleRepository { get; } |
|
|
|
protected IIdentityUserRepository UserRepository { get; } |
|
|
|
protected IOrganizationUnitRepository OrganizationUnitRepository { get; } |
|
|
|
protected IIdentityUserRepository IdentityUserRepository { get; } |
|
|
|
protected ISettingProvider SettingProvider { get; } |
|
|
|
protected ICancellationTokenProvider CancellationTokenProvider { get; } |
|
|
|
|
|
|
|
@ -42,7 +41,6 @@ namespace Volo.Abp.Identity |
|
|
|
ILogger<IdentityUserManager> logger, |
|
|
|
ICancellationTokenProvider cancellationTokenProvider, |
|
|
|
IOrganizationUnitRepository organizationUnitRepository, |
|
|
|
IIdentityUserRepository identityUserRepository, |
|
|
|
ISettingProvider settingProvider) |
|
|
|
: base( |
|
|
|
store, |
|
|
|
@ -56,7 +54,6 @@ namespace Volo.Abp.Identity |
|
|
|
logger) |
|
|
|
{ |
|
|
|
OrganizationUnitRepository = organizationUnitRepository; |
|
|
|
IdentityUserRepository = identityUserRepository; |
|
|
|
SettingProvider = settingProvider; |
|
|
|
RoleRepository = roleRepository; |
|
|
|
UserRepository = userRepository; |
|
|
|
@ -98,27 +95,27 @@ namespace Volo.Abp.Identity |
|
|
|
|
|
|
|
public virtual async Task<bool> IsInOrganizationUnitAsync(Guid userId, Guid ouId) |
|
|
|
{ |
|
|
|
var user = await IdentityUserRepository.GetAsync(userId, cancellationToken: CancellationToken); |
|
|
|
var user = await UserRepository.GetAsync(userId, cancellationToken: CancellationToken); |
|
|
|
return user.IsInOrganizationUnit(ouId); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task<bool> IsInOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou) |
|
|
|
{ |
|
|
|
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
await UserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
return user.IsInOrganizationUnit(ou.Id); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task AddToOrganizationUnitAsync(Guid userId, Guid ouId) |
|
|
|
{ |
|
|
|
await AddToOrganizationUnitAsync( |
|
|
|
await IdentityUserRepository.GetAsync(userId, cancellationToken: CancellationToken), |
|
|
|
await UserRepository.GetAsync(userId, cancellationToken: CancellationToken), |
|
|
|
await OrganizationUnitRepository.GetAsync(ouId, cancellationToken: CancellationToken) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task AddToOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou) |
|
|
|
{ |
|
|
|
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
await UserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
|
|
|
|
if (user.OrganizationUnits.Any(cou => cou.OrganizationUnitId == ou.Id)) |
|
|
|
{ |
|
|
|
@ -132,13 +129,13 @@ namespace Volo.Abp.Identity |
|
|
|
|
|
|
|
public virtual async Task RemoveFromOrganizationUnitAsync(Guid userId, Guid ouId) |
|
|
|
{ |
|
|
|
var user = await IdentityUserRepository.GetAsync(userId, cancellationToken: CancellationToken); |
|
|
|
var user = await UserRepository.GetAsync(userId, cancellationToken: CancellationToken); |
|
|
|
user.RemoveOrganizationUnit(ouId); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual async Task RemoveFromOrganizationUnitAsync(IdentityUser user, OrganizationUnit ou) |
|
|
|
{ |
|
|
|
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
await UserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
|
|
|
|
user.RemoveOrganizationUnit(ou.Id); |
|
|
|
} |
|
|
|
@ -146,7 +143,7 @@ namespace Volo.Abp.Identity |
|
|
|
public virtual async Task SetOrganizationUnitsAsync(Guid userId, params Guid[] organizationUnitIds) |
|
|
|
{ |
|
|
|
await SetOrganizationUnitsAsync( |
|
|
|
await IdentityUserRepository.GetAsync(userId, cancellationToken: CancellationToken), |
|
|
|
await UserRepository.GetAsync(userId, cancellationToken: CancellationToken), |
|
|
|
organizationUnitIds |
|
|
|
); |
|
|
|
} |
|
|
|
@ -158,7 +155,7 @@ namespace Volo.Abp.Identity |
|
|
|
|
|
|
|
await CheckMaxUserOrganizationUnitMembershipCountAsync(organizationUnitIds.Length); |
|
|
|
|
|
|
|
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
await UserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
|
|
|
|
//Remove from removed OUs
|
|
|
|
foreach (var ouId in user.OrganizationUnits.Select(uou => uou.OrganizationUnitId).ToArray()) |
|
|
|
@ -192,7 +189,7 @@ namespace Volo.Abp.Identity |
|
|
|
[UnitOfWork] |
|
|
|
public virtual async Task<List<OrganizationUnit>> GetOrganizationUnitsAsync(IdentityUser user, bool includeDetails = false) |
|
|
|
{ |
|
|
|
await IdentityUserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
await UserRepository.EnsureCollectionLoadedAsync(user, u => u.OrganizationUnits, CancellationTokenProvider.Token); |
|
|
|
|
|
|
|
return await OrganizationUnitRepository.GetListAsync( |
|
|
|
user.OrganizationUnits.Select(t => t.OrganizationUnitId), |
|
|
|
@ -208,12 +205,12 @@ namespace Volo.Abp.Identity |
|
|
|
{ |
|
|
|
if (includeChildren) |
|
|
|
{ |
|
|
|
return await IdentityUserRepository |
|
|
|
return await UserRepository |
|
|
|
.GetUsersInOrganizationUnitWithChildrenAsync(organizationUnit.Code, CancellationToken); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return await IdentityUserRepository |
|
|
|
return await UserRepository |
|
|
|
.GetUsersInOrganizationUnitAsync(organizationUnit.Id, CancellationToken); |
|
|
|
} |
|
|
|
} |
|
|
|
|