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

recompute full storage each time

This commit is contained in:
Kyle Spearrin
2017-07-10 22:08:52 -04:00
parent de8b2de8e6
commit 8684b9c8e5
10 changed files with 70 additions and 53 deletions

View File

@ -302,7 +302,6 @@ namespace Bit.Core.Services
{
var attachments = cipher.GetAttachments();
var hasAttachments = (attachments?.Count ?? 0) > 0;
var storageAdjustment = attachments?.Sum(a => a.Value.Size) ?? 0;
var updatedCipher = false;
var migratedAttachments = false;
@ -329,8 +328,8 @@ namespace Bit.Core.Services
throw new BadRequestException("This organization cannot use attachments.");
}
var storageBytesRemaining = org.StorageBytesRemaining();
if(storageBytesRemaining < storageAdjustment)
var storageAdjustment = attachments?.Sum(a => a.Value.Size) ?? 0;
if(org.StorageBytesRemaining() < storageAdjustment)
{
throw new BadRequestException("Not enough storage available for this organization.");
}
@ -367,8 +366,8 @@ namespace Bit.Core.Services
if(updatedCipher)
{
await _userRepository.UpdateStorageAsync(sharingUserId, storageAdjustment);
await _organizationRepository.UpdateStorageAsync(organizationId, -1 * storageAdjustment);
await _userRepository.UpdateStorageAsync(sharingUserId);
await _organizationRepository.UpdateStorageAsync(organizationId);
}
foreach(var attachment in attachments)