Browse Source

IdentityRoleClaim improvements

pull/503/head
Yunus Emre Kalkan 8 years ago
parent
commit
0094796052
  1. 6
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  2. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs
  3. 33
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityRoleRepository.cs
  4. 24
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityRoleRepository.cs

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

@ -22,6 +22,12 @@ namespace Volo.Abp.Identity
CancellationToken cancellationToken = default
);
Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> claims);
Task<List<IdentityRoleClaim>> GetClaimsAsync(
Guid id,
CancellationToken cancellationToken = default);
Task<long> GetCountAsync(
CancellationToken cancellationToken = default
);

2
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityRoleClaim.cs

@ -32,7 +32,7 @@ namespace Volo.Abp.Identity
RoleId = roleId;
}
protected internal IdentityRoleClaim(
public IdentityRoleClaim(
Guid id,
Guid roleId,
[NotNull] string claimType,

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

@ -7,15 +7,18 @@ 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 EfCoreIdentityRoleRepository : EfCoreRepository<IIdentityDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{
public EfCoreIdentityRoleRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
private readonly IGuidGenerator _guidGenerator;
public EfCoreIdentityRoleRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider, IGuidGenerator guidGenerator)
: base(dbContextProvider)
{
_guidGenerator = guidGenerator;
}
public virtual async Task<IdentityRole> FindByNormalizedNameAsync(
@ -42,6 +45,32 @@ namespace Volo.Abp.Identity.EntityFrameworkCore
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> claims)
{
var dbSet = DbContext.Set<IdentityRoleClaim>();
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<List<IdentityRoleClaim>> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default)
{
var query = from roleClaim in DbContext.Set<IdentityRoleClaim>()
where roleClaim.RoleId == id
select roleClaim;
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await this.LongCountAsync(GetCancellationToken(cancellationToken));

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

@ -7,15 +7,19 @@ using System.Linq.Dynamic.Core;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.Guids;
using Volo.Abp.MongoDB;
namespace Volo.Abp.Identity.MongoDB
{
public class MongoIdentityRoleRepository : MongoDbRepository<IAbpIdentityMongoDbContext, IdentityRole, Guid>, IIdentityRoleRepository
{
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider)
private readonly IGuidGenerator _guidGenerator;
public MongoIdentityRoleRepository(IMongoDbContextProvider<IAbpIdentityMongoDbContext> dbContextProvider, IGuidGenerator guidGenerator)
: base(dbContextProvider)
{
_guidGenerator = guidGenerator;
}
public async Task<IdentityRole> FindByNormalizedNameAsync(
@ -40,6 +44,24 @@ namespace Volo.Abp.Identity.MongoDB
.ToListAsync(GetCancellationToken(cancellationToken));
}
public async Task UpdateClaimsAsync(Guid id, List<IdentityRoleClaim> 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<List<IdentityRoleClaim>> GetClaimsAsync(Guid id, CancellationToken cancellationToken = default)
{
var role = await GetAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
return role.Claims.ToList();
}
public async Task<long> GetCountAsync(CancellationToken cancellationToken = default)
{
return await GetMongoQueryable()

Loading…
Cancel
Save