1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-22 12:04:27 -05:00

date range search on logs

This commit is contained in:
Kyle Spearrin 2019-10-01 09:02:36 -04:00
parent b99f6cdbc1
commit 47fed7ab80
3 changed files with 17 additions and 2 deletions

View File

@ -27,7 +27,7 @@ namespace Bit.Admin.Controllers
}
public async Task<IActionResult> Index(string cursor = null, int count = 50,
LogEventLevel? level = null, string project = null)
LogEventLevel? level = null, string project = null, DateTime? start = null, DateTime? end = null)
{
var collectionLink = UriFactory.CreateDocumentCollectionUri(Database, Collection);
using(var client = new DocumentClient(new Uri(_globalSettings.DocumentDb.Uri),
@ -48,6 +48,14 @@ namespace Bit.Admin.Controllers
{
query = query.Where(l => l.Properties != null && l.Properties["Project"] == (object)project);
}
if(start.HasValue)
{
query = query.Where(l => l.Timestamp >= start.Value);
}
if(end.HasValue)
{
query = query.Where(l => l.Timestamp <= end.Value);
}
var docQuery = query.OrderByDescending(l => l.Timestamp).AsDocumentQuery();
var response = await docQuery.ExecuteNextAsync<LogModel>();
@ -56,6 +64,8 @@ namespace Bit.Admin.Controllers
{
Level = level,
Project = project,
Start = start,
End = end,
Items = response.ToList(),
Count = count,
Cursor = cursor,

View File

@ -1,4 +1,5 @@
using Serilog.Events;
using System;
using Serilog.Events;
namespace Bit.Admin.Models
{
@ -6,5 +7,7 @@ namespace Bit.Admin.Models
{
public LogEventLevel? Level { get; set; }
public string Project { get; set; }
public DateTime? Start { get; set; }
public DateTime? End { get; set; }
}
}

View File

@ -25,6 +25,8 @@
<option asp-selected="@(Model.Project == "Notifications")" value="Notifications">Notifications</option>
<option asp-selected="@(Model.Project == "Icons")" value="Icons">Icons</option>
</select>
<input class="form-control mb-2 mr-2" type="datetime-local" asp-for="Start" name="start">
<input class="form-control mb-2 mr-2" type="datetime-local" asp-for="End" name="end">
<button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>
</form>