diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs index a123868799..6795735793 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs @@ -24,13 +24,13 @@ namespace Volo.Abp.Identity.MongoDB { if (ignoredId == null) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(ct => ct.Name == name) .AnyAsync(GetCancellationToken(cancellationToken)); } else { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(ct => ct.Id != ignoredId && ct.Name == name) .AnyAsync(GetCancellationToken(cancellationToken)); } @@ -43,7 +43,7 @@ namespace Volo.Abp.Identity.MongoDB string filter, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -59,7 +59,7 @@ namespace Volo.Abp.Identity.MongoDB string filter = null, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs index 6e8d53821b..43bad94271 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityLinkUserRepository.cs @@ -19,7 +19,7 @@ namespace Volo.Abp.Identity.MongoDB public async Task FindAsync(IdentityLinkUserInfo sourceLinkUserInfo, IdentityLinkUserInfo targetLinkUserInfo, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.SourceUserId == sourceLinkUserInfo.UserId && x.SourceTenantId == sourceLinkUserInfo.TenantId && x.TargetUserId == targetLinkUserInfo.UserId && x.TargetTenantId == targetLinkUserInfo.TenantId || @@ -30,7 +30,7 @@ namespace Volo.Abp.Identity.MongoDB public async Task> GetListAsync(IdentityLinkUserInfo linkUserInfo, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().Where(x => + return await (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.SourceUserId == linkUserInfo.UserId && x.SourceTenantId == linkUserInfo.TenantId || x.TargetUserId == linkUserInfo.UserId && x.TargetTenantId == linkUserInfo.TenantId) .ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs index 9c6bccf74f..0731008f57 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs @@ -23,7 +23,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = true, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, GetCancellationToken(cancellationToken)); } @@ -36,7 +36,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.NormalizedName.Contains(filter)) @@ -50,7 +50,7 @@ namespace Volo.Abp.Identity.MongoDB IEnumerable ids, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(t => ids.Contains(t.Id)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -59,14 +59,16 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken)); + return await (await GetMongoQueryableAsync(cancellationToken)) + .Where(r => r.IsDefault) + .ToListAsync(GetCancellationToken(cancellationToken)); } public async Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf(!filter.IsNullOrWhiteSpace(), x => x.Name.Contains(filter) || x.NormalizedName.Contains(filter)) diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs index b63a6001f9..a0a8b9b103 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs @@ -35,7 +35,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - var query = GetListQuery( + var query = await GetListQueryAsync( startTime, endTime, applicationName, @@ -65,7 +65,7 @@ namespace Volo.Abp.Identity.MongoDB string correlationId = null, CancellationToken cancellationToken = default) { - var query = GetListQuery( + var query = await GetListQueryAsync( startTime, endTime, applicationName, @@ -85,11 +85,11 @@ namespace Volo.Abp.Identity.MongoDB public async Task GetByUserIdAsync(Guid id, Guid userId, bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable().OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, + return await (await GetMongoQueryableAsync(cancellationToken)).OrderBy(x => x.Id).FirstOrDefaultAsync(x => x.Id == id && x.UserId == userId, GetCancellationToken(cancellationToken)); } - protected virtual IQueryable GetListQuery( + protected virtual async Task> GetListQueryAsync( DateTime? startTime = null, DateTime? endTime = null, string applicationName = null, @@ -100,7 +100,7 @@ namespace Volo.Abp.Identity.MongoDB string clientId = null, string correlationId = null) { - return GetMongoQueryable() + return (await GetMongoQueryableAsync()) .WhereIf(startTime.HasValue, securityLog => securityLog.CreationTime >= startTime.Value) .WhereIf(endTime.HasValue, securityLog => securityLog.CreationTime < endTime.Value.AddDays(1).Date) .WhereIf(!applicationName.IsNullOrWhiteSpace(), diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs index 692e5d5016..0864f7b01c 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityUserRepository.cs @@ -24,7 +24,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = true, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .OrderBy(x => x.Id) .FirstOrDefaultAsync( u => u.NormalizedUserName == normalizedUserName, @@ -40,14 +40,17 @@ namespace Volo.Abp.Identity.MongoDB var organizationUnitIds = user.OrganizationUnits .Select(r => r.OrganizationUnitId) .ToArray(); - var organizationUnits = DbContext.OrganizationUnits + + var dbContext = await GetDbContextAsync(cancellationToken); + + var organizationUnits = dbContext.OrganizationUnits .AsQueryable() .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var allRoleIds = orgUnitRoleIds.Union(roleIds); - return await DbContext.Roles.AsQueryable().Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)); + return await dbContext.Roles.AsQueryable().Where(r => allRoleIds.Contains(r.Id)).Select(r => r.Name).ToListAsync(GetCancellationToken(cancellationToken)); } public async Task> GetRoleNamesInOrganizationUnitAsync( @@ -60,14 +63,16 @@ namespace Volo.Abp.Identity.MongoDB .Select(r => r.OrganizationUnitId) .ToArray(); - var organizationUnits = DbContext.OrganizationUnits + var dbContext = await GetDbContextAsync(cancellationToken); + + var organizationUnits = dbContext.OrganizationUnits .AsQueryable() .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToArray(); var roleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); - return await DbContext.Roles //TODO: Such usage suppress filters! + return await dbContext.Roles //TODO: Such usage suppress filters! .AsQueryable() .Where(r => roleIds.Contains(r.Id)) .Select(r => r.Name) @@ -80,7 +85,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = true, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.Logins.Any(login => login.LoginProvider == loginProvider && login.ProviderKey == providerKey)) .OrderBy(x => x.Id) .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); @@ -91,7 +96,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = true, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.NormalizedEmail == normalizedEmail, GetCancellationToken(cancellationToken)); } @@ -100,7 +105,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.Claims.Any(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value)) .ToListAsync(GetCancellationToken(cancellationToken)); } @@ -110,19 +115,21 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - var role = await DbContext.Roles.AsQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + + var role = await (await GetDbContextAsync(cancellationToken)).Roles.AsQueryable() //TODO: Such usages breaks data filters .Where(x => x.NormalizedName == normalizedRoleName) .OrderBy(x => x.Id) - .FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); + .FirstOrDefaultAsync(cancellationToken); if (role == null) { return new List(); } - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.Roles.Any(r => r.RoleId == role.Id)) - .ToListAsync(GetCancellationToken(cancellationToken)); + .ToListAsync(cancellationToken); } public virtual async Task> GetListAsync( @@ -133,7 +140,7 @@ namespace Volo.Abp.Identity.MongoDB bool includeDetails = false, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -158,14 +165,17 @@ namespace Volo.Abp.Identity.MongoDB var organizationUnitIds = user.OrganizationUnits .Select(r => r.OrganizationUnitId) .ToArray(); - var organizationUnits = DbContext.OrganizationUnits + + var dbContext = await GetDbContextAsync(cancellationToken); + + var organizationUnits = dbContext.OrganizationUnits .AsQueryable() .Where(ou => organizationUnitIds.Contains(ou.Id)) .ToArray(); var orgUnitRoleIds = organizationUnits.SelectMany(x => x.Roles.Select(r => r.RoleId)).ToArray(); var roleIds = user.Roles.Select(r => r.RoleId).ToArray(); var allRoleIds = orgUnitRoleIds.Union(roleIds); - return await DbContext.Roles.AsQueryable().Where(r => allRoleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)); + return await dbContext.Roles.AsQueryable().Where(r => allRoleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } public async Task> GetOrganizationUnitsAsync( @@ -175,17 +185,19 @@ namespace Volo.Abp.Identity.MongoDB { var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); var organizationUnitIds = user.OrganizationUnits.Select(r => r.OrganizationUnitId); - return await DbContext.OrganizationUnits.AsQueryable() + + var dbContext = await GetDbContextAsync(cancellationToken); + + return await dbContext.OrganizationUnits.AsQueryable() .Where(ou => organizationUnitIds.Contains(ou.Id)) - .ToListAsync(GetCancellationToken(cancellationToken)) - ; + .ToListAsync(GetCancellationToken(cancellationToken)); } public virtual async Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default) { - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .WhereIf>( !filter.IsNullOrWhiteSpace(), u => @@ -202,7 +214,7 @@ namespace Volo.Abp.Identity.MongoDB Guid organizationUnitId, CancellationToken cancellationToken = default) { - var result = await GetMongoQueryable() + var result = await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => uou.OrganizationUnitId == organizationUnitId)) .ToListAsync(GetCancellationToken(cancellationToken)) ; @@ -213,7 +225,7 @@ namespace Volo.Abp.Identity.MongoDB List organizationUnitIds, CancellationToken cancellationToken = default) { - var result = await GetMongoQueryable() + var result = await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) .ToListAsync(GetCancellationToken(cancellationToken)) ; @@ -224,16 +236,17 @@ namespace Volo.Abp.Identity.MongoDB string code, CancellationToken cancellationToken = default) { - var organizationUnitIds = await DbContext.OrganizationUnits.AsQueryable() + cancellationToken = GetCancellationToken(cancellationToken); + + var organizationUnitIds = await (await GetDbContextAsync(cancellationToken)).OrganizationUnits.AsQueryable() .Where(ou => ou.Code.StartsWith(code)) .Select(ou => ou.Id) - .ToListAsync(GetCancellationToken(cancellationToken)) + .ToListAsync(cancellationToken) ; - return await GetMongoQueryable() + return await (await GetMongoQueryableAsync(cancellationToken)) .Where(u => u.OrganizationUnits.Any(uou => organizationUnitIds.Contains(uou.OrganizationUnitId))) - .ToListAsync(GetCancellationToken(cancellationToken)) - ; + .ToListAsync(cancellationToken); } } }