Browse Source

Merge pull request #4331 from abpframework/liangshiwei/module-identity-patch-1

Update IIdentityClaimTypeRepository & IIdentityRoleRepository
pull/4415/head
maliming 6 years ago
committed by GitHub
parent
commit
2175231589
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs
  2. 13
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  3. 36
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs
  4. 11
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  5. 33
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs
  6. 15
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs
  7. 6
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs
  8. 6
      modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

23
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -15,8 +16,24 @@ namespace Volo.Abp.Identity
/// An Id value to ignore on checking.
/// If there is an entity with given <paramref name="ignoredId"/> it's ignored.
/// </param>
Task<bool> AnyAsync(string name, Guid? ignoredId = null);
/// <param name="cancellationToken">Cancel token</param>
Task<bool> AnyAsync(
string name,
Guid? ignoredId = null,
CancellationToken cancellationToken = default
);
Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter);
Task<List<IdentityClaimType>> GetListAsync(
string sorting,
int maxResultCount,
int skipCount,
string filter,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
}
}
}

13
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -21,15 +21,20 @@ namespace Volo.Abp.Identity
string filter = null,
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default
);
Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids,
CancellationToken cancellationToken = default
);
Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false,
CancellationToken cancellationToken = default
);
Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default
);
}
}

36
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -11,20 +12,27 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
{
public class EfCoreIdentityClaimTypeRepository : EfCoreRepository<IIdentityDbContext, IdentityClaimType, Guid>, IIdentityClaimTypeRepository
{
public EfCoreIdentityClaimTypeRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
public EfCoreIdentityClaimTypeRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public virtual async Task<bool> AnyAsync(string name, Guid? ignoredId = null)
public virtual async Task<bool> AnyAsync(
string name,
Guid? ignoredId = null,
CancellationToken cancellationToken = default)
{
return await DbSet
.WhereIf(ignoredId != null, ct => ct.Id != ignoredId)
.CountAsync(ct => ct.Name == name) > 0;
.WhereIf(ignoredId != null, ct => ct.Id != ignoredId)
.CountAsync(ct => ct.Name == name, GetCancellationToken(cancellationToken)) > 0;
}
public virtual async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
public virtual async Task<List<IdentityClaimType>> GetListAsync(
string sorting,
int maxResultCount,
int skipCount,
string filter,
CancellationToken cancellationToken = default)
{
var identityClaimTypes = await DbSet
.WhereIf(
@ -34,9 +42,21 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
)
.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
return identityClaimTypes;
}
public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)
{
return await DbSet
.WhereIf(
!filter.IsNullOrWhiteSpace(),
u =>
u.Name.Contains(filter)
).LongCountAsync(GetCancellationToken(cancellationToken));
}
}
}
}

11
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs

@ -60,6 +60,17 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
return await DbSet.IncludeDetails(includeDetails).Where(r => r.IsDefault).ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)
{
return await DbSet
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.LongCountAsync(GetCancellationToken(cancellationToken));
}
public override IQueryable<IdentityRole> WithDetails()
{
return GetQueryable().IncludeDetails();

33
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs

@ -5,6 +5,7 @@ using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
@ -16,23 +17,31 @@ namespace Volo.Abp.Identity.MongoDB
{
}
public virtual async Task<bool> AnyAsync(string name, Guid? ignoredId = null)
public virtual async Task<bool> AnyAsync(
string name,
Guid? ignoredId = null,
CancellationToken cancellationToken = default)
{
if (ignoredId == null)
{
return await GetMongoQueryable()
.Where(ct => ct.Name == name)
.AnyAsync();
.AnyAsync(GetCancellationToken(cancellationToken));
}
else
{
return await GetMongoQueryable()
.Where(ct => ct.Id != ignoredId && ct.Name == name)
.AnyAsync();
.AnyAsync(GetCancellationToken(cancellationToken));
}
}
public virtual async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
public virtual async Task<List<IdentityClaimType>> GetListAsync(
string sorting,
int maxResultCount,
int skipCount,
string filter,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(
@ -43,7 +52,21 @@ namespace Volo.Abp.Identity.MongoDB
.OrderBy(sorting ?? nameof(IdentityClaimType.Name))
.As<IMongoQueryable<IdentityClaimType>>()
.PageBy<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(skipCount, maxResultCount)
.ToListAsync();
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(
!filter.IsNullOrWhiteSpace(),
u =>
u.Name.Contains(filter)
)
.As<IMongoQueryable<IdentityClaimType>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
}
}

15
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

@ -54,9 +54,22 @@ namespace Volo.Abp.Identity.MongoDB
}
public virtual async Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, CancellationToken cancellationToken = default)
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable().Where(r => r.IsDefault).ToListAsync(cancellationToken: GetCancellationToken(cancellationToken));
}
public async Task<long> GetCountAsync(
string filter = null,
CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()
.WhereIf(!filter.IsNullOrWhiteSpace(),
x => x.Name.Contains(filter) ||
x.NormalizedName.Contains(filter))
.As<IMongoQueryable<IdentityRole>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
}
}
}

6
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityClaimTypeRepository_Tests.cs

@ -36,5 +36,11 @@ namespace Volo.Abp.Identity
result2.ShouldBe(false);
}
[Fact]
public async Task GetCountAsync_With_Filter()
{
(await ClaimTypeRepository.GetCountAsync("Age")).ShouldBe(1);
}
}
}

6
modules/identity/test/Volo.Abp.Identity.TestBase/Volo/Abp/Identity/IdentityRoleRepository_Tests.cs

@ -53,6 +53,12 @@ namespace Volo.Abp.Identity
(await RoleRepository.GetCountAsync()).ShouldBeGreaterThan(0);
}
[Fact]
public async Task GetCountAsync_With_Filter()
{
(await RoleRepository.GetCountAsync("admin")).ShouldBe(1);
}
[Fact]
public async Task Should_Eager_Load_Role_Collections()
{

Loading…
Cancel
Save