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:
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
@ -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>();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user