1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-12 08:38:13 -05:00

new client event types, pass date to event funcs

This commit is contained in:
Kyle Spearrin 2019-07-09 11:44:09 -04:00
parent f7be870bfe
commit da5c385d4a
6 changed files with 37 additions and 31 deletions

View File

@ -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,

View File

@ -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);
}
}

View File

@ -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<IEvent>
{
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);
}

View File

@ -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);
}

View File

@ -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;

View File

@ -7,5 +7,6 @@ namespace Bit.Events.Models
{
public EventType Type { get; set; }
public Guid? CipherId { get; set; }
public DateTime Date { get; set; }
}
}