mirror of
https://github.com/bitwarden/server.git
synced 2025-04-16 10:38:17 -05:00
events collect endpoint
This commit is contained in:
parent
fd8a8c8b67
commit
268b162c0a
@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Bit.Core;
|
using Bit.Core;
|
||||||
|
using Bit.Core.Enums;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
using Bit.Core.Services;
|
using Bit.Core.Services;
|
||||||
using Bit.Events.Models;
|
using Bit.Events.Models;
|
||||||
@ -26,20 +26,39 @@ namespace Events.Controllers
|
|||||||
_cipherRepository = cipherRepository;
|
_cipherRepository = cipherRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("~/cipher/{id}")]
|
[HttpGet("~/collect")]
|
||||||
public async Task PostCipher(Guid id, [FromBody]EventModel model)
|
public Task<IActionResult> GetCollect([FromQuery]EventModel model)
|
||||||
{
|
{
|
||||||
var cipher = await _cipherRepository.GetByIdAsync(id, _currentContext.UserId.Value);
|
return PostCollect(model);
|
||||||
if(cipher != null)
|
|
||||||
{
|
|
||||||
await _eventService.LogCipherEventAsync(cipher, model.Type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("~/user")]
|
[HttpPost("~/collect")]
|
||||||
public async Task PostUser([FromBody]EventModel model)
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@ namespace Bit.Events.Models
|
|||||||
public class EventModel
|
public class EventModel
|
||||||
{
|
{
|
||||||
public EventType Type { get; set; }
|
public EventType Type { get; set; }
|
||||||
|
public Guid? CipherId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user