1
0
mirror of https://github.com/bitwarden/server synced 2025-12-29 14:43:39 +00:00

Turn on file scoped namespaces (#2225)

This commit is contained in:
Justin Baur
2022-08-29 14:53:16 -04:00
committed by GitHub
parent 7c4521e0b4
commit 34fb4cca2a
1206 changed files with 73816 additions and 75022 deletions

View File

@@ -8,99 +8,98 @@ using Bit.Events.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Events.Controllers
namespace Bit.Events.Controllers;
[Route("collect")]
[Authorize("Application")]
public class CollectController : Controller
{
[Route("collect")]
[Authorize("Application")]
public class CollectController : Controller
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)
{
private readonly ICurrentContext _currentContext;
private readonly IEventService _eventService;
private readonly ICipherRepository _cipherRepository;
private readonly IOrganizationRepository _organizationRepository;
_currentContext = currentContext;
_eventService = eventService;
_cipherRepository = cipherRepository;
_organizationRepository = organizationRepository;
}
public CollectController(
ICurrentContext currentContext,
IEventService eventService,
ICipherRepository cipherRepository,
IOrganizationRepository organizationRepository)
[HttpPost]
public async Task<IActionResult> Post([FromBody] IEnumerable<EventModel> model)
{
if (model == null || !model.Any())
{
_currentContext = currentContext;
_eventService = eventService;
_cipherRepository = cipherRepository;
_organizationRepository = organizationRepository;
return new BadRequestResult();
}
[HttpPost]
public async Task<IActionResult> Post([FromBody] IEnumerable<EventModel> model)
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
var ciphersCache = new Dictionary<Guid, Cipher>();
foreach (var eventModel in model)
{
if (model == null || !model.Any())
switch (eventModel.Type)
{
return new BadRequestResult();
}
var cipherEvents = new List<Tuple<Cipher, EventType, DateTime?>>();
var ciphersCache = new Dictionary<Guid, Cipher>();
foreach (var eventModel in model)
{
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:
// 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();
}
if (cipherEvents.Any())
{
foreach (var eventsBatch in cipherEvents.Batch(50))
{
await _eventService.LogCipherEventsAsync(eventsBatch);
}
}
return new OkResult();
}
}

View File

@@ -1,21 +1,20 @@
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Mvc;
namespace Bit.Events.Controllers
{
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
namespace Bit.Events.Controllers;
[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
public class InfoController : Controller
{
[HttpGet("~/alive")]
[HttpGet("~/now")]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[HttpGet("~/version")]
public JsonResult GetVersion()
{
return Json(CoreHelpers.GetVersion());
}
}