1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-25 12:45:18 +01:00

event fixes

This commit is contained in:
Kyle Spearrin 2017-12-12 15:04:14 -05:00
parent 5c91949f2d
commit 6649c29a8b
5 changed files with 27 additions and 17 deletions

View File

@ -68,22 +68,22 @@ namespace Bit.Core.Repositories.SqlServer
eventsTable.Columns.Add(idColumn);
var typeColumn = new DataColumn(nameof(e.Type), typeof(int));
eventsTable.Columns.Add(typeColumn);
var dateColumn = new DataColumn(nameof(e.Date), e.Date.GetType());
eventsTable.Columns.Add(dateColumn);
var userIdColumn = new DataColumn(nameof(e.UserId), typeof(Guid));
eventsTable.Columns.Add(userIdColumn);
var organizationIdColumn = new DataColumn(nameof(e.OrganizationId), typeof(Guid));
eventsTable.Columns.Add(organizationIdColumn);
var cipherIdColumn = new DataColumn(nameof(e.CipherId), typeof(Guid));
eventsTable.Columns.Add(cipherIdColumn);
var groupIdColumn = new DataColumn(nameof(e.GroupId), typeof(Guid));
eventsTable.Columns.Add(groupIdColumn);
var collectionIdColumn = new DataColumn(nameof(e.CollectionId), typeof(Guid));
eventsTable.Columns.Add(collectionIdColumn);
var groupIdColumn = new DataColumn(nameof(e.GroupId), typeof(Guid));
eventsTable.Columns.Add(groupIdColumn);
var actingUserIdColumn = new DataColumn(nameof(e.ActingUserId), typeof(Guid));
eventsTable.Columns.Add(actingUserIdColumn);
var organizationUserIdColumn = new DataColumn(nameof(e.OrganizationUserId), typeof(Guid));
eventsTable.Columns.Add(organizationUserIdColumn);
var dateColumn = new DataColumn(nameof(e.Date), e.Date.GetType());
eventsTable.Columns.Add(dateColumn);
var keys = new DataColumn[1];
keys[0] = idColumn;
@ -96,15 +96,16 @@ namespace Bit.Core.Repositories.SqlServer
var row = eventsTable.NewRow();
row[idColumn] = ev.Id;
row[typeColumn] = ev.Type;
row[typeColumn] = (int)ev.Type;
row[dateColumn] = ev.Date;
row[userIdColumn] = ev.UserId;
row[organizationIdColumn] = ev.OrganizationId;
row[cipherIdColumn] = ev.CipherId;
row[groupIdColumn] = ev.GroupId;
row[collectionIdColumn] = ev.CollectionId;
row[actingUserIdColumn] = ev.ActingUserId;
row[organizationUserIdColumn] = ev.OrganizationUserId;
row[userIdColumn] = ev.UserId.HasValue ? (object)ev.UserId.Value : DBNull.Value;
row[organizationIdColumn] = ev.OrganizationId.HasValue ? (object)ev.OrganizationId.Value : DBNull.Value;
row[cipherIdColumn] = ev.CipherId.HasValue ? (object)ev.CipherId.Value : DBNull.Value;
row[groupIdColumn] = ev.GroupId.HasValue ? (object)ev.GroupId.Value : DBNull.Value;
row[collectionIdColumn] = ev.CollectionId.HasValue ? (object)ev.CollectionId.Value : DBNull.Value;
row[actingUserIdColumn] = ev.ActingUserId.HasValue ? (object)ev.ActingUserId.Value : DBNull.Value;
row[organizationUserIdColumn] = ev.OrganizationUserId.HasValue ?
(object)ev.OrganizationUserId.Value : DBNull.Value;
eventsTable.Rows.Add(row);
}

View File

@ -78,7 +78,8 @@ namespace Bit.Core.Services
public async Task LogCipherEventAsync(Cipher cipher, EventType type)
{
if(!cipher.OrganizationId.HasValue && (!_currentContext?.UserId.HasValue ?? true))
// Only logging organization cipher events for now.
if(!cipher.OrganizationId.HasValue || (!_currentContext?.UserId.HasValue ?? true))
{
return;
}

View File

@ -7,6 +7,7 @@
@CollectionId UNIQUEIDENTIFIER,
@GroupId UNIQUEIDENTIFIER,
@OrganizationUserId UNIQUEIDENTIFIER,
@ActingUserId UNIQUEIDENTIFIER,
@Date DATETIME2(7)
AS
BEGIN
@ -22,6 +23,7 @@ BEGIN
[CollectionId],
[GroupId],
[OrganizationUserId],
[ActingUserId],
[Date]
)
VALUES
@ -34,6 +36,7 @@ BEGIN
@CollectionId,
@GroupId,
@OrganizationUserId,
@ActingUserId,
@Date
)
END

View File

@ -7,12 +7,13 @@
[CollectionId] UNIQUEIDENTIFIER NULL,
[GroupId] UNIQUEIDENTIFIER NULL,
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
[ActingUserId] UNIQUEIDENTIFIER NULL,
[Date] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
);
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Event_Date]
ON [dbo].[Event]([Date] ASC);
CREATE NONCLUSTERED INDEX [IX_Event_DateOrganizationIdUserId]
ON [dbo].[Event]([Date] ASC, [OrganizationId] ASC, [UserId] ASC);

View File

@ -9,12 +9,13 @@ BEGIN
[CollectionId] UNIQUEIDENTIFIER NULL,
[GroupId] UNIQUEIDENTIFIER NULL,
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
[ActingUserId] UNIQUEIDENTIFIER NULL,
[Date] DATETIME2 (7) NOT NULL,
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE UNIQUE NONCLUSTERED INDEX [IX_Event_Date]
ON [dbo].[Event]([Date] ASC);
CREATE NONCLUSTERED INDEX [IX_Event_DateOrganizationIdUserId]
ON [dbo].[Event]([Date] ASC, [OrganizationId] ASC, [UserId] ASC);
END
GO
@ -33,6 +34,7 @@ CREATE PROCEDURE [dbo].[Event_Create]
@CollectionId UNIQUEIDENTIFIER,
@GroupId UNIQUEIDENTIFIER,
@OrganizationUserId UNIQUEIDENTIFIER,
@ActingUserId UNIQUEIDENTIFIER,
@Date DATETIME2(7)
AS
BEGIN
@ -48,6 +50,7 @@ BEGIN
[CollectionId],
[GroupId],
[OrganizationUserId],
[ActingUserId],
[Date]
)
VALUES
@ -60,6 +63,7 @@ BEGIN
@CollectionId,
@GroupId,
@OrganizationUserId,
@ActingUserId,
@Date
)
END