mirror of
https://github.com/bitwarden/server.git
synced 2025-05-24 04:51:03 -05:00

* PM-18939 refactoring send service to 'cqrs' * PM-18939 fixing import issue with sendValidationService * PM-18939 fixing code based on PR comments * PM-18339 reverting to previous code in test * PM-18939 adding XMLdocs to services * PM-18939 reverting send validation methods * PM-18939 updating code to match main * PM-18939 reverting validateUserCanSaveAsync to match main * PM-18939 fill our param and return sections of XMLdocs * PM-18939 updating XMLdocs based on PR comments * Update src/Core/Tools/SendFeatures/Commands/Interfaces/IAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Commands/Interfaces/INonAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Commands/Interfaces/INonAnonymousSendCommand.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * Update src/Core/Tools/SendFeatures/Services/Interfaces/ISendStorageService.cs Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.com> * PM-18939 adding commits to change tuple to enum type * PM-18939 resetting stream position to 0 when uploading file * PM-18939 updating XMLdocs based on PR comments * PM-18939 updating XMLdocs * PM-18939 removing circular dependency * PM-18939 fixing based on comments * PM-18939 updating method name and documentation --------- Co-authored-by: ✨ Audrey ✨ <ajensen@bitwarden.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.ToSend(existing, _sendAuthorizationService));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|