audit logging repository filter changes

pull/892/head
Yunus Emre Kalkan 7 years ago
parent 8ce2bf8eef
commit 87ad22ca04

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
@ -15,14 +16,23 @@ namespace Volo.Abp.AuditLogging
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxExecutionDuration = null,
int? minExecutionDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true);
bool includeDetails = false,
CancellationToken cancellationToken = default);
Task<long> GetCountAsync(
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxExecutionDuration = null,
int? minExecutionDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true);
CancellationToken cancellationToken = default);
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
@ -25,10 +26,15 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxExecutionDuration = null,
int? minExecutionDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true)
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails);
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, httpStatusCode, includeDetails);
var auditLogs = await query.OrderBy(sorting ?? "executionTime desc")
.PageBy(skipCount, maxResultCount)
@ -41,10 +47,14 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxExecutionDuration = null,
int? minExecutionDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true)
CancellationToken cancellationToken = default)
{
var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails);
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxExecutionDuration, minExecutionDuration, httpStatusCode);
var totalCount = await query.LongCountAsync();
@ -55,15 +65,23 @@ namespace Volo.Abp.AuditLogging.EntityFrameworkCore
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxExecutionDuration = null,
int? minExecutionDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true)
bool includeDetails = false)
{
return DbSet.AsNoTracking()
.IncludeDetails(includeDetails)
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode);
.WhereIf(string.IsNullOrWhiteSpace(url), auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(string.IsNullOrWhiteSpace(userName), auditLog => auditLog.UserName != null && auditLog.UserName.ToLowerInvariant() == userName.ToLowerInvariant())
.WhereIf(string.IsNullOrWhiteSpace(applicationName), auditLog => auditLog.ApplicationName != null && auditLog.ApplicationName.ToLowerInvariant() == applicationName.ToLowerInvariant())
.WhereIf(string.IsNullOrWhiteSpace(correlationId), auditLog => auditLog.CorrelationId != null && auditLog.CorrelationId.ToLowerInvariant() == correlationId.ToLowerInvariant())
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode)
.WhereIf(maxExecutionDuration != null && maxExecutionDuration > 0, auditLog => auditLog.ExecutionDuration <= maxExecutionDuration)
.WhereIf(minExecutionDuration != null && minExecutionDuration > 0, auditLog => auditLog.ExecutionDuration >= minExecutionDuration);
}
public override IQueryable<AuditLog> WithDetails()

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
@ -19,19 +20,40 @@ namespace Volo.Abp.AuditLogging.MongoDB
}
public async Task<List<AuditLog>> GetListAsync(string sorting = null, int maxResultCount = 50, int skipCount = 0,
string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = true)
public async Task<List<AuditLog>> GetListAsync(
string sorting = null,
int maxResultCount = 50,
int skipCount = 0,
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxDuration = null,
int? minDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = false,
CancellationToken cancellationToken = default)
{
var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails);
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, httpStatusCode, includeDetails);
return await query.OrderBy(sorting ?? "executionTime desc").As<IMongoQueryable<AuditLog>>()
.PageBy<AuditLog, IMongoQueryable<AuditLog>>(skipCount, maxResultCount)
.ToListAsync();
}
public async Task<long> GetCountAsync(string httpMethod = null, string url = null, string userName = null, HttpStatusCode? httpStatusCode = null, bool includeDetails = true)
public async Task<long> GetCountAsync(
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxDuration = null,
int? minDuration = null,
HttpStatusCode? httpStatusCode = null,
CancellationToken cancellationToken = default)
{
var query = GetListQuery(httpMethod, url, userName, httpStatusCode, includeDetails);
var query = GetListQuery(httpMethod, url, userName, applicationName, correlationId, maxDuration, minDuration, httpStatusCode);
var count = await query.As<IMongoQueryable<AuditLog>>().LongCountAsync();
@ -42,14 +64,22 @@ namespace Volo.Abp.AuditLogging.MongoDB
string httpMethod = null,
string url = null,
string userName = null,
string applicationName = null,
string correlationId = null,
int? maxDuration = null,
int? minDuration = null,
HttpStatusCode? httpStatusCode = null,
bool includeDetails = true)
bool includeDetails = false)
{
return GetMongoQueryable()
.WhereIf(httpMethod != null, auditLog => auditLog.HttpMethod != null && auditLog.HttpMethod.ToLowerInvariant() == httpMethod.ToLowerInvariant())
.WhereIf(url != null, auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(userName != null, auditLog => auditLog.UserName != null && auditLog.UserName == userName)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode);
.WhereIf(string.IsNullOrWhiteSpace(url), auditLog => auditLog.Url != null && auditLog.Url.ToLowerInvariant().Contains(url.ToLowerInvariant()))
.WhereIf(string.IsNullOrWhiteSpace(userName), auditLog => auditLog.UserName != null && auditLog.UserName == userName)
.WhereIf(string.IsNullOrWhiteSpace(applicationName), auditLog => auditLog.ApplicationName == applicationName)
.WhereIf(string.IsNullOrWhiteSpace(correlationId), auditLog => auditLog.CorrelationId == correlationId)
.WhereIf(httpStatusCode != null && httpStatusCode > 0, auditLog => auditLog.HttpStatusCode == (int?)httpStatusCode)
.WhereIf(maxDuration != null && maxDuration > 0, auditLog => auditLog.ExecutionDuration <= maxDuration)
.WhereIf(minDuration != null && minDuration > 0, auditLog => auditLog.ExecutionDuration >= minDuration); ;
}
}
}

Loading…
Cancel
Save