mirror of
https://github.com/bitwarden/server.git
synced 2025-04-08 14:38:15 -05:00
use EventTableEntity instead of TableEntity
This commit is contained in:
parent
f898b92f87
commit
c01fd359f0
@ -14,20 +14,20 @@ namespace Bit.Core.Models.Data
|
|||||||
CipherId = cipher.Id;
|
CipherId = cipher.Id;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
ActingUserId = actingUserId;
|
ActingUserId = actingUserId;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
if(OrganizationId.HasValue)
|
if(OrganizationId.HasValue)
|
||||||
{
|
{
|
||||||
UserId = null;
|
UserId = null;
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__CipherId={1}__ActingUserId={2}__Type={3}",
|
RowKey = string.Format("Date={0}__CipherId={1}__ActingUserId={2}__Type={3}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), CipherId, ActingUserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), CipherId, ActingUserId, Type);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PartitionKey = $"UserId={UserId}";
|
PartitionKey = $"UserId={UserId}";
|
||||||
RowKey = string.Format("Date={0}__CipherId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__CipherId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), CipherId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), CipherId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,11 @@ namespace Bit.Core.Models.Data
|
|||||||
CollectionId = collection.Id;
|
CollectionId = collection.Id;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
ActingUserId = actingUserId;
|
ActingUserId = actingUserId;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ namespace Bit.Core.Models.Data
|
|||||||
{
|
{
|
||||||
public class EventTableEntity : TableEntity
|
public class EventTableEntity : TableEntity
|
||||||
{
|
{
|
||||||
|
public DateTime Date { get; set; }
|
||||||
public int Type { get; set; }
|
public int Type { get; set; }
|
||||||
public Guid? UserId { get; set; }
|
public Guid? UserId { get; set; }
|
||||||
public Guid? OrganizationId { get; set; }
|
public Guid? OrganizationId { get; set; }
|
||||||
|
@ -13,11 +13,11 @@ namespace Bit.Core.Models.Data
|
|||||||
GroupId = group.Id;
|
GroupId = group.Id;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
ActingUserId = actingUserId;
|
ActingUserId = actingUserId;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,11 @@ namespace Bit.Core.Models.Data
|
|||||||
OrganizationId = organization.Id;
|
OrganizationId = organization.Id;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
ActingUserId = actingUserId;
|
ActingUserId = actingUserId;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,11 +14,11 @@ namespace Bit.Core.Models.Data
|
|||||||
OrganizationUserId = organizationUser.Id;
|
OrganizationUserId = organizationUser.Id;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
ActingUserId = actingUserId;
|
ActingUserId = actingUserId;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__ActingUserId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), ActingUserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), ActingUserId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,11 @@ namespace Bit.Core.Models.Data
|
|||||||
{
|
{
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
|
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"UserId={UserId}";
|
PartitionKey = $"UserId={UserId}";
|
||||||
RowKey = string.Format("Date={0}__Type={1}",
|
RowKey = string.Format("Date={0}__Type={1}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), Type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserEvent(Guid userId, Guid organizationId, EventType type)
|
public UserEvent(Guid userId, Guid organizationId, EventType type)
|
||||||
@ -22,11 +22,11 @@ namespace Bit.Core.Models.Data
|
|||||||
OrganizationId = organizationId;
|
OrganizationId = organizationId;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
Type = (int)type;
|
Type = (int)type;
|
||||||
|
Date = DateTime.UtcNow;
|
||||||
Timestamp = DateTime.UtcNow;
|
|
||||||
PartitionKey = $"OrganizationId={OrganizationId}";
|
PartitionKey = $"OrganizationId={OrganizationId}";
|
||||||
RowKey = string.Format("Date={0}__UserId={1}__Type={2}",
|
RowKey = string.Format("Date={0}__UserId={1}__Type={2}",
|
||||||
CoreHelpers.DateTimeToTableStorageKey(Timestamp.DateTime), UserId, Type);
|
CoreHelpers.DateTimeToTableStorageKey(Date), UserId, Type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
|
||||||
|
|
||||||
namespace Bit.Core.Repositories
|
namespace Bit.Core.Repositories
|
||||||
{
|
{
|
||||||
public interface IEventRepository
|
public interface IEventRepository
|
||||||
{
|
{
|
||||||
Task<ICollection<EventTableEntity>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate);
|
Task<ICollection<EventTableEntity>> GetManyByUserAsync(Guid userId, DateTime startDate, DateTime endDate);
|
||||||
Task CreateAsync(ITableEntity entity);
|
Task CreateAsync(EventTableEntity entity);
|
||||||
Task CreateManyAsync(IList<ITableEntity> entities);
|
Task CreateManyAsync(IList<EventTableEntity> entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,12 +49,12 @@ namespace Bit.Core.Repositories.TableStorage
|
|||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateAsync(ITableEntity entity)
|
public async Task CreateAsync(EventTableEntity entity)
|
||||||
{
|
{
|
||||||
await Table.ExecuteAsync(TableOperation.Insert(entity));
|
await Table.ExecuteAsync(TableOperation.Insert(entity));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateManyAsync(IList<ITableEntity> entities)
|
public async Task CreateManyAsync(IList<EventTableEntity> entities)
|
||||||
{
|
{
|
||||||
if(!entities?.Any() ?? true)
|
if(!entities?.Any() ?? true)
|
||||||
{
|
{
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
public interface IEventWriteService
|
public interface IEventWriteService
|
||||||
{
|
{
|
||||||
Task CreateAsync(ITableEntity entity);
|
Task CreateAsync(EventTableEntity entity);
|
||||||
Task CreateManyAsync(IList<ITableEntity> entities);
|
Task CreateManyAsync(IList<EventTableEntity> entities);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
|
||||||
using Microsoft.WindowsAzure.Storage;
|
using Microsoft.WindowsAzure.Storage;
|
||||||
using Microsoft.WindowsAzure.Storage.Queue;
|
using Microsoft.WindowsAzure.Storage.Queue;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -29,14 +29,14 @@ namespace Bit.Core.Services
|
|||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateAsync(ITableEntity entity)
|
public async Task CreateAsync(EventTableEntity entity)
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(entity, _jsonSettings);
|
var json = JsonConvert.SerializeObject(entity, _jsonSettings);
|
||||||
var message = new CloudQueueMessage(json);
|
var message = new CloudQueueMessage(json);
|
||||||
await _queue.AddMessageAsync(message);
|
await _queue.AddMessageAsync(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateManyAsync(IList<ITableEntity> entities)
|
public async Task CreateManyAsync(IList<EventTableEntity> entities)
|
||||||
{
|
{
|
||||||
var json = JsonConvert.SerializeObject(entities, _jsonSettings);
|
var json = JsonConvert.SerializeObject(entities, _jsonSettings);
|
||||||
var message = new CloudQueueMessage(json);
|
var message = new CloudQueueMessage(json);
|
||||||
|
@ -5,7 +5,6 @@ using Bit.Core.Repositories;
|
|||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
|
||||||
using Bit.Core.Models.Table;
|
using Bit.Core.Models.Table;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
@ -31,7 +30,7 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public async Task LogUserEventAsync(Guid userId, EventType type)
|
public async Task LogUserEventAsync(Guid userId, EventType type)
|
||||||
{
|
{
|
||||||
var events = new List<ITableEntity> { new UserEvent(userId, type) };
|
var events = new List<EventTableEntity> { new UserEvent(userId, type) };
|
||||||
|
|
||||||
IEnumerable<UserEvent> orgEvents;
|
IEnumerable<UserEvent> orgEvents;
|
||||||
if(_currentContext.UserId.HasValue)
|
if(_currentContext.UserId.HasValue)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -18,12 +18,12 @@ namespace Bit.Core.Services
|
|||||||
_globalSettings = globalSettings;
|
_globalSettings = globalSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateAsync(ITableEntity entity)
|
public async Task CreateAsync(EventTableEntity entity)
|
||||||
{
|
{
|
||||||
await _eventRepository.CreateAsync(entity);
|
await _eventRepository.CreateAsync(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CreateManyAsync(IList<ITableEntity> entities)
|
public async Task CreateManyAsync(IList<EventTableEntity> entities)
|
||||||
{
|
{
|
||||||
await _eventRepository.CreateManyAsync(entities);
|
await _eventRepository.CreateManyAsync(entities);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.WindowsAzure.Storage.Table;
|
using Bit.Core.Models.Data;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
public class NoopEventWriteService : IEventWriteService
|
public class NoopEventWriteService : IEventWriteService
|
||||||
{
|
{
|
||||||
public Task CreateAsync(ITableEntity entity)
|
public Task CreateAsync(EventTableEntity entity)
|
||||||
{
|
{
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task CreateManyAsync(IList<ITableEntity> entities)
|
public Task CreateManyAsync(IList<EventTableEntity> entities)
|
||||||
{
|
{
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user