mirror of
https://github.com/bitwarden/server.git
synced 2024-12-27 17:47:37 +01:00
collect many events
This commit is contained in:
parent
69731ecb9d
commit
db41a1bd13
@ -9,7 +9,7 @@
|
||||
User_Recovered2fa = 1004,
|
||||
User_FailedLogIn = 1005,
|
||||
User_FailedLogIn2fa = 1006,
|
||||
User_ExportedVault = 1007,
|
||||
User_ClientExportedVault = 1007,
|
||||
|
||||
Cipher_Created = 1100,
|
||||
Cipher_Updated = 1101,
|
||||
|
@ -1,4 +1,6 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Bit.Core;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Repositories;
|
||||
@ -27,19 +29,39 @@ namespace Bit.Events.Controllers
|
||||
_cipherRepository = cipherRepository;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public Task<IActionResult> Get([FromQuery]EventModel model)
|
||||
{
|
||||
return Post(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody]EventModel model)
|
||||
{
|
||||
if(await LogEventAsync(model))
|
||||
{
|
||||
return new OkResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
return new BadRequestResult();
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("many")]
|
||||
public async Task<IActionResult> PostMany([FromBody]IEnumerable<EventModel> model)
|
||||
{
|
||||
if(model == null || !model.Any())
|
||||
{
|
||||
return new BadRequestResult();
|
||||
}
|
||||
foreach(var eventModel in model)
|
||||
{
|
||||
await LogEventAsync(eventModel);
|
||||
}
|
||||
return new OkResult();
|
||||
}
|
||||
|
||||
private async Task<bool> LogEventAsync(EventModel model)
|
||||
{
|
||||
switch(model.Type)
|
||||
{
|
||||
// User events
|
||||
case EventType.User_ExportedVault:
|
||||
case EventType.User_ClientExportedVault:
|
||||
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type);
|
||||
break;
|
||||
// Cipher events
|
||||
@ -51,20 +73,20 @@ namespace Bit.Events.Controllers
|
||||
case EventType.Cipher_ClientViewed:
|
||||
if(!model.CipherId.HasValue)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
return false;
|
||||
}
|
||||
var cipher = await _cipherRepository.GetByIdAsync(model.CipherId.Value,
|
||||
_currentContext.UserId.Value);
|
||||
if(cipher == null)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
return false;
|
||||
}
|
||||
await _eventService.LogCipherEventAsync(cipher, model.Type);
|
||||
break;
|
||||
default:
|
||||
return new BadRequestResult();
|
||||
return false;
|
||||
}
|
||||
return new OkResult();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user