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

[Soft-Delete] Simplify the data-tier, removed extra sprocs and reuse update

This commit is contained in:
Chad Scharf
2020-04-01 16:39:27 -04:00
parent f6044f0d00
commit d07f27f274
14 changed files with 65 additions and 200 deletions

View File

@ -671,7 +671,16 @@ namespace Bit.Core.Services
throw new BadRequestException("You do not have permissions to soft delete this.");
}
await _cipherRepository.SoftDeleteAsync(cipher);
if (cipher.DeletedDate.HasValue)
{
// Already soft-deleted, we can safely ignore this
return;
}
cipher.DeletedDate = DateTime.UtcNow;
cipher.RevisionDate = DateTime.UtcNow;
await _cipherRepository.UpsertAsync(cipher);
await _eventService.LogCipherEventAsync(cipher, EventType.Cipher_SoftDeleted);
// push
@ -704,7 +713,16 @@ namespace Bit.Core.Services
throw new BadRequestException("You do not have permissions to delete this.");
}
await _cipherRepository.RestoreAsync(cipher);
if (!cipher.DeletedDate.HasValue)
{
// Already restored, we can safely ignore this
return;
}
cipher.DeletedDate = null;
cipher.RevisionDate = DateTime.UtcNow;
await _cipherRepository.UpsertAsync(cipher);
await _eventService.LogCipherEventAsync(cipher, EventType.Cipher_Restored);
// push