mirror of
https://github.com/bitwarden/server
synced 2025-12-25 04:33:26 +00:00
Revert filescoped (#2227)
* Revert "Add git blame entry (#2226)" This reverts commit239286737d. * Revert "Turn on file scoped namespaces (#2225)" This reverts commit34fb4cca2a.
This commit is contained in:
@@ -8,98 +8,99 @@ using Bit.Events.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bit.Events.Controllers;
|
||||
|
||||
[Route("collect")]
|
||||
[Authorize("Application")]
|
||||
public class CollectController : Controller
|
||||
namespace Bit.Events.Controllers
|
||||
{
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
|
||||
public CollectController(
|
||||
ICurrentContext currentContext,
|
||||
IEventService eventService,
|
||||
ICipherRepository cipherRepository,
|
||||
IOrganizationRepository organizationRepository)
|
||||
[Route("collect")]
|
||||
[Authorize("Application")]
|
||||
public class CollectController : Controller
|
||||
{
|
||||
_currentContext = currentContext;
|
||||
_eventService = eventService;
|
||||
_cipherRepository = cipherRepository;
|
||||
_organizationRepository = organizationRepository;
|
||||
}
|
||||
private readonly ICurrentContext _currentContext;
|
||||
private readonly IEventService _eventService;
|
||||
private readonly ICipherRepository _cipherRepository;
|
||||
private readonly IOrganizationRepository _organizationRepository;
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] IEnumerable<EventModel> model)
|
||||
{
|
||||
if (model == null || !model.Any())
|
||||
public CollectController(
|
||||
ICurrentContext currentContext,
|
||||
IEventService eventService,
|
||||
ICipherRepository cipherRepository,
|
||||
IOrganizationRepository organizationRepository)
|
||||
{
|
||||
return new BadRequestResult();
|
||||
_currentContext = currentContext;
|
||||
_eventService = eventService;
|
||||
_cipherRepository = cipherRepository;
|
||||
_organizationRepository = organizationRepository;
|
||||
}
|
||||
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
|
||||
var ciphersCache = new Dictionary<Guid, Cipher>();
|
||||
foreach (var eventModel in model)
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] IEnumerable<EventModel> model)
|
||||
{
|
||||
switch (eventModel.Type)
|
||||
if (model == null || !model.Any())
|
||||
{
|
||||
// User events
|
||||
case EventType.User_ClientExportedVault:
|
||||
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, eventModel.Type, eventModel.Date);
|
||||
break;
|
||||
// Cipher events
|
||||
case EventType.Cipher_ClientAutofilled:
|
||||
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:
|
||||
if (!eventModel.CipherId.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Cipher cipher = null;
|
||||
if (ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
cipher = ciphersCache[eventModel.CipherId.Value];
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value,
|
||||
_currentContext.UserId.Value);
|
||||
}
|
||||
if (cipher == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
ciphersCache.Add(eventModel.CipherId.Value, cipher);
|
||||
}
|
||||
cipherEvents.Add(new Tuple<Cipher, EventType, DateTime?>(cipher, eventModel.Type, eventModel.Date));
|
||||
break;
|
||||
case EventType.Organization_ClientExportedVault:
|
||||
if (!eventModel.OrganizationId.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var organization = await _organizationRepository.GetByIdAsync(eventModel.OrganizationId.Value);
|
||||
await _eventService.LogOrganizationEventAsync(organization, eventModel.Type, eventModel.Date);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
return new BadRequestResult();
|
||||
}
|
||||
}
|
||||
if (cipherEvents.Any())
|
||||
{
|
||||
foreach (var eventsBatch in cipherEvents.Batch(50))
|
||||
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
|
||||
var ciphersCache = new Dictionary<Guid, Cipher>();
|
||||
foreach (var eventModel in model)
|
||||
{
|
||||
await _eventService.LogCipherEventsAsync(eventsBatch);
|
||||
switch (eventModel.Type)
|
||||
{
|
||||
// User events
|
||||
case EventType.User_ClientExportedVault:
|
||||
await _eventService.LogUserEventAsync(_currentContext.UserId.Value, eventModel.Type, eventModel.Date);
|
||||
break;
|
||||
// Cipher events
|
||||
case EventType.Cipher_ClientAutofilled:
|
||||
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:
|
||||
if (!eventModel.CipherId.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
Cipher cipher = null;
|
||||
if (ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
cipher = ciphersCache[eventModel.CipherId.Value];
|
||||
}
|
||||
else
|
||||
{
|
||||
cipher = await _cipherRepository.GetByIdAsync(eventModel.CipherId.Value,
|
||||
_currentContext.UserId.Value);
|
||||
}
|
||||
if (cipher == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!ciphersCache.ContainsKey(eventModel.CipherId.Value))
|
||||
{
|
||||
ciphersCache.Add(eventModel.CipherId.Value, cipher);
|
||||
}
|
||||
cipherEvents.Add(new Tuple<Cipher, EventType, DateTime?>(cipher, eventModel.Type, eventModel.Date));
|
||||
break;
|
||||
case EventType.Organization_ClientExportedVault:
|
||||
if (!eventModel.OrganizationId.HasValue)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var organization = await _organizationRepository.GetByIdAsync(eventModel.OrganizationId.Value);
|
||||
await _eventService.LogOrganizationEventAsync(organization, eventModel.Type, eventModel.Date);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (cipherEvents.Any())
|
||||
{
|
||||
foreach (var eventsBatch in cipherEvents.Batch(50))
|
||||
{
|
||||
await _eventService.LogCipherEventsAsync(eventsBatch);
|
||||
}
|
||||
}
|
||||
return new OkResult();
|
||||
}
|
||||
return new OkResult();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,21 @@
|
||||
using Bit.Core.Utilities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Bit.Events.Controllers;
|
||||
|
||||
public class InfoController : Controller
|
||||
namespace Bit.Events.Controllers
|
||||
{
|
||||
[HttpGet("~/alive")]
|
||||
[HttpGet("~/now")]
|
||||
public DateTime GetAlive()
|
||||
public class InfoController : Controller
|
||||
{
|
||||
return DateTime.UtcNow;
|
||||
}
|
||||
[HttpGet("~/alive")]
|
||||
[HttpGet("~/now")]
|
||||
public DateTime GetAlive()
|
||||
{
|
||||
return DateTime.UtcNow;
|
||||
}
|
||||
|
||||
[HttpGet("~/version")]
|
||||
public JsonResult GetVersion()
|
||||
{
|
||||
return Json(CoreHelpers.GetVersion());
|
||||
[HttpGet("~/version")]
|
||||
public JsonResult GetVersion()
|
||||
{
|
||||
return Json(CoreHelpers.GetVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user