1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00

SM-281: Secrets Manager Trash (#2688)

This commit is contained in:
Colton Hurst
2023-02-20 13:01:49 -05:00
committed by GitHub
parent 34544f2292
commit 16bdd67cad
12 changed files with 525 additions and 2 deletions

View File

@ -0,0 +1,28 @@
using Bit.Core.Exceptions;
using Bit.Core.SecretsManager.Commands.Trash.Interfaces;
using Bit.Core.SecretsManager.Repositories;
namespace Bit.Commercial.Core.SecretsManager.Commands.Trash;
public class EmptyTrashCommand : IEmptyTrashCommand
{
private readonly ISecretRepository _secretRepository;
public EmptyTrashCommand(ISecretRepository secretRepository)
{
_secretRepository = secretRepository;
}
public async Task EmptyTrash(Guid organizationId, List<Guid> ids)
{
var secrets = await _secretRepository.GetManyByOrganizationIdInTrashByIdsAsync(organizationId, ids);
var missingId = ids.Except(secrets.Select(_ => _.Id)).Any();
if (missingId)
{
throw new NotFoundException();
}
await _secretRepository.HardDeleteManyByIdAsync(ids);
}
}

View File

@ -0,0 +1,28 @@
using Bit.Core.Exceptions;
using Bit.Core.SecretsManager.Commands.Trash.Interfaces;
using Bit.Core.SecretsManager.Repositories;
namespace Bit.Commercial.Core.SecretsManager.Commands.Trash;
public class RestoreTrashCommand : IRestoreTrashCommand
{
private readonly ISecretRepository _secretRepository;
public RestoreTrashCommand(ISecretRepository secretRepository)
{
_secretRepository = secretRepository;
}
public async Task RestoreTrash(Guid organizationId, List<Guid> ids)
{
var secrets = await _secretRepository.GetManyByOrganizationIdInTrashByIdsAsync(organizationId, ids);
var missingId = ids.Except(secrets.Select(_ => _.Id)).Any();
if (missingId)
{
throw new NotFoundException();
}
await _secretRepository.RestoreManyByIdAsync(ids);
}
}

View File

@ -4,12 +4,14 @@ using Bit.Commercial.Core.SecretsManager.Commands.Porting;
using Bit.Commercial.Core.SecretsManager.Commands.Projects;
using Bit.Commercial.Core.SecretsManager.Commands.Secrets;
using Bit.Commercial.Core.SecretsManager.Commands.ServiceAccounts;
using Bit.Commercial.Core.SecretsManager.Commands.Trash;
using Bit.Core.SecretsManager.Commands.AccessPolicies.Interfaces;
using Bit.Core.SecretsManager.Commands.AccessTokens.Interfaces;
using Bit.Core.SecretsManager.Commands.Porting.Interfaces;
using Bit.Core.SecretsManager.Commands.Projects.Interfaces;
using Bit.Core.SecretsManager.Commands.Secrets.Interfaces;
using Bit.Core.SecretsManager.Commands.ServiceAccounts.Interfaces;
using Bit.Core.SecretsManager.Commands.Trash.Interfaces;
using Microsoft.Extensions.DependencyInjection;
namespace Bit.Commercial.Core.SecretsManager;
@ -32,5 +34,7 @@ public static class SecretsManagerCollectionExtensions
services.AddScoped<IUpdateAccessPolicyCommand, UpdateAccessPolicyCommand>();
services.AddScoped<IDeleteAccessPolicyCommand, DeleteAccessPolicyCommand>();
services.AddScoped<IImportCommand, ImportCommand>();
services.AddScoped<IEmptyTrashCommand, EmptyTrashCommand>();
services.AddScoped<IRestoreTrashCommand, RestoreTrashCommand>();
}
}