mirror of
https://github.com/bitwarden/server
synced 2025-12-26 13:13:24 +00:00
organize event models. stub out event services
This commit is contained in:
@@ -2,15 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
using Microsoft.WindowsAzure.Storage.Table;
|
||||
|
||||
namespace Bit.Core.Repositories.TableStorage
|
||||
{
|
||||
public class EventRepository
|
||||
public class EventRepository : IEventRepository
|
||||
{
|
||||
public EventRepository(GlobalSettings globalSettings)
|
||||
{
|
||||
@@ -21,7 +20,7 @@ namespace Bit.Core.Repositories.TableStorage
|
||||
|
||||
protected CloudTable Table { get; set; }
|
||||
|
||||
public async Task<ICollection<EventTableEntiity>> GetManyByUserAsync(Guid userId,
|
||||
public async Task<ICollection<EventTableEntity>> GetManyByUserAsync(Guid userId,
|
||||
DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var start = CoreHelpers.DateTimeToTableStorageKey(startDate);
|
||||
@@ -37,8 +36,8 @@ namespace Bit.Core.Repositories.TableStorage
|
||||
TableOperators.And,
|
||||
rowFilter);
|
||||
|
||||
var query = new TableQuery<EventTableEntiity>().Where(filter);
|
||||
var results = new List<EventTableEntiity>();
|
||||
var query = new TableQuery<EventTableEntity>().Where(filter);
|
||||
var results = new List<EventTableEntity>();
|
||||
TableContinuationToken continuationToken = null;
|
||||
do
|
||||
{
|
||||
@@ -82,84 +81,4 @@ namespace Bit.Core.Repositories.TableStorage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class UserEvent : EventTableEntiity
|
||||
{
|
||||
public UserEvent(Guid userId, EventType type)
|
||||
{
|
||||
PartitionKey = $"UserId={userId}";
|
||||
RowKey = string.Format("Date={0}__Type={1}",
|
||||
CoreHelpers.DateTimeToTableStorageKey(), type);
|
||||
|
||||
UserId = userId;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public UserEvent(Guid userId, Guid organizationId, EventType type)
|
||||
{
|
||||
PartitionKey = $"OrganizationId={organizationId}";
|
||||
RowKey = string.Format("Date={0}__UserId={1}__Type={2}",
|
||||
CoreHelpers.DateTimeToTableStorageKey(), userId, type);
|
||||
|
||||
OrganizationId = organizationId;
|
||||
UserId = userId;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public class CipherEvent : EventTableEntiity
|
||||
{
|
||||
public CipherEvent(Cipher cipher, EventType type)
|
||||
{
|
||||
if(cipher.OrganizationId.HasValue)
|
||||
{
|
||||
PartitionKey = $"OrganizationId={cipher.OrganizationId.Value}";
|
||||
}
|
||||
else
|
||||
{
|
||||
PartitionKey = $"UserId={cipher.UserId.Value}";
|
||||
}
|
||||
|
||||
RowKey = string.Format("Date={0}__CipherId={1}__Type={2}",
|
||||
CoreHelpers.DateTimeToTableStorageKey(), cipher.Id, type);
|
||||
|
||||
OrganizationId = cipher.OrganizationId;
|
||||
UserId = cipher.UserId;
|
||||
CipherId = cipher.Id;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public class OrganizationEvent : EventTableEntiity
|
||||
{
|
||||
public OrganizationEvent(Guid organizationId, EventType type)
|
||||
{
|
||||
PartitionKey = $"OrganizationId={organizationId}";
|
||||
RowKey = string.Format("Date={0}__Type={1}",
|
||||
CoreHelpers.DateTimeToTableStorageKey(), type);
|
||||
|
||||
OrganizationId = organizationId;
|
||||
Type = type;
|
||||
}
|
||||
|
||||
public OrganizationEvent(Guid organizationId, Guid userId, EventType type)
|
||||
{
|
||||
PartitionKey = $"OrganizationId={organizationId}";
|
||||
RowKey = string.Format("Date={0}__UserId={1}__Type={2}",
|
||||
CoreHelpers.DateTimeToTableStorageKey(), userId, type);
|
||||
|
||||
OrganizationId = organizationId;
|
||||
UserId = userId;
|
||||
Type = type;
|
||||
}
|
||||
}
|
||||
|
||||
public class EventTableEntiity : TableEntity
|
||||
{
|
||||
public EventType Type { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public ICollection<Guid> CipherIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user