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

delete attachments

This commit is contained in:
Kyle Spearrin
2017-07-07 11:07:22 -04:00
parent d3c18381f9
commit 43262e577c
9 changed files with 155 additions and 18 deletions

View File

@ -154,6 +154,7 @@ namespace Bit.Core.Services
};
await _cipherRepository.UpdateAttachmentAsync(attachment);
cipher.AddAttachment(attachmentId, data);
}
catch
{
@ -186,6 +187,28 @@ namespace Bit.Core.Services
await _pushService.PushSyncCiphersAsync(deletingUserId);
}
public async Task DeleteAttachmentAsync(Cipher cipher, string attachmentId, Guid deletingUserId, bool orgAdmin = false)
{
if(!orgAdmin && !(await UserCanEditAsync(cipher, deletingUserId)))
{
throw new BadRequestException("You do not have permissions to delete this.");
}
if(!cipher.ContainsAttachment(attachmentId))
{
throw new NotFoundException();
}
await _cipherRepository.DeleteAttachmentAsync(cipher.Id, attachmentId);
cipher.DeleteAttachment(attachmentId);
var storedFilename = $"{cipher.Id}/{attachmentId}";
await _attachmentStorageService.DeleteAttachmentAsync(storedFilename);
// push
await _pushService.PushSyncCipherUpdateAsync(cipher);
}
public async Task MoveManyAsync(IEnumerable<Guid> cipherIds, Guid? destinationFolderId, Guid movingUserId)
{
if(destinationFolderId.HasValue)