Browse Source

Add `GetListAsync` and `GetCountAsync ` to `IIdentitySessionRepository `.

pull/18242/head
maliming 3 years ago
parent
commit
e26c32e2a4
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 2
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySecurityLogRepository.cs
  2. 15
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySessionRepository.cs
  3. 2
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs
  4. 6
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs
  5. 30
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs
  6. 2
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs
  7. 32
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs

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

@ -10,7 +10,7 @@ public interface IIdentitySecurityLogRepository : IBasicRepository<IdentitySecur
{ {
Task<List<IdentitySecurityLog>> GetListAsync( Task<List<IdentitySecurityLog>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,

15
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentitySessionRepository.cs

@ -12,7 +12,20 @@ public interface IIdentitySessionRepository : IBasicRepository<IdentitySession,
Task<IdentitySession> GetAsync(string sessionId, CancellationToken cancellationToken = default); Task<IdentitySession> GetAsync(string sessionId, CancellationToken cancellationToken = default);
Task<List<IdentitySession>> GetListAsync(Guid userId, CancellationToken cancellationToken = default); Task<List<IdentitySession>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default);
Task<long> GetCountAsync(
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default);
Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default); Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default);

2
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/AbpIdentityEntityFrameworkCoreModule.cs

@ -17,7 +17,7 @@ public class AbpIdentityEntityFrameworkCoreModule : AbpModule
options.AddRepository<IdentityRole, EfCoreIdentityRoleRepository>(); options.AddRepository<IdentityRole, EfCoreIdentityRoleRepository>();
options.AddRepository<IdentityClaimType, EfCoreIdentityClaimTypeRepository>(); options.AddRepository<IdentityClaimType, EfCoreIdentityClaimTypeRepository>();
options.AddRepository<OrganizationUnit, EfCoreOrganizationUnitRepository>(); options.AddRepository<OrganizationUnit, EfCoreOrganizationUnitRepository>();
options.AddRepository<IdentitySecurityLog, EFCoreIdentitySecurityLogRepository>(); options.AddRepository<IdentitySecurityLog, EfCoreIdentitySecurityLogRepository>();
options.AddRepository<IdentityLinkUser, EfCoreIdentityLinkUserRepository>(); options.AddRepository<IdentityLinkUser, EfCoreIdentityLinkUserRepository>();
options.AddRepository<IdentityUserDelegation, EfCoreIdentityUserDelegationRepository>(); options.AddRepository<IdentityUserDelegation, EfCoreIdentityUserDelegationRepository>();
options.AddRepository<IdentitySession, EfCoreIdentitySessionRepository>(); options.AddRepository<IdentitySession, EfCoreIdentitySessionRepository>();

6
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EFCoreIdentitySecurityLogRepository.cs → modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySecurityLogRepository.cs

@ -10,9 +10,9 @@ using Volo.Abp.EntityFrameworkCore;
namespace Volo.Abp.Identity.EntityFrameworkCore; namespace Volo.Abp.Identity.EntityFrameworkCore;
public class EFCoreIdentitySecurityLogRepository : EfCoreRepository<IIdentityDbContext, IdentitySecurityLog, Guid>, IIdentitySecurityLogRepository public class EfCoreIdentitySecurityLogRepository : EfCoreRepository<IIdentityDbContext, IdentitySecurityLog, Guid>, IIdentitySecurityLogRepository
{ {
public EFCoreIdentitySecurityLogRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider) public EfCoreIdentitySecurityLogRepository(IDbContextProvider<IIdentityDbContext> dbContextProvider)
: base(dbContextProvider) : base(dbContextProvider)
{ {
@ -20,7 +20,7 @@ public class EFCoreIdentitySecurityLogRepository : EfCoreRepository<IIdentityDbC
public virtual async Task<List<IdentitySecurityLog>> GetListAsync( public virtual async Task<List<IdentitySecurityLog>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,

30
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentitySessionRepository.cs

@ -35,9 +35,35 @@ public class EfCoreIdentitySessionRepository : EfCoreRepository<IIdentityDbConte
return session; return session;
} }
public virtual async Task<List<IdentitySession>> GetListAsync(Guid userId, CancellationToken cancellationToken = default) public virtual async Task<List<IdentitySession>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).Where(x => x.UserId == userId).ToListAsync(GetCancellationToken(cancellationToken)); return await (await GetDbSetAsync())
.WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySession.LastAccessed)} desc" : sorting)
.PageBy(skipCount, maxResultCount)
.ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default)
{
return await (await GetDbSetAsync())
.WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default) public virtual async Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default)

2
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySecurityLogRepository.cs

@ -21,7 +21,7 @@ public class MongoIdentitySecurityLogRepository :
public virtual async Task<List<IdentitySecurityLog>> GetListAsync( public virtual async Task<List<IdentitySecurityLog>> GetListAsync(
string sorting = null, string sorting = null,
int maxResultCount = 50, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
DateTime? startTime = null, DateTime? startTime = null,
DateTime? endTime = null, DateTime? endTime = null,

32
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentitySessionRepository.cs

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
@ -36,11 +38,37 @@ public class MongoIdentitySessionRepository : MongoDbRepository<IAbpIdentityMong
return session; return session;
} }
public virtual async Task<List<IdentitySession>> GetListAsync(Guid userId, CancellationToken cancellationToken = default) public virtual async Task<List<IdentitySession>> GetListAsync(
string sorting = null,
int maxResultCount = int.MaxValue,
int skipCount = 0,
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken))) return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.OrderBy(sorting.IsNullOrWhiteSpace() ? $"{nameof(IdentitySession.LastAccessed)} desc" : sorting)
.PageBy(skipCount, maxResultCount)
.As<IMongoQueryable<IdentitySession>>() .As<IMongoQueryable<IdentitySession>>()
.Where(x => x.UserId == userId).ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
}
public virtual async Task<long> GetCountAsync(
Guid? userId = null,
string device = null,
string clientId = null,
CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(GetCancellationToken(cancellationToken)))
.WhereIf(userId.HasValue, x => x.UserId == userId)
.WhereIf(!device.IsNullOrWhiteSpace(), x => x.Device == device)
.WhereIf(!clientId.IsNullOrWhiteSpace(), x => x.ClientId == clientId)
.As<IMongoQueryable<IdentitySession>>()
.LongCountAsync(GetCancellationToken(cancellationToken));
} }
public virtual async Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default) public virtual async Task DeleteAllAsync(Guid userId, Guid? exceptSessionId = null, CancellationToken cancellationToken = default)

Loading…
Cancel
Save