mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00

* Move key rotation & validators to km ownership * Fix build errors * Fix build errors * Fix import ordering * Update validator namespace * Move key rotation data to km ownership * Fix linting * Fix namespaces * Fix namespace * Fix namespaces * Move rotateuserkeycommandtests to km ownership
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using Bit.Api.Vault.Models.Request;
|
|
using Bit.Core.Entities;
|
|
using Bit.Core.Exceptions;
|
|
using Bit.Core.Vault.Entities;
|
|
using Bit.Core.Vault.Repositories;
|
|
|
|
namespace Bit.Api.KeyManagement.Validators;
|
|
|
|
public class FolderRotationValidator : IRotationValidator<IEnumerable<FolderWithIdRequestModel>, IEnumerable<Folder>>
|
|
{
|
|
private readonly IFolderRepository _folderRepository;
|
|
|
|
public FolderRotationValidator(IFolderRepository folderRepository)
|
|
{
|
|
_folderRepository = folderRepository;
|
|
}
|
|
|
|
public async Task<IEnumerable<Folder>> ValidateAsync(User user, IEnumerable<FolderWithIdRequestModel> folders)
|
|
{
|
|
var result = new List<Folder>();
|
|
|
|
var existingFolders = await _folderRepository.GetManyByUserIdAsync(user.Id);
|
|
if (existingFolders == null || existingFolders.Count == 0)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
foreach (var existing in existingFolders)
|
|
{
|
|
var folder = folders.FirstOrDefault(c => c.Id == existing.Id);
|
|
if (folder == null)
|
|
{
|
|
throw new BadRequestException("All existing folders must be included in the rotation.");
|
|
}
|
|
result.Add(folder.ToFolder(existing));
|
|
}
|
|
return result;
|
|
}
|
|
}
|