mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d
. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a
.
This commit is contained in:
@ -2,153 +2,154 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.Azure.Cosmos.Table;
|
||||
|
||||
namespace Bit.Core.Models.Data;
|
||||
|
||||
public class EventTableEntity : TableEntity, IEvent
|
||||
namespace Bit.Core.Models.Data
|
||||
{
|
||||
public EventTableEntity() { }
|
||||
|
||||
private EventTableEntity(IEvent e)
|
||||
public class EventTableEntity : TableEntity, IEvent
|
||||
{
|
||||
Date = e.Date;
|
||||
Type = e.Type;
|
||||
UserId = e.UserId;
|
||||
OrganizationId = e.OrganizationId;
|
||||
InstallationId = e.InstallationId;
|
||||
ProviderId = e.ProviderId;
|
||||
CipherId = e.CipherId;
|
||||
CollectionId = e.CollectionId;
|
||||
PolicyId = e.PolicyId;
|
||||
GroupId = e.GroupId;
|
||||
OrganizationUserId = e.OrganizationUserId;
|
||||
ProviderUserId = e.ProviderUserId;
|
||||
ProviderOrganizationId = e.ProviderOrganizationId;
|
||||
DeviceType = e.DeviceType;
|
||||
IpAddress = e.IpAddress;
|
||||
ActingUserId = e.ActingUserId;
|
||||
}
|
||||
public EventTableEntity() { }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
public EventType Type { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? InstallationId { get; set; }
|
||||
public Guid? ProviderId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public Guid? ProviderUserId { get; set; }
|
||||
public Guid? ProviderOrganizationId { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
public string IpAddress { get; set; }
|
||||
public Guid? ActingUserId { get; set; }
|
||||
|
||||
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
|
||||
{
|
||||
var result = base.WriteEntity(operationContext);
|
||||
|
||||
var typeName = nameof(Type);
|
||||
if (result.ContainsKey(typeName))
|
||||
private EventTableEntity(IEvent e)
|
||||
{
|
||||
result[typeName] = new EntityProperty((int)Type);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(typeName, new EntityProperty((int)Type));
|
||||
Date = e.Date;
|
||||
Type = e.Type;
|
||||
UserId = e.UserId;
|
||||
OrganizationId = e.OrganizationId;
|
||||
InstallationId = e.InstallationId;
|
||||
ProviderId = e.ProviderId;
|
||||
CipherId = e.CipherId;
|
||||
CollectionId = e.CollectionId;
|
||||
PolicyId = e.PolicyId;
|
||||
GroupId = e.GroupId;
|
||||
OrganizationUserId = e.OrganizationUserId;
|
||||
ProviderUserId = e.ProviderUserId;
|
||||
ProviderOrganizationId = e.ProviderOrganizationId;
|
||||
DeviceType = e.DeviceType;
|
||||
IpAddress = e.IpAddress;
|
||||
ActingUserId = e.ActingUserId;
|
||||
}
|
||||
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if (result.ContainsKey(deviceTypeName))
|
||||
public DateTime Date { get; set; }
|
||||
public EventType Type { get; set; }
|
||||
public Guid? UserId { get; set; }
|
||||
public Guid? OrganizationId { get; set; }
|
||||
public Guid? InstallationId { get; set; }
|
||||
public Guid? ProviderId { get; set; }
|
||||
public Guid? CipherId { get; set; }
|
||||
public Guid? CollectionId { get; set; }
|
||||
public Guid? PolicyId { get; set; }
|
||||
public Guid? GroupId { get; set; }
|
||||
public Guid? OrganizationUserId { get; set; }
|
||||
public Guid? ProviderUserId { get; set; }
|
||||
public Guid? ProviderOrganizationId { get; set; }
|
||||
public DeviceType? DeviceType { get; set; }
|
||||
public string IpAddress { get; set; }
|
||||
public Guid? ActingUserId { get; set; }
|
||||
|
||||
public override IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
|
||||
{
|
||||
result[deviceTypeName] = new EntityProperty((int?)DeviceType);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Add(deviceTypeName, new EntityProperty((int?)DeviceType));
|
||||
}
|
||||
var result = base.WriteEntity(operationContext);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
|
||||
OperationContext operationContext)
|
||||
{
|
||||
base.ReadEntity(properties, operationContext);
|
||||
|
||||
var typeName = nameof(Type);
|
||||
if (properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
|
||||
{
|
||||
Type = (EventType)properties[typeName].Int32Value.Value;
|
||||
}
|
||||
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if (properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
|
||||
{
|
||||
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static List<EventTableEntity> IndexEvent(EventMessage e)
|
||||
{
|
||||
var uniquifier = e.IdempotencyId.GetValueOrDefault(Guid.NewGuid());
|
||||
|
||||
var pKey = GetPartitionKey(e);
|
||||
|
||||
var dateKey = CoreHelpers.DateTimeToTableStorageKey(e.Date);
|
||||
|
||||
var entities = new List<EventTableEntity>
|
||||
{
|
||||
new EventTableEntity(e)
|
||||
var typeName = nameof(Type);
|
||||
if (result.ContainsKey(typeName))
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"Date={dateKey}__Uniquifier={uniquifier}"
|
||||
result[typeName] = new EntityProperty((int)Type);
|
||||
}
|
||||
};
|
||||
|
||||
if (e.OrganizationId.HasValue && e.ActingUserId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
else
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
}
|
||||
result.Add(typeName, new EntityProperty((int)Type));
|
||||
}
|
||||
|
||||
if (!e.OrganizationId.HasValue && e.ProviderId.HasValue && e.ActingUserId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if (result.ContainsKey(deviceTypeName))
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
}
|
||||
|
||||
if (e.CipherId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
result[deviceTypeName] = new EntityProperty((int?)DeviceType);
|
||||
}
|
||||
else
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"CipherId={e.CipherId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
result.Add(deviceTypeName, new EntityProperty((int?)DeviceType));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
private static string GetPartitionKey(EventMessage e)
|
||||
{
|
||||
if (e.OrganizationId.HasValue)
|
||||
public override void ReadEntity(IDictionary<string, EntityProperty> properties,
|
||||
OperationContext operationContext)
|
||||
{
|
||||
return $"OrganizationId={e.OrganizationId}";
|
||||
base.ReadEntity(properties, operationContext);
|
||||
|
||||
var typeName = nameof(Type);
|
||||
if (properties.ContainsKey(typeName) && properties[typeName].Int32Value.HasValue)
|
||||
{
|
||||
Type = (EventType)properties[typeName].Int32Value.Value;
|
||||
}
|
||||
|
||||
var deviceTypeName = nameof(DeviceType);
|
||||
if (properties.ContainsKey(deviceTypeName) && properties[deviceTypeName].Int32Value.HasValue)
|
||||
{
|
||||
DeviceType = (DeviceType)properties[deviceTypeName].Int32Value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.ProviderId.HasValue)
|
||||
public static List<EventTableEntity> IndexEvent(EventMessage e)
|
||||
{
|
||||
return $"ProviderId={e.ProviderId}";
|
||||
var uniquifier = e.IdempotencyId.GetValueOrDefault(Guid.NewGuid());
|
||||
|
||||
var pKey = GetPartitionKey(e);
|
||||
|
||||
var dateKey = CoreHelpers.DateTimeToTableStorageKey(e.Date);
|
||||
|
||||
var entities = new List<EventTableEntity>
|
||||
{
|
||||
new EventTableEntity(e)
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"Date={dateKey}__Uniquifier={uniquifier}"
|
||||
}
|
||||
};
|
||||
|
||||
if (e.OrganizationId.HasValue && e.ActingUserId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
}
|
||||
|
||||
if (!e.OrganizationId.HasValue && e.ProviderId.HasValue && e.ActingUserId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"ActingUserId={e.ActingUserId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
}
|
||||
|
||||
if (e.CipherId.HasValue)
|
||||
{
|
||||
entities.Add(new EventTableEntity(e)
|
||||
{
|
||||
PartitionKey = pKey,
|
||||
RowKey = $"CipherId={e.CipherId}__Date={dateKey}__Uniquifier={uniquifier}"
|
||||
});
|
||||
}
|
||||
|
||||
return entities;
|
||||
}
|
||||
|
||||
return $"UserId={e.UserId}";
|
||||
private static string GetPartitionKey(EventMessage e)
|
||||
{
|
||||
if (e.OrganizationId.HasValue)
|
||||
{
|
||||
return $"OrganizationId={e.OrganizationId}";
|
||||
}
|
||||
|
||||
if (e.ProviderId.HasValue)
|
||||
{
|
||||
return $"ProviderId={e.ProviderId}";
|
||||
}
|
||||
|
||||
return $"UserId={e.UserId}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user