diff --git a/src/Core/Enums/EventType.cs b/src/Core/Enums/EventType.cs index 7f87861804..8f4e28ad25 100644 --- a/src/Core/Enums/EventType.cs +++ b/src/Core/Enums/EventType.cs @@ -21,9 +21,11 @@ Cipher_ClientViewed = 1107, Cipher_ClientToggledPasswordVisible = 1108, Cipher_ClientToggledHiddenFieldVisible = 1109, - Cipher_ClientCopiedPassword = 1110, - Cipher_ClientCopedHiddenField = 1111, - Cipher_ClientAutofilled = 1112, + Cipher_ClientToggledCardCodeVisible = 1110, + Cipher_ClientCopiedPassword = 1111, + Cipher_ClientCopiedHiddenField = 1112, + Cipher_ClientCopiedCardCode = 1113, + Cipher_ClientAutofilled = 1114, Collection_Created = 1300, Collection_Updated = 1301, diff --git a/src/Core/Services/IEventService.cs b/src/Core/Services/IEventService.cs index 61e72be796..e7901e96de 100644 --- a/src/Core/Services/IEventService.cs +++ b/src/Core/Services/IEventService.cs @@ -7,11 +7,11 @@ namespace Bit.Core.Services { public interface IEventService { - Task LogUserEventAsync(Guid userId, EventType type); - Task LogCipherEventAsync(Cipher cipher, EventType type); - Task LogCollectionEventAsync(Collection collection, EventType type); - Task LogGroupEventAsync(Group group, EventType type); - Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type); - Task LogOrganizationEventAsync(Organization organization, EventType type); + Task LogUserEventAsync(Guid userId, EventType type, DateTime? date = null); + Task LogCipherEventAsync(Cipher cipher, EventType type, DateTime? date = null); + Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null); + Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null); + Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type, DateTime? date = null); + Task LogOrganizationEventAsync(Organization organization, EventType type, DateTime? date = null); } } diff --git a/src/Core/Services/Implementations/EventService.cs b/src/Core/Services/Implementations/EventService.cs index 729bf69d63..3df4af31c6 100644 --- a/src/Core/Services/Implementations/EventService.cs +++ b/src/Core/Services/Implementations/EventService.cs @@ -31,9 +31,8 @@ namespace Bit.Core.Services _globalSettings = globalSettings; } - public async Task LogUserEventAsync(Guid userId, EventType type) + public async Task LogUserEventAsync(Guid userId, EventType type, DateTime? date = null) { - var now = DateTime.UtcNow; var events = new List { new EventMessage(_currentContext) @@ -41,7 +40,7 @@ namespace Bit.Core.Services UserId = userId, ActingUserId = userId, Type = type, - Date = now + Date = date.GetValueOrDefault(DateTime.UtcNow) } }; @@ -68,7 +67,7 @@ namespace Bit.Core.Services } } - public async Task LogCipherEventAsync(Cipher cipher, EventType type) + public async Task LogCipherEventAsync(Cipher cipher, EventType type, DateTime? date = null) { // Only logging organization cipher events for now. if(!cipher.OrganizationId.HasValue || (!_currentContext?.UserId.HasValue ?? true)) @@ -92,12 +91,12 @@ namespace Bit.Core.Services CipherId = cipher.Id, Type = type, ActingUserId = _currentContext?.UserId, - Date = DateTime.UtcNow + Date = date.GetValueOrDefault(DateTime.UtcNow) }; await _eventWriteService.CreateAsync(e); } - public async Task LogCollectionEventAsync(Collection collection, EventType type) + public async Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null) { var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync(); if(!CanUseEvents(orgAbilities, collection.OrganizationId)) @@ -111,12 +110,12 @@ namespace Bit.Core.Services CollectionId = collection.Id, Type = type, ActingUserId = _currentContext?.UserId, - Date = DateTime.UtcNow + Date = date.GetValueOrDefault(DateTime.UtcNow) }; await _eventWriteService.CreateAsync(e); } - public async Task LogGroupEventAsync(Group group, EventType type) + public async Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null) { var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync(); if(!CanUseEvents(orgAbilities, group.OrganizationId)) @@ -130,12 +129,13 @@ namespace Bit.Core.Services GroupId = group.Id, Type = type, ActingUserId = _currentContext?.UserId, - Date = DateTime.UtcNow + Date = date.GetValueOrDefault(DateTime.UtcNow) }; await _eventWriteService.CreateAsync(e); } - public async Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type) + public async Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type, + DateTime? date = null) { var orgAbilities = await _applicationCacheService.GetOrganizationAbilitiesAsync(); if(!CanUseEvents(orgAbilities, organizationUser.OrganizationId)) @@ -150,12 +150,12 @@ namespace Bit.Core.Services OrganizationUserId = organizationUser.Id, Type = type, ActingUserId = _currentContext?.UserId, - Date = DateTime.UtcNow + Date = date.GetValueOrDefault(DateTime.UtcNow) }; await _eventWriteService.CreateAsync(e); } - public async Task LogOrganizationEventAsync(Organization organization, EventType type) + public async Task LogOrganizationEventAsync(Organization organization, EventType type, DateTime? date = null) { if(!organization.Enabled || !organization.UseEvents) { @@ -167,7 +167,7 @@ namespace Bit.Core.Services OrganizationId = organization.Id, Type = type, ActingUserId = _currentContext?.UserId, - Date = DateTime.UtcNow + Date = date.GetValueOrDefault(DateTime.UtcNow) }; await _eventWriteService.CreateAsync(e); } diff --git a/src/Core/Services/NoopImplementations/NoopEventService.cs b/src/Core/Services/NoopImplementations/NoopEventService.cs index 2afd4c5837..95a603f938 100644 --- a/src/Core/Services/NoopImplementations/NoopEventService.cs +++ b/src/Core/Services/NoopImplementations/NoopEventService.cs @@ -7,32 +7,33 @@ namespace Bit.Core.Services { public class NoopEventService : IEventService { - public Task LogCipherEventAsync(Cipher cipher, EventType type) + public Task LogCipherEventAsync(Cipher cipher, EventType type, DateTime? date = null) { return Task.FromResult(0); } - public Task LogCollectionEventAsync(Collection collection, EventType type) + public Task LogCollectionEventAsync(Collection collection, EventType type, DateTime? date = null) { return Task.FromResult(0); } - public Task LogGroupEventAsync(Group group, EventType type) + public Task LogGroupEventAsync(Group group, EventType type, DateTime? date = null) { return Task.FromResult(0); } - public Task LogOrganizationEventAsync(Organization organization, EventType type) + public Task LogOrganizationEventAsync(Organization organization, EventType type, DateTime? date = null) { return Task.FromResult(0); } - public Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type) + public Task LogOrganizationUserEventAsync(OrganizationUser organizationUser, EventType type, + DateTime? date = null) { return Task.FromResult(0); } - public Task LogUserEventAsync(Guid userId, EventType type) + public Task LogUserEventAsync(Guid userId, EventType type, DateTime? date = null) { return Task.FromResult(0); } diff --git a/src/Events/Controllers/CollectController.cs b/src/Events/Controllers/CollectController.cs index 205da6107c..d64d562c66 100644 --- a/src/Events/Controllers/CollectController.cs +++ b/src/Events/Controllers/CollectController.cs @@ -49,12 +49,14 @@ namespace Bit.Events.Controllers { // User events case EventType.User_ClientExportedVault: - await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type); + await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type, model.Date); break; // Cipher events case EventType.Cipher_ClientAutofilled: - case EventType.Cipher_ClientCopedHiddenField: + case EventType.Cipher_ClientCopiedHiddenField: case EventType.Cipher_ClientCopiedPassword: + case EventType.Cipher_ClientCopiedCardCode: + case EventType.Cipher_ClientToggledCardCodeVisible: case EventType.Cipher_ClientToggledHiddenFieldVisible: case EventType.Cipher_ClientToggledPasswordVisible: case EventType.Cipher_ClientViewed: @@ -68,7 +70,7 @@ namespace Bit.Events.Controllers { return false; } - await _eventService.LogCipherEventAsync(cipher, model.Type); + await _eventService.LogCipherEventAsync(cipher, model.Type, model.Date); break; default: return false; diff --git a/src/Events/Models/EventModel.cs b/src/Events/Models/EventModel.cs index 5f40816e17..16f369dea6 100644 --- a/src/Events/Models/EventModel.cs +++ b/src/Events/Models/EventModel.cs @@ -7,5 +7,6 @@ namespace Bit.Events.Models { public EventType Type { get; set; } public Guid? CipherId { get; set; } + public DateTime Date { get; set; } } }