diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs index 78fc5d54a6..d27de75865 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs @@ -22,12 +22,6 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); - Task UpdateClaimsAsync(Guid id, List claims); - - Task> GetClaimsAsync( - Guid id, - CancellationToken cancellationToken = default); - Task GetCountAsync( CancellationToken cancellationToken = default ); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index 20eb1a749d..98269da005 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs @@ -40,8 +40,6 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); - Task UpdateClaimsAsync(Guid id, List claims); - Task> GetListByNormalizedRoleNameAsync( string normalizedRoleName, bool includeDetails = false, @@ -63,10 +61,6 @@ namespace Volo.Abp.Identity CancellationToken cancellationToken = default ); - Task> GetClaimsAsync( - Guid id, - CancellationToken cancellationToken = default); - Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs index d64218a68f..6b40b59ddb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityClaim.cs @@ -20,6 +20,11 @@ namespace Volo.Abp.Identity /// public virtual string ClaimValue { get; protected set; } + public virtual bool Equals([NotNull] string claimType, [NotNull] string claimValue) + { + return ClaimType == claimType && ClaimValue == claimValue; + } + protected IdentityClaim() { diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs index 1b2a849438..825266e993 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRole.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Linq; using System.Security.Claims; using JetBrains.Annotations; using Volo.Abp.Auditing; @@ -85,6 +86,13 @@ namespace Volo.Abp.Identity } } + public virtual IdentityRoleClaim FindClaim([NotNull] Claim claim) + { + Check.NotNull(claim, nameof(claim)); + + return Claims.FirstOrDefault(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value); + } + public virtual void RemoveClaim([NotNull] Claim claim) { Check.NotNull(claim, nameof(claim)); diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs index 38c1904532..365704914b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityUser.cs @@ -201,6 +201,13 @@ namespace Volo.Abp.Identity } } + public virtual IdentityUserClaim FindClaim([NotNull] Claim claim) + { + Check.NotNull(claim, nameof(claim)); + + return Claims.FirstOrDefault(c => c.ClaimType == claim.Type && c.ClaimValue == claim.Value); + } + public virtual void ReplaceClaim([NotNull] Claim claim, [NotNull] Claim newClaim) { Check.NotNull(claim, nameof(claim)); diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs index 7a317ee530..a9850164ef 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs @@ -13,12 +13,9 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { public class EfCoreIdentityRoleRepository : EfCoreRepository, IIdentityRoleRepository { - private readonly IGuidGenerator _guidGenerator; - - public EfCoreIdentityRoleRepository(IDbContextProvider dbContextProvider, IGuidGenerator guidGenerator) + public EfCoreIdentityRoleRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { - _guidGenerator = guidGenerator; } public virtual async Task FindByNormalizedNameAsync( @@ -45,37 +42,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task UpdateClaimsAsync(Guid id, List claims) - { - var dbSet = DbContext.Set(); - - var oldClaims = dbSet.Where(c => c.RoleId == id).ToList(); - - foreach (var oldClaim in oldClaims) - { - dbSet.Remove(oldClaim); - } - - foreach (var claim in claims) - { - dbSet.Add(new IdentityRoleClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id)); - } - } - - public async Task> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default) - { - var query = from roleClaim in DbContext.Set() - where roleClaim.RoleId == id - select roleClaim; - - return await query.ToListAsync(GetCancellationToken(cancellationToken)); - } - - public virtual async Task GetCountAsync(CancellationToken cancellationToken = default) - { - return await this.LongCountAsync(GetCancellationToken(cancellationToken)); - } - public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs index 7cef5b5735..cab891bc94 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityUserRepository.cs @@ -8,18 +8,14 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; -using Volo.Abp.Guids; namespace Volo.Abp.Identity.EntityFrameworkCore { public class EfCoreIdentityUserRepository : EfCoreRepository, IIdentityUserRepository { - private readonly IGuidGenerator _guidGenerator; - - public EfCoreIdentityUserRepository(IDbContextProvider dbContextProvider, IGuidGenerator guidGenerator) + public EfCoreIdentityUserRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { - _guidGenerator = guidGenerator; } public virtual async Task FindByNormalizedUserNameAsync( @@ -134,34 +130,6 @@ namespace Volo.Abp.Identity.EntityFrameworkCore return await query.ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual async Task> GetClaimsAsync( - Guid id, - CancellationToken cancellationToken = default) - { - var query = from userClaim in DbContext.Set() - where userClaim.UserId == id - select userClaim; - - return await query.ToListAsync(GetCancellationToken(cancellationToken)); - } - - public async Task UpdateClaimsAsync(Guid id, List claims) - { - var dbSet = DbContext.Set(); - - var oldClaims = dbSet.Where(c => c.UserId == id).ToList(); - - foreach (var oldClaim in oldClaims) - { - dbSet.Remove(oldClaim); - } - - foreach (var claim in claims) - { - dbSet.Add(new IdentityUserClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id)); - } - } - public virtual async Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default) 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 b8975ac441..81c6106b7d 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 @@ -44,24 +44,6 @@ namespace Volo.Abp.Identity.MongoDB .ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task UpdateClaimsAsync(Guid id, List claims) - { - var role = await GetAsync(id); - - role.Claims.Clear(); - - foreach (var claim in claims) - { - role.Claims.Add(new IdentityRoleClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id)); - } - } - - public async Task> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default) - { - var role = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); - return role.Claims.ToList(); - } - public async Task GetCountAsync(CancellationToken cancellationToken = default) { return await GetMongoQueryable() 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 9bbea54e72..3d6f188c56 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 @@ -121,24 +121,6 @@ namespace Volo.Abp.Identity.MongoDB return await DbContext.Roles.AsQueryable().Where(r => roleIds.Contains(r.Id)).ToListAsync(GetCancellationToken(cancellationToken)); } - public async Task> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default) - { - var user = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken)); - return user.Claims.ToList(); - } - - public async Task UpdateClaimsAsync(Guid id, List claims) - { - var user = await GetAsync(id); - - user.Claims.Clear(); - - foreach (var claim in claims) - { - user.Claims.Add(new IdentityUserClaim(_guidGenerator.Create(), id, claim.ClaimType, claim.ClaimValue, CurrentTenant.Id)); - } - } - public async Task GetCountAsync( string filter = null, CancellationToken cancellationToken = default)