mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
support for sharing new attachments
This commit is contained in:
parent
7cda459127
commit
331ee3266a
@ -373,7 +373,8 @@ namespace Bit.Core.Services
|
||||
IEnumerable<Guid> collectionIds, Guid sharingUserId)
|
||||
{
|
||||
var attachments = cipher.GetAttachments();
|
||||
var hasAttachments = (attachments?.Count ?? 0) > 0;
|
||||
var hasAttachments = attachments?.Any() ?? false;
|
||||
var hasOldAttachments = attachments?.Any(a => a.Key == null) ?? false;
|
||||
var updatedCipher = false;
|
||||
var migratedAttachments = false;
|
||||
|
||||
@ -418,16 +419,22 @@ namespace Bit.Core.Services
|
||||
updatedCipher = true;
|
||||
await _eventService.LogCipherEventAsync(cipher, Enums.EventType.Cipher_Shared);
|
||||
|
||||
if(hasAttachments)
|
||||
if(hasOldAttachments)
|
||||
{
|
||||
// migrate attachments
|
||||
foreach(var attachment in attachments)
|
||||
// migrate old attachments
|
||||
foreach(var attachment in attachments.Where(a => a.Key == null))
|
||||
{
|
||||
await _attachmentStorageService.StartShareAttachmentAsync(cipher.Id, organizationId,
|
||||
attachment.Key);
|
||||
migratedAttachments = true;
|
||||
}
|
||||
|
||||
// commit attachment migration
|
||||
await _attachmentStorageService.CleanupAsync(cipher.Id);
|
||||
}
|
||||
|
||||
// push
|
||||
await _pushService.PushSyncCipherUpdateAsync(cipher, collectionIds);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@ -437,7 +444,7 @@ namespace Bit.Core.Services
|
||||
await _cipherRepository.ReplaceAsync(originalCipher);
|
||||
}
|
||||
|
||||
if(!hasAttachments || !migratedAttachments)
|
||||
if(!hasOldAttachments || !migratedAttachments)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
@ -448,7 +455,7 @@ namespace Bit.Core.Services
|
||||
await _organizationRepository.UpdateStorageAsync(organizationId);
|
||||
}
|
||||
|
||||
foreach(var attachment in attachments)
|
||||
foreach(var attachment in attachments.Where(a => a.Key == null))
|
||||
{
|
||||
await _attachmentStorageService.RollbackShareAttachmentAsync(cipher.Id, organizationId,
|
||||
attachment.Key);
|
||||
@ -457,12 +464,6 @@ namespace Bit.Core.Services
|
||||
await _attachmentStorageService.CleanupAsync(cipher.Id);
|
||||
throw;
|
||||
}
|
||||
|
||||
// commit attachment migration
|
||||
await _attachmentStorageService.CleanupAsync(cipher.Id);
|
||||
|
||||
// push
|
||||
await _pushService.PushSyncCipherUpdateAsync(cipher, collectionIds);
|
||||
}
|
||||
|
||||
public async Task ShareManyAsync(IEnumerable<Cipher> ciphers, Guid organizationId,
|
||||
@ -486,11 +487,6 @@ namespace Bit.Core.Services
|
||||
throw new BadRequestException("One or more ciphers do not belong to you.");
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(cipher.Attachments))
|
||||
{
|
||||
throw new BadRequestException("One or more ciphers have attachments.");
|
||||
}
|
||||
|
||||
cipher.UserId = null;
|
||||
cipher.OrganizationId = organizationId;
|
||||
cipher.RevisionDate = DateTime.UtcNow;
|
||||
|
Loading…
Reference in New Issue
Block a user