mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
event fixes
This commit is contained in:
parent
5c91949f2d
commit
6649c29a8b
@ -68,22 +68,22 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
eventsTable.Columns.Add(idColumn);
|
eventsTable.Columns.Add(idColumn);
|
||||||
var typeColumn = new DataColumn(nameof(e.Type), typeof(int));
|
var typeColumn = new DataColumn(nameof(e.Type), typeof(int));
|
||||||
eventsTable.Columns.Add(typeColumn);
|
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));
|
var userIdColumn = new DataColumn(nameof(e.UserId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(userIdColumn);
|
eventsTable.Columns.Add(userIdColumn);
|
||||||
var organizationIdColumn = new DataColumn(nameof(e.OrganizationId), typeof(Guid));
|
var organizationIdColumn = new DataColumn(nameof(e.OrganizationId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(organizationIdColumn);
|
eventsTable.Columns.Add(organizationIdColumn);
|
||||||
var cipherIdColumn = new DataColumn(nameof(e.CipherId), typeof(Guid));
|
var cipherIdColumn = new DataColumn(nameof(e.CipherId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(cipherIdColumn);
|
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));
|
var collectionIdColumn = new DataColumn(nameof(e.CollectionId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(collectionIdColumn);
|
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));
|
var actingUserIdColumn = new DataColumn(nameof(e.ActingUserId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(actingUserIdColumn);
|
eventsTable.Columns.Add(actingUserIdColumn);
|
||||||
var organizationUserIdColumn = new DataColumn(nameof(e.OrganizationUserId), typeof(Guid));
|
var organizationUserIdColumn = new DataColumn(nameof(e.OrganizationUserId), typeof(Guid));
|
||||||
eventsTable.Columns.Add(organizationUserIdColumn);
|
eventsTable.Columns.Add(organizationUserIdColumn);
|
||||||
|
var dateColumn = new DataColumn(nameof(e.Date), e.Date.GetType());
|
||||||
|
eventsTable.Columns.Add(dateColumn);
|
||||||
|
|
||||||
var keys = new DataColumn[1];
|
var keys = new DataColumn[1];
|
||||||
keys[0] = idColumn;
|
keys[0] = idColumn;
|
||||||
@ -96,15 +96,16 @@ namespace Bit.Core.Repositories.SqlServer
|
|||||||
var row = eventsTable.NewRow();
|
var row = eventsTable.NewRow();
|
||||||
|
|
||||||
row[idColumn] = ev.Id;
|
row[idColumn] = ev.Id;
|
||||||
row[typeColumn] = ev.Type;
|
row[typeColumn] = (int)ev.Type;
|
||||||
row[dateColumn] = ev.Date;
|
row[dateColumn] = ev.Date;
|
||||||
row[userIdColumn] = ev.UserId;
|
row[userIdColumn] = ev.UserId.HasValue ? (object)ev.UserId.Value : DBNull.Value;
|
||||||
row[organizationIdColumn] = ev.OrganizationId;
|
row[organizationIdColumn] = ev.OrganizationId.HasValue ? (object)ev.OrganizationId.Value : DBNull.Value;
|
||||||
row[cipherIdColumn] = ev.CipherId;
|
row[cipherIdColumn] = ev.CipherId.HasValue ? (object)ev.CipherId.Value : DBNull.Value;
|
||||||
row[groupIdColumn] = ev.GroupId;
|
row[groupIdColumn] = ev.GroupId.HasValue ? (object)ev.GroupId.Value : DBNull.Value;
|
||||||
row[collectionIdColumn] = ev.CollectionId;
|
row[collectionIdColumn] = ev.CollectionId.HasValue ? (object)ev.CollectionId.Value : DBNull.Value;
|
||||||
row[actingUserIdColumn] = ev.ActingUserId;
|
row[actingUserIdColumn] = ev.ActingUserId.HasValue ? (object)ev.ActingUserId.Value : DBNull.Value;
|
||||||
row[organizationUserIdColumn] = ev.OrganizationUserId;
|
row[organizationUserIdColumn] = ev.OrganizationUserId.HasValue ?
|
||||||
|
(object)ev.OrganizationUserId.Value : DBNull.Value;
|
||||||
|
|
||||||
eventsTable.Rows.Add(row);
|
eventsTable.Rows.Add(row);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,8 @@ namespace Bit.Core.Services
|
|||||||
|
|
||||||
public async Task LogCipherEventAsync(Cipher cipher, EventType type)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
@CollectionId UNIQUEIDENTIFIER,
|
@CollectionId UNIQUEIDENTIFIER,
|
||||||
@GroupId UNIQUEIDENTIFIER,
|
@GroupId UNIQUEIDENTIFIER,
|
||||||
@OrganizationUserId UNIQUEIDENTIFIER,
|
@OrganizationUserId UNIQUEIDENTIFIER,
|
||||||
|
@ActingUserId UNIQUEIDENTIFIER,
|
||||||
@Date DATETIME2(7)
|
@Date DATETIME2(7)
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -22,6 +23,7 @@ BEGIN
|
|||||||
[CollectionId],
|
[CollectionId],
|
||||||
[GroupId],
|
[GroupId],
|
||||||
[OrganizationUserId],
|
[OrganizationUserId],
|
||||||
|
[ActingUserId],
|
||||||
[Date]
|
[Date]
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
@ -34,6 +36,7 @@ BEGIN
|
|||||||
@CollectionId,
|
@CollectionId,
|
||||||
@GroupId,
|
@GroupId,
|
||||||
@OrganizationUserId,
|
@OrganizationUserId,
|
||||||
|
@ActingUserId,
|
||||||
@Date
|
@Date
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -7,12 +7,13 @@
|
|||||||
[CollectionId] UNIQUEIDENTIFIER NULL,
|
[CollectionId] UNIQUEIDENTIFIER NULL,
|
||||||
[GroupId] UNIQUEIDENTIFIER NULL,
|
[GroupId] UNIQUEIDENTIFIER NULL,
|
||||||
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
|
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[ActingUserId] UNIQUEIDENTIFIER NULL,
|
||||||
[Date] DATETIME2 (7) NOT NULL,
|
[Date] DATETIME2 (7) NOT NULL,
|
||||||
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
|
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
GO
|
GO
|
||||||
CREATE UNIQUE NONCLUSTERED INDEX [IX_Event_Date]
|
CREATE NONCLUSTERED INDEX [IX_Event_DateOrganizationIdUserId]
|
||||||
ON [dbo].[Event]([Date] ASC);
|
ON [dbo].[Event]([Date] ASC, [OrganizationId] ASC, [UserId] ASC);
|
||||||
|
|
||||||
|
@ -9,12 +9,13 @@ BEGIN
|
|||||||
[CollectionId] UNIQUEIDENTIFIER NULL,
|
[CollectionId] UNIQUEIDENTIFIER NULL,
|
||||||
[GroupId] UNIQUEIDENTIFIER NULL,
|
[GroupId] UNIQUEIDENTIFIER NULL,
|
||||||
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
|
[OrganizationUserId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[ActingUserId] UNIQUEIDENTIFIER NULL,
|
||||||
[Date] DATETIME2 (7) NOT NULL,
|
[Date] DATETIME2 (7) NOT NULL,
|
||||||
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
|
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||||
);
|
);
|
||||||
|
|
||||||
CREATE UNIQUE NONCLUSTERED INDEX [IX_Event_Date]
|
CREATE NONCLUSTERED INDEX [IX_Event_DateOrganizationIdUserId]
|
||||||
ON [dbo].[Event]([Date] ASC);
|
ON [dbo].[Event]([Date] ASC, [OrganizationId] ASC, [UserId] ASC);
|
||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ CREATE PROCEDURE [dbo].[Event_Create]
|
|||||||
@CollectionId UNIQUEIDENTIFIER,
|
@CollectionId UNIQUEIDENTIFIER,
|
||||||
@GroupId UNIQUEIDENTIFIER,
|
@GroupId UNIQUEIDENTIFIER,
|
||||||
@OrganizationUserId UNIQUEIDENTIFIER,
|
@OrganizationUserId UNIQUEIDENTIFIER,
|
||||||
|
@ActingUserId UNIQUEIDENTIFIER,
|
||||||
@Date DATETIME2(7)
|
@Date DATETIME2(7)
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -48,6 +50,7 @@ BEGIN
|
|||||||
[CollectionId],
|
[CollectionId],
|
||||||
[GroupId],
|
[GroupId],
|
||||||
[OrganizationUserId],
|
[OrganizationUserId],
|
||||||
|
[ActingUserId],
|
||||||
[Date]
|
[Date]
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
@ -60,6 +63,7 @@ BEGIN
|
|||||||
@CollectionId,
|
@CollectionId,
|
||||||
@GroupId,
|
@GroupId,
|
||||||
@OrganizationUserId,
|
@OrganizationUserId,
|
||||||
|
@ActingUserId,
|
||||||
@Date
|
@Date
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
Loading…
Reference in New Issue
Block a user