mirror of
https://github.com/bitwarden/server
synced 2026-01-12 21:44:13 +00:00
* update send api models to support new `email` field
* normalize authentication field evaluation order
* document send response converters
* add FIXME to remove unused constructor argument
* add FIXME to remove unused constructor argument
* introduce `tools-send-email-otp-listing` feature flag
* add `ISendOwnerQuery` to dependency graph
* fix broken tests
* added AuthType prop to send related models with test coverage and debt cleanup
* dotnet format
* add migrations
* dotnet format
* make SendsController null safe (tech debt)
* add AuthType col to Sends table, change Emails col length to 4000, and run migrations
* dotnet format
* update SPs to expect AuthType
* include SP updates in migrations
* remove migrations not intended for merge
* Revert "remove migrations not intended for merge"
This reverts commit 7df56e346a.
undo migrations removal
* extract AuthType inference to util method and remove SQLite file
* fix lints
* address review comments
* fix incorrect assignment and adopt SQL conventions
* fix column assignment order in Send_Update.sql
* remove space added to email list
* assign SQL default value of NULL to AuthType
* update SPs to match migration changes
---------
Co-authored-by: Daniel James Smith <2670567+djsmith85@users.noreply.github.com>
Co-authored-by: Alex Dragovich <46065570+itsadrago@users.noreply.github.com>
Co-authored-by: John Harrington <84741727+harr1424@users.noreply.github.com>
53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using Bit.Api.Tools.Models.Request;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Core.Tools.Entities;
|
|
using Bit.Core.Tools.Repositories;
|
|
using Bit.Core.Tools.Services;
|
|
|
|
namespace Bit.Api.KeyManagement.Validators;
|
|
|
|
/// <summary>
|
|
/// Send implementation for <see cref="IRotationValidator{T,R}"/>
|
|
/// </summary>
|
|
public class SendRotationValidator : IRotationValidator<IEnumerable<SendWithIdRequestModel>, IReadOnlyList<Send>>
|
|
{
|
|
private readonly ISendAuthorizationService _sendAuthorizationService;
|
|
private readonly ISendRepository _sendRepository;
|
|
|
|
/// <summary>
|
|
/// Instantiates a new <see cref="SendRotationValidator"/>
|
|
/// </summary>
|
|
/// <param name="sendAuthorizationService">Enables conversion of <see cref="SendWithIdRequestModel"/> to <see cref="Send"/></param>
|
|
/// <param name="sendRepository">Retrieves all user <see cref="Send"/>s</param>
|
|
public SendRotationValidator(ISendAuthorizationService sendAuthorizationService, ISendRepository sendRepository)
|
|
{
|
|
_sendAuthorizationService = sendAuthorizationService;
|
|
_sendRepository = sendRepository;
|
|
}
|
|
|
|
public async Task<IReadOnlyList<Send>> ValidateAsync(User user, IEnumerable<SendWithIdRequestModel> sends)
|
|
{
|
|
var result = new List<Send>();
|
|
|
|
var existingSends = await _sendRepository.GetManyByUserIdAsync(user.Id);
|
|
if (existingSends == null || existingSends.Count == 0)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
foreach (var existing in existingSends)
|
|
{
|
|
var send = sends.FirstOrDefault(c => c.Id == existing.Id);
|
|
if (send == null)
|
|
{
|
|
throw new BadRequestException("All existing sends must be included in the rotation.");
|
|
}
|
|
|
|
result.Add(send.UpdateSend(existing, _sendAuthorizationService));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|