1
0
mirror of https://github.com/bitwarden/server.git synced 2025-02-06 00:11:22 +01:00

events collect endpoint

This commit is contained in:
Kyle Spearrin 2019-03-19 17:26:34 -04:00
parent fd8a8c8b67
commit 268b162c0a
2 changed files with 32 additions and 12 deletions

View File

@ -1,6 +1,6 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Bit.Core;
using Bit.Core.Enums;
using Bit.Core.Repositories;
using Bit.Core.Services;
using Bit.Events.Models;
@ -26,20 +26,39 @@ namespace Events.Controllers
_cipherRepository = cipherRepository;
}
[HttpPost("~/cipher/{id}")]
public async Task PostCipher(Guid id, [FromBody]EventModel model)
[HttpGet("~/collect")]
public Task<IActionResult> GetCollect([FromQuery]EventModel model)
{
var cipher = await _cipherRepository.GetByIdAsync(id, _currentContext.UserId.Value);
if(cipher != null)
{
await _eventService.LogCipherEventAsync(cipher, model.Type);
}
return PostCollect(model);
}
[HttpPost("~/user")]
public async Task PostUser([FromBody]EventModel model)
[HttpPost("~/collect")]
public async Task<IActionResult> PostCollect([FromBody]EventModel model)
{
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type);
switch(model.Type)
{
// User events
case EventType.User_LoggedIn:
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, model.Type);
break;
// Cipher events
case EventType.Cipher_Created:
if(!model.CipherId.HasValue)
{
return new BadRequestResult();
}
var cipher = await _cipherRepository.GetByIdAsync(model.CipherId.Value,
_currentContext.UserId.Value);
if(cipher == null)
{
return new BadRequestResult();
}
await _eventService.LogCipherEventAsync(cipher, model.Type);
break;
default:
return new BadRequestResult();
}
return new OkResult();
}
}
}

View File

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