|
|
@ -1,9 +1,7 @@
|
|
|
|
using MongoDB.Bson;
|
|
|
|
using MongoDB.Driver;
|
|
|
|
using MongoDB.Driver;
|
|
|
|
|
|
|
|
using MongoDB.Driver.Linq;
|
|
|
|
using MongoDB.Driver.Linq;
|
|
|
|
using System;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Data;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
|
using System.Linq.Dynamic.Core;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading;
|
|
|
@ -11,7 +9,6 @@ using System.Threading.Tasks;
|
|
|
|
using Volo.Abp.Domain.Repositories.MongoDB;
|
|
|
|
using Volo.Abp.Domain.Repositories.MongoDB;
|
|
|
|
using Volo.Abp.MongoDB;
|
|
|
|
using Volo.Abp.MongoDB;
|
|
|
|
using Volo.Abp.MultiTenancy;
|
|
|
|
using Volo.Abp.MultiTenancy;
|
|
|
|
using Volo.Abp.Uow;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Volo.Abp.Identity.MongoDB
|
|
|
|
namespace Volo.Abp.Identity.MongoDB
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -30,7 +27,7 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await GetMongoQueryable()
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken))
|
|
|
|
.Where(ou => ou.ParentId == parentId)
|
|
|
|
.Where(ou => ou.ParentId == parentId)
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -41,7 +38,7 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await GetMongoQueryable()
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken))
|
|
|
|
.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value)
|
|
|
|
.Where(ou => ou.Code.StartsWith(code) && ou.Id != parentId.Value)
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -51,7 +48,7 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await GetMongoQueryable()
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken))
|
|
|
|
.Where(t => ids.Contains(t.Id))
|
|
|
|
.Where(t => ids.Contains(t.Id))
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -63,7 +60,7 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await GetMongoQueryable()
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken))
|
|
|
|
.OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName))
|
|
|
|
.OrderBy(sorting ?? nameof(OrganizationUnit.DisplayName))
|
|
|
|
.As<IMongoQueryable<OrganizationUnit>>()
|
|
|
|
.As<IMongoQueryable<OrganizationUnit>>()
|
|
|
|
.PageBy<OrganizationUnit, IMongoQueryable<OrganizationUnit>>(skipCount, maxResultCount)
|
|
|
|
.PageBy<OrganizationUnit, IMongoQueryable<OrganizationUnit>>(skipCount, maxResultCount)
|
|
|
@ -75,7 +72,7 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = true,
|
|
|
|
bool includeDetails = true,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await GetMongoQueryable()
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken))
|
|
|
|
.OrderBy(x => x.Id)
|
|
|
|
.OrderBy(x => x.Id)
|
|
|
|
.FirstOrDefaultAsync(
|
|
|
|
.FirstOrDefaultAsync(
|
|
|
|
ou => ou.DisplayName == displayName,
|
|
|
|
ou => ou.DisplayName == displayName,
|
|
|
@ -92,7 +89,10 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)))
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(
|
|
|
|
|
|
|
|
dbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id))
|
|
|
|
|
|
|
|
)
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityRole.Name))
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityRole.Name))
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
|
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
|
|
|
|
.PageBy<IdentityRole, IMongoQueryable<IdentityRole>>(skipCount, maxResultCount)
|
|
|
@ -104,7 +104,10 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>( DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)))
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(
|
|
|
|
|
|
|
|
dbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id))
|
|
|
|
|
|
|
|
)
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
|
.CountAsync(cancellationToken);
|
|
|
|
.CountAsync(cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -119,7 +122,8 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(DbContext.Roles.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(dbContext.Roles.AsQueryable())
|
|
|
|
.Where(r => !roleIds.Contains(r.Id))
|
|
|
|
.Where(r => !roleIds.Contains(r.Id))
|
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
|
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityRole.Name))
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityRole.Name))
|
|
|
@ -134,7 +138,8 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
var roleIds = organizationUnit.Roles.Select(r => r.RoleId).ToArray();
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(DbContext.Roles.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityRole>, IdentityRole>(dbContext.Roles.AsQueryable())
|
|
|
|
.Where(r => !roleIds.Contains(r.Id))
|
|
|
|
.Where(r => !roleIds.Contains(r.Id))
|
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
|
|
|
|
.WhereIf(!filter.IsNullOrWhiteSpace(), r => r.Name.Contains(filter))
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
|
.As<IMongoQueryable<IdentityRole>>()
|
|
|
@ -150,13 +155,13 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var query = CreateGetMembersFilteredQuery(organizationUnit, filter);
|
|
|
|
cancellationToken = GetCancellationToken(cancellationToken);
|
|
|
|
|
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken);
|
|
|
|
return await query
|
|
|
|
return await query
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityUser.UserName))
|
|
|
|
.OrderBy(sorting ?? nameof(IdentityUser.UserName))
|
|
|
|
.As<IMongoQueryable<IdentityUser>>()
|
|
|
|
.As<IMongoQueryable<IdentityUser>>()
|
|
|
|
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
|
|
|
|
.PageBy<IdentityUser, IMongoQueryable<IdentityUser>>(skipCount, maxResultCount)
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
.ToListAsync(cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task<int> GetMembersCountAsync(
|
|
|
|
public virtual async Task<int> GetMembersCountAsync(
|
|
|
@ -164,9 +169,9 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
string filter = null,
|
|
|
|
string filter = null,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var query = CreateGetMembersFilteredQuery(organizationUnit, filter);
|
|
|
|
cancellationToken = GetCancellationToken(cancellationToken);
|
|
|
|
|
|
|
|
var query = await CreateGetMembersFilteredQueryAsync(organizationUnit, filter, cancellationToken);
|
|
|
|
return await query.CountAsync(GetCancellationToken(cancellationToken));
|
|
|
|
return await query.CountAsync(cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<IdentityUser>> GetUnaddedUsersAsync(
|
|
|
|
public async Task<List<IdentityUser>> GetUnaddedUsersAsync(
|
|
|
@ -178,7 +183,8 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
bool includeDetails = false,
|
|
|
|
bool includeDetails = false,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(DbContext.Users.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(dbContext.Users.AsQueryable())
|
|
|
|
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
@ -196,7 +202,8 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
public async Task<int> GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null,
|
|
|
|
public async Task<int> GetUnaddedUsersCountAsync(OrganizationUnit organizationUnit, string filter = null,
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(DbContext.Users.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(dbContext.Users.AsQueryable())
|
|
|
|
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.Where(u => !u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
@ -217,7 +224,8 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
|
|
|
|
|
|
|
|
public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default)
|
|
|
|
public virtual async Task RemoveAllMembersAsync(OrganizationUnit organizationUnit, CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var users = await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(DbContext.Users.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
var users = await ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(dbContext.Users.AsQueryable())
|
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.As<IMongoQueryable<IdentityUser>>()
|
|
|
|
.As<IMongoQueryable<IdentityUser>>()
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken));
|
|
|
@ -225,13 +233,17 @@ namespace Volo.Abp.Identity.MongoDB
|
|
|
|
foreach (var user in users)
|
|
|
|
foreach (var user in users)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
user.RemoveOrganizationUnit(organizationUnit.Id);
|
|
|
|
user.RemoveOrganizationUnit(organizationUnit.Id);
|
|
|
|
DbContext.Users.ReplaceOne(u => u.Id == user.Id, user);
|
|
|
|
await dbContext.Users.ReplaceOneAsync(u => u.Id == user.Id, user, cancellationToken: cancellationToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual IMongoQueryable<IdentityUser> CreateGetMembersFilteredQuery(OrganizationUnit organizationUnit, string filter = null)
|
|
|
|
protected virtual async Task<IMongoQueryable<IdentityUser>> CreateGetMembersFilteredQueryAsync(
|
|
|
|
|
|
|
|
OrganizationUnit organizationUnit,
|
|
|
|
|
|
|
|
string filter = null,
|
|
|
|
|
|
|
|
CancellationToken cancellationToken = default)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(DbContext.Users.AsQueryable())
|
|
|
|
var dbContext = await GetDbContextAsync(cancellationToken);
|
|
|
|
|
|
|
|
return ApplyDataFilters<IMongoQueryable<IdentityUser>, IdentityUser>(dbContext.Users.AsQueryable())
|
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnit.Id))
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
.WhereIf<IdentityUser, IMongoQueryable<IdentityUser>>(
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
|
!filter.IsNullOrWhiteSpace(),
|
|
|
|