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;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories; using Volo.Abp.Domain.Repositories;
@ -15,8 +16,24 @@ namespace Volo.Abp.Identity
/// An Id value to ignore on checking. /// An Id value to ignore on checking.
/// If there is an entity with given <paramref name="ignoredId"/> it's ignored. /// If there is an entity with given <paramref name="ignoredId"/> it's ignored.
/// </param> /// </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, string filter = null,
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<IdentityRole>> GetListAsync( Task<List<IdentityRole>> GetListAsync(
IEnumerable<Guid> ids, IEnumerable<Guid> ids,
CancellationToken cancellationToken = default CancellationToken cancellationToken = default
); );
Task<List<IdentityRole>> GetDefaultOnesAsync( Task<List<IdentityRole>> GetDefaultOnesAsync(
bool includeDetails = false, bool includeDetails = false,
CancellationToken cancellationToken = default 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.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.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 class EfCoreIdentityClaimTypeRepository : EfCoreRepository<IIdentityDbContext, IdentityClaimType, Guid>, IIdentityClaimTypeRepository
{ {
public EfCoreIdentityClaimTypeRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider) public EfCoreIdentityClaimTypeRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(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 return await DbSet
.WhereIf(ignoredId != null, ct => ct.Id != ignoredId) .WhereIf(ignoredId != null, ct => ct.Id != ignoredId)
.CountAsync(ct => ct.Name == name) > 0; .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 var identityClaimTypes = await DbSet
.WhereIf( .WhereIf(
@ -34,9 +42,21 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
) )
.OrderBy(sorting ?? "name desc") .OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount) .PageBy(skipCount, maxResultCount)
.ToListAsync(); .ToListAsync(GetCancellationToken(cancellationToken));
return identityClaimTypes; 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)); 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() public override IQueryable<IdentityRole> WithDetails()
{ {
return GetQueryable().IncludeDetails(); 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 MongoDB.Driver.Linq;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.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) if (ignoredId == null)
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(ct => ct.Name == name) .Where(ct => ct.Name == name)
.AnyAsync(); .AnyAsync(GetCancellationToken(cancellationToken));
} }
else else
{ {
return await GetMongoQueryable() return await GetMongoQueryable()
.Where(ct => ct.Id != ignoredId && ct.Name == name) .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() return await GetMongoQueryable()
.WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>( .WhereIf<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(
@ -43,7 +52,21 @@ namespace Volo.Abp.Identity.MongoDB
.OrderBy(sorting ?? nameof(IdentityClaimType.Name)) .OrderBy(sorting ?? nameof(IdentityClaimType.Name))
.As<IMongoQueryable<IdentityClaimType>>() .As<IMongoQueryable<IdentityClaimType>>()
.PageBy<IdentityClaimType, IMongoQueryable<IdentityClaimType>>(skipCount, maxResultCount) .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( 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)); 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); 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); (await RoleRepository.GetCountAsync()).ShouldBeGreaterThan(0);
} }
[Fact]
public async Task GetCountAsync_With_Filter()
{
(await RoleRepository.GetCountAsync("admin")).ShouldBe(1);
}
[Fact] [Fact]
public async Task Should_Eager_Load_Role_Collections() public async Task Should_Eager_Load_Role_Collections()
{ {

Loading…
Cancel
Save